Port preflow push max flow alg. from svn -r3516 (#176)
Namely,
- port the files
- apply the migrate script
- apply the unify script
- break the long lines in lemon/preflow.h
- convert the .dim test file to .lgf
- fix compilation problems
1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #include <lemon/concepts/digraph.h>
20 #include <lemon/smart_graph.h>
21 #include <lemon/list_graph.h>
22 #include <lemon/lgf_reader.h>
23 #include <lemon/dijkstra.h>
24 #include <lemon/path.h>
25 #include <lemon/bin_heap.h>
27 #include "graph_test.h"
28 #include "test_tools.h"
30 using namespace lemon;
53 void checkDijkstraCompile()
56 typedef concepts::Digraph Digraph;
57 typedef concepts::ReadMap<Digraph::Arc,VType> LengthMap;
58 typedef Dijkstra<Digraph, LengthMap> DType;
59 typedef Digraph::Node Node;
60 typedef Digraph::Arc Arc;
73 DType dijkstra_test(G,length);
76 dijkstra_test.run(s,t);
78 l = dijkstra_test.dist(t);
79 e = dijkstra_test.predArc(t);
80 s = dijkstra_test.predNode(t);
81 b = dijkstra_test.reached(t);
82 d = dijkstra_test.distMap();
83 p = dijkstra_test.predMap();
84 pp = dijkstra_test.path(t);
88 ::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
89 ::SetDistMap<concepts::ReadWriteMap<Node,VType> >
90 ::SetProcessedMap<concepts::WriteMap<Node,bool> >
91 ::SetStandardProcessedMap
92 ::SetOperationTraits<DijkstraWidestPathOperationTraits<VType> >
93 ::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > >
94 ::SetStandardHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > >
95 ::Create dijkstra_test(G,length);
98 dijkstra_test.run(s,t);
100 l = dijkstra_test.dist(t);
101 e = dijkstra_test.predArc(t);
102 s = dijkstra_test.predNode(t);
103 b = dijkstra_test.reached(t);
104 pp = dijkstra_test.path(t);
109 void checkDijkstraFunctionCompile()
112 typedef concepts::Digraph Digraph;
113 typedef Digraph::Arc Arc;
114 typedef Digraph::Node Node;
115 typedef concepts::ReadMap<Digraph::Arc,VType> LengthMap;
119 dijkstra(g,LengthMap()).run(Node());
120 b=dijkstra(g,LengthMap()).run(Node(),Node());
121 dijkstra(g,LengthMap())
122 .predMap(concepts::ReadWriteMap<Node,Arc>())
123 .distMap(concepts::ReadWriteMap<Node,VType>())
124 .processedMap(concepts::WriteMap<Node,bool>())
126 b=dijkstra(g,LengthMap())
127 .predMap(concepts::ReadWriteMap<Node,Arc>())
128 .distMap(concepts::ReadWriteMap<Node,VType>())
129 .processedMap(concepts::WriteMap<Node,bool>())
130 .path(concepts::Path<Digraph>())
135 template <class Digraph>
136 void checkDijkstra() {
137 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
138 typedef typename Digraph::template ArcMap<int> LengthMap;
144 std::istringstream input(test_lgf);
145 digraphReader(G, input).
146 arcMap("length", length).
151 Dijkstra<Digraph, LengthMap>
152 dijkstra_test(G, length);
153 dijkstra_test.run(s);
155 check(dijkstra_test.dist(t)==3,"Dijkstra found a wrong path.");
157 Path<Digraph> p = dijkstra_test.path(t);
158 check(p.length()==3,"path() found a wrong path.");
159 check(checkPath(G, p),"path() found a wrong path.");
160 check(pathSource(G, p) == s,"path() found a wrong path.");
161 check(pathTarget(G, p) == t,"path() found a wrong path.");
163 for(ArcIt e(G); e!=INVALID; ++e) {
166 check( !dijkstra_test.reached(u) ||
167 (dijkstra_test.dist(v) - dijkstra_test.dist(u) <= length[e]),
168 "Wrong output. dist(target)-dist(source)-arc_length=" <<
169 dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e]);
172 for(NodeIt v(G); v!=INVALID; ++v) {
173 if (dijkstra_test.reached(v)) {
174 check(v==s || dijkstra_test.predArc(v)!=INVALID, "Wrong tree.");
175 if (dijkstra_test.predArc(v)!=INVALID ) {
176 Arc e=dijkstra_test.predArc(v);
178 check(u==dijkstra_test.predNode(v),"Wrong tree.");
179 check(dijkstra_test.dist(v) - dijkstra_test.dist(u) == length[e],
180 "Wrong distance! Difference: " <<
181 std::abs(dijkstra_test.dist(v)-dijkstra_test.dist(u)-length[e]));
187 NullMap<Node,Arc> myPredMap;
188 dijkstra(G,length).predMap(myPredMap).run(s);
193 checkDijkstra<ListDigraph>();
194 checkDijkstra<SmartDigraph>();