| 1 | //======================================================================= |
| 2 | // Copyright 2013 Maciej Piechotka |
| 3 | // Authors: Maciej Piechotka |
| 4 | // |
| 5 | // Distributed under the Boost Software License, Version 1.0. (See |
| 6 | // accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | //======================================================================= |
| 9 | |
| 10 | #include <boost/config.hpp> |
| 11 | #include <boost/test/minimal.hpp> |
| 12 | |
| 13 | #include <boost/dynamic_bitset.hpp> |
| 14 | #include <boost/graph/adjacency_list.hpp> |
| 15 | #include <boost/graph/random.hpp> |
| 16 | #include <boost/graph/edge_coloring.hpp> |
| 17 | #include <boost/random/mersenne_twister.hpp> |
| 18 | |
| 19 | template<typename Graph, typename ColorMap> |
| 20 | void test_graph(Graph &graph, ColorMap color) |
| 21 | { |
| 22 | typedef typename boost::property_traits<ColorMap>::value_type color_t; |
| 23 | color_t colors_no = boost::edge_coloring(graph, color); |
| 24 | BGL_FORALL_VERTICES_T(v, graph, Graph) { |
| 25 | boost::dynamic_bitset<> used_colors(colors_no); |
| 26 | BGL_FORALL_OUTEDGES_T(v, e, graph, Graph) { |
| 27 | BOOST_CHECK(!used_colors.test(get(color, e))); |
| 28 | used_colors.set(get(color, e)); |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | // usage: edge_coloring.exe [vertices=100] [edges=5*vertices] |
| 34 | |
| 35 | int test_main(int argc, char* argv[]) |
| 36 | { |
| 37 | size_t vertices = 100; |
| 38 | if (argc > 1) { |
| 39 | vertices = atoi(argv[1]); |
| 40 | } |
| 41 | size_t edges = 5 * vertices; |
| 42 | if (argc > 2) { |
| 43 | edges = atoi(argv[2]); |
| 44 | } |
| 45 | using namespace boost; |
| 46 | typedef adjacency_list<vecS, vecS, undirectedS, no_property, size_t, no_property> Graph; |
| 47 | Graph G; |
| 48 | boost::mt19937 gen; |
| 49 | generate_random_graph(G, vertices, edges, gen, false, false); |
| 50 | test_graph(G, get(edge_bundle, G)); |
| 51 | return 0; |
| 52 | } |