COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/athos/min_cost_flow.cc @ 920:2d6c8075d9d0

Last change on this file since 920:2d6c8075d9d0 was 672:6c7bd0edd1d7, checked in by athos, 20 years ago

Seems to work. More tests required.

File size: 2.8 KB
RevLine 
[659]1#include <iostream>
[661]2//#include "test_tools.h"
[659]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;
[672]14
[659]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}
[672]23
[659]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
[662]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
[659]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
[661]61  ListGraph::EdgeMap<int> cost(graph);
[659]62
[661]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);
[659]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> >
[661]89    min_cost_flow_test(graph, cost, supply_demand);
[659]90
[662]91  min_cost_flow_test.run();
92  //int k=1;
[672]93  check(min_cost_flow_test.checkOptimality(), "Is the primal-dual solution pair really optimal?");
[659]94
95  /*
[661]96  check(  min_cost_flow_test.run(s,t,k) == 1 && min_cost_flow_test.totalLength() == 19,"One path, total cost should be 19");
[659]97
98  check(min_cost_flow_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
99 
100  k=2;
101 
[661]102  check(  min_cost_flow_test.run(s,t,k) == 2 && min_cost_flow_test.totalLength() == 41,"Two paths, total cost should be 41");
[659]103
104  check(min_cost_flow_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
105 
106 
107  k=4;
108
[661]109  check(  min_cost_flow_test.run(s,t,k) == 3 && min_cost_flow_test.totalLength() == 64,"Three paths, total cost should be 64");
[659]110
111  check(min_cost_flow_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
112
[672]113  */
[659]114  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
115       << endl;
116
117  return passed ? 0 : 1;
[672]118 
[659]119}
Note: See TracBrowser for help on using the repository browser.