Ticket #8317: 0001-Add-tests-for-edge-coloring.patch

File 0001-Add-tests-for-edge-coloring.patch, 2.8 KB (added by uzytkownik2@…, 9 years ago)

Tests for edge coloring

  • libs/graph/test/Jamfile.v2

    From 6b4833684d4a39d527625925a400d5917b78b7ae Mon Sep 17 00:00:00 2001
    From: Maciej Piechotka <uzytkownik2@gmail.com>
    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 b test-suite graph_test :  
    131131    [ run hawick_circuits.cpp ]
    132132    [ run successive_shortest_path_nonnegative_weights_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
    133133    [ run cycle_canceling_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
     134    [ run edge_coloring.cpp ]
    134135    ;
    135136
    136137# Run SDB tests only when -sSDB= is set.
  • new file libs/graph/test/edge_coloring.cpp

    diff --git a/libs/graph/test/edge_coloring.cpp b/libs/graph/test/edge_coloring.cpp
    new file mode 100644
    index 0000000..69ec277
    - +  
     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
     19template<typename Graph, typename ColorMap>
     20void 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
     35int 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}