Skip to content

Commit

Permalink
merged temp_commit with master
Browse files Browse the repository at this point in the history
  • Loading branch information
hbae003 committed Mar 13, 2017
2 parents 01f5109 + cf903a9 commit fb3e592
Showing 13 changed files with 80 additions and 100 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -6,6 +6,10 @@
*.lo
*.o
*.obj
<<<<<<< HEAD
=======
*.dot
>>>>>>> temp_commit

# Precompiled Headers
*.gch
18 changes: 6 additions & 12 deletions Header/graph_color.h
Original file line number Diff line number Diff line change
@@ -21,10 +21,8 @@ using std::cerr;
using std::endl;

namespace GraphColoring {
enum Algorithm {kNone,kDSATUR,kMCS,kTABUCOL,kHybrid,kLMXRLF,kHybridDSATUR};
class GraphColor {
protected:
Algorithm algorithm;
map<string,vector<string> > graph;
map<string,int> coloring;
bool colored;
@@ -34,36 +32,32 @@ namespace GraphColoring {
string get_color_string(int color,int max_color);
int find_max_color();
public:
//Default coloring algorithm is DSATUR

GraphColor(map<string, vector<string> > input_graph):colored(false){
graph = input_graph;
algorithm = kNone;
}

/* Mutators */
void add_edge(string source,string sink);
void add_node(string new_node) { graph.insert(pair<string,vector<string> >(new_node,vector<string>())); }
void set_algorithm(Algorithm new_algorithm) { algorithm = new_algorithm; }
virtual void set_condition(int con) {}

/* Coloring functions */
virtual map<string,int> color(int condition = 0) = 0;
virtual map<string,int> color() = 0;
bool verify();

/* Accessors */
unsigned size() { return graph.size(); }
Algorithm get_algorithm() { return algorithm; }
map<string,int> get_coloring() { return coloring; }
string get_algorithm_string();
virtual string get_algorithm_string() = 0;

/* Mutators */
void set_graph(map<string,vector<string> > new_graph) { graph = new_graph; }
void set_coloring(map<string,int> new_coloring) { coloring = new_coloring; }

/* Print functions */
void print_coloring();
virtual void print_coloring();
void print_chromatic();
void write_graph(string graph_name = "");
};
}

#endif // _GRAPH_COLOR_H_
#endif // _GRAPH_COLOR_H_
15 changes: 9 additions & 6 deletions Header/lmxrlf.h
Original file line number Diff line number Diff line change
@@ -4,12 +4,12 @@
#include "graph_color.h"

using GraphColoring::GraphColor;
using GraphColoring::Algorithm;

namespace GraphColoring{
class lmxrlf : public GraphColor {
class Lmxrlf : public GraphColor {
private:
//helper functions
int condition;
vector<string> get_independent(vector<string> set);
vector<string> make_independent_set();
int objf(vector<string> set);
@@ -20,10 +20,13 @@ namespace GraphColoring{
vector<string> uncolored_neighbor(vector<string> new_set);
map<string,int> lmxrlf_alg(int endcond);
public:
lmxrlf(map<string, vector<string> > input_graph) :GraphColor(input_graph) {
algorithm = kLMXRLF;
}
map<string,int> color(int condition = 0);
Lmxrlf(map<string, vector<string> > input_graph) :GraphColor(input_graph) { }
Lmxrlf(map<string, vector<string> > input_graph, int con) :GraphColor(input_graph){
condition = con;
}
map<string,int> color();
string get_algorithm_string() { return "LMXRLF"; }
void set_condition(int con) { condition = con; }
};
}

4 changes: 2 additions & 2 deletions Source/dsatur.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../Header/dsatur.h"

map<string,int> GraphColoring::dsatur::color(int condition) {

map<string,int> GraphColoring::Dsatur::color() {

vector<string> todo;
string max_degree = "";
@@ -123,4 +124,3 @@ map<string,int> GraphColoring::dsatur::color(int condition) {
}
return coloring;
}

41 changes: 2 additions & 39 deletions Source/graph_color.cpp
Original file line number Diff line number Diff line change
@@ -12,33 +12,8 @@ using std::ifstream;
using std::ofstream;
using std::ostringstream;

string GraphColoring::GraphColor::get_algorithm_string() {
switch (algorithm) {
case kDSATUR:
return "DSATUR";
break;
case kMCS:
return "MCS";
break;
case kLMXRLF:
return "LMXRLF";
break;
case kHybrid:
return "Hybrid";
break;
case kHybridDSATUR:
return "HybridDSATUR";
break;
case kNone:
break;
default:
break;
}
return "None";
}

//TODO: What conditions are needed for each algorithm?
map<string,int> GraphColoring::GraphColor::color(int condition) {
map<string,int> GraphColoring::GraphColor::color() {

return coloring;
}
@@ -76,24 +51,12 @@ void GraphColoring::GraphColor::print_chromatic() {

//Used to print the color of each node in the graph
void GraphColoring::GraphColor::print_coloring() {
std::cout << "----------" << algorithm << " Colorings----------" << endl;
std::cout << "----------" << get_algorithm_string() << " Colorings----------" << endl;
for(map< string,int >::iterator i = coloring.begin(); i != coloring.end(); i++) {
std::cout << (*i).first << " " << (*i).second << endl;
}
}

void GraphColoring::GraphColor::add_edge(string source,string sink) {
map<string,vector<string> >::iterator source_node;
map<string,vector<string> >::iterator sink_node;
// Find each node. find will insert the node if it does not exist in the
// graph
source_node = graph.insert(pair<string,vector<string> >(source,vector<string>())).first;
sink_node = graph.insert(pair<string,vector<string> >(sink,vector<string>())).first;
// Add the opposite node to the edge list for each node
(*source_node).second.push_back(sink);
(*sink_node).second.push_back(source);
}

int GraphColoring::GraphColor::find_max_color() {
map<string,int>::iterator color_it = coloring.begin();
int max_color = 0;
24 changes: 14 additions & 10 deletions Source/hybrid.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "../Header/hybrid.h"

map<string,int> GraphColoring::hybrid::color(int condition) {
if (condition == 0) {
condition = graph.size() / 2;
map<string,int> GraphColoring::Hybrid::color() {
if (this->condition == 0) {
this->condition = graph.size() / 2;
}

GraphColor *alg_graph = new lmxrlf(this->graph);
coloring = alg_graph->color(condition);
GraphColor *alg_graph = new Lmxrlf(this->graph, this->condition);
coloring = alg_graph->color();
//coloring = lmxrlf_base(Graph,CARR);

//*********************************
@@ -23,7 +23,8 @@ map<string,int> GraphColoring::hybrid::color(int condition) {
map< string,int > Colors_temp = coloring;

//coloring = lmxrlf(graph.size());
coloring = alg_graph->color(graph.size());
alg_graph->set_condition(graph.size());
coloring = alg_graph->color();
int Color = 0;
for(map< string,int >::iterator i = coloring.begin(); i != coloring.end(); i++) {
if((*i).second > Color) {
@@ -37,9 +38,10 @@ map<string,int> GraphColoring::hybrid::color(int condition) {
//******************************************************
int subset_color = Color;

alg_graph = new tabucol(get_subgraph(Colors_temp));
alg_graph = new Tabucol(get_subgraph(Colors_temp));
alg_graph->set_coloring(Colors_temp);
alg_graph->color(subset_color);
alg_graph->set_condition(subset_color);
alg_graph->color();
map<string,int> tabu_color = alg_graph->get_coloring();

//map< string,vector<string> > Graph_subset = get_subgraph(Colors_temp);
@@ -48,8 +50,9 @@ map<string,int> GraphColoring::hybrid::color(int condition) {
while(tabu_color.size() > 0) {
best = tabu_color;
subset_color -= 1;
alg_graph->set_condition(subset_color);
//tabu_color = tabucol(Graph_subset,subset_color);
alg_graph->set_coloring(alg_graph->color(subset_color));
alg_graph->set_coloring(alg_graph->color());
tabu_color = alg_graph->get_coloring();
}
if(best.size() > 0) {
@@ -60,7 +63,8 @@ map<string,int> GraphColoring::hybrid::color(int condition) {
return coloring;
}

map< string,vector<string> > GraphColoring::hybrid::get_subgraph(map< string,int > coloring) {

map< string,vector<string> > GraphColoring::Hybrid::get_subgraph(map< string,int > coloring) {
map< string,vector<string> > subgraph;
for(map< string,vector<string> >::iterator i = graph.begin(); i != graph.end(); i++) {
if(coloring[(*i).first] == -1) {
12 changes: 7 additions & 5 deletions Source/hybrid_dsatur.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "../Header/hybrid_dsatur.h"

map<string,int> GraphColoring::hybrid_dsatur::color(int condition) {
GraphColor *temp_graph = new dsatur(this->graph);

map<string,int> GraphColoring::HybridDsatur::color() {
GraphColor *temp_graph = new Dsatur(this->graph);
coloring = temp_graph->color();
delete temp_graph;

@@ -12,15 +13,16 @@ map<string,int> GraphColoring::hybrid_dsatur::color(int condition) {
}
largest += 1;

temp_graph = new tabucol(this->graph);
temp_graph = new Tabucol(this->graph, largest);

map< string,int > best = coloring;
map< string,int > tabu_color = temp_graph->color(largest);
map< string,int > tabu_color = temp_graph->color();
while(tabu_color.size() > 0)
{
best = tabu_color;
largest -= 1;
tabu_color = temp_graph->color(largest);
temp_graph->set_condition(largest);
tabu_color = temp_graph->color();
}
coloring = best;
delete temp_graph;
24 changes: 12 additions & 12 deletions Source/lmxrlf.cpp
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ int F = 1;
int LOCAL = 10;

//Returns an independent set from given set
vector<string> GraphColoring::lmxrlf::get_independent(vector<string> set) {
vector<string> GraphColoring::Lmxrlf::get_independent(vector<string> set) {
vector<string> delta;
for(unsigned i=0; i<set.size(); i++) {
delta.push_back(set[i]);
@@ -34,7 +34,7 @@ vector<string> GraphColoring::lmxrlf::get_independent(vector<string> set) {
}

//Creates an independent set from the graph
vector<string> GraphColoring::lmxrlf::make_independent_set() {
vector<string> GraphColoring::Lmxrlf::make_independent_set() {
vector<string> set;
vector<string> todo = get_independent(set);
while(todo.size()) {
@@ -45,7 +45,7 @@ vector<string> GraphColoring::lmxrlf::make_independent_set() {
}

//Objective function for LMXRLF
int GraphColoring::lmxrlf::objf(vector<string> set) {
int GraphColoring::Lmxrlf::objf(vector<string> set) {
int sum = 0;
for(unsigned i=0; i<set.size(); i++) {
int non = graph[set[i]].size();
@@ -61,7 +61,7 @@ int GraphColoring::lmxrlf::objf(vector<string> set) {
}

//Returns the value from the list of best solutions with the minimum objective function
int GraphColoring::lmxrlf::min_objf(vector< vector<string> > list_of_best) {
int GraphColoring::Lmxrlf::min_objf(vector< vector<string> > list_of_best) {
if(list_of_best.size() == 0) {
cerr << "List of Best Solutions is of size 0" << endl;
return -1;
@@ -77,7 +77,7 @@ int GraphColoring::lmxrlf::min_objf(vector< vector<string> > list_of_best) {
}

//Returns the value from the list of best solutions with the maximum objective function
int GraphColoring::lmxrlf::max_objf(vector< vector<string> > list_of_best) {
int GraphColoring::Lmxrlf::max_objf(vector< vector<string> > list_of_best) {
if(list_of_best.size() == 0) {
cerr << "List of Best Solutions is of size 0" << endl;
return -1;
@@ -93,7 +93,7 @@ int GraphColoring::lmxrlf::max_objf(vector< vector<string> > list_of_best) {
}

//Returns the index from the list of best solutions with the minimum objective function
int GraphColoring::lmxrlf::min_pos_objf(vector< vector<string> > list_of_best) {
int GraphColoring::Lmxrlf::min_pos_objf(vector< vector<string> > list_of_best) {
if(list_of_best.size() == 0) {
cerr << "List of Best Solutions is of size 0" << endl;
return -1;
@@ -111,7 +111,7 @@ int GraphColoring::lmxrlf::min_pos_objf(vector< vector<string> > list_of_best) {
}

//Returns the index from the list of best solutions with the maximum objective function
int GraphColoring::lmxrlf::max_pos_objf(vector< vector<string> > list_of_best) {
int GraphColoring::Lmxrlf::max_pos_objf(vector< vector<string> > list_of_best) {
if(list_of_best.size() == 0) {
cerr << "List of Best Solutions is of size 0" << endl;
return -1;
@@ -129,7 +129,7 @@ int GraphColoring::lmxrlf::max_pos_objf(vector< vector<string> > list_of_best) {
}

//Returns a set of uncolored neighbors from the input set
vector<string> GraphColoring::lmxrlf::uncolored_neighbor(vector<string> new_set) {
vector<string> GraphColoring::Lmxrlf::uncolored_neighbor(vector<string> new_set) {
vector<string> delta;
for(map< string, vector<string> >::iterator i = graph.begin(); i != graph.end(); i++) {
int flag = 0;
@@ -167,7 +167,7 @@ vector<string> GraphColoring::lmxrlf::uncolored_neighbor(vector<string> new_set)
return out;
}

map<string,int> GraphColoring::lmxrlf::lmxrlf_alg(int endcond) {
map<string,int> GraphColoring::Lmxrlf::lmxrlf_alg(int endcond) {
map< string, vector<string> > Graph_temp;
vector< vector<string> > list_of_best_solutions;
srand(time(NULL));
@@ -259,11 +259,11 @@ map<string,int> GraphColoring::lmxrlf::lmxrlf_alg(int endcond) {
}

//Runs LMXRLF starting with a fully uncolored graph
map<string,int> GraphColoring::lmxrlf::color(int condition) {
if (condition == 0) { condition = graph.size(); }
map<string,int> GraphColoring::Lmxrlf::color() {
if (this->condition == 0) { this->condition = graph.size(); }
for(map< string, vector<string> >::iterator i = graph.begin(); i != graph.end(); i++) {
coloring[(*i).first] = -1;
}
return lmxrlf_alg(condition);
return lmxrlf_alg(this->condition);
}

Loading

0 comments on commit fb3e592

Please sign in to comment.