1.1 --- a/test/hao_orlin_test.cc Sat Apr 18 21:54:30 2009 +0200
1.2 +++ b/test/hao_orlin_test.cc Tue Apr 21 10:34:49 2009 +0100
1.3 @@ -19,9 +19,12 @@
1.4 #include <sstream>
1.5
1.6 #include <lemon/smart_graph.h>
1.7 +#include <lemon/adaptors.h>
1.8 +#include <lemon/concepts/digraph.h>
1.9 +#include <lemon/concepts/maps.h>
1.10 +#include <lemon/lgf_reader.h>
1.11 #include <lemon/hao_orlin.h>
1.12
1.13 -#include <lemon/lgf_reader.h>
1.14 #include "test_tools.h"
1.15
1.16 using namespace lemon;
1.17 @@ -37,27 +40,124 @@
1.18 "4\n"
1.19 "5\n"
1.20 "@edges\n"
1.21 - " label capacity\n"
1.22 - "0 1 0 2\n"
1.23 - "1 2 1 2\n"
1.24 - "2 0 2 2\n"
1.25 - "3 4 3 2\n"
1.26 - "4 5 4 2\n"
1.27 - "5 3 5 2\n"
1.28 - "2 3 6 3\n";
1.29 + " cap1 cap2 cap3\n"
1.30 + "0 1 1 1 1 \n"
1.31 + "0 2 2 2 4 \n"
1.32 + "1 2 4 4 4 \n"
1.33 + "3 4 1 1 1 \n"
1.34 + "3 5 2 2 4 \n"
1.35 + "4 5 4 4 4 \n"
1.36 + "5 4 4 4 4 \n"
1.37 + "2 3 1 6 6 \n"
1.38 + "4 0 1 6 6 \n";
1.39 +
1.40 +void checkHaoOrlinCompile()
1.41 +{
1.42 + typedef int Value;
1.43 + typedef concepts::Digraph Digraph;
1.44 +
1.45 + typedef Digraph::Node Node;
1.46 + typedef Digraph::Arc Arc;
1.47 + typedef concepts::ReadMap<Arc, Value> CapMap;
1.48 + typedef concepts::WriteMap<Node, bool> CutMap;
1.49 +
1.50 + Digraph g;
1.51 + Node n;
1.52 + CapMap cap;
1.53 + CutMap cut;
1.54 + Value v;
1.55 +
1.56 + HaoOrlin<Digraph, CapMap> ho_test(g, cap);
1.57 + const HaoOrlin<Digraph, CapMap>&
1.58 + const_ho_test = ho_test;
1.59 +
1.60 + ho_test.init();
1.61 + ho_test.init(n);
1.62 + ho_test.calculateOut();
1.63 + ho_test.calculateIn();
1.64 + ho_test.run();
1.65 + ho_test.run(n);
1.66 +
1.67 + v = const_ho_test.minCutValue();
1.68 + v = const_ho_test.minCutMap(cut);
1.69 +}
1.70 +
1.71 +template <typename Graph, typename CapMap, typename CutMap>
1.72 +typename CapMap::Value
1.73 + cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut)
1.74 +{
1.75 + typename CapMap::Value sum = 0;
1.76 + for (typename Graph::ArcIt a(graph); a != INVALID; ++a) {
1.77 + if (cut[graph.source(a)] && !cut[graph.target(a)])
1.78 + sum += cap[a];
1.79 + }
1.80 + return sum;
1.81 +}
1.82
1.83 int main() {
1.84 - SmartGraph graph;
1.85 - SmartGraph::EdgeMap<int> capacity(graph);
1.86 + SmartDigraph graph;
1.87 + SmartDigraph::ArcMap<int> cap1(graph), cap2(graph), cap3(graph);
1.88 + SmartDigraph::NodeMap<bool> cut(graph);
1.89
1.90 - istringstream lgfs(lgf);
1.91 - graphReader(graph, lgfs).
1.92 - edgeMap("capacity", capacity).run();
1.93 + istringstream input(lgf);
1.94 + digraphReader(graph, input)
1.95 + .arcMap("cap1", cap1)
1.96 + .arcMap("cap2", cap2)
1.97 + .arcMap("cap3", cap3)
1.98 + .run();
1.99
1.100 - HaoOrlin<SmartGraph, SmartGraph::EdgeMap<int> > ho(graph, capacity);
1.101 - ho.run();
1.102 + {
1.103 + HaoOrlin<SmartDigraph> ho(graph, cap1);
1.104 + ho.run();
1.105 + ho.minCutMap(cut);
1.106 +
1.107 + check(ho.minCutValue() == 1, "Wrong cut value");
1.108 + check(ho.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value");
1.109 + }
1.110 + {
1.111 + HaoOrlin<SmartDigraph> ho(graph, cap2);
1.112 + ho.run();
1.113 + ho.minCutMap(cut);
1.114
1.115 - check(ho.minCutValue() == 3, "Wrong cut value");
1.116 + check(ho.minCutValue() == 1, "Wrong cut value");
1.117 + check(ho.minCutValue() == cutValue(graph, cap2, cut), "Wrong cut value");
1.118 + }
1.119 + {
1.120 + HaoOrlin<SmartDigraph> ho(graph, cap3);
1.121 + ho.run();
1.122 + ho.minCutMap(cut);
1.123 +
1.124 + check(ho.minCutValue() == 1, "Wrong cut value");
1.125 + check(ho.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value");
1.126 + }
1.127 +
1.128 + typedef Undirector<SmartDigraph> UGraph;
1.129 + UGraph ugraph(graph);
1.130 +
1.131 + {
1.132 + HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap1);
1.133 + ho.run();
1.134 + ho.minCutMap(cut);
1.135 +
1.136 + check(ho.minCutValue() == 2, "Wrong cut value");
1.137 + check(ho.minCutValue() == cutValue(ugraph, cap1, cut), "Wrong cut value");
1.138 + }
1.139 + {
1.140 + HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap2);
1.141 + ho.run();
1.142 + ho.minCutMap(cut);
1.143 +
1.144 + check(ho.minCutValue() == 5, "Wrong cut value");
1.145 + check(ho.minCutValue() == cutValue(ugraph, cap2, cut), "Wrong cut value");
1.146 + }
1.147 + {
1.148 + HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap3);
1.149 + ho.run();
1.150 + ho.minCutMap(cut);
1.151 +
1.152 + check(ho.minCutValue() == 5, "Wrong cut value");
1.153 + check(ho.minCutValue() == cutValue(ugraph, cap3, cut), "Wrong cut value");
1.154 + }
1.155
1.156 return 0;
1.157 }