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/bfs.h>
24 #include <lemon/path.h>
26 #include "graph_test.h"
27 #include "test_tools.h"
29 using namespace lemon;
53 void checkBfsCompile()
55 typedef concepts::Digraph Digraph;
56 typedef Bfs<Digraph> BType;
57 typedef Digraph::Node Node;
58 typedef Digraph::Arc Arc;
77 e = bfs_test.predArc(t);
78 s = bfs_test.predNode(t);
79 b = bfs_test.reached(t);
80 d = bfs_test.distMap();
81 p = bfs_test.predMap();
82 pp = bfs_test.path(t);
86 ::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
87 ::SetDistMap<concepts::ReadWriteMap<Node,int> >
88 ::SetReachedMap<concepts::ReadWriteMap<Node,bool> >
89 ::SetProcessedMap<concepts::WriteMap<Node,bool> >
90 ::SetStandardProcessedMap
98 e = bfs_test.predArc(t);
99 s = bfs_test.predNode(t);
100 b = bfs_test.reached(t);
101 pp = bfs_test.path(t);
105 void checkBfsFunctionCompile()
108 typedef concepts::Digraph Digraph;
109 typedef Digraph::Arc Arc;
110 typedef Digraph::Node Node;
115 b=bfs(g).run(Node(),Node());
118 .predMap(concepts::ReadWriteMap<Node,Arc>())
119 .distMap(concepts::ReadWriteMap<Node,VType>())
120 .reachedMap(concepts::ReadWriteMap<Node,bool>())
121 .processedMap(concepts::WriteMap<Node,bool>())
124 .predMap(concepts::ReadWriteMap<Node,Arc>())
125 .distMap(concepts::ReadWriteMap<Node,VType>())
126 .reachedMap(concepts::ReadWriteMap<Node,bool>())
127 .processedMap(concepts::WriteMap<Node,bool>())
128 .path(concepts::Path<Digraph>())
132 .predMap(concepts::ReadWriteMap<Node,Arc>())
133 .distMap(concepts::ReadWriteMap<Node,VType>())
134 .reachedMap(concepts::ReadWriteMap<Node,bool>())
135 .processedMap(concepts::WriteMap<Node,bool>())
139 template <class Digraph>
141 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
146 std::istringstream input(test_lgf);
147 digraphReader(G, input).
152 Bfs<Digraph> bfs_test(G);
155 check(bfs_test.dist(t)==2,"Bfs found a wrong path.");
157 Path<Digraph> p = bfs_test.path(t);
158 check(p.length()==2,"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.");
164 for(ArcIt a(G); a!=INVALID; ++a) {
167 check( !bfs_test.reached(u) ||
168 (bfs_test.dist(v) <= bfs_test.dist(u)+1),
169 "Wrong output. " << G.id(u) << "->" << G.id(v));
172 for(NodeIt v(G); v!=INVALID; ++v) {
173 if (bfs_test.reached(v)) {
174 check(v==s || bfs_test.predArc(v)!=INVALID, "Wrong tree.");
175 if (bfs_test.predArc(v)!=INVALID ) {
176 Arc a=bfs_test.predArc(v);
178 check(u==bfs_test.predNode(v),"Wrong tree.");
179 check(bfs_test.dist(v) - bfs_test.dist(u) == 1,
180 "Wrong distance. Difference: "
181 << std::abs(bfs_test.dist(v) - bfs_test.dist(u) - 1));
187 NullMap<Node,Arc> myPredMap;
188 bfs(G).predMap(myPredMap).run(s);
194 checkBfs<ListDigraph>();
195 checkBfs<SmartDigraph>();