edge_coloring.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include <iostream>
  10. #include <boost/config.hpp>
  11. #include <boost/graph/adjacency_list.hpp>
  12. #include <boost/graph/edge_coloring.hpp>
  13. #include <boost/graph/properties.hpp>
  14. /*
  15. Sample output
  16. Colored using 5 colors
  17. a-d: 4
  18. a-f: 0
  19. b-c: 2
  20. b-e: 3
  21. b-g: 1
  22. b-j: 0
  23. c-d: 0
  24. c-e: 1
  25. d-f: 2
  26. d-i: 1
  27. e-g: 4
  28. f-g: 3
  29. f-h: 1
  30. g-h: 0
  31. */
  32. int main(int, char *[])
  33. {
  34. using namespace boost;
  35. using namespace std;
  36. typedef adjacency_list<vecS, vecS, undirectedS, no_property, size_t, no_property> Graph;
  37. typedef std::pair<std::size_t, std::size_t> Pair;
  38. Pair edges[14] = { Pair(0,3), //a-d
  39. Pair(0,5), //a-f
  40. Pair(1,2), //b-c
  41. Pair(1,4), //b-e
  42. Pair(1,6), //b-g
  43. Pair(1,9), //b-j
  44. Pair(2,3), //c-d
  45. Pair(2,4), //c-e
  46. Pair(3,5), //d-f
  47. Pair(3,8), //d-i
  48. Pair(4,6), //e-g
  49. Pair(5,6), //f-g
  50. Pair(5,7), //f-h
  51. Pair(6,7) }; //g-h
  52. Graph G(10);
  53. for (size_t i = 0; i < sizeof(edges)/sizeof(edges[0]); i++)
  54. add_edge(edges[i].first, edges[i].second, G);
  55. size_t colors = edge_coloring(G, get(edge_bundle, G));
  56. cout << "Colored using " << colors << " colors" << endl;
  57. for (size_t i = 0; i < sizeof(edges)/sizeof(edges[0]); i++) {
  58. cout << " " << (char)('a' + edges[i].first) << "-" << (char)('a' + edges[i].second) << ": " << G[edge(edges[i].first, edges[i].second, G).first] << endl;
  59. }
  60. return 0;
  61. }