94 uint32_t vertex_num = boost::num_vertices(this->
m_graph);
95 uint32_t edge_num = boost::num_edges(this->
m_graph);
96 uint32_t vertex_variable_num = vertex_num<<1;
98 boost::unordered_map<graph_edge_type, uint32_t, edge_hash_type> hEdgeIdx;
100 uint32_t stitch_cnt = 0;
101 edge_iterator_type ei, eie;
102 for (boost::tie(ei, eie) = boost::edges(this->
m_graph); ei != eie; ++ei)
104 edge_weight_type w = boost::get(boost::edge_weight, this->
m_graph, *ei);
106 hEdgeIdx[*ei] = stitch_cnt;
114 model_type opt_model;
119 std::vector<model_type::variable_type> vVertexBit;
120 std::vector<model_type::variable_type> vEdgeBit;
129 vVertexBit.reserve(vertex_variable_num);
130 for (uint32_t i = 0; i != vertex_variable_num; ++i)
132 uint32_t vertex_idx = (i>>1);
133 std::ostringstream oss;
138 if ((i&1) == 0) color_bit = (this->
m_vColor[vertex_idx]>>1)&1;
139 else color_bit = this->
m_vColor[vertex_idx]&1;
171 std::vector<model_type::variable_type> vBigEdgeBit;
172 vBigEdgeBit.reserve(this->m_big_edge_num);
174 for (uint32_t i = 0; i != this->m_big_edge_num; ++i)
176 std::ostringstream oss;
179 obj += vBigEdgeBit[i];
182 vEdgeBit.reserve(stitch_cnt);
183 for (uint32_t i = 0; i != stitch_cnt; ++i)
185 std::ostringstream oss;
189 for (boost::tie(ei, eie) = edges(this->
m_graph); ei != eie; ++ei)
191 edge_weight_type w = boost::get(boost::edge_weight, this->
m_graph, *ei);
199 uint32_t constr_num = 0;
200 for (boost::tie(ei, eie) = boost::edges(this->
m_graph); ei != eie; ++ei)
202 graph_vertex_type s = boost::source(*ei, this->
m_graph);
203 graph_vertex_type t = boost::target(*ei, this->
m_graph);
205 uint32_t vertex_idx1 = s<<1;
206 uint32_t vertex_idx2 = t<<1;
209 edge_weight_type w = boost::get(boost::edge_weight, this->
m_graph, *ei);
211 edge_idx = hEdgeIdx[*ei];
215 string tmpConstr_name;
218 int big_e_index = this->m_edge_index_vector[(uint32_t)(this->m_stitch_relation_set[(
int)s]*this->m_stitch_index + this->m_stitch_relation_set[(
int)t])];
219 sprintf(buf,
"R%u", constr_num++);
221 vVertexBit[vertex_idx1] + vVertexBit[vertex_idx1+1]
222 + vVertexBit[vertex_idx2] + vVertexBit[vertex_idx2+1]
223 + vBigEdgeBit[big_e_index] >= 1
226 sprintf(buf,
"R%u", constr_num++);
228 - vVertexBit[vertex_idx1] + vVertexBit[vertex_idx1+1]
229 - vVertexBit[vertex_idx2] + vVertexBit[vertex_idx2+1]
230 + vBigEdgeBit[big_e_index] >= -1
233 sprintf(buf,
"R%u", constr_num++);
235 vVertexBit[vertex_idx1] - vVertexBit[vertex_idx1+1]
236 + vVertexBit[vertex_idx2] - vVertexBit[vertex_idx2+1]
237 + vBigEdgeBit[big_e_index] >= -1
240 sprintf(buf,
"R%u", constr_num++);
242 - vVertexBit[vertex_idx1] - vVertexBit[vertex_idx1+1]
243 - vVertexBit[vertex_idx2] - vVertexBit[vertex_idx2+1]
244 + vBigEdgeBit[big_e_index] >= -3
251 sprintf(buf,
"R%u", constr_num++);
253 vVertexBit[vertex_idx1] - vVertexBit[vertex_idx2] - vEdgeBit[edge_idx] <= 0
256 sprintf(buf,
"R%u", constr_num++);
258 vVertexBit[vertex_idx2] - vVertexBit[vertex_idx1] - vEdgeBit[edge_idx] <= 0
261 sprintf(buf,
"R%u", constr_num++);
263 vVertexBit[vertex_idx1+1] - vVertexBit[vertex_idx2+1] - vEdgeBit[edge_idx] <= 0
266 sprintf(buf,
"R%u", constr_num++);
268 vVertexBit[vertex_idx2+1] - vVertexBit[vertex_idx1+1] - vEdgeBit[edge_idx] <= 0
277 for(uint32_t k = 0; k != vertex_variable_num; k += 2)
279 sprintf(buf,
"R%u", constr_num++);
280 opt_model.
addConstraint(vVertexBit[k] + vVertexBit[k+1] <= 1, buf);
285 solver_type solver (&opt_model);
286 int32_t opt_status = solver(&gurobiParams);
287#ifdef DEBUG_ILPColoringUpdated
288 opt_model.
print(
"graph.lp");
293 cout <<
"ERROR: The model is infeasible... EXIT" << endl;
297#ifdef DEBUG_ILPColoringUpdated
302 for (uint32_t k = 0; k != vertex_variable_num; k += 2)
305 uint32_t vertex_idx = (k>>1);
308 if (this->
m_vColor[vertex_idx] >= 0 && this->
m_vColor[vertex_idx] < this->m_color_num)
322 std::ofstream out((filename+
".gv").c_str());
323 out <<
"graph D { \n"
325 <<
" size=\"4, 3\"\n"
326 <<
" ratio=\"fill\"\n"
327 <<
" edge[style=\"bold\",fontsize=200]\n"
328 <<
" node[shape=\"circle\",fontsize=200]\n";
331 uint32_t vertex_num = boost::num_vertices(this->
m_graph);
332 for(uint32_t k = 0; k < vertex_num; ++k)
334 out <<
" " << k <<
"[shape=\"circle\"";
341 edge_iterator_type ei, eie;
342 for (boost::tie(ei, eie) = boost::edges(this->
m_graph); ei != eie; ++ei)
344 edge_weight_type w = boost::get(boost::edge_weight, this->
m_graph, *ei);
345 graph_vertex_type s = boost::source(*ei, this->
m_graph);
346 graph_vertex_type t = boost::target(*ei, this->
m_graph);
353 out <<
" " << s <<
"--" << t <<
"[color=\"red\",style=\"solid\",penwidth=3]\n";
355 out <<
" " << s <<
"--" << t <<
"[color=\"black\",style=\"solid\",penwidth=3]\n";
358 out <<
" " << s <<
"--" << t <<
"[color=\"blue\",style=\"dotted\",penwidth=3]\n";
362 la::graphviz2pdf(filename);