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/smart_graph.h>
23 #include <lemon/max_cardinality_search.h>
24 #include <lemon/concepts/digraph.h>
25 #include <lemon/concepts/maps.h>
26 #include <lemon/concepts/heap.h>
27 #include <lemon/lgf_reader.h>
29 using namespace lemon;
53 void checkMaxCardSearchCompile() {
55 typedef concepts::Digraph Digraph;
57 typedef Digraph::Node Node;
58 typedef Digraph::Arc Arc;
59 typedef concepts::ReadMap<Arc,Value> CapMap;
60 typedef concepts::ReadWriteMap<Node,Value> CardMap;
61 typedef concepts::ReadWriteMap<Node,bool> ProcMap;
62 typedef Digraph::NodeMap<int> HeapCrossRef;
69 HeapCrossRef crossref(g);
71 typedef MaxCardinalitySearch<Digraph,CapMap>
72 ::SetCapacityMap<CapMap>
73 ::SetCardinalityMap<CardMap>
74 ::SetProcessedMap<ProcMap>
75 ::SetStandardHeap<BinHeap<Value,HeapCrossRef> >
78 MaxCardType maxcard(g,cap);
79 const MaxCardType& const_maxcard = maxcard;
81 const MaxCardType::Heap& heap_const = const_maxcard.heap();
82 MaxCardType::Heap& heap = const_cast<MaxCardType::Heap&>(heap_const);
83 maxcard.heap(heap,crossref);
85 maxcard.capacityMap(cap).cardinalityMap(card).processedMap(proc);
89 n = maxcard.nextNode();
90 maxcard.processNextNode();
96 void checkWithIntMap( std::istringstream& input)
98 typedef SmartDigraph Digraph;
99 typedef Digraph::Node Node;
100 typedef Digraph::ArcMap<int> CapMap;
106 DigraphReader<Digraph>(g,input).
107 arcMap("capacity", cap).
114 MaxCardinalitySearch<Digraph,CapMap> maxcard(g,cap);
117 maxcard.addSource(s);
120 check(maxcard.processed(s) && !maxcard.processed(x) &&
121 !maxcard.processed(y), "Wrong processed()!");
123 a=maxcard.nextNode();
124 check(maxcard.processNextNode()==a,
125 "Wrong nextNode() or processNextNode() return value!");
127 check(maxcard.processed(a), "Wrong processNextNode()!");
130 check(maxcard.cardinality(x)==2 && maxcard.cardinality(y)>=4,
131 "Wrong cardinalities!");
134 void checkWithConst1Map(std::istringstream &input) {
135 typedef SmartDigraph Digraph;
136 typedef Digraph::Node Node;
141 DigraphReader<Digraph>(g,input).
148 MaxCardinalitySearch<Digraph> maxcard(g);
150 check(maxcard.cardinality(x)==1 &&
151 maxcard.cardinality(y)+maxcard.cardinality(z)==3,
152 "Wrong cardinalities!");
157 std::istringstream input1(test_lgf);
158 checkWithIntMap(input1);
160 std::istringstream input2(test_lgf);
161 checkWithConst1Map(input2);