Limbo 3.5.4
Loading...
Searching...
No Matches
test_ChromaticNumber.cpp
Go to the documentation of this file.
1
7
8#include <iostream>
9#include <fstream>
10#include <string>
12#include <boost/graph/graphviz.hpp>
13#include <boost/graph/graph_utility.hpp>
14#include <boost/graph/adjacency_list.hpp>
15#include <boost/graph/undirected_graph.hpp>
18#include <boost/graph/erdos_renyi_generator.hpp>
19#include <boost/random/mersenne_twister.hpp>
20#include <boost/graph/random.hpp>
21#include <boost/graph/iteration_macros.hpp>
22
23#include <boost/version.hpp>
24#if BOOST_VERSION <= 14601
25#include <boost/graph/detail/is_same.hpp>
26#else
27#include <boost/type_traits/is_same.hpp>
28#endif
29
30using std::cout;
31using std::endl;
32using std::ofstream;
33using std::string;
34using namespace boost;
35
38template <typename GraphType>
40{
41 GraphType& g;
42
45 MisVisitor(GraphType& g_) : g(g_) {}
48 MisVisitor(MisVisitor const& rhs) : g(rhs.g) {}
49
53 template <typename MisType>
54 void mis(MisType const& is)
55 {
56 typename property_map<GraphType, vertex_index_t>::type vertex_index_map = get(vertex_index, g);
57
58#if 1
59 if (num_vertices(g) < 20)
60 {
61 cout << "independent sets" << endl;
62 for (typename MisType::const_iterator it = is.begin();
63 it != is.end(); ++it)
64 {
65 cout << vertex_index_map[*it] << " ";
66 }
67 cout << endl;
68 }
69#endif
70 }
71};
72
78int main()
79{
80 // do not use setS, it does not compile for subgraph
81 // do not use custom property tags, it does not compile for most utilities
82 typedef adjacency_list<vecS, vecS, undirectedS,
83 property<vertex_index_t, std::size_t>,
84 property<edge_index_t, std::size_t, property<edge_weight_t, int> >,
85 property<graph_name_t, string> > graph_type;
86 typedef subgraph<graph_type> subgraph_type;
87 typedef property<vertex_index_t, std::size_t> VertexId;
88 typedef property<edge_index_t, std::size_t> EdgeID;
89 typedef typename boost::graph_traits<subgraph_type>::vertex_descriptor vertex_descriptor;
90
91#if 1
92 mt19937 gen;
93 subgraph_type g;
94 int N = 40;
95 std::vector<vertex_descriptor> vertex_set;
96 std::vector< std::pair<vertex_descriptor, vertex_descriptor> > edge_set;
97 generate_random_graph(g, N, N * 2, gen,
98 std::back_inserter(vertex_set),
99 std::back_inserter(edge_set));
100#else
101 subgraph_type g;
102
103 {
104 vertex_descriptor v1 = add_vertex(g);
105 vertex_descriptor v2 = add_vertex(g);
106 vertex_descriptor v3 = add_vertex(g);
107 vertex_descriptor v4 = add_vertex(g);
108 vertex_descriptor v5 = add_vertex(g);
109 add_edge(v1, v2, g);
110 add_edge(v1, v3, g);
111 add_edge(v1, v4, g);
112 add_edge(v2, v3, g);
113 add_edge(v2, v4, g);
114 add_edge(v3, v4, g);
115 add_edge(v3, v5, g);
116 }
117
118#endif
119
120 property_map<subgraph_type, vertex_index_t>::type vertex_index_map = get(vertex_index, g);
121 property_map<subgraph_type, edge_index_t>::type edge_index_map = get(edge_index, g);
122
123 cout << "original graph" << endl;
124 print_edges2(g, vertex_index_map, edge_index_map);
125 print_graph(g, vertex_index_map);
126
127 dynamic_properties dp;
128 //dp.property("style", edge_style);
129 //dp.property("pos", vertex_pos);
130 //dp.property("len", weight);
131 dp.property("node_id", get(vertex_index, g));
132 ofstream out("graph.gv");
133 write_graphviz_dp(out, g, dp);
134 system("dot -Tpdf graph.gv -o graph.pdf");
135
136 // test complement_graph
137 {
138 subgraph_type gp;
139 std::map<vertex_descriptor, vertex_descriptor> mCompG2G;
141
142 cout << "complement graph" << endl;
143 BGL_FORALL_VERTICES_T(v, gp, subgraph_type)
144 {
145 cout << vertex_index_map[mCompG2G[v]] << " <--> ";
146 boost::graph_traits<subgraph_type>::out_edge_iterator e, e_end;
147 for (boost::tie(e, e_end) = out_edges(v, gp); e != e_end; ++e)
148 cout << vertex_index_map[mCompG2G[target(*e, gp)]] << " ";
149 cout << endl;
150 }
151 }
152
153 // test max_independent_set
154 {
156 }
157
158 // test LawlerChromaticNumber
159 {
161 cout << "chromatic number = " << lcn(g) << endl;
162 }
163
164 // test DsatColoring
165 {
167 cout << "dsat coloring number = " << dc() << endl;
168 }
169
170 return 0;
171}
assertion with message
return chromatic number of a graph
coloring a graph with saturation degree based heuristics
Boost.Geometry.
Definition GdsObjects.h:740
void complement_graph(GraphType const &g, GraphType &gp, std::map< typename boost::graph_traits< GraphType >::vertex_descriptor, typename boost::graph_traits< GraphType >::vertex_descriptor > &mCompG2G)
get the complement graph of original graph
void max_independent_set(GraphType const &g, VisitorType vis, AlgorithmType const &)
MisVisitor(MisVisitor const &rhs)
void mis(MisType const &is)
GraphType & g
graph
MisVisitor(GraphType &g_)
int main()