fork download
  1. #include <iostream> //std::cin,cout,ios_base
  2. #include <vector> //std::vector
  3. #include <tuple> //std::tie
  4. #include <limits.h> //INT_MAX (no `std::')
  5.  
  6. #include <boost/graph/adjacency_list.hpp>
  7. #include <boost/graph/graph_traits.hpp>
  8.  
  9. #include <boost/graph/push_relabel_max_flow.hpp>
  10.  
  11. using namespace boost;
  12.  
  13. struct VertexProperties{
  14.  
  15. };
  16.  
  17. struct EdgeProperties{
  18. int id;
  19. int capacity;
  20. int residual_capacity;
  21. };
  22.  
  23. typedef boost::adjacency_list<vecS,vecS,directedS,VertexProperties,EdgeProperties> Graph;
  24. typedef boost::graph_traits<Graph> Traits;
  25. typedef Traits::vertex_descriptor Vertex;
  26. typedef Traits::edge_descriptor Edge;
  27.  
  28. void do_add_edge(int& next_id, const Vertex& a, const Vertex& b, const int c, Graph& g,std::map<Edge,Edge>& reverse_edge_of);
  29.  
  30. int main(int arc, char* argv[]){
  31. std::ios_base::sync_with_stdio(false);
  32.  
  33. int n = 3; //nof vertices ( >2)
  34.  
  35. Graph g(n);
  36.  
  37. Vertex s = vertex(n-2,g); //source
  38. Vertex t = vertex(n-1,g); //sink
  39.  
  40. Vertex u = vertex(0,g);
  41.  
  42. std::map<Edge,Edge> reverse_edge_map;
  43. int next_id = 0;
  44.  
  45. do_add_edge(next_id,s,u,3,g,reverse_edge_map);
  46. do_add_edge(next_id,u,t,1,g,reverse_edge_map);
  47.  
  48. std::vector<int> rescap(num_edges(g));
  49.  
  50. //this doesn't work
  51. int maxflow = push_relabel_max_flow(
  52. g,
  53. s,
  54. t,
  55. capacity_map(get(&EdgeProperties::capacity,g))
  56. .residual_capacity_map(get(&EdgeProperties::residual_capacity,g))
  57. .reverse_edge_map(make_assoc_property_map(reverse_edge_map))
  58. .vertex_index_map(get(vertex_index,g))
  59. );
  60. /* this would work
  61. int maxflow = push_relabel_max_flow(
  62. g,
  63. s,
  64. t,
  65. get(&EdgeProperties::capacity,g),
  66. get(&EdgeProperties::residual_capacity,g),
  67. make_assoc_property_map(reverse_edge_map),
  68. get(vertex_index,g)
  69. );
  70. */
  71.  
  72. std::cout << "maxflow = " << maxflow << "\n";
  73.  
  74. return 0;
  75. }
  76.  
  77. void do_add_edge(int& next_id, const Vertex& a, const Vertex& b, const int c, Graph& g,std::map<Edge,Edge>& reverse_edge_of){
  78. Edge e,re; bool success;
  79.  
  80. std::tie(e,success) = add_edge(a,b,g);
  81. g[e].id = next_id;
  82. g[e].capacity = c;
  83. g[e].residual_capacity = c;
  84.  
  85. //reverse edge
  86. std::tie(re,success) = add_edge(b,a,g);
  87. g[re].id = next_id + 1;
  88. g[re].capacity = 0;
  89. g[re].residual_capacity = 0;
  90.  
  91. reverse_edge_of[e] = re;
  92. reverse_edge_of[re] = e;
  93.  
  94. next_id += 2;
  95. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/boost/graph/adjacency_list.hpp:246:0,
                 from prog.cpp:6:
/usr/include/boost/graph/detail/adjacency_list.hpp: In instantiation of 'struct boost::detail::adj_list_any_edge_pmap::bind_<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties>, EdgeProperties, boost::edge_capacity_t>':
/usr/include/boost/graph/detail/adjacency_list.hpp:2683:12:   required from 'struct boost::detail::adj_list_choose_edge_pmap<boost::edge_capacity_t, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties>, EdgeProperties>'
/usr/include/boost/graph/detail/adjacency_list.hpp:2688:14:   required from 'struct boost::detail::adj_list_edge_property_selector::bind_<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties>, EdgeProperties, boost::edge_capacity_t>'
/usr/include/boost/graph/properties.hpp:208:12:   required from 'struct boost::detail::edge_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties>, boost::edge_capacity_t>'
/usr/include/boost/graph/properties.hpp:228:10:   required from 'struct boost::property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties>, boost::edge_capacity_t, void>'
/usr/include/boost/mpl/eval_if.hpp:38:31:   recursively required from 'struct boost::mpl::eval_if<mpl_::bool_<true>, boost::detail::const_type_as_type<boost::property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties>, boost::edge_capacity_t, void> >, boost::property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties>, boost::edge_capacity_t, void> >'
/usr/include/boost/mpl/eval_if.hpp:38:31:   required from 'struct boost::mpl::eval_if<boost::is_same<boost::param_not_found, boost::param_not_found>, boost::mpl::eval_if<mpl_::bool_<true>, boost::detail::const_type_as_type<boost::property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties>, boost::edge_capacity_t, void> >, boost::property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties>, boost::edge_capacity_t, void> >, boost::mpl::identity<boost::param_not_found> >'
/usr/include/boost/graph/named_function_params.hpp:269:12:   required from 'struct boost::detail::choose_impl_result<mpl_::bool_<true>, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties>, boost::param_not_found, boost::edge_capacity_t>'
/usr/include/boost/graph/named_function_params.hpp:326:156:   required from 'struct boost::detail::edge_capacity_value<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties>, boost::vec_adj_list_vertex_id_map<VertexProperties, unsigned int>, boost::vertex_index_t, boost::bgl_named_params<boost::associative_property_map<std::map<boost::detail::edge_desc_impl<boost::directed_tag, unsigned int>, boost::detail::edge_desc_impl<boost::directed_tag, unsigned int> > >, boost::edge_reverse_t, boost::bgl_named_params<boost::adj_list_edge_property_map<boost::directed_tag, int, int&, unsigned int, EdgeProperties, int EdgeProperties::*>, boost::edge_residual_capacity_t, boost::bgl_named_params<boost::adj_list_edge_property_map<boost::directed_tag, int, int&, unsigned int, EdgeProperties, int EdgeProperties::*>, boost::edge_capacity_t, boost::no_property> > > >'
/usr/include/boost/graph/push_relabel_max_flow.hpp:714:3:   required by substitution of 'template<class Graph, class P, class T, class R> typename boost::detail::edge_capacity_value<Graph, P, T, R>::type boost::push_relabel_max_flow(Graph&, typename boost::graph_traits<Graph>::vertex_descriptor, typename boost::graph_traits<Graph>::vertex_descriptor, const boost::bgl_named_params<T, Tag, Base>&) [with Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties>; P = boost::vec_adj_list_vertex_id_map<VertexProperties, unsigned int>; T = boost::vertex_index_t; R = boost::bgl_named_params<boost::associative_property_map<std::map<boost::detail::edge_desc_impl<boost::directed_tag, unsigned int>, boost::detail::edge_desc_impl<boost::directed_tag, unsigned int> > >, boost::edge_reverse_t, boost::bgl_named_params<boost::adj_list_edge_property_map<boost::directed_tag, int, int&, unsigned int, EdgeProperties, int EdgeProperties::*>, boost::edge_residual_capacity_t, boost::bgl_named_params<boost::adj_list_edge_property_map<boost::directed_tag, int, int&, unsigned int, EdgeProperties, int EdgeProperties::*>, boost::edge_capacity_t, boost::no_property> > >]'
prog.cpp:59:2:   required from here
/usr/include/boost/graph/detail/adjacency_list.hpp:2651:29: error: forming reference to void
         typedef value_type& reference;
                             ^
/usr/include/boost/graph/detail/adjacency_list.hpp:2652:35: error: forming reference to void
         typedef const value_type& const_reference;
                                   ^
/usr/include/boost/graph/detail/adjacency_list.hpp:2656:61: error: forming reference to void
             typename Graph::vertex_descriptor,Property,Tag> type;
                                                             ^
/usr/include/boost/graph/detail/adjacency_list.hpp:2659:68: error: forming reference to void
             typename Graph::vertex_descriptor,const Property, Tag> const_type;
                                                                    ^
prog.cpp: In function 'int main(int, char**)':
prog.cpp:59:2: error: no matching function for call to 'push_relabel_max_flow(Graph&, Vertex&, Vertex&, boost::bgl_named_params<boost::vec_adj_list_vertex_id_map<VertexProperties, unsigned int>, boost::vertex_index_t, boost::bgl_named_params<boost::associative_property_map<std::map<boost::detail::edge_desc_impl<boost::directed_tag, unsigned int>, boost::detail::edge_desc_impl<boost::directed_tag, unsigned int> > >, boost::edge_reverse_t, boost::bgl_named_params<boost::adj_list_edge_property_map<boost::directed_tag, int, int&, unsigned int, EdgeProperties, int EdgeProperties::*>, boost::edge_residual_capacity_t, boost::bgl_named_params<boost::adj_list_edge_property_map<boost::directed_tag, int, int&, unsigned int, EdgeProperties, int EdgeProperties::*>, boost::edge_capacity_t, boost::no_property> > > >)'
  );
  ^
