11 #include <boost/graph/graphviz.hpp>
12 #include <boost/graph/graph_utility.hpp>
13 #include <boost/graph/adjacency_list.hpp>
14 #include <boost/graph/undirected_graph.hpp>
16 #include <boost/graph/erdos_renyi_generator.hpp>
17 #include <boost/random/mersenne_twister.hpp>
18 #include <boost/graph/random.hpp>
19 #include <boost/graph/iteration_macros.hpp>
21 #include <boost/version.hpp>
22 #if BOOST_VERSION <= 14601
23 #include <boost/graph/detail/is_same.hpp>
25 #include <boost/type_traits/is_same.hpp>
34 using namespace boost;
39 typedef adjacency_list<vecS, vecS, undirectedS,
40 property<vertex_index_t, std::size_t, property<vertex_color_t, int> >,
41 property<edge_index_t, std::size_t, property<edge_weight_t, int> >,
42 property<graph_name_t, string> > graph_type;
43 typedef subgraph<graph_type> subgraph_type;
44 typedef property<vertex_index_t, std::size_t> VertexId;
45 typedef property<edge_index_t, std::size_t> EdgeID;
46 typedef graph_traits<graph_type>::vertex_descriptor vertex_descriptor;
47 typedef graph_traits<graph_type>::edge_descriptor edge_descriptor;
48 typedef property_map<graph_type, edge_weight_t>::type edge_weight_map_type;
49 typedef property_map<graph_type, vertex_color_t>::type vertex_color_map_type;
58 std::vector<vertex_descriptor> vertex_set;
59 std::vector< std::pair<vertex_descriptor, vertex_descriptor> > edge_set;
60 generate_random_graph(g, N, N * 2, gen,
61 std::back_inserter(vertex_set),
62 std::back_inserter(edge_set));
63 BOOST_AUTO(edge_weight_map,
get(edge_weight, g));
65 graph_traits<graph_type>::edge_iterator eit, eit_end;
66 for (tie(eit, eit_end) = edges(g); eit != eit_end; ++eit, ++i)
70 edge_weight_map[*eit] = -1;
73 edge_weight_map[*eit] = 1;
82 cout <<
"final cost = " << cost << endl;
89 ifstream in (filename.c_str());
93 typedef adjacency_list<vecS, vecS, undirectedS,
94 property<vertex_index_t, std::size_t, property<vertex_color_t, int, property<vertex_name_t, std::size_t> > >,
95 property<edge_index_t, std::size_t, property<edge_weight_t, int> >,
96 property<graph_name_t, string> > tmp_graph_type;
98 dynamic_properties tmpdp;
99 tmpdp.property(
"node_id",
get(vertex_name, tmpg));
100 tmpdp.property(
"label",
get(vertex_name, tmpg));
101 tmpdp.property(
"weight",
get(edge_weight, tmpg));
102 tmpdp.property(
"label",
get(edge_weight, tmpg));
103 assert(read_graphviz(in, tmpg, tmpdp,
"node_id"));
106 graph_type g (num_vertices(tmpg));
107 graph_traits<tmp_graph_type>::vertex_iterator vit, vit_end;
108 for (tie(vit, vit_end) = vertices(tmpg); vit != vit_end; ++vit)
110 size_t name =
get(vertex_name, tmpg, *vit);
111 int color =
get(vertex_color, tmpg, *vit);
112 put(vertex_color, g, (vertex_descriptor)name, color);
115 graph_traits<tmp_graph_type>::edge_iterator eit, eit_end;
116 for (tie(eit, eit_end) = edges(tmpg); eit != eit_end; ++eit)
118 size_t s_name =
get(vertex_name, tmpg, source(*eit, tmpg));
119 size_t t_name =
get(vertex_name, tmpg, target(*eit, tmpg));
120 pair<edge_descriptor, bool> pe = add_edge(s_name, t_name, g);
122 int weight =
get(edge_weight, g, *eit);
123 put(edge_weight, g, pe.first, weight);
126 #ifdef DEBUG_LPCOLORING
127 dynamic_properties dp;
128 dp.property(
"id",
get(vertex_index, g));
129 dp.property(
"node_id",
get(vertex_index, g));
130 dp.property(
"label",
get(vertex_index, g));
131 dp.property(
"weight",
get(edge_weight, g));
132 dp.property(
"label",
get(edge_weight, g));
133 ofstream out (
"graph_init.gv");
134 write_graphviz_dp(out, g, dp,
string(
"id"));
136 system(
"dot -Tpdf graph_init.gv -o graph_init.pdf");
145 cout <<
"final cost = " << cost << endl;
155 int main(
int argc,
char** argv)
void randomGraph()
test 1: a random graph
coloring algorithm based on integer linear programming (ILP) with Gurobi as ILP solver.
virtual double stitch_weight() const
virtual void color_num(ColorNumType cn)
int main(int argc, char **argv)
void realGraph(string const &filename)