src/work/athos/min_cost_flow.cc
changeset 659 c5984e925384
child 661 d306e777117e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/work/athos/min_cost_flow.cc	Tue May 25 12:31:18 2004 +0000
     1.3 @@ -0,0 +1,110 @@
     1.4 +#include <iostream>
     1.5 +#include "test_tools.h"
     1.6 +#include <hugo/list_graph.h>
     1.7 +#include <mincostflow.h>
     1.8 +//#include <path.h>
     1.9 +//#include <maps.h>
    1.10 +
    1.11 +using namespace std;
    1.12 +using namespace hugo;
    1.13 +
    1.14 +
    1.15 +
    1.16 +bool passed = true;
    1.17 +/*
    1.18 +void check(bool rc, char *msg="") {
    1.19 +  passed = passed && rc;
    1.20 +  if(!rc) {
    1.21 +    std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
    1.22 + 
    1.23 +
    1.24 +  }
    1.25 +}
    1.26 +*/
    1.27 +
    1.28 +
    1.29 +int main()
    1.30 +{
    1.31 +
    1.32 +  typedef ListGraph::Node Node;
    1.33 +  typedef ListGraph::Edge Edge;
    1.34 +
    1.35 +  ListGraph graph;
    1.36 +
    1.37 +  //Ahuja könyv példája
    1.38 +
    1.39 +  Node s=graph.addNode();
    1.40 +  Node v1=graph.addNode();  
    1.41 +  Node v2=graph.addNode();
    1.42 +  Node v3=graph.addNode();
    1.43 +  Node v4=graph.addNode();
    1.44 +  Node v5=graph.addNode();
    1.45 +  Node t=graph.addNode();
    1.46 +
    1.47 +  Edge s_v1=graph.addEdge(s, v1);
    1.48 +  Edge v1_v2=graph.addEdge(v1, v2);
    1.49 +  Edge s_v3=graph.addEdge(s, v3);
    1.50 +  Edge v2_v4=graph.addEdge(v2, v4);
    1.51 +  Edge v2_v5=graph.addEdge(v2, v5);
    1.52 +  Edge v3_v5=graph.addEdge(v3, v5);
    1.53 +  Edge v4_t=graph.addEdge(v4, t);
    1.54 +  Edge v5_t=graph.addEdge(v5, t);
    1.55 +  
    1.56 +
    1.57 +  ListGraph::EdgeMap<int> length(graph);
    1.58 +
    1.59 +  length.set(s_v1, 6);
    1.60 +  length.set(v1_v2, 4);
    1.61 +  length.set(s_v3, 10);
    1.62 +  length.set(v2_v4, 5);
    1.63 +  length.set(v2_v5, 1);
    1.64 +  length.set(v3_v5, 4);
    1.65 +  length.set(v4_t, 8);
    1.66 +  length.set(v5_t, 8);
    1.67 +
    1.68 +  /*
    1.69 +  ListGraph::EdgeMap<int> capacity(graph);
    1.70 +
    1.71 +  capacity.set(s_v1, 2);
    1.72 +  capacity.set(v1_v2, 2);
    1.73 +  capacity.set(s_v3, 1);
    1.74 +  capacity.set(v2_v4, 1);
    1.75 +  capacity.set(v2_v5, 1);
    1.76 +  capacity.set(v3_v5, 1);
    1.77 +  capacity.set(v4_t, 1);
    1.78 +  capacity.set(v5_t, 2);
    1.79 +  */
    1.80 +
    1.81 +  //  ConstMap<Edge, int> const1map(1);
    1.82 +  std::cout << "Enhanced capacity scaling algorithm test (for the mincostflow problem)..." << std::endl;
    1.83 +
    1.84 +  MinCostFlow< ListGraph, ListGraph::EdgeMap<int>, ListGraph::NodeMap<int> >
    1.85 +    min_cost_flow_test(graph, length, supply_demand);
    1.86 +
    1.87 +  int k=1;
    1.88 +
    1.89 +  /*
    1.90 +  check(  min_cost_flow_test.run(s,t,k) == 1 && min_cost_flow_test.totalLength() == 19,"One path, total length should be 19");
    1.91 +
    1.92 +  check(min_cost_flow_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
    1.93 +  
    1.94 +  k=2;
    1.95 +  
    1.96 +  check(  min_cost_flow_test.run(s,t,k) == 2 && min_cost_flow_test.totalLength() == 41,"Two paths, total length should be 41");
    1.97 +
    1.98 +  check(min_cost_flow_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
    1.99 +  
   1.100 +  
   1.101 +  k=4;
   1.102 +
   1.103 +  check(  min_cost_flow_test.run(s,t,k) == 3 && min_cost_flow_test.totalLength() == 64,"Three paths, total length should be 64");
   1.104 +
   1.105 +  check(min_cost_flow_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
   1.106 +
   1.107 +
   1.108 +  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
   1.109 +       << endl;
   1.110 +
   1.111 +  return passed ? 0 : 1;
   1.112 +  */
   1.113 +}