max_flow_algorithms_bundled_properties_and_named_params.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #define BOOST_TEST_MODULE max_flow_algorithms_named_parameters_and_bundled_params_test
  2. #include <boost/graph/adjacency_list.hpp>
  3. #include <boost/test/unit_test.hpp>
  4. #include <boost/graph/edmonds_karp_max_flow.hpp>
  5. #include "min_cost_max_flow_utils.hpp"
  6. typedef boost::adjacency_list_traits<boost::vecS,boost::vecS,boost::directedS> traits;
  7. struct edge_t {
  8. double capacity;
  9. float cost;
  10. float residual_capacity;
  11. traits::edge_descriptor reversed_edge;
  12. };
  13. struct node_t {
  14. traits::edge_descriptor predecessor;
  15. int dist;
  16. int dist_prev;
  17. boost::vertex_index_t id;
  18. boost::default_color_type color;
  19. };
  20. typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, node_t, edge_t > Graph;
  21. BOOST_AUTO_TEST_CASE(using_named_parameters_and_bundled_params_on_edmonds_karp_max_flow_test)
  22. {
  23. Graph g;
  24. traits::vertex_descriptor s,t;
  25. boost::property_map<Graph,double edge_t::* >::type capacity = get(&edge_t::capacity, g);
  26. boost::property_map<Graph,float edge_t::* >::type cost = get(&edge_t::cost, g);
  27. boost::property_map<Graph,float edge_t::* >::type residual_capacity = get(&edge_t::residual_capacity, g);
  28. boost::property_map<Graph,traits::edge_descriptor edge_t::* >::type rev = get(&edge_t::reversed_edge, g);
  29. boost::property_map<Graph,traits::edge_descriptor node_t::* >::type pred = get(&node_t::predecessor, g);
  30. boost::property_map<Graph,boost::default_color_type node_t::* >::type col = get(&node_t::color, g);
  31. boost::SampleGraph::getSampleGraph(g,s,t,capacity,residual_capacity,cost,rev);
  32. // The "named parameter version" (producing errors)
  33. // I chose to show the error with edmonds_karp_max_flow().
  34. int flow_value = edmonds_karp_max_flow(g, s, t,
  35. boost::capacity_map(capacity)
  36. .residual_capacity_map(residual_capacity)
  37. .reverse_edge_map(rev)
  38. .color_map(col)
  39. .predecessor_map(pred));
  40. BOOST_CHECK_EQUAL(flow_value,4);
  41. }