sequential_vertex_coloring.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2004 The Trustees of Indiana University.
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Authors: Douglas Gregor
  6. // Andrew Lumsdaine
  7. #include <boost/graph/sequential_vertex_coloring.hpp>
  8. #include <boost/test/minimal.hpp>
  9. #include <boost/graph/adjacency_list.hpp>
  10. #include <utility>
  11. using namespace boost;
  12. int test_main(int, char*[])
  13. {
  14. typedef adjacency_list<listS, vecS, undirectedS> Graph;
  15. typedef graph_traits<Graph>::vertices_size_type vertices_size_type;
  16. typedef property_map<Graph, vertex_index_t>::const_type vertex_index_map;
  17. typedef std::pair<int, int> Edge;
  18. enum nodes {A, B, C, D, E, n};
  19. Edge edge_array[] = { Edge(A, C), Edge(B, B), Edge(B, D), Edge(B, E),
  20. Edge(C, B), Edge(C, D), Edge(D, E), Edge(E, A),
  21. Edge(E, B) };
  22. int m = sizeof(edge_array) / sizeof(Edge);
  23. Graph g(edge_array, edge_array + m, n);
  24. // Test with the normal order
  25. std::vector<vertices_size_type> color_vec(num_vertices(g));
  26. iterator_property_map<vertices_size_type*, vertex_index_map,
  27. vertices_size_type, vertices_size_type&>
  28. color(&color_vec.front(), get(vertex_index, g));
  29. vertices_size_type num_colors = sequential_vertex_coloring(g, color);
  30. BOOST_CHECK(num_colors == 3);
  31. BOOST_CHECK(get(color, (vertices_size_type)A) == 0);
  32. BOOST_CHECK(get(color, (vertices_size_type)B) == 0);
  33. BOOST_CHECK(get(color, (vertices_size_type)C) == 1);
  34. BOOST_CHECK(get(color, (vertices_size_type)D) == 2);
  35. BOOST_CHECK(get(color, (vertices_size_type)E) == 1);
  36. return 0;
  37. }