Ticket #10805: main.cpp

File main.cpp, 2.1 KB (added by Pablo Madoery <madoerypablo@…>, 8 years ago)

It makes a graph that have problematic attributes on the esges

Line 
1#include <iostream>
2#include <boost/graph/adjacency_list.hpp>
3#include <boost/graph/push_relabel_max_flow.hpp>
4#include <boost/graph/graphviz.hpp>
5#include <boost/test/floating_point_comparison.hpp>
6
7using namespace std;
8using namespace boost;
9
10struct vertexInfo
11{
12
13};
14
15struct edgeInfo
16{
17 double capacity;
18 double residualCapacity;
19 adjacency_list_traits<vecS, vecS, bidirectionalS>::edge_descriptor rev;
20};
21
22typedef adjacency_list<vecS, vecS, bidirectionalS, vertexInfo, edgeInfo> Graph;
23typedef Graph::edge_descriptor edge_d;
24
25const char* names[] =
26{ "SV", "L1", "L2", "L3", "L4", "ET"};
27
28template<typename Vertex>
29void create_edge(Graph& g, Vertex v0, Vertex v1, double capacity)
30{
31 //the algorithm requires that for each edge u-v in the graph, the edge v-u also exists
32 Graph::edge_descriptor ep0 = (add_edge(v0, v1, g)).first;
33 Graph::edge_descriptor ep1 = (add_edge(v1, v0, g)).first;
34 g[ep0].capacity = capacity;
35 g[ep0].rev = ep1;
36 g[ep1].capacity = 0; // the capacity of v-u needs to be 0
37 g[ep1].rev = ep0;
38}
39
40int main()
41{
42 Graph graph;
43
44 Graph::vertex_descriptor SV = add_vertex(graph);
45 Graph::vertex_descriptor L1 = add_vertex(graph);
46 Graph::vertex_descriptor L2 = add_vertex(graph);
47 Graph::vertex_descriptor L3 = add_vertex(graph);
48 Graph::vertex_descriptor L4 = add_vertex(graph);
49 Graph::vertex_descriptor ET = add_vertex(graph);
50
51
52
53 create_edge(graph, SV, L1, std::numeric_limits<double>::max());
54 create_edge(graph, SV, L2, std::numeric_limits<double>::max());
55 create_edge(graph, SV, L4, std::numeric_limits<double>::max());
56
57 create_edge(graph, L3, ET, 1000);
58 create_edge(graph, ET, L3, 1000);
59
60 create_edge(graph, L4, L3, 1000);
61 create_edge(graph, L2, L3, 1000);
62 create_edge(graph, L1, L2, 1000);
63
64 // arcos de vuelta
65 create_edge(graph, L3, L4, 1000);
66 create_edge(graph, L3, L2, 1000);
67 create_edge(graph, L2, L1, 1000);
68
69 std::cout << "Max flow: "
70 << push_relabel_max_flow(graph, SV, L3, get(&edgeInfo::capacity, graph), get(&edgeInfo::residualCapacity, graph),
71 get(&edgeInfo::rev, graph), get(boost::vertex_index, graph)) << std::endl;
72
73
74
75 cout<<"end"<<endl;
76 return 0;
77}