1 #include <lemon/smart_graph.h>
29 int main(
int argc,
char **argv)
31 GRAPH_TYPEDEFS(SmartGraph);
33 ifstream graphFile(argv[1]);
36 if (
string(argv[2]) ==
"GRA") {
45 cout <<
"Graph reading time: " << timer.
elapsed() << endl;
48 int n = countNodes(g);
49 cout <<
"Total nodes: " << n << endl;
50 cout <<
"Total edges: " << countEdges(g) << endl;
53 cout <<
"Using greedy nearest:" << endl;
56 cout <<
"Creation elapsed time: " << greedyNearest.
creationTime() << endl;
58 cout <<
"Initialisation elapsed time: " << greedyNearest.
initTime() << endl;
61 cout <<
"Algorithm running time: " << greedyNearest.
runTime() << endl;
62 cout <<
"Max colours: " << greedyNearest.maxK() << endl;
63 cout <<
"Colours used: " << greedyNearest.totalColours() << endl;
64 cout <<
"LCA value: " << greedyNearest.lcaValue() << endl;
67 cout <<
"Could not find a solution!" << endl;
72 cout <<
"Using greedy least cost:" << endl;
75 cout <<
"Creation elapsed time: " << greedyLeastCost.
creationTime() << endl;
76 greedyLeastCost.
init();
77 cout <<
"Initialisation elapsed time: " << greedyLeastCost.
initTime() << endl;
80 cout <<
"Algorithm running time: " << greedyLeastCost.
runTime() << endl;
81 cout <<
"Max colours: " << greedyLeastCost.maxK() << endl;
82 cout <<
"Colours used: " << greedyLeastCost.totalColours() << endl;
83 cout <<
"LCA value: " << greedyLeastCost.lcaValue() << endl;
86 cout <<
"Could not find a solution!" << endl;
93 if (greedyLeastCost.lcaValue() < greedyNearest.lcaValue()) {
94 k = greedyLeastCost.totalColours();
97 k = greedyNearest.totalColours();
100 cout <<
"Using MIP model:" << endl;
105 mipModel.timeLimit(atof(argv[4]));
109 mipModel.model().getEnv().set(GRB_StringParam_LogFile, argv[5]);
112 mipModel.model().getEnv().set(GRB_IntParam_Method, GRB_METHOD_CONCURRENT);
113 cout <<
"Initialisation elapsed time: " << mipModel.
initTime() << endl;
116 if (greedyLeastCost.lcaValue() < greedyNearest.lcaValue()) {
117 mipModel.initialSolution(greedyLeastCost.colouring());
120 mipModel.initialSolution(greedyNearest.colouring());
127 cout <<
"Algorithm running time: " << mipModel.
runTime() << endl;
128 cout <<
"Max colours: " << mipModel.maxK() << endl;
129 cout <<
"Colours used: " << mipModel.totalColours() << endl;
130 cout <<
"LCA value: " << mipModel.lcaValue() << endl;
131 cout <<
"Optimal?: ";
133 if (mipModel.model().getModel().get(GRB_IntAttr_Status) == GRB_OPTIMAL) {
143 ofstream outfile(argv[3], ofstream::out | ofstream::trunc);
145 for (
int i = 0; i < n - 1; ++i) {
146 Node v = g.nodeFromId(i);
147 outfile << mipModel.colouring()[v] <<
' ';
150 outfile << mipModel.colouring()[g.nodeFromId(n - 1)] << endl;
155 cout <<
"Could not find a solution!" << endl;
GraphFormat
Available graph formats.
double initialSolutionTime()
Retrieve the duration of setting the initial solution.
void readGraph(Graph &g, GraphFormat f=RMF, IS &in=std::cin)
Read a graph.
double runTime()
Retrieve the duration of running the algorithm.
virtual MinLCAStatus run()
Run the algorithm.
int main(int argc, char **argv)
Main function.
Solution has been found after running.
Default namespace Default namespace for MinLCA algorithms.
Class for timing MinLCA algorithms.
Functions for reading graphs and getting graph properties.
double initTime()
Retrieve the duration of initialising the algorithm.
double creationTime()
Retrieve the duration of instantiating the algorithm class.
Interface for the Gurobi MIP solver.
Contains the definitions for timing MinLCA algorithms.
double elapsed() const
Retrieve elapsed time.
Class for timing MinLCA optimisation algorithms.
void init(Args &&...args)
Reset the data structures of the algorithm.
Defines the integer linear programming model for MinLCA.
Contains the definitions for timing MinLCA optimisation algorithms.
Namespace for util functions and classes.