COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/athos/min_cost_flow.cc @ 662:0155001b6f65

Last change on this file since 662:0155001b6f65 was 662:0155001b6f65, checked in by athos, 20 years ago

Almost compiles.

File size: 2.7 KB
Line 
1#include <iostream>
2//#include "test_tools.h"
3#include <hugo/list_graph.h>
4#include <mincostflow.h>
5//#include <path.h>
6//#include <maps.h>
7
8using namespace std;
9using namespace hugo;
10
11
12
13bool passed = true;
14/*
15void check(bool rc, char *msg="") {
16  passed = passed && rc;
17  if(!rc) {
18    std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
19 
20
21  }
22}
23*/
24
25
26int main()
27{
28
29  typedef ListGraph::Node Node;
30  typedef ListGraph::Edge Edge;
31
32  ListGraph graph;
33
34  //Ahuja könyv példája
35
36  Node s=graph.addNode();
37  Node v1=graph.addNode(); 
38  Node v2=graph.addNode();
39  Node v3=graph.addNode();
40  Node v4=graph.addNode();
41  Node v5=graph.addNode();
42  Node t=graph.addNode();
43
44  ListGraph::NodeMap<int> supply_demand(graph);
45
46  supply_demand.set(s, 2);
47  supply_demand.set(v1, 3);
48  supply_demand.set(v3, -1);
49  supply_demand.set(t, -4);
50
51  Edge s_v1=graph.addEdge(s, v1);
52  Edge v1_v2=graph.addEdge(v1, v2);
53  Edge s_v3=graph.addEdge(s, v3);
54  Edge v2_v4=graph.addEdge(v2, v4);
55  Edge v2_v5=graph.addEdge(v2, v5);
56  Edge v3_v5=graph.addEdge(v3, v5);
57  Edge v4_t=graph.addEdge(v4, t);
58  Edge v5_t=graph.addEdge(v5, t);
59 
60
61  ListGraph::EdgeMap<int> cost(graph);
62
63  cost.set(s_v1, 6);
64  cost.set(v1_v2, 4);
65  cost.set(s_v3, 10);
66  cost.set(v2_v4, 5);
67  cost.set(v2_v5, 1);
68  cost.set(v3_v5, 4);
69  cost.set(v4_t, 8);
70  cost.set(v5_t, 8);
71
72  /*
73  ListGraph::EdgeMap<int> capacity(graph);
74
75  capacity.set(s_v1, 2);
76  capacity.set(v1_v2, 2);
77  capacity.set(s_v3, 1);
78  capacity.set(v2_v4, 1);
79  capacity.set(v2_v5, 1);
80  capacity.set(v3_v5, 1);
81  capacity.set(v4_t, 1);
82  capacity.set(v5_t, 2);
83  */
84
85  //  ConstMap<Edge, int> const1map(1);
86  std::cout << "Enhanced capacity scaling algorithm test (for the mincostflow problem)..." << std::endl;
87
88  MinCostFlow< ListGraph, ListGraph::EdgeMap<int>, ListGraph::NodeMap<int> >
89    min_cost_flow_test(graph, cost, supply_demand);
90
91  min_cost_flow_test.run();
92  //int k=1;
93
94  /*
95  check(  min_cost_flow_test.run(s,t,k) == 1 && min_cost_flow_test.totalLength() == 19,"One path, total cost should be 19");
96
97  check(min_cost_flow_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
98 
99  k=2;
100 
101  check(  min_cost_flow_test.run(s,t,k) == 2 && min_cost_flow_test.totalLength() == 41,"Two paths, total cost should be 41");
102
103  check(min_cost_flow_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
104 
105 
106  k=4;
107
108  check(  min_cost_flow_test.run(s,t,k) == 3 && min_cost_flow_test.totalLength() == 64,"Three paths, total cost should be 64");
109
110  check(min_cost_flow_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
111
112
113  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
114       << endl;
115
116  return passed ? 0 : 1;
117  */
118}
Note: See TracBrowser for help on using the repository browser.