From 6b4833684d4a39d527625925a400d5917b78b7ae Mon Sep 17 00:00:00 2001 From: Maciej Piechotka Date: Sun, 29 Sep 2013 14:30:41 +0200 Subject: [PATCH] Add tests for edge coloring --- libs/graph/test/Jamfile.v2 | 1 + libs/graph/test/edge_coloring.cpp | 52 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 libs/graph/test/edge_coloring.cpp diff --git a/libs/graph/test/Jamfile.v2 b/libs/graph/test/Jamfile.v2 index a41d233..c86c2b1 100644 --- a/libs/graph/test/Jamfile.v2 +++ b/libs/graph/test/Jamfile.v2 @@ -131,6 +131,7 @@ test-suite graph_test : [ run hawick_circuits.cpp ] [ run successive_shortest_path_nonnegative_weights_test.cpp ../../test/build//boost_unit_test_framework/static ] [ run cycle_canceling_test.cpp ../../test/build//boost_unit_test_framework/static ] + [ run edge_coloring.cpp ] ; # Run SDB tests only when -sSDB= is set. diff --git a/libs/graph/test/edge_coloring.cpp b/libs/graph/test/edge_coloring.cpp new file mode 100644 index 0000000..69ec277 --- /dev/null +++ b/libs/graph/test/edge_coloring.cpp @@ -0,0 +1,52 @@ +//======================================================================= +// Copyright 2013 Maciej Piechotka +// Authors: Maciej Piechotka +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + +#include +#include + +#include +#include +#include +#include +#include + +template +void test_graph(Graph &graph, ColorMap color) +{ + typedef typename boost::property_traits::value_type color_t; + color_t colors_no = boost::edge_coloring(graph, color); + BGL_FORALL_VERTICES_T(v, graph, Graph) { + boost::dynamic_bitset<> used_colors(colors_no); + BGL_FORALL_OUTEDGES_T(v, e, graph, Graph) { + BOOST_CHECK(!used_colors.test(get(color, e))); + used_colors.set(get(color, e)); + } + } +} + +// usage: edge_coloring.exe [vertices=100] [edges=5*vertices] + +int test_main(int argc, char* argv[]) +{ + size_t vertices = 100; + if (argc > 1) { + vertices = atoi(argv[1]); + } + size_t edges = 5 * vertices; + if (argc > 2) { + edges = atoi(argv[2]); + } + using namespace boost; + typedef adjacency_list Graph; + Graph G; + boost::mt19937 gen; + generate_random_graph(G, vertices, edges, gen, false, false); + test_graph(G, get(edge_bundle, G)); + return 0; +} -- 1.8.3.2