In file included from prog.cpp:9:0:
/usr/include/boost/graph/push_relabel_max_flow.hpp:689:3: note: candidate: template<class Graph, class CapacityEdgeMap, class ResidualCapacityEdgeMap, class ReverseEdgeMap, class VertexIndexMap> typename boost::property_traits<IndexMap>::value_type boost::push_relabel_max_flow(Graph&, typename boost::graph_traits<Graph>::vertex_descriptor, typename boost::graph_traits<Graph>::vertex_descriptor, CapacityEdgeMap, ResidualCapacityEdgeMap, ReverseEdgeMap, VertexIndexMap)
   push_relabel_max_flow
   ^
/usr/include/boost/graph/push_relabel_max_flow.hpp:689:3: note:   template argument deduction/substitution failed:
prog.cpp:59:2: note:   candidate expects 7 arguments, 4 provided
  );
  ^
In file included from prog.cpp:9:0:
/usr/include/boost/graph/push_relabel_max_flow.hpp:714:3: note: candidate: template<class Graph, class P, class T, class R> typename boost::detail::edge_capacity_value<Graph, P, T, R>::type boost::push_relabel_max_flow(Graph&, typename boost::graph_traits<Graph>::vertex_descriptor, typename boost::graph_traits<Graph>::vertex_descriptor, const boost::bgl_named_params<T, Tag, Base>&)
   push_relabel_max_flow
   ^
/usr/include/boost/graph/push_relabel_max_flow.hpp:714:3: note:   substitution of deduced template arguments resulted in errors seen above
/usr/include/boost/graph/push_relabel_max_flow.hpp:734:3: note: candidate: template<class Graph> typename boost::property_traits<typename boost::property_map<Graph, boost::edge_capacity_t>::const_type>::value_type boost::push_relabel_max_flow(Graph&, typename boost::graph_traits<Graph>::vertex_descriptor, typename boost::graph_traits<Graph>::vertex_descriptor)
   push_relabel_max_flow
   ^
/usr/include/boost/graph/push_relabel_max_flow.hpp:734:3: note:   template argument deduction/substitution failed:
prog.cpp:59:2: note:   candidate expects 3 arguments, 4 provided
  );
  ^
stdout
Standard output is empty