1 #ifndef __MINLCA_MINLCA_LP_MODEL_HH
2 #define __MINLCA_MINLCA_LP_MODEL_HH
7 #include <lemon/core.h>
8 #include <lemon/smart_graph.h>
26 template<
typename Graph = lemon::SmartGraph>
30 TEMPLATE_GRAPH_TYPEDEFS(Graph);
35 typename Graph::template NodeMap<vector<Lp::Col>>
37 typename Graph::template NodeMap<Lp::Expr>
39 typename Graph::template EdgeMap<Lp::Col>
58 _model.
getEnv().set(GRB_IntParam_LogToConsole, 0);
61 _model.
getEnv().set(GRB_IntParam_LogToConsole, 1);
64 _model.addColSet(_used_colours);
66 for (NodeIt v(g); v != lemon::INVALID; ++v) {
71 _model.addColSet(
_dist);
75 for (
int c = 0; c <
_k; ++c) {
76 _model.colBounds(_used_colours[c], 0, 1);
79 for (NodeIt v(g); v != lemon::INVALID; ++v) {
80 Lp::Expr oneColourPerVertex = 0;
82 for (
int c = 0; c <
_k; ++c) {
84 _model.colBounds(nodeColour, 0, 1);
86 oneColourPerVertex += nodeColour;
88 _model.addRow(nodeColour - _used_colours[c] <= 0);
92 _model.addRow(1, oneColourPerVertex, 1);
95 for (EdgeIt e(g); e != lemon::INVALID; ++e) {
96 Node u = g.u(e), v = g.v(e);
98 for (
int c = 0; c <
_k; ++c) {
102 _model.colBounds(
_dist[e], 1, _k - 1);
106 _lca_expr +=
_dist[e];
110 _model.obj(_lca_expr);
121 return _model.primal();
129 return _model.primal();
141 std::vector<std::pair<double, int>> colourAndPrecedence(_k);
143 for (
int c = 0; c <
_k; ++c) {
144 colourAndPrecedence[c] = std::make_pair(-_model.primal(
_vertex_colours[v][c]),
148 std::sort(colourAndPrecedence.begin(), colourAndPrecedence.end());
150 std::vector<int> colourOrder(_k);
152 for (
int i = 0; i <
_k; ++i) {
153 colourOrder[i] = colourAndPrecedence[i].second;
Lp::Expr _lca_expr
Expression with the objective function (the cost)
Header of the LEMON-Gurobi solver interface.
Class defining a relaxed linear programming model for MinLCA.
Interface for the Gurobi LP solver.
Graph::template NodeMap< Lp::Expr > _vertex_c
Map of expressions to calculate the colour of a vertex.
Graph::template EdgeMap< Lp::Col > _dist
Map of expressions to calculate the cost of an edge.
Default namespace Default namespace for MinLCA algorithms.
void forceModelUpdate()
Force model update.
Functions for reading graphs and getting graph properties.
GRBEnv getEnv() const
Get the environment of the underlying Gurobi model.
MinLCALpModel(const Graph &g, int maxK, bool silent=true)
Constructor.
int _k
Index of the largest colour.
double solve()
Solve the linear model.
double getValue()
Retrieve the value of the objective function.
Lp _model
The internal Lp model.
std::vector< int > getColourOrder(const Node &v)
Get the colour preference induced by the solution.
Graph::template NodeMap< vector< Lp::Col > > _vertex_colours
Model variables for vertex colours.
std::vector< Lp::Col > _used_colours
Model variables for used colours.