Fix wrong iteration in ListGraph snapshot, part II. (#598)
1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2013
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
21 #include "test_tools.h"
22 #include <lemon/list_graph.h>
23 #include <lemon/circulation.h>
24 #include <lemon/lgf_reader.h>
25 #include <lemon/concepts/digraph.h>
26 #include <lemon/concepts/maps.h>
28 using namespace lemon;
52 void checkCirculationCompile()
55 typedef concepts::Digraph Digraph;
57 typedef Digraph::Node Node;
58 typedef Digraph::Arc Arc;
59 typedef concepts::ReadMap<Arc,VType> CapMap;
60 typedef concepts::ReadMap<Node,VType> SupplyMap;
61 typedef concepts::ReadWriteMap<Arc,VType> FlowMap;
62 typedef concepts::WriteMap<Node,bool> BarrierMap;
64 typedef Elevator<Digraph, Digraph::Node> Elev;
65 typedef LinkedElevator<Digraph, Digraph::Node> LinkedElev;
76 ::lemon::ignore_unused_variable_warning(v,b);
78 typedef Circulation<Digraph, CapMap, CapMap, SupplyMap>
81 ::SetStandardElevator<LinkedElev>
82 ::Create CirculationType;
83 CirculationType circ_test(g, lcap, ucap, supply);
84 const CirculationType& const_circ_test = circ_test;
92 const CirculationType::Elevator& elev = const_circ_test.elevator();
93 circ_test.elevator(const_cast<CirculationType::Elevator&>(elev));
94 CirculationType::Tolerance tol = const_circ_test.tolerance();
95 circ_test.tolerance(tol);
98 circ_test.greedyInit();
102 v = const_circ_test.flow(a);
103 const FlowMap& fm = const_circ_test.flowMap();
104 b = const_circ_test.barrier(n);
105 const_circ_test.barrierMap(bar);
107 ::lemon::ignore_unused_variable_warning(fm);
110 template <class G, class LM, class UM, class DM>
111 void checkCirculation(const G& g, const LM& lm, const UM& um,
112 const DM& dm, bool find)
114 Circulation<G, LM, UM, DM> circ(g, lm, um, dm);
115 bool ret = circ.run();
117 check(ret, "A feasible solution should have been found.");
118 check(circ.checkFlow(), "The found flow is corrupt.");
119 check(!circ.checkBarrier(), "A barrier should not have been found.");
121 check(!ret, "A feasible solution should not have been found.");
122 check(circ.checkBarrier(), "The found barrier is corrupt.");
126 int main (int, char*[])
128 typedef ListDigraph Digraph;
129 DIGRAPH_TYPEDEFS(Digraph);
132 IntArcMap lo(g), up(g);
133 IntNodeMap delta(g, 0);
136 std::istringstream input(test_lgf);
137 DigraphReader<Digraph>(g,input).
144 delta[s] = 7; delta[t] = -7;
145 checkCirculation(g, lo, up, delta, true);
147 delta[s] = 13; delta[t] = -13;
148 checkCirculation(g, lo, up, delta, true);
150 delta[s] = 6; delta[t] = -6;
151 checkCirculation(g, lo, up, delta, false);
153 delta[s] = 14; delta[t] = -14;
154 checkCirculation(g, lo, up, delta, false);
156 delta[s] = 7; delta[t] = -13;
157 checkCirculation(g, lo, up, delta, true);
159 delta[s] = 5; delta[t] = -15;
160 checkCirculation(g, lo, up, delta, true);
162 delta[s] = 10; delta[t] = -11;
163 checkCirculation(g, lo, up, delta, true);
165 delta[s] = 11; delta[t] = -10;
166 checkCirculation(g, lo, up, delta, false);