alpar@906
|
1 |
/* -*- C++ -*-
|
alpar@906
|
2 |
*
|
alpar@1956
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
alpar@1956
|
4 |
*
|
alpar@1956
|
5 |
* Copyright (C) 2003-2006
|
alpar@1956
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@1359
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@906
|
8 |
*
|
alpar@906
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@906
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@906
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@906
|
12 |
*
|
alpar@906
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@906
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@906
|
15 |
* purpose.
|
alpar@906
|
16 |
*
|
alpar@906
|
17 |
*/
|
alpar@906
|
18 |
|
alpar@1401
|
19 |
#ifndef LEMON_GRAPH_ADAPTOR_H
|
alpar@1401
|
20 |
#define LEMON_GRAPH_ADAPTOR_H
|
marci@556
|
21 |
|
deba@2031
|
22 |
/// \ingroup graph_adaptors
|
deba@2031
|
23 |
/// \file
|
deba@2031
|
24 |
/// \brief Several graph adaptors.
|
marci@556
|
25 |
///
|
deba@2031
|
26 |
/// This file contains several useful graph adaptor functions.
|
marci@556
|
27 |
///
|
deba@2031
|
28 |
/// \author Marton Makai and Balazs Dezso
|
marci@556
|
29 |
|
deba@1993
|
30 |
#include <lemon/bits/invalid.h>
|
alpar@921
|
31 |
#include <lemon/maps.h>
|
deba@1979
|
32 |
|
deba@1999
|
33 |
#include <lemon/bits/base_extender.h>
|
deba@1979
|
34 |
#include <lemon/bits/graph_adaptor_extender.h>
|
deba@1791
|
35 |
#include <lemon/bits/graph_extender.h>
|
deba@1979
|
36 |
|
alpar@774
|
37 |
#include <iostream>
|
marci@556
|
38 |
|
alpar@921
|
39 |
namespace lemon {
|
marci@556
|
40 |
|
klao@1951
|
41 |
///\brief Base type for the Graph Adaptors
|
klao@1951
|
42 |
///\ingroup graph_adaptors
|
klao@1951
|
43 |
///
|
klao@1951
|
44 |
///Base type for the Graph Adaptors
|
klao@1951
|
45 |
///
|
klao@1951
|
46 |
///\warning Graph adaptors are in even
|
klao@1951
|
47 |
///more experimental state than the other
|
klao@1951
|
48 |
///parts of the lib. Use them at you own risk.
|
klao@1951
|
49 |
///
|
klao@1951
|
50 |
///This is the base type for most of LEMON graph adaptors.
|
klao@1951
|
51 |
///This class implements a trivial graph adaptor i.e. it only wraps the
|
klao@1951
|
52 |
///functions and types of the graph. The purpose of this class is to
|
klao@1951
|
53 |
///make easier implementing graph adaptors. E.g. if an adaptor is
|
klao@1951
|
54 |
///considered which differs from the wrapped graph only in some of its
|
klao@1951
|
55 |
///functions or types, then it can be derived from GraphAdaptor,
|
klao@1951
|
56 |
///and only the
|
klao@1951
|
57 |
///differences should be implemented.
|
klao@1951
|
58 |
///
|
klao@1951
|
59 |
///author Marton Makai
|
marci@970
|
60 |
template<typename _Graph>
|
alpar@1401
|
61 |
class GraphAdaptorBase {
|
marci@970
|
62 |
public:
|
marci@970
|
63 |
typedef _Graph Graph;
|
deba@2031
|
64 |
typedef GraphAdaptorBase Adaptor;
|
marci@970
|
65 |
typedef Graph ParentGraph;
|
marci@970
|
66 |
|
marci@556
|
67 |
protected:
|
marci@556
|
68 |
Graph* graph;
|
alpar@1401
|
69 |
GraphAdaptorBase() : graph(0) { }
|
marci@556
|
70 |
void setGraph(Graph& _graph) { graph=&_graph; }
|
marci@556
|
71 |
|
marci@556
|
72 |
public:
|
alpar@1401
|
73 |
GraphAdaptorBase(Graph& _graph) : graph(&_graph) { }
|
marci@556
|
74 |
|
alpar@774
|
75 |
typedef typename Graph::Node Node;
|
alpar@774
|
76 |
typedef typename Graph::Edge Edge;
|
marci@556
|
77 |
|
marci@970
|
78 |
void first(Node& i) const { graph->first(i); }
|
marci@970
|
79 |
void first(Edge& i) const { graph->first(i); }
|
marci@970
|
80 |
void firstIn(Edge& i, const Node& n) const { graph->firstIn(i, n); }
|
marci@970
|
81 |
void firstOut(Edge& i, const Node& n ) const { graph->firstOut(i, n); }
|
marci@556
|
82 |
|
marci@970
|
83 |
void next(Node& i) const { graph->next(i); }
|
marci@970
|
84 |
void next(Edge& i) const { graph->next(i); }
|
marci@970
|
85 |
void nextIn(Edge& i) const { graph->nextIn(i); }
|
marci@970
|
86 |
void nextOut(Edge& i) const { graph->nextOut(i); }
|
marci@970
|
87 |
|
alpar@986
|
88 |
Node source(const Edge& e) const { return graph->source(e); }
|
alpar@986
|
89 |
Node target(const Edge& e) const { return graph->target(e); }
|
marci@556
|
90 |
|
deba@1697
|
91 |
typedef NodeNumTagIndicator<Graph> NodeNumTag;
|
marci@556
|
92 |
int nodeNum() const { return graph->nodeNum(); }
|
deba@1697
|
93 |
|
deba@1697
|
94 |
typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
|
marci@556
|
95 |
int edgeNum() const { return graph->edgeNum(); }
|
deba@1697
|
96 |
|
deba@1697
|
97 |
typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
|
deba@1697
|
98 |
Edge findEdge(const Node& source, const Node& target,
|
deba@1697
|
99 |
const Edge& prev = INVALID) {
|
deba@1697
|
100 |
return graph->findEdge(source, target, prev);
|
deba@1697
|
101 |
}
|
marci@556
|
102 |
|
deba@1697
|
103 |
Node addNode() const {
|
deba@1697
|
104 |
return Node(graph->addNode());
|
deba@1697
|
105 |
}
|
deba@1697
|
106 |
|
alpar@986
|
107 |
Edge addEdge(const Node& source, const Node& target) const {
|
deba@1697
|
108 |
return Edge(graph->addEdge(source, target));
|
deba@1697
|
109 |
}
|
marci@556
|
110 |
|
marci@556
|
111 |
void erase(const Node& i) const { graph->erase(i); }
|
marci@556
|
112 |
void erase(const Edge& i) const { graph->erase(i); }
|
marci@556
|
113 |
|
marci@556
|
114 |
void clear() const { graph->clear(); }
|
marci@556
|
115 |
|
marci@739
|
116 |
int id(const Node& v) const { return graph->id(v); }
|
marci@739
|
117 |
int id(const Edge& e) const { return graph->id(e); }
|
deba@1991
|
118 |
|
deba@2031
|
119 |
Node fromNodeId(int id) const {
|
deba@2031
|
120 |
return graph->fromNodeId(id);
|
deba@2031
|
121 |
}
|
deba@2031
|
122 |
|
deba@2031
|
123 |
Edge fromEdgeId(int id) const {
|
deba@2031
|
124 |
return graph->fromEdgeId(id);
|
deba@2031
|
125 |
}
|
deba@2031
|
126 |
|
deba@1991
|
127 |
int maxNodeId() const {
|
deba@1991
|
128 |
return graph->maxNodeId();
|
deba@1991
|
129 |
}
|
deba@1991
|
130 |
|
deba@1991
|
131 |
int maxEdgeId() const {
|
deba@1991
|
132 |
return graph->maxEdgeId();
|
deba@1991
|
133 |
}
|
deba@1991
|
134 |
|
deba@1991
|
135 |
typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
|
deba@1991
|
136 |
|
deba@1991
|
137 |
NodeNotifier& getNotifier(Node) const {
|
deba@1991
|
138 |
return graph->getNotifier(Node());
|
deba@1991
|
139 |
}
|
deba@1991
|
140 |
|
deba@1991
|
141 |
typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
|
deba@1991
|
142 |
|
deba@1991
|
143 |
EdgeNotifier& getNotifier(Edge) const {
|
deba@1991
|
144 |
return graph->getNotifier(Edge());
|
deba@1991
|
145 |
}
|
marci@650
|
146 |
|
marci@970
|
147 |
template <typename _Value>
|
deba@2031
|
148 |
class NodeMap : public Graph::template NodeMap<_Value> {
|
marci@970
|
149 |
public:
|
deba@2031
|
150 |
|
deba@2031
|
151 |
typedef typename Graph::template NodeMap<_Value> Parent;
|
deba@2031
|
152 |
|
deba@2031
|
153 |
explicit NodeMap(const Adaptor& ga)
|
deba@2031
|
154 |
: Parent(*ga.graph) {}
|
deba@2031
|
155 |
|
deba@2031
|
156 |
NodeMap(const Adaptor& ga, const _Value& value)
|
deba@1991
|
157 |
: Parent(*ga.graph, value) { }
|
deba@2031
|
158 |
|
deba@2031
|
159 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@2031
|
160 |
return operator=<NodeMap>(cmap);
|
deba@2031
|
161 |
}
|
deba@2031
|
162 |
|
deba@2031
|
163 |
template <typename CMap>
|
deba@2031
|
164 |
NodeMap& operator=(const CMap& cmap) {
|
deba@2031
|
165 |
Parent::operator=(cmap);
|
deba@2031
|
166 |
return *this;
|
deba@2031
|
167 |
}
|
deba@2031
|
168 |
|
marci@970
|
169 |
};
|
marci@556
|
170 |
|
marci@970
|
171 |
template <typename _Value>
|
deba@2031
|
172 |
class EdgeMap : public Graph::template EdgeMap<_Value> {
|
marci@970
|
173 |
public:
|
deba@2031
|
174 |
|
deba@2031
|
175 |
typedef typename Graph::template EdgeMap<_Value> Parent;
|
deba@2031
|
176 |
|
deba@2031
|
177 |
explicit EdgeMap(const Adaptor& ga)
|
deba@2031
|
178 |
: Parent(*ga.graph) {}
|
deba@2031
|
179 |
|
deba@2031
|
180 |
EdgeMap(const Adaptor& ga, const _Value& value)
|
deba@2031
|
181 |
: Parent(*ga.graph, value) {}
|
deba@2031
|
182 |
|
deba@2031
|
183 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@2031
|
184 |
return operator=<EdgeMap>(cmap);
|
deba@2031
|
185 |
}
|
deba@2031
|
186 |
|
deba@2031
|
187 |
template <typename CMap>
|
deba@2031
|
188 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@2031
|
189 |
Parent::operator=(cmap);
|
deba@2031
|
190 |
return *this;
|
deba@2031
|
191 |
}
|
deba@2031
|
192 |
|
marci@970
|
193 |
};
|
deba@877
|
194 |
|
marci@556
|
195 |
};
|
marci@556
|
196 |
|
marci@970
|
197 |
template <typename _Graph>
|
alpar@1401
|
198 |
class GraphAdaptor :
|
deba@1979
|
199 |
public GraphAdaptorExtender<GraphAdaptorBase<_Graph> > {
|
marci@970
|
200 |
public:
|
marci@970
|
201 |
typedef _Graph Graph;
|
deba@1979
|
202 |
typedef GraphAdaptorExtender<GraphAdaptorBase<_Graph> > Parent;
|
marci@970
|
203 |
protected:
|
alpar@1401
|
204 |
GraphAdaptor() : Parent() { }
|
marci@569
|
205 |
|
marci@970
|
206 |
public:
|
deba@1755
|
207 |
explicit GraphAdaptor(Graph& _graph) { setGraph(_graph); }
|
marci@970
|
208 |
};
|
marci@569
|
209 |
|
deba@1991
|
210 |
/// \brief Just gives back a graph adaptor
|
deba@1991
|
211 |
///
|
deba@1991
|
212 |
/// Just gives back a graph adaptor which
|
deba@1991
|
213 |
/// should be provide original graph
|
deba@1991
|
214 |
template<typename Graph>
|
deba@1991
|
215 |
GraphAdaptor<const Graph>
|
deba@1991
|
216 |
graphAdaptor(const Graph& graph) {
|
deba@1991
|
217 |
return GraphAdaptor<const Graph>(graph);
|
deba@1991
|
218 |
}
|
deba@1991
|
219 |
|
deba@1991
|
220 |
|
marci@997
|
221 |
template <typename _Graph>
|
alpar@1401
|
222 |
class RevGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
|
marci@997
|
223 |
public:
|
marci@997
|
224 |
typedef _Graph Graph;
|
alpar@1401
|
225 |
typedef GraphAdaptorBase<_Graph> Parent;
|
marci@997
|
226 |
protected:
|
alpar@1401
|
227 |
RevGraphAdaptorBase() : Parent() { }
|
marci@997
|
228 |
public:
|
marci@997
|
229 |
typedef typename Parent::Node Node;
|
marci@997
|
230 |
typedef typename Parent::Edge Edge;
|
marci@997
|
231 |
|
marci@997
|
232 |
void firstIn(Edge& i, const Node& n) const { Parent::firstOut(i, n); }
|
marci@997
|
233 |
void firstOut(Edge& i, const Node& n ) const { Parent::firstIn(i, n); }
|
marci@997
|
234 |
|
marci@997
|
235 |
void nextIn(Edge& i) const { Parent::nextOut(i); }
|
marci@997
|
236 |
void nextOut(Edge& i) const { Parent::nextIn(i); }
|
marci@997
|
237 |
|
marci@997
|
238 |
Node source(const Edge& e) const { return Parent::target(e); }
|
marci@997
|
239 |
Node target(const Edge& e) const { return Parent::source(e); }
|
deba@1991
|
240 |
|
deba@1991
|
241 |
typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
|
deba@1991
|
242 |
Edge findEdge(const Node& source, const Node& target,
|
deba@1991
|
243 |
const Edge& prev = INVALID) {
|
deba@1991
|
244 |
return Parent::findEdge(target, source, prev);
|
deba@1991
|
245 |
}
|
deba@1991
|
246 |
|
marci@997
|
247 |
};
|
marci@997
|
248 |
|
marci@997
|
249 |
|
alpar@1949
|
250 |
///\brief A graph adaptor which reverses the orientation of the edges.
|
alpar@1949
|
251 |
///\ingroup graph_adaptors
|
alpar@1949
|
252 |
///
|
alpar@1949
|
253 |
///\warning Graph adaptors are in even more experimental
|
alpar@1949
|
254 |
///state than the other
|
alpar@879
|
255 |
///parts of the lib. Use them at you own risk.
|
alpar@879
|
256 |
///
|
alpar@1949
|
257 |
/// If \c g is defined as
|
alpar@1946
|
258 |
///\code
|
marci@923
|
259 |
/// ListGraph g;
|
alpar@1946
|
260 |
///\endcode
|
alpar@1949
|
261 |
/// then
|
alpar@1946
|
262 |
///\code
|
deba@1991
|
263 |
/// RevGraphAdaptor<ListGraph> ga(g);
|
alpar@1946
|
264 |
///\endcode
|
alpar@1949
|
265 |
///implements the graph obtained from \c g by
|
alpar@1949
|
266 |
/// reversing the orientation of its edges.
|
alpar@1946
|
267 |
|
marci@997
|
268 |
template<typename _Graph>
|
alpar@1401
|
269 |
class RevGraphAdaptor :
|
deba@1979
|
270 |
public GraphAdaptorExtender<RevGraphAdaptorBase<_Graph> > {
|
marci@650
|
271 |
public:
|
marci@997
|
272 |
typedef _Graph Graph;
|
deba@1979
|
273 |
typedef GraphAdaptorExtender<
|
alpar@1401
|
274 |
RevGraphAdaptorBase<_Graph> > Parent;
|
marci@556
|
275 |
protected:
|
alpar@1401
|
276 |
RevGraphAdaptor() { }
|
marci@556
|
277 |
public:
|
deba@1755
|
278 |
explicit RevGraphAdaptor(_Graph& _graph) { setGraph(_graph); }
|
marci@997
|
279 |
};
|
marci@556
|
280 |
|
deba@1991
|
281 |
/// \brief Just gives back a reverse graph adaptor
|
deba@1991
|
282 |
///
|
deba@1991
|
283 |
/// Just gives back a reverse graph adaptor
|
deba@1991
|
284 |
template<typename Graph>
|
deba@1991
|
285 |
RevGraphAdaptor<const Graph>
|
deba@1991
|
286 |
revGraphAdaptor(const Graph& graph) {
|
deba@1991
|
287 |
return RevGraphAdaptor<const Graph>(graph);
|
deba@1991
|
288 |
}
|
deba@1991
|
289 |
|
deba@1681
|
290 |
template <typename _Graph, typename NodeFilterMap,
|
deba@1681
|
291 |
typename EdgeFilterMap, bool checked = true>
|
alpar@1401
|
292 |
class SubGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
|
marci@992
|
293 |
public:
|
marci@992
|
294 |
typedef _Graph Graph;
|
deba@2031
|
295 |
typedef SubGraphAdaptorBase Adaptor;
|
alpar@1401
|
296 |
typedef GraphAdaptorBase<_Graph> Parent;
|
marci@992
|
297 |
protected:
|
marci@992
|
298 |
NodeFilterMap* node_filter_map;
|
marci@992
|
299 |
EdgeFilterMap* edge_filter_map;
|
alpar@1401
|
300 |
SubGraphAdaptorBase() : Parent(),
|
marci@992
|
301 |
node_filter_map(0), edge_filter_map(0) { }
|
marci@775
|
302 |
|
marci@992
|
303 |
void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
|
marci@992
|
304 |
node_filter_map=&_node_filter_map;
|
marci@992
|
305 |
}
|
marci@992
|
306 |
void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
|
marci@992
|
307 |
edge_filter_map=&_edge_filter_map;
|
marci@992
|
308 |
}
|
marci@992
|
309 |
|
marci@992
|
310 |
public:
|
marci@992
|
311 |
|
marci@992
|
312 |
typedef typename Parent::Node Node;
|
marci@992
|
313 |
typedef typename Parent::Edge Edge;
|
marci@992
|
314 |
|
marci@992
|
315 |
void first(Node& i) const {
|
marci@992
|
316 |
Parent::first(i);
|
marci@992
|
317 |
while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i);
|
marci@992
|
318 |
}
|
deba@1681
|
319 |
|
deba@1681
|
320 |
void first(Edge& i) const {
|
deba@1681
|
321 |
Parent::first(i);
|
deba@1681
|
322 |
while (i!=INVALID && (!(*edge_filter_map)[i]
|
deba@1681
|
323 |
|| !(*node_filter_map)[Parent::source(i)]
|
deba@1681
|
324 |
|| !(*node_filter_map)[Parent::target(i)])) Parent::next(i);
|
deba@1681
|
325 |
}
|
deba@1681
|
326 |
|
deba@1681
|
327 |
void firstIn(Edge& i, const Node& n) const {
|
deba@1681
|
328 |
Parent::firstIn(i, n);
|
deba@1681
|
329 |
while (i!=INVALID && (!(*edge_filter_map)[i]
|
deba@1681
|
330 |
|| !(*node_filter_map)[Parent::source(i)])) Parent::nextIn(i);
|
deba@1681
|
331 |
}
|
deba@1681
|
332 |
|
deba@1681
|
333 |
void firstOut(Edge& i, const Node& n) const {
|
deba@1681
|
334 |
Parent::firstOut(i, n);
|
deba@1681
|
335 |
while (i!=INVALID && (!(*edge_filter_map)[i]
|
deba@1681
|
336 |
|| !(*node_filter_map)[Parent::target(i)])) Parent::nextOut(i);
|
deba@1681
|
337 |
}
|
deba@1681
|
338 |
|
deba@1681
|
339 |
void next(Node& i) const {
|
deba@1681
|
340 |
Parent::next(i);
|
deba@1681
|
341 |
while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i);
|
deba@1681
|
342 |
}
|
deba@1681
|
343 |
|
deba@1681
|
344 |
void next(Edge& i) const {
|
deba@1681
|
345 |
Parent::next(i);
|
deba@1681
|
346 |
while (i!=INVALID && (!(*edge_filter_map)[i]
|
deba@1681
|
347 |
|| !(*node_filter_map)[Parent::source(i)]
|
deba@1681
|
348 |
|| !(*node_filter_map)[Parent::target(i)])) Parent::next(i);
|
deba@1681
|
349 |
}
|
deba@1681
|
350 |
|
deba@1681
|
351 |
void nextIn(Edge& i) const {
|
deba@1681
|
352 |
Parent::nextIn(i);
|
deba@1681
|
353 |
while (i!=INVALID && (!(*edge_filter_map)[i]
|
deba@1681
|
354 |
|| !(*node_filter_map)[Parent::source(i)])) Parent::nextIn(i);
|
deba@1681
|
355 |
}
|
deba@1681
|
356 |
|
deba@1681
|
357 |
void nextOut(Edge& i) const {
|
deba@1681
|
358 |
Parent::nextOut(i);
|
deba@1681
|
359 |
while (i!=INVALID && (!(*edge_filter_map)[i]
|
deba@1681
|
360 |
|| !(*node_filter_map)[Parent::target(i)])) Parent::nextOut(i);
|
deba@1681
|
361 |
}
|
deba@1681
|
362 |
|
klao@1951
|
363 |
///\e
|
alpar@1949
|
364 |
|
klao@1951
|
365 |
/// This function hides \c n in the graph, i.e. the iteration
|
klao@1951
|
366 |
/// jumps over it. This is done by simply setting the value of \c n
|
klao@1951
|
367 |
/// to be false in the corresponding node-map.
|
deba@1681
|
368 |
void hide(const Node& n) const { node_filter_map->set(n, false); }
|
deba@1681
|
369 |
|
klao@1951
|
370 |
///\e
|
alpar@1949
|
371 |
|
klao@1951
|
372 |
/// This function hides \c e in the graph, i.e. the iteration
|
klao@1951
|
373 |
/// jumps over it. This is done by simply setting the value of \c e
|
klao@1951
|
374 |
/// to be false in the corresponding edge-map.
|
deba@1681
|
375 |
void hide(const Edge& e) const { edge_filter_map->set(e, false); }
|
deba@1681
|
376 |
|
klao@1951
|
377 |
///\e
|
alpar@1949
|
378 |
|
klao@1951
|
379 |
/// The value of \c n is set to be true in the node-map which stores
|
klao@1951
|
380 |
/// hide information. If \c n was hidden previuosly, then it is shown
|
klao@1951
|
381 |
/// again
|
deba@1681
|
382 |
void unHide(const Node& n) const { node_filter_map->set(n, true); }
|
deba@1681
|
383 |
|
klao@1951
|
384 |
///\e
|
alpar@1949
|
385 |
|
klao@1951
|
386 |
/// The value of \c e is set to be true in the edge-map which stores
|
klao@1951
|
387 |
/// hide information. If \c e was hidden previuosly, then it is shown
|
klao@1951
|
388 |
/// again
|
deba@1681
|
389 |
void unHide(const Edge& e) const { edge_filter_map->set(e, true); }
|
deba@1681
|
390 |
|
klao@1951
|
391 |
/// Returns true if \c n is hidden.
|
alpar@1949
|
392 |
|
klao@1951
|
393 |
///\e
|
klao@1951
|
394 |
///
|
deba@1681
|
395 |
bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
|
deba@1681
|
396 |
|
klao@1951
|
397 |
/// Returns true if \c n is hidden.
|
alpar@1949
|
398 |
|
klao@1951
|
399 |
///\e
|
klao@1951
|
400 |
///
|
deba@1681
|
401 |
bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
|
deba@1681
|
402 |
|
deba@1697
|
403 |
typedef False NodeNumTag;
|
deba@1697
|
404 |
typedef False EdgeNumTag;
|
deba@1991
|
405 |
|
deba@1991
|
406 |
typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
|
deba@1991
|
407 |
Edge findEdge(const Node& source, const Node& target,
|
deba@1991
|
408 |
const Edge& prev = INVALID) {
|
deba@1991
|
409 |
if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
|
deba@1991
|
410 |
return INVALID;
|
deba@1991
|
411 |
}
|
deba@1991
|
412 |
Edge edge = Parent::findEdge(source, target, prev);
|
deba@1991
|
413 |
while (edge != INVALID && !(*edge_filter_map)[edge]) {
|
deba@1991
|
414 |
edge = Parent::findEdge(source, target, edge);
|
deba@1991
|
415 |
}
|
deba@1991
|
416 |
return edge;
|
deba@1991
|
417 |
}
|
deba@2031
|
418 |
|
deba@2031
|
419 |
template <typename _Value>
|
deba@2031
|
420 |
class NodeMap
|
deba@2031
|
421 |
: public SubMapExtender<Adaptor,
|
deba@2031
|
422 |
typename Parent::template NodeMap<_Value> >
|
deba@2031
|
423 |
{
|
deba@2031
|
424 |
public:
|
deba@2031
|
425 |
typedef Adaptor Graph;
|
deba@2031
|
426 |
typedef SubMapExtender<Adaptor, typename Parent::
|
deba@2031
|
427 |
template NodeMap<_Value> > Parent;
|
deba@2031
|
428 |
|
deba@2031
|
429 |
NodeMap(const Graph& graph)
|
deba@2031
|
430 |
: Parent(graph) {}
|
deba@2031
|
431 |
NodeMap(const Graph& graph, const _Value& value)
|
deba@2031
|
432 |
: Parent(graph, value) {}
|
deba@2031
|
433 |
|
deba@2031
|
434 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@2031
|
435 |
return operator=<NodeMap>(cmap);
|
deba@2031
|
436 |
}
|
deba@2031
|
437 |
|
deba@2031
|
438 |
template <typename CMap>
|
deba@2031
|
439 |
NodeMap& operator=(const CMap& cmap) {
|
deba@2031
|
440 |
Parent::operator=(cmap);
|
deba@2031
|
441 |
return *this;
|
deba@2031
|
442 |
}
|
deba@2031
|
443 |
};
|
deba@2031
|
444 |
|
deba@2031
|
445 |
template <typename _Value>
|
deba@2031
|
446 |
class EdgeMap
|
deba@2031
|
447 |
: public SubMapExtender<Adaptor,
|
deba@2031
|
448 |
typename Parent::template EdgeMap<_Value> >
|
deba@2031
|
449 |
{
|
deba@2031
|
450 |
public:
|
deba@2031
|
451 |
typedef Adaptor Graph;
|
deba@2031
|
452 |
typedef SubMapExtender<Adaptor, typename Parent::
|
deba@2031
|
453 |
template EdgeMap<_Value> > Parent;
|
deba@2031
|
454 |
|
deba@2031
|
455 |
EdgeMap(const Graph& graph)
|
deba@2031
|
456 |
: Parent(graph) {}
|
deba@2031
|
457 |
EdgeMap(const Graph& graph, const _Value& value)
|
deba@2031
|
458 |
: Parent(graph, value) {}
|
deba@2031
|
459 |
|
deba@2031
|
460 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@2031
|
461 |
return operator=<EdgeMap>(cmap);
|
deba@2031
|
462 |
}
|
deba@2031
|
463 |
|
deba@2031
|
464 |
template <typename CMap>
|
deba@2031
|
465 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@2031
|
466 |
Parent::operator=(cmap);
|
deba@2031
|
467 |
return *this;
|
deba@2031
|
468 |
}
|
deba@2031
|
469 |
};
|
deba@2031
|
470 |
|
deba@1681
|
471 |
};
|
deba@1681
|
472 |
|
deba@1681
|
473 |
template <typename _Graph, typename NodeFilterMap, typename EdgeFilterMap>
|
deba@1681
|
474 |
class SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap, false>
|
deba@1681
|
475 |
: public GraphAdaptorBase<_Graph> {
|
deba@1681
|
476 |
public:
|
deba@1681
|
477 |
typedef _Graph Graph;
|
deba@2031
|
478 |
typedef SubGraphAdaptorBase Adaptor;
|
deba@1681
|
479 |
typedef GraphAdaptorBase<_Graph> Parent;
|
deba@1681
|
480 |
protected:
|
deba@1681
|
481 |
NodeFilterMap* node_filter_map;
|
deba@1681
|
482 |
EdgeFilterMap* edge_filter_map;
|
deba@1681
|
483 |
SubGraphAdaptorBase() : Parent(),
|
deba@1681
|
484 |
node_filter_map(0), edge_filter_map(0) { }
|
deba@1681
|
485 |
|
deba@1681
|
486 |
void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
|
deba@1681
|
487 |
node_filter_map=&_node_filter_map;
|
deba@1681
|
488 |
}
|
deba@1681
|
489 |
void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
|
deba@1681
|
490 |
edge_filter_map=&_edge_filter_map;
|
deba@1681
|
491 |
}
|
deba@1681
|
492 |
|
deba@1681
|
493 |
public:
|
deba@1681
|
494 |
|
deba@1681
|
495 |
typedef typename Parent::Node Node;
|
deba@1681
|
496 |
typedef typename Parent::Edge Edge;
|
deba@1681
|
497 |
|
deba@1681
|
498 |
void first(Node& i) const {
|
deba@1681
|
499 |
Parent::first(i);
|
deba@1681
|
500 |
while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i);
|
deba@1681
|
501 |
}
|
deba@1681
|
502 |
|
marci@992
|
503 |
void first(Edge& i) const {
|
marci@992
|
504 |
Parent::first(i);
|
marci@992
|
505 |
while (i!=INVALID && !(*edge_filter_map)[i]) Parent::next(i);
|
marci@992
|
506 |
}
|
deba@1681
|
507 |
|
marci@992
|
508 |
void firstIn(Edge& i, const Node& n) const {
|
marci@992
|
509 |
Parent::firstIn(i, n);
|
marci@992
|
510 |
while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextIn(i);
|
marci@992
|
511 |
}
|
deba@1681
|
512 |
|
marci@992
|
513 |
void firstOut(Edge& i, const Node& n) const {
|
marci@992
|
514 |
Parent::firstOut(i, n);
|
marci@992
|
515 |
while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextOut(i);
|
marci@992
|
516 |
}
|
marci@992
|
517 |
|
marci@992
|
518 |
void next(Node& i) const {
|
marci@992
|
519 |
Parent::next(i);
|
marci@992
|
520 |
while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i);
|
marci@992
|
521 |
}
|
marci@992
|
522 |
void next(Edge& i) const {
|
marci@992
|
523 |
Parent::next(i);
|
marci@992
|
524 |
while (i!=INVALID && !(*edge_filter_map)[i]) Parent::next(i);
|
marci@992
|
525 |
}
|
marci@992
|
526 |
void nextIn(Edge& i) const {
|
marci@992
|
527 |
Parent::nextIn(i);
|
marci@992
|
528 |
while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextIn(i);
|
marci@992
|
529 |
}
|
deba@1681
|
530 |
|
marci@992
|
531 |
void nextOut(Edge& i) const {
|
marci@992
|
532 |
Parent::nextOut(i);
|
marci@992
|
533 |
while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextOut(i);
|
marci@992
|
534 |
}
|
marci@992
|
535 |
|
klao@1951
|
536 |
///\e
|
alpar@1949
|
537 |
|
klao@1951
|
538 |
/// This function hides \c n in the graph, i.e. the iteration
|
klao@1951
|
539 |
/// jumps over it. This is done by simply setting the value of \c n
|
klao@1951
|
540 |
/// to be false in the corresponding node-map.
|
marci@992
|
541 |
void hide(const Node& n) const { node_filter_map->set(n, false); }
|
marci@992
|
542 |
|
klao@1951
|
543 |
///\e
|
alpar@1949
|
544 |
|
klao@1951
|
545 |
/// This function hides \c e in the graph, i.e. the iteration
|
klao@1951
|
546 |
/// jumps over it. This is done by simply setting the value of \c e
|
klao@1951
|
547 |
/// to be false in the corresponding edge-map.
|
marci@992
|
548 |
void hide(const Edge& e) const { edge_filter_map->set(e, false); }
|
marci@992
|
549 |
|
klao@1951
|
550 |
///\e
|
alpar@1949
|
551 |
|
klao@1951
|
552 |
/// The value of \c n is set to be true in the node-map which stores
|
klao@1951
|
553 |
/// hide information. If \c n was hidden previuosly, then it is shown
|
klao@1951
|
554 |
/// again
|
marci@992
|
555 |
void unHide(const Node& n) const { node_filter_map->set(n, true); }
|
marci@992
|
556 |
|
klao@1951
|
557 |
///\e
|
alpar@1949
|
558 |
|
klao@1951
|
559 |
/// The value of \c e is set to be true in the edge-map which stores
|
klao@1951
|
560 |
/// hide information. If \c e was hidden previuosly, then it is shown
|
klao@1951
|
561 |
/// again
|
marci@992
|
562 |
void unHide(const Edge& e) const { edge_filter_map->set(e, true); }
|
marci@992
|
563 |
|
klao@1951
|
564 |
/// Returns true if \c n is hidden.
|
alpar@1949
|
565 |
|
klao@1951
|
566 |
///\e
|
klao@1951
|
567 |
///
|
marci@992
|
568 |
bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
|
marci@992
|
569 |
|
klao@1951
|
570 |
/// Returns true if \c n is hidden.
|
alpar@1949
|
571 |
|
klao@1951
|
572 |
///\e
|
klao@1951
|
573 |
///
|
marci@992
|
574 |
bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
|
marci@992
|
575 |
|
deba@1697
|
576 |
typedef False NodeNumTag;
|
deba@1697
|
577 |
typedef False EdgeNumTag;
|
deba@1991
|
578 |
|
deba@1991
|
579 |
typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
|
deba@1991
|
580 |
Edge findEdge(const Node& source, const Node& target,
|
deba@1991
|
581 |
const Edge& prev = INVALID) {
|
deba@1991
|
582 |
if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
|
deba@1991
|
583 |
return INVALID;
|
deba@1991
|
584 |
}
|
deba@1991
|
585 |
Edge edge = Parent::findEdge(source, target, prev);
|
deba@1991
|
586 |
while (edge != INVALID && !(*edge_filter_map)[edge]) {
|
deba@1991
|
587 |
edge = Parent::findEdge(source, target, edge);
|
deba@1991
|
588 |
}
|
deba@1991
|
589 |
return edge;
|
deba@1991
|
590 |
}
|
deba@2031
|
591 |
|
deba@2031
|
592 |
template <typename _Value>
|
deba@2031
|
593 |
class NodeMap
|
deba@2031
|
594 |
: public SubMapExtender<Adaptor,
|
deba@2031
|
595 |
typename Parent::template NodeMap<_Value> >
|
deba@2031
|
596 |
{
|
deba@2031
|
597 |
public:
|
deba@2031
|
598 |
typedef Adaptor Graph;
|
deba@2031
|
599 |
typedef SubMapExtender<Adaptor, typename Parent::
|
deba@2031
|
600 |
template NodeMap<_Value> > Parent;
|
deba@2031
|
601 |
|
deba@2031
|
602 |
NodeMap(const Graph& graph)
|
deba@2031
|
603 |
: Parent(graph) {}
|
deba@2031
|
604 |
NodeMap(const Graph& graph, const _Value& value)
|
deba@2031
|
605 |
: Parent(graph, value) {}
|
deba@2031
|
606 |
|
deba@2031
|
607 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@2031
|
608 |
return operator=<NodeMap>(cmap);
|
deba@2031
|
609 |
}
|
deba@2031
|
610 |
|
deba@2031
|
611 |
template <typename CMap>
|
deba@2031
|
612 |
NodeMap& operator=(const CMap& cmap) {
|
deba@2031
|
613 |
Parent::operator=(cmap);
|
deba@2031
|
614 |
return *this;
|
deba@2031
|
615 |
}
|
deba@2031
|
616 |
};
|
deba@2031
|
617 |
|
deba@2031
|
618 |
template <typename _Value>
|
deba@2031
|
619 |
class EdgeMap
|
deba@2031
|
620 |
: public SubMapExtender<Adaptor,
|
deba@2031
|
621 |
typename Parent::template EdgeMap<_Value> >
|
deba@2031
|
622 |
{
|
deba@2031
|
623 |
public:
|
deba@2031
|
624 |
typedef Adaptor Graph;
|
deba@2031
|
625 |
typedef SubMapExtender<Adaptor, typename Parent::
|
deba@2031
|
626 |
template EdgeMap<_Value> > Parent;
|
deba@2031
|
627 |
|
deba@2031
|
628 |
EdgeMap(const Graph& graph)
|
deba@2031
|
629 |
: Parent(graph) {}
|
deba@2031
|
630 |
EdgeMap(const Graph& graph, const _Value& value)
|
deba@2031
|
631 |
: Parent(graph, value) {}
|
deba@2031
|
632 |
|
deba@2031
|
633 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@2031
|
634 |
return operator=<EdgeMap>(cmap);
|
deba@2031
|
635 |
}
|
deba@2031
|
636 |
|
deba@2031
|
637 |
template <typename CMap>
|
deba@2031
|
638 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@2031
|
639 |
Parent::operator=(cmap);
|
deba@2031
|
640 |
return *this;
|
deba@2031
|
641 |
}
|
deba@2031
|
642 |
};
|
deba@2031
|
643 |
|
marci@992
|
644 |
};
|
marci@775
|
645 |
|
klao@1951
|
646 |
/// \brief A graph adaptor for hiding nodes and edges from a graph.
|
klao@1951
|
647 |
/// \ingroup graph_adaptors
|
klao@1951
|
648 |
///
|
klao@1951
|
649 |
/// \warning Graph adaptors are in even more experimental state than the
|
klao@1951
|
650 |
/// other parts of the lib. Use them at you own risk.
|
klao@1951
|
651 |
///
|
klao@1951
|
652 |
/// SubGraphAdaptor shows the graph with filtered node-set and
|
klao@1951
|
653 |
/// edge-set. If the \c checked parameter is true then it filters the edgeset
|
klao@1951
|
654 |
/// to do not get invalid edges without source or target.
|
klao@1952
|
655 |
/// Let \f$ G=(V, A) \f$ be a directed graph
|
klao@1951
|
656 |
/// and suppose that the graph instance \c g of type ListGraph
|
klao@1952
|
657 |
/// implements \f$ G \f$.
|
klao@1952
|
658 |
/// Let moreover \f$ b_V \f$ and \f$ b_A \f$ be bool-valued functions resp.
|
klao@1951
|
659 |
/// on the node-set and edge-set.
|
klao@1951
|
660 |
/// SubGraphAdaptor<...>::NodeIt iterates
|
klao@1952
|
661 |
/// on the node-set \f$ \{v\in V : b_V(v)=true\} \f$ and
|
klao@1951
|
662 |
/// SubGraphAdaptor<...>::EdgeIt iterates
|
klao@1952
|
663 |
/// on the edge-set \f$ \{e\in A : b_A(e)=true\} \f$. Similarly,
|
klao@1951
|
664 |
/// SubGraphAdaptor<...>::OutEdgeIt and
|
klao@1951
|
665 |
/// SubGraphAdaptor<...>::InEdgeIt iterates
|
klao@1951
|
666 |
/// only on edges leaving and entering a specific node which have true value.
|
klao@1951
|
667 |
///
|
klao@1951
|
668 |
/// If the \c checked template parameter is false then we have to note that
|
klao@1951
|
669 |
/// the node-iterator cares only the filter on the node-set, and the
|
klao@1951
|
670 |
/// edge-iterator cares only the filter on the edge-set.
|
klao@1951
|
671 |
/// This way the edge-map
|
klao@1951
|
672 |
/// should filter all edges which's source or target is filtered by the
|
klao@1951
|
673 |
/// node-filter.
|
alpar@1957
|
674 |
///\code
|
klao@1951
|
675 |
/// typedef ListGraph Graph;
|
klao@1951
|
676 |
/// Graph g;
|
klao@1951
|
677 |
/// typedef Graph::Node Node;
|
klao@1951
|
678 |
/// typedef Graph::Edge Edge;
|
klao@1951
|
679 |
/// Node u=g.addNode(); //node of id 0
|
klao@1951
|
680 |
/// Node v=g.addNode(); //node of id 1
|
klao@1951
|
681 |
/// Node e=g.addEdge(u, v); //edge of id 0
|
klao@1951
|
682 |
/// Node f=g.addEdge(v, u); //edge of id 1
|
klao@1951
|
683 |
/// Graph::NodeMap<bool> nm(g, true);
|
klao@1951
|
684 |
/// nm.set(u, false);
|
klao@1951
|
685 |
/// Graph::EdgeMap<bool> em(g, true);
|
klao@1951
|
686 |
/// em.set(e, false);
|
deba@1991
|
687 |
/// typedef SubGraphAdaptor<Graph, Graph::NodeMap<bool>, Graph::EdgeMap<bool> > SubGA;
|
deba@1991
|
688 |
/// SubGA ga(g, nm, em);
|
deba@1991
|
689 |
/// for (SubGA::NodeIt n(ga); n!=INVALID; ++n) std::cout << g.id(n) << std::endl;
|
klao@1951
|
690 |
/// std::cout << ":-)" << std::endl;
|
deba@1991
|
691 |
/// for (SubGA::EdgeIt e(ga); e!=INVALID; ++e) std::cout << g.id(e) << std::endl;
|
alpar@1957
|
692 |
///\endcode
|
klao@1951
|
693 |
/// The output of the above code is the following.
|
alpar@1957
|
694 |
///\code
|
klao@1951
|
695 |
/// 1
|
klao@1951
|
696 |
/// :-)
|
klao@1951
|
697 |
/// 1
|
alpar@1957
|
698 |
///\endcode
|
deba@1991
|
699 |
/// Note that \c n is of type \c SubGA::NodeIt, but it can be converted to
|
klao@1951
|
700 |
/// \c Graph::Node that is why \c g.id(n) can be applied.
|
klao@1951
|
701 |
///
|
klao@1951
|
702 |
/// For other examples see also the documentation of NodeSubGraphAdaptor and
|
klao@1951
|
703 |
/// EdgeSubGraphAdaptor.
|
klao@1951
|
704 |
///
|
klao@1951
|
705 |
/// \author Marton Makai
|
marci@1242
|
706 |
|
marci@992
|
707 |
template<typename _Graph, typename NodeFilterMap,
|
deba@1681
|
708 |
typename EdgeFilterMap, bool checked = true>
|
alpar@1401
|
709 |
class SubGraphAdaptor :
|
deba@1979
|
710 |
public GraphAdaptorExtender<
|
deba@1681
|
711 |
SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap, checked> > {
|
marci@650
|
712 |
public:
|
marci@992
|
713 |
typedef _Graph Graph;
|
deba@2031
|
714 |
typedef GraphAdaptorExtender< SubGraphAdaptorBase<_Graph, NodeFilterMap,
|
deba@2031
|
715 |
EdgeFilterMap, checked> >
|
deba@2031
|
716 |
Parent;
|
deba@2031
|
717 |
|
marci@556
|
718 |
protected:
|
alpar@1401
|
719 |
SubGraphAdaptor() { }
|
marci@992
|
720 |
public:
|
deba@2031
|
721 |
|
alpar@1401
|
722 |
SubGraphAdaptor(_Graph& _graph, NodeFilterMap& _node_filter_map,
|
marci@992
|
723 |
EdgeFilterMap& _edge_filter_map) {
|
marci@992
|
724 |
setGraph(_graph);
|
marci@992
|
725 |
setNodeFilterMap(_node_filter_map);
|
marci@992
|
726 |
setEdgeFilterMap(_edge_filter_map);
|
marci@992
|
727 |
}
|
deba@2031
|
728 |
|
marci@992
|
729 |
};
|
marci@556
|
730 |
|
deba@1991
|
731 |
/// \brief Just gives back a sub graph adaptor
|
deba@1991
|
732 |
///
|
deba@1991
|
733 |
/// Just gives back a sub graph adaptor
|
deba@1991
|
734 |
template<typename Graph, typename NodeFilterMap, typename EdgeFilterMap>
|
deba@1991
|
735 |
SubGraphAdaptor<const Graph, NodeFilterMap, EdgeFilterMap>
|
deba@1991
|
736 |
subGraphAdaptor(const Graph& graph,
|
deba@1991
|
737 |
NodeFilterMap& nfm, EdgeFilterMap& efm) {
|
deba@1991
|
738 |
return SubGraphAdaptor<const Graph, NodeFilterMap, EdgeFilterMap>
|
deba@1991
|
739 |
(graph, nfm, efm);
|
deba@1991
|
740 |
}
|
deba@1991
|
741 |
|
deba@1991
|
742 |
template<typename Graph, typename NodeFilterMap, typename EdgeFilterMap>
|
deba@1991
|
743 |
SubGraphAdaptor<const Graph, const NodeFilterMap, EdgeFilterMap>
|
deba@1991
|
744 |
subGraphAdaptor(const Graph& graph,
|
deba@1991
|
745 |
NodeFilterMap& nfm, EdgeFilterMap& efm) {
|
deba@1991
|
746 |
return SubGraphAdaptor<const Graph, const NodeFilterMap, EdgeFilterMap>
|
deba@1991
|
747 |
(graph, nfm, efm);
|
deba@1991
|
748 |
}
|
deba@1991
|
749 |
|
deba@1991
|
750 |
template<typename Graph, typename NodeFilterMap, typename EdgeFilterMap>
|
deba@1991
|
751 |
SubGraphAdaptor<const Graph, NodeFilterMap, const EdgeFilterMap>
|
deba@1991
|
752 |
subGraphAdaptor(const Graph& graph,
|
deba@1991
|
753 |
NodeFilterMap& nfm, EdgeFilterMap& efm) {
|
deba@1991
|
754 |
return SubGraphAdaptor<const Graph, NodeFilterMap, const EdgeFilterMap>
|
deba@1991
|
755 |
(graph, nfm, efm);
|
deba@1991
|
756 |
}
|
deba@1991
|
757 |
|
deba@1991
|
758 |
template<typename Graph, typename NodeFilterMap, typename EdgeFilterMap>
|
deba@1991
|
759 |
SubGraphAdaptor<const Graph, const NodeFilterMap, const EdgeFilterMap>
|
deba@1991
|
760 |
subGraphAdaptor(const Graph& graph,
|
deba@1991
|
761 |
NodeFilterMap& nfm, EdgeFilterMap& efm) {
|
deba@1991
|
762 |
return SubGraphAdaptor<const Graph, const NodeFilterMap,
|
deba@1991
|
763 |
const EdgeFilterMap>(graph, nfm, efm);
|
deba@1991
|
764 |
}
|
deba@1991
|
765 |
|
marci@556
|
766 |
|
marci@569
|
767 |
|
klao@1951
|
768 |
///\brief An adaptor for hiding nodes from a graph.
|
klao@1951
|
769 |
///\ingroup graph_adaptors
|
klao@1951
|
770 |
///
|
klao@1951
|
771 |
///\warning Graph adaptors are in even more experimental state
|
klao@1951
|
772 |
///than the other
|
klao@1951
|
773 |
///parts of the lib. Use them at you own risk.
|
klao@1951
|
774 |
///
|
klao@1951
|
775 |
///An adaptor for hiding nodes from a graph.
|
klao@1951
|
776 |
///This adaptor specializes SubGraphAdaptor in the way that only
|
klao@1951
|
777 |
///the node-set
|
klao@1951
|
778 |
///can be filtered. In usual case the checked parameter is true, we get the
|
klao@1951
|
779 |
///induced subgraph. But if the checked parameter is false then we can only
|
klao@1951
|
780 |
///filter only isolated nodes.
|
klao@1951
|
781 |
///\author Marton Makai
|
deba@1681
|
782 |
template<typename Graph, typename NodeFilterMap, bool checked = true>
|
alpar@1401
|
783 |
class NodeSubGraphAdaptor :
|
alpar@1401
|
784 |
public SubGraphAdaptor<Graph, NodeFilterMap,
|
deba@1681
|
785 |
ConstMap<typename Graph::Edge,bool>, checked> {
|
marci@933
|
786 |
public:
|
deba@2031
|
787 |
|
alpar@1401
|
788 |
typedef SubGraphAdaptor<Graph, NodeFilterMap,
|
deba@2031
|
789 |
ConstMap<typename Graph::Edge,bool>, checked >
|
deba@2031
|
790 |
Parent;
|
deba@2031
|
791 |
|
marci@933
|
792 |
protected:
|
marci@933
|
793 |
ConstMap<typename Graph::Edge, bool> const_true_map;
|
deba@1991
|
794 |
|
deba@1991
|
795 |
NodeSubGraphAdaptor() : const_true_map(true) {
|
deba@1991
|
796 |
Parent::setEdgeFilterMap(const_true_map);
|
deba@1991
|
797 |
}
|
deba@1991
|
798 |
|
marci@933
|
799 |
public:
|
deba@2031
|
800 |
|
alpar@1401
|
801 |
NodeSubGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map) :
|
marci@933
|
802 |
Parent(), const_true_map(true) {
|
marci@933
|
803 |
Parent::setGraph(_graph);
|
marci@933
|
804 |
Parent::setNodeFilterMap(_node_filter_map);
|
marci@933
|
805 |
Parent::setEdgeFilterMap(const_true_map);
|
marci@933
|
806 |
}
|
deba@2031
|
807 |
|
marci@933
|
808 |
};
|
marci@933
|
809 |
|
marci@933
|
810 |
|
deba@1991
|
811 |
/// \brief Just gives back a node sub graph adaptor
|
deba@1991
|
812 |
///
|
deba@1991
|
813 |
/// Just gives back a node sub graph adaptor
|
deba@1991
|
814 |
template<typename Graph, typename NodeFilterMap>
|
deba@1991
|
815 |
NodeSubGraphAdaptor<const Graph, NodeFilterMap>
|
deba@1991
|
816 |
nodeSubGraphAdaptor(const Graph& graph, NodeFilterMap& nfm) {
|
deba@1991
|
817 |
return NodeSubGraphAdaptor<const Graph, NodeFilterMap>(graph, nfm);
|
deba@1991
|
818 |
}
|
deba@1991
|
819 |
|
deba@1991
|
820 |
template<typename Graph, typename NodeFilterMap>
|
deba@1991
|
821 |
NodeSubGraphAdaptor<const Graph, const NodeFilterMap>
|
deba@1991
|
822 |
nodeSubGraphAdaptor(const Graph& graph, const NodeFilterMap& nfm) {
|
deba@1991
|
823 |
return NodeSubGraphAdaptor<const Graph, const NodeFilterMap>(graph, nfm);
|
deba@1991
|
824 |
}
|
deba@1991
|
825 |
|
klao@1951
|
826 |
///\brief An adaptor for hiding edges from a graph.
|
klao@1951
|
827 |
///
|
klao@1951
|
828 |
///\warning Graph adaptors are in even more experimental state
|
klao@1951
|
829 |
///than the other parts of the lib. Use them at you own risk.
|
klao@1951
|
830 |
///
|
klao@1951
|
831 |
///An adaptor for hiding edges from a graph.
|
klao@1951
|
832 |
///This adaptor specializes SubGraphAdaptor in the way that
|
klao@1951
|
833 |
///only the edge-set
|
klao@1951
|
834 |
///can be filtered. The usefulness of this adaptor is demonstrated in the
|
klao@1951
|
835 |
///problem of searching a maximum number of edge-disjoint shortest paths
|
klao@1951
|
836 |
///between
|
klao@1951
|
837 |
///two nodes \c s and \c t. Shortest here means being shortest w.r.t.
|
klao@1951
|
838 |
///non-negative edge-lengths. Note that
|
klao@1951
|
839 |
///the comprehension of the presented solution
|
klao@1951
|
840 |
///need's some elementary knowledge from combinatorial optimization.
|
klao@1951
|
841 |
///
|
klao@1951
|
842 |
///If a single shortest path is to be
|
klao@1951
|
843 |
///searched between \c s and \c t, then this can be done easily by
|
klao@1951
|
844 |
///applying the Dijkstra algorithm. What happens, if a maximum number of
|
klao@1951
|
845 |
///edge-disjoint shortest paths is to be computed. It can be proved that an
|
klao@1951
|
846 |
///edge can be in a shortest path if and only
|
klao@1951
|
847 |
///if it is tight with respect to
|
klao@1951
|
848 |
///the potential function computed by Dijkstra.
|
klao@1951
|
849 |
///Moreover, any path containing
|
klao@1951
|
850 |
///only such edges is a shortest one.
|
klao@1951
|
851 |
///Thus we have to compute a maximum number
|
klao@1951
|
852 |
///of edge-disjoint paths between \c s and \c t in
|
klao@1951
|
853 |
///the graph which has edge-set
|
klao@1951
|
854 |
///all the tight edges. The computation will be demonstrated
|
klao@1951
|
855 |
///on the following
|
klao@1951
|
856 |
///graph, which is read from the dimacs file \c sub_graph_adaptor_demo.dim.
|
klao@1951
|
857 |
///The full source code is available in \ref sub_graph_adaptor_demo.cc.
|
klao@1951
|
858 |
///If you are interested in more demo programs, you can use
|
klao@1951
|
859 |
///\ref dim_to_dot.cc to generate .dot files from dimacs files.
|
klao@1951
|
860 |
///The .dot file of the following figure was generated by
|
klao@1951
|
861 |
///the demo program \ref dim_to_dot.cc.
|
klao@1951
|
862 |
///
|
klao@1951
|
863 |
///\dot
|
klao@1951
|
864 |
///digraph lemon_dot_example {
|
klao@1951
|
865 |
///node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
|
klao@1951
|
866 |
///n0 [ label="0 (s)" ];
|
klao@1951
|
867 |
///n1 [ label="1" ];
|
klao@1951
|
868 |
///n2 [ label="2" ];
|
klao@1951
|
869 |
///n3 [ label="3" ];
|
klao@1951
|
870 |
///n4 [ label="4" ];
|
klao@1951
|
871 |
///n5 [ label="5" ];
|
klao@1951
|
872 |
///n6 [ label="6 (t)" ];
|
klao@1951
|
873 |
///edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
|
klao@1951
|
874 |
///n5 -> n6 [ label="9, length:4" ];
|
klao@1951
|
875 |
///n4 -> n6 [ label="8, length:2" ];
|
klao@1951
|
876 |
///n3 -> n5 [ label="7, length:1" ];
|
klao@1951
|
877 |
///n2 -> n5 [ label="6, length:3" ];
|
klao@1951
|
878 |
///n2 -> n6 [ label="5, length:5" ];
|
klao@1951
|
879 |
///n2 -> n4 [ label="4, length:2" ];
|
klao@1951
|
880 |
///n1 -> n4 [ label="3, length:3" ];
|
klao@1951
|
881 |
///n0 -> n3 [ label="2, length:1" ];
|
klao@1951
|
882 |
///n0 -> n2 [ label="1, length:2" ];
|
klao@1951
|
883 |
///n0 -> n1 [ label="0, length:3" ];
|
klao@1951
|
884 |
///}
|
klao@1951
|
885 |
///\enddot
|
klao@1951
|
886 |
///
|
klao@1951
|
887 |
///\code
|
klao@1951
|
888 |
///Graph g;
|
klao@1951
|
889 |
///Node s, t;
|
klao@1951
|
890 |
///LengthMap length(g);
|
klao@1951
|
891 |
///
|
klao@1951
|
892 |
///readDimacs(std::cin, g, length, s, t);
|
klao@1951
|
893 |
///
|
klao@1951
|
894 |
///cout << "edges with lengths (of form id, source--length->target): " << endl;
|
klao@1951
|
895 |
///for(EdgeIt e(g); e!=INVALID; ++e)
|
klao@1951
|
896 |
/// cout << g.id(e) << ", " << g.id(g.source(e)) << "--"
|
klao@1951
|
897 |
/// << length[e] << "->" << g.id(g.target(e)) << endl;
|
klao@1951
|
898 |
///
|
klao@1951
|
899 |
///cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
|
klao@1951
|
900 |
///\endcode
|
klao@1951
|
901 |
///Next, the potential function is computed with Dijkstra.
|
klao@1951
|
902 |
///\code
|
klao@1951
|
903 |
///typedef Dijkstra<Graph, LengthMap> Dijkstra;
|
klao@1951
|
904 |
///Dijkstra dijkstra(g, length);
|
klao@1951
|
905 |
///dijkstra.run(s);
|
klao@1951
|
906 |
///\endcode
|
klao@1951
|
907 |
///Next, we consrtruct a map which filters the edge-set to the tight edges.
|
klao@1951
|
908 |
///\code
|
klao@1951
|
909 |
///typedef TightEdgeFilterMap<Graph, const Dijkstra::DistMap, LengthMap>
|
klao@1951
|
910 |
/// TightEdgeFilter;
|
klao@1951
|
911 |
///TightEdgeFilter tight_edge_filter(g, dijkstra.distMap(), length);
|
klao@1951
|
912 |
///
|
deba@1991
|
913 |
///typedef EdgeSubGraphAdaptor<Graph, TightEdgeFilter> SubGA;
|
deba@1991
|
914 |
///SubGA ga(g, tight_edge_filter);
|
klao@1951
|
915 |
///\endcode
|
klao@1951
|
916 |
///Then, the maximum nimber of edge-disjoint \c s-\c t paths are computed
|
klao@1951
|
917 |
///with a max flow algorithm Preflow.
|
klao@1951
|
918 |
///\code
|
klao@1951
|
919 |
///ConstMap<Edge, int> const_1_map(1);
|
klao@1951
|
920 |
///Graph::EdgeMap<int> flow(g, 0);
|
klao@1951
|
921 |
///
|
deba@1991
|
922 |
///Preflow<SubGA, int, ConstMap<Edge, int>, Graph::EdgeMap<int> >
|
deba@1991
|
923 |
/// preflow(ga, s, t, const_1_map, flow);
|
klao@1951
|
924 |
///preflow.run();
|
klao@1951
|
925 |
///\endcode
|
klao@1951
|
926 |
///Last, the output is:
|
klao@1951
|
927 |
///\code
|
klao@1951
|
928 |
///cout << "maximum number of edge-disjoint shortest path: "
|
klao@1951
|
929 |
/// << preflow.flowValue() << endl;
|
klao@1951
|
930 |
///cout << "edges of the maximum number of edge-disjoint shortest s-t paths: "
|
klao@1951
|
931 |
/// << endl;
|
klao@1951
|
932 |
///for(EdgeIt e(g); e!=INVALID; ++e)
|
klao@1951
|
933 |
/// if (flow[e])
|
klao@1951
|
934 |
/// cout << " " << g.id(g.source(e)) << "--"
|
klao@1951
|
935 |
/// << length[e] << "->" << g.id(g.target(e)) << endl;
|
klao@1951
|
936 |
///\endcode
|
klao@1951
|
937 |
///The program has the following (expected :-)) output:
|
klao@1951
|
938 |
///\code
|
klao@1951
|
939 |
///edges with lengths (of form id, source--length->target):
|
klao@1951
|
940 |
/// 9, 5--4->6
|
klao@1951
|
941 |
/// 8, 4--2->6
|
klao@1951
|
942 |
/// 7, 3--1->5
|
klao@1951
|
943 |
/// 6, 2--3->5
|
klao@1951
|
944 |
/// 5, 2--5->6
|
klao@1951
|
945 |
/// 4, 2--2->4
|
klao@1951
|
946 |
/// 3, 1--3->4
|
klao@1951
|
947 |
/// 2, 0--1->3
|
klao@1951
|
948 |
/// 1, 0--2->2
|
klao@1951
|
949 |
/// 0, 0--3->1
|
klao@1951
|
950 |
///s: 0 t: 6
|
klao@1951
|
951 |
///maximum number of edge-disjoint shortest path: 2
|
klao@1951
|
952 |
///edges of the maximum number of edge-disjoint shortest s-t paths:
|
klao@1951
|
953 |
/// 9, 5--4->6
|
klao@1951
|
954 |
/// 8, 4--2->6
|
klao@1951
|
955 |
/// 7, 3--1->5
|
klao@1951
|
956 |
/// 4, 2--2->4
|
klao@1951
|
957 |
/// 2, 0--1->3
|
klao@1951
|
958 |
/// 1, 0--2->2
|
klao@1951
|
959 |
///\endcode
|
klao@1951
|
960 |
///
|
klao@1951
|
961 |
///\author Marton Makai
|
marci@932
|
962 |
template<typename Graph, typename EdgeFilterMap>
|
alpar@1401
|
963 |
class EdgeSubGraphAdaptor :
|
alpar@1401
|
964 |
public SubGraphAdaptor<Graph, ConstMap<typename Graph::Node,bool>,
|
deba@1681
|
965 |
EdgeFilterMap, false> {
|
marci@932
|
966 |
public:
|
alpar@1401
|
967 |
typedef SubGraphAdaptor<Graph, ConstMap<typename Graph::Node,bool>,
|
deba@1685
|
968 |
EdgeFilterMap, false> Parent;
|
marci@932
|
969 |
protected:
|
marci@932
|
970 |
ConstMap<typename Graph::Node, bool> const_true_map;
|
deba@1991
|
971 |
|
deba@1991
|
972 |
EdgeSubGraphAdaptor() : const_true_map(true) {
|
deba@1991
|
973 |
Parent::setNodeFilterMap(const_true_map);
|
deba@1991
|
974 |
}
|
deba@1991
|
975 |
|
marci@932
|
976 |
public:
|
deba@2031
|
977 |
|
alpar@1401
|
978 |
EdgeSubGraphAdaptor(Graph& _graph, EdgeFilterMap& _edge_filter_map) :
|
marci@932
|
979 |
Parent(), const_true_map(true) {
|
marci@932
|
980 |
Parent::setGraph(_graph);
|
marci@932
|
981 |
Parent::setNodeFilterMap(const_true_map);
|
marci@932
|
982 |
Parent::setEdgeFilterMap(_edge_filter_map);
|
marci@932
|
983 |
}
|
deba@2031
|
984 |
|
marci@932
|
985 |
};
|
marci@932
|
986 |
|
deba@1991
|
987 |
/// \brief Just gives back an edge sub graph adaptor
|
deba@1991
|
988 |
///
|
deba@1991
|
989 |
/// Just gives back an edge sub graph adaptor
|
deba@1991
|
990 |
template<typename Graph, typename EdgeFilterMap>
|
deba@1991
|
991 |
EdgeSubGraphAdaptor<const Graph, EdgeFilterMap>
|
deba@1991
|
992 |
edgeSubGraphAdaptor(const Graph& graph, EdgeFilterMap& efm) {
|
deba@1991
|
993 |
return EdgeSubGraphAdaptor<const Graph, EdgeFilterMap>(graph, efm);
|
deba@1991
|
994 |
}
|
deba@1991
|
995 |
|
deba@1991
|
996 |
template<typename Graph, typename EdgeFilterMap>
|
deba@1991
|
997 |
EdgeSubGraphAdaptor<const Graph, const EdgeFilterMap>
|
deba@1991
|
998 |
edgeSubGraphAdaptor(const Graph& graph, const EdgeFilterMap& efm) {
|
deba@1991
|
999 |
return EdgeSubGraphAdaptor<const Graph, const EdgeFilterMap>(graph, efm);
|
deba@1991
|
1000 |
}
|
deba@1991
|
1001 |
|
deba@1991
|
1002 |
template <typename _Graph, typename Enable = void>
|
deba@1980
|
1003 |
class UndirGraphAdaptorBase :
|
deba@1979
|
1004 |
public UGraphBaseExtender<GraphAdaptorBase<_Graph> > {
|
marci@1383
|
1005 |
public:
|
marci@1383
|
1006 |
typedef _Graph Graph;
|
deba@2031
|
1007 |
typedef UndirGraphAdaptorBase Adaptor;
|
deba@1979
|
1008 |
typedef UGraphBaseExtender<GraphAdaptorBase<_Graph> > Parent;
|
deba@1991
|
1009 |
|
marci@1383
|
1010 |
protected:
|
deba@1991
|
1011 |
|
deba@1991
|
1012 |
UndirGraphAdaptorBase() : Parent() {}
|
deba@1991
|
1013 |
|
marci@1383
|
1014 |
public:
|
deba@1991
|
1015 |
|
klao@1909
|
1016 |
typedef typename Parent::UEdge UEdge;
|
marci@1383
|
1017 |
typedef typename Parent::Edge Edge;
|
deba@1991
|
1018 |
|
deba@2031
|
1019 |
private:
|
marci@1383
|
1020 |
|
deba@1991
|
1021 |
template <typename _Value>
|
deba@2031
|
1022 |
class EdgeMapBase {
|
deba@1991
|
1023 |
private:
|
deba@1991
|
1024 |
|
deba@1991
|
1025 |
typedef typename _Graph::template EdgeMap<_Value> MapImpl;
|
deba@1991
|
1026 |
|
marci@1383
|
1027 |
public:
|
deba@1991
|
1028 |
|
deba@1991
|
1029 |
typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag;
|
deba@1991
|
1030 |
|
deba@1991
|
1031 |
typedef _Value Value;
|
marci@1383
|
1032 |
typedef Edge Key;
|
marci@1383
|
1033 |
|
deba@2031
|
1034 |
EdgeMapBase(const Adaptor& adaptor) :
|
deba@2031
|
1035 |
forward_map(*adaptor.graph), backward_map(*adaptor.graph) {}
|
marci@569
|
1036 |
|
deba@2031
|
1037 |
EdgeMapBase(const Adaptor& adaptor, const Value& v)
|
deba@2031
|
1038 |
: forward_map(*adaptor.graph, v), backward_map(*adaptor.graph, v) {}
|
marci@1383
|
1039 |
|
deba@1991
|
1040 |
void set(const Edge& e, const Value& a) {
|
deba@1991
|
1041 |
if (Parent::direction(e)) {
|
marci@1383
|
1042 |
forward_map.set(e, a);
|
deba@1991
|
1043 |
} else {
|
deba@1991
|
1044 |
backward_map.set(e, a);
|
deba@1991
|
1045 |
}
|
marci@1383
|
1046 |
}
|
marci@556
|
1047 |
|
deba@1991
|
1048 |
typename MapTraits<MapImpl>::ConstReturnValue operator[](Edge e) const {
|
deba@1991
|
1049 |
if (Parent::direction(e)) {
|
marci@1383
|
1050 |
return forward_map[e];
|
deba@1991
|
1051 |
} else {
|
marci@1383
|
1052 |
return backward_map[e];
|
deba@1991
|
1053 |
}
|
marci@556
|
1054 |
}
|
deba@1991
|
1055 |
|
deba@1991
|
1056 |
typename MapTraits<MapImpl>::ReturnValue operator[](Edge e) {
|
deba@1991
|
1057 |
if (Parent::direction(e)) {
|
deba@1991
|
1058 |
return forward_map[e];
|
deba@1991
|
1059 |
} else {
|
deba@1991
|
1060 |
return backward_map[e];
|
deba@1991
|
1061 |
}
|
deba@1991
|
1062 |
}
|
deba@1991
|
1063 |
|
deba@1991
|
1064 |
protected:
|
deba@1991
|
1065 |
|
deba@1991
|
1066 |
MapImpl forward_map, backward_map;
|
deba@1991
|
1067 |
|
marci@556
|
1068 |
};
|
deba@2031
|
1069 |
|
deba@2031
|
1070 |
public:
|
deba@2031
|
1071 |
|
deba@2031
|
1072 |
template <typename _Value>
|
deba@2031
|
1073 |
class EdgeMap
|
deba@2031
|
1074 |
: public SubMapExtender<Adaptor, EdgeMapBase<_Value> >
|
deba@2031
|
1075 |
{
|
deba@2031
|
1076 |
public:
|
deba@2031
|
1077 |
typedef Adaptor Graph;
|
deba@2031
|
1078 |
typedef SubMapExtender<Adaptor, EdgeMapBase<_Value> > Parent;
|
deba@2031
|
1079 |
|
deba@2031
|
1080 |
EdgeMap(const Graph& graph)
|
deba@2031
|
1081 |
: Parent(graph) {}
|
deba@2031
|
1082 |
EdgeMap(const Graph& graph, const _Value& value)
|
deba@2031
|
1083 |
: Parent(graph, value) {}
|
deba@2031
|
1084 |
|
deba@2031
|
1085 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@2031
|
1086 |
return operator=<EdgeMap>(cmap);
|
deba@2031
|
1087 |
}
|
deba@2031
|
1088 |
|
deba@2031
|
1089 |
template <typename CMap>
|
deba@2031
|
1090 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@2031
|
1091 |
Parent::operator=(cmap);
|
deba@2031
|
1092 |
return *this;
|
deba@2031
|
1093 |
}
|
deba@2031
|
1094 |
};
|
marci@1383
|
1095 |
|
deba@1991
|
1096 |
template <typename _Value>
|
deba@2031
|
1097 |
class UEdgeMap : public Graph::template EdgeMap<_Value> {
|
marci@1383
|
1098 |
public:
|
deba@2031
|
1099 |
|
deba@2031
|
1100 |
typedef typename Graph::template EdgeMap<_Value> Parent;
|
deba@2031
|
1101 |
|
deba@2031
|
1102 |
explicit UEdgeMap(const Adaptor& ga)
|
deba@2031
|
1103 |
: Parent(*ga.graph) {}
|
deba@1991
|
1104 |
|
deba@2031
|
1105 |
UEdgeMap(const Adaptor& ga, const _Value& value)
|
deba@2031
|
1106 |
: Parent(*ga.graph, value) {}
|
deba@1991
|
1107 |
|
deba@2031
|
1108 |
UEdgeMap& operator=(const UEdgeMap& cmap) {
|
deba@2031
|
1109 |
return operator=<UEdgeMap>(cmap);
|
deba@2031
|
1110 |
}
|
deba@1991
|
1111 |
|
deba@2031
|
1112 |
template <typename CMap>
|
deba@2031
|
1113 |
UEdgeMap& operator=(const CMap& cmap) {
|
deba@2031
|
1114 |
Parent::operator=(cmap);
|
deba@2031
|
1115 |
return *this;
|
deba@2031
|
1116 |
}
|
deba@2031
|
1117 |
|
deba@1991
|
1118 |
};
|
deba@1991
|
1119 |
|
deba@1991
|
1120 |
};
|
marci@556
|
1121 |
|
deba@1991
|
1122 |
template <typename _Graph>
|
deba@1991
|
1123 |
class UndirGraphAdaptorBase<
|
deba@1991
|
1124 |
_Graph, typename enable_if<
|
deba@1991
|
1125 |
typename _Graph::EdgeNotifier::Notifier>::type >
|
deba@1991
|
1126 |
: public UGraphBaseExtender<GraphAdaptorBase<_Graph> > {
|
deba@1991
|
1127 |
public:
|
deba@1991
|
1128 |
|
deba@1991
|
1129 |
typedef _Graph Graph;
|
deba@2031
|
1130 |
typedef UndirGraphAdaptorBase Adaptor;
|
deba@1991
|
1131 |
typedef UGraphBaseExtender<GraphAdaptorBase<_Graph> > Parent;
|
deba@1991
|
1132 |
|
deba@1991
|
1133 |
protected:
|
deba@1991
|
1134 |
|
deba@1991
|
1135 |
UndirGraphAdaptorBase()
|
deba@1999
|
1136 |
: edge_notifier(*this), edge_notifier_proxy(edge_notifier) {}
|
deba@1991
|
1137 |
|
deba@1991
|
1138 |
void setGraph(_Graph& graph) {
|
deba@1991
|
1139 |
Parent::setGraph(graph);
|
deba@1991
|
1140 |
edge_notifier_proxy.setUEdgeNotifier(graph.getNotifier(UEdge()));
|
deba@1991
|
1141 |
}
|
deba@1991
|
1142 |
|
deba@1991
|
1143 |
public:
|
deba@1991
|
1144 |
|
deba@1991
|
1145 |
~UndirGraphAdaptorBase() {
|
deba@1999
|
1146 |
edge_notifier.clear();
|
deba@1999
|
1147 |
}
|
deba@1999
|
1148 |
|
deba@1999
|
1149 |
int maxId(typename Parent::Edge) const {
|
deba@1999
|
1150 |
return Parent::maxEdgeId();
|
deba@1991
|
1151 |
}
|
deba@1991
|
1152 |
|
deba@1991
|
1153 |
|
deba@1991
|
1154 |
typedef typename Parent::UEdge UEdge;
|
deba@1991
|
1155 |
typedef typename Parent::Edge Edge;
|
deba@1991
|
1156 |
|
deba@1991
|
1157 |
typedef typename Parent::EdgeNotifier UEdgeNotifier;
|
deba@1991
|
1158 |
|
deba@1991
|
1159 |
using Parent::getNotifier;
|
deba@1991
|
1160 |
|
deba@1999
|
1161 |
typedef AlterationNotifier<UndirGraphAdaptorBase, Edge> EdgeNotifier;
|
deba@1991
|
1162 |
EdgeNotifier& getNotifier(Edge) const { return edge_notifier; }
|
deba@1991
|
1163 |
|
deba@1991
|
1164 |
protected:
|
deba@1991
|
1165 |
|
deba@1991
|
1166 |
class NotifierProxy : public UEdgeNotifier::ObserverBase {
|
deba@1991
|
1167 |
public:
|
deba@1991
|
1168 |
|
deba@1991
|
1169 |
typedef typename UEdgeNotifier::ObserverBase Parent;
|
deba@1991
|
1170 |
typedef UndirGraphAdaptorBase AdaptorBase;
|
marci@1383
|
1171 |
|
deba@1991
|
1172 |
NotifierProxy(EdgeNotifier& _edge_notifier)
|
deba@1991
|
1173 |
: Parent(), edge_notifier(_edge_notifier) {
|
marci@1383
|
1174 |
}
|
marci@556
|
1175 |
|
deba@1991
|
1176 |
virtual ~NotifierProxy() {
|
deba@1991
|
1177 |
if (Parent::attached()) {
|
deba@1991
|
1178 |
Parent::detach();
|
deba@1991
|
1179 |
}
|
marci@1383
|
1180 |
}
|
deba@1991
|
1181 |
|
deba@1991
|
1182 |
void setUEdgeNotifier(UEdgeNotifier& _uedge_notifier) {
|
deba@1991
|
1183 |
Parent::attach(_uedge_notifier);
|
deba@1991
|
1184 |
}
|
deba@1991
|
1185 |
|
deba@1991
|
1186 |
|
deba@1991
|
1187 |
protected:
|
deba@1991
|
1188 |
|
deba@1991
|
1189 |
virtual void add(const UEdge& uedge) {
|
deba@1991
|
1190 |
std::vector<Edge> edges;
|
deba@1991
|
1191 |
edges.push_back(AdaptorBase::Parent::direct(uedge, true));
|
deba@1991
|
1192 |
edges.push_back(AdaptorBase::Parent::direct(uedge, false));
|
deba@1991
|
1193 |
edge_notifier.add(edges);
|
deba@1991
|
1194 |
}
|
deba@1991
|
1195 |
virtual void add(const std::vector<UEdge>& uedges) {
|
deba@1991
|
1196 |
std::vector<Edge> edges;
|
deba@1991
|
1197 |
for (int i = 0; i < (int)uedges.size(); ++i) {
|
deba@1991
|
1198 |
edges.push_back(AdaptorBase::Parent::direct(uedges[i], true));
|
deba@1991
|
1199 |
edges.push_back(AdaptorBase::Parent::direct(uedges[i], false));
|
deba@1991
|
1200 |
}
|
deba@1991
|
1201 |
edge_notifier.add(edges);
|
deba@1991
|
1202 |
}
|
deba@1991
|
1203 |
virtual void erase(const UEdge& uedge) {
|
deba@1991
|
1204 |
std::vector<Edge> edges;
|
deba@1991
|
1205 |
edges.push_back(AdaptorBase::Parent::direct(uedge, true));
|
deba@1991
|
1206 |
edges.push_back(AdaptorBase::Parent::direct(uedge, false));
|
deba@1991
|
1207 |
edge_notifier.erase(edges);
|
deba@1991
|
1208 |
}
|
deba@1991
|
1209 |
virtual void erase(const std::vector<UEdge>& uedges) {
|
deba@1991
|
1210 |
std::vector<Edge> edges;
|
deba@1991
|
1211 |
for (int i = 0; i < (int)uedges.size(); ++i) {
|
deba@1991
|
1212 |
edges.push_back(AdaptorBase::Parent::direct(uedges[i], true));
|
deba@1991
|
1213 |
edges.push_back(AdaptorBase::Parent::direct(uedges[i], false));
|
deba@1991
|
1214 |
}
|
deba@1991
|
1215 |
edge_notifier.erase(edges);
|
deba@1991
|
1216 |
}
|
deba@1991
|
1217 |
virtual void build() {
|
deba@1991
|
1218 |
edge_notifier.build();
|
deba@1991
|
1219 |
}
|
deba@1991
|
1220 |
virtual void clear() {
|
deba@1991
|
1221 |
edge_notifier.clear();
|
deba@1991
|
1222 |
}
|
deba@1991
|
1223 |
|
deba@1991
|
1224 |
EdgeNotifier& edge_notifier;
|
deba@1991
|
1225 |
};
|
deba@1991
|
1226 |
|
deba@1991
|
1227 |
|
deba@1991
|
1228 |
mutable EdgeNotifier edge_notifier;
|
deba@1991
|
1229 |
NotifierProxy edge_notifier_proxy;
|
deba@1991
|
1230 |
|
deba@2031
|
1231 |
private:
|
deba@1991
|
1232 |
|
deba@1991
|
1233 |
template <typename _Value>
|
deba@2031
|
1234 |
class EdgeMapBase {
|
deba@1991
|
1235 |
private:
|
deba@1991
|
1236 |
|
deba@1991
|
1237 |
typedef typename _Graph::template EdgeMap<_Value> MapImpl;
|
deba@1991
|
1238 |
|
deba@1991
|
1239 |
public:
|
deba@1991
|
1240 |
|
deba@1991
|
1241 |
typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag;
|
deba@1991
|
1242 |
|
deba@1991
|
1243 |
typedef _Value Value;
|
deba@1991
|
1244 |
typedef Edge Key;
|
deba@1991
|
1245 |
|
deba@2031
|
1246 |
EdgeMapBase(const Adaptor& adaptor) :
|
deba@2031
|
1247 |
forward_map(*adaptor.graph), backward_map(*adaptor.graph) {}
|
deba@1991
|
1248 |
|
deba@2031
|
1249 |
EdgeMapBase(const Adaptor& adaptor, const Value& v)
|
deba@2031
|
1250 |
: forward_map(*adaptor.graph, v), backward_map(*adaptor.graph, v) {}
|
deba@1991
|
1251 |
|
deba@1991
|
1252 |
void set(const Edge& e, const Value& a) {
|
deba@1991
|
1253 |
if (Parent::direction(e)) {
|
deba@1991
|
1254 |
forward_map.set(e, a);
|
deba@1991
|
1255 |
} else {
|
deba@1991
|
1256 |
backward_map.set(e, a);
|
deba@1991
|
1257 |
}
|
deba@1991
|
1258 |
}
|
deba@1991
|
1259 |
|
deba@2031
|
1260 |
typename MapTraits<MapImpl>::ConstReturnValue operator[](Edge e) const {
|
deba@1991
|
1261 |
if (Parent::direction(e)) {
|
deba@1991
|
1262 |
return forward_map[e];
|
deba@1991
|
1263 |
} else {
|
deba@1991
|
1264 |
return backward_map[e];
|
deba@1991
|
1265 |
}
|
deba@1991
|
1266 |
}
|
deba@1991
|
1267 |
|
deba@2031
|
1268 |
typename MapTraits<MapImpl>::ReturnValue operator[](Edge e) {
|
deba@1991
|
1269 |
if (Parent::direction(e)) {
|
deba@1991
|
1270 |
return forward_map[e];
|
deba@1991
|
1271 |
} else {
|
deba@1991
|
1272 |
return backward_map[e];
|
deba@1991
|
1273 |
}
|
deba@1991
|
1274 |
}
|
deba@1991
|
1275 |
|
deba@1991
|
1276 |
protected:
|
deba@1991
|
1277 |
|
deba@1991
|
1278 |
MapImpl forward_map, backward_map;
|
deba@1991
|
1279 |
|
deba@1991
|
1280 |
};
|
deba@2031
|
1281 |
|
deba@2031
|
1282 |
public:
|
deba@2031
|
1283 |
|
deba@2031
|
1284 |
template <typename _Value>
|
deba@2031
|
1285 |
class EdgeMap
|
deba@2031
|
1286 |
: public SubMapExtender<Adaptor, EdgeMapBase<_Value> >
|
deba@2031
|
1287 |
{
|
deba@2031
|
1288 |
public:
|
deba@2031
|
1289 |
typedef Adaptor Graph;
|
deba@2031
|
1290 |
typedef SubMapExtender<Adaptor, EdgeMapBase<_Value> > Parent;
|
deba@2031
|
1291 |
|
deba@2031
|
1292 |
EdgeMap(const Graph& graph)
|
deba@2031
|
1293 |
: Parent(graph) {}
|
deba@2031
|
1294 |
EdgeMap(const Graph& graph, const _Value& value)
|
deba@2031
|
1295 |
: Parent(graph, value) {}
|
deba@2031
|
1296 |
|
deba@2031
|
1297 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@2031
|
1298 |
return operator=<EdgeMap>(cmap);
|
deba@2031
|
1299 |
}
|
deba@2031
|
1300 |
|
deba@2031
|
1301 |
template <typename CMap>
|
deba@2031
|
1302 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@2031
|
1303 |
Parent::operator=(cmap);
|
deba@2031
|
1304 |
return *this;
|
deba@2031
|
1305 |
}
|
deba@2031
|
1306 |
};
|
deba@1991
|
1307 |
|
deba@1991
|
1308 |
template <typename _Value>
|
deba@2031
|
1309 |
class UEdgeMap : public Graph::template EdgeMap<_Value> {
|
deba@1991
|
1310 |
public:
|
deba@2031
|
1311 |
|
deba@2031
|
1312 |
typedef typename Graph::template EdgeMap<_Value> Parent;
|
deba@2031
|
1313 |
|
deba@2031
|
1314 |
explicit UEdgeMap(const Adaptor& ga)
|
deba@2031
|
1315 |
: Parent(*ga.graph) {}
|
deba@1991
|
1316 |
|
deba@2031
|
1317 |
UEdgeMap(const Adaptor& ga, const _Value& value)
|
deba@2031
|
1318 |
: Parent(*ga.graph, value) {}
|
deba@1991
|
1319 |
|
deba@2031
|
1320 |
UEdgeMap& operator=(const UEdgeMap& cmap) {
|
deba@2031
|
1321 |
return operator=<UEdgeMap>(cmap);
|
deba@2031
|
1322 |
}
|
deba@1991
|
1323 |
|
deba@2031
|
1324 |
template <typename CMap>
|
deba@2031
|
1325 |
UEdgeMap& operator=(const CMap& cmap) {
|
deba@2031
|
1326 |
Parent::operator=(cmap);
|
deba@2031
|
1327 |
return *this;
|
deba@2031
|
1328 |
}
|
deba@2031
|
1329 |
|
marci@1383
|
1330 |
};
|
marci@1383
|
1331 |
|
marci@1383
|
1332 |
};
|
marci@1383
|
1333 |
|
klao@1951
|
1334 |
///\brief An undirected graph is made from a directed graph by an adaptor
|
klao@1951
|
1335 |
///\ingroup graph_adaptors
|
klao@1951
|
1336 |
///
|
klao@1951
|
1337 |
/// Undocumented, untested!!!
|
klao@1951
|
1338 |
/// If somebody knows nice demo application, let's polulate it.
|
klao@1951
|
1339 |
///
|
klao@1951
|
1340 |
/// \author Marton Makai
|
marci@1383
|
1341 |
template<typename _Graph>
|
deba@1980
|
1342 |
class UndirGraphAdaptor :
|
deba@1979
|
1343 |
public UGraphAdaptorExtender<
|
deba@1980
|
1344 |
UndirGraphAdaptorBase<_Graph> > {
|
marci@1383
|
1345 |
public:
|
marci@1383
|
1346 |
typedef _Graph Graph;
|
deba@1979
|
1347 |
typedef UGraphAdaptorExtender<
|
deba@1980
|
1348 |
UndirGraphAdaptorBase<_Graph> > Parent;
|
marci@1383
|
1349 |
protected:
|
deba@1980
|
1350 |
UndirGraphAdaptor() { }
|
marci@1383
|
1351 |
public:
|
deba@1980
|
1352 |
UndirGraphAdaptor(_Graph& _graph) {
|
marci@1383
|
1353 |
setGraph(_graph);
|
marci@556
|
1354 |
}
|
marci@556
|
1355 |
|
deba@1991
|
1356 |
template <typename _ForwardMap, typename _BackwardMap>
|
deba@1991
|
1357 |
class CombinedEdgeMap {
|
deba@1991
|
1358 |
public:
|
deba@1991
|
1359 |
|
deba@1991
|
1360 |
typedef _ForwardMap ForwardMap;
|
deba@1991
|
1361 |
typedef _BackwardMap BackwardMap;
|
marci@992
|
1362 |
|
deba@1991
|
1363 |
typedef typename MapTraits<ForwardMap>::ReferenceMapTag ReferenceMapTag;
|
marci@992
|
1364 |
|
deba@1991
|
1365 |
typedef typename ForwardMap::Value Value;
|
deba@1991
|
1366 |
typedef typename Parent::Edge Key;
|
deba@1991
|
1367 |
|
deba@1991
|
1368 |
CombinedEdgeMap() : forward_map(0), backward_map(0) {}
|
marci@992
|
1369 |
|
deba@1991
|
1370 |
CombinedEdgeMap(ForwardMap& _forward_map, BackwardMap& _backward_map)
|
deba@1991
|
1371 |
: forward_map(&_forward_map), backward_map(&_backward_map) {}
|
marci@992
|
1372 |
|
deba@1991
|
1373 |
void set(const Key& e, const Value& a) {
|
deba@1991
|
1374 |
if (Parent::direction(e)) {
|
deba@1991
|
1375 |
forward_map->set(e, a);
|
deba@1991
|
1376 |
} else {
|
deba@1991
|
1377 |
backward_map->set(e, a);
|
deba@1991
|
1378 |
}
|
marci@992
|
1379 |
}
|
marci@992
|
1380 |
|
deba@1991
|
1381 |
typename MapTraits<ForwardMap>::ConstReturnValue
|
deba@1991
|
1382 |
operator[](const Key& e) const {
|
deba@1991
|
1383 |
if (Parent::direction(e)) {
|
deba@1991
|
1384 |
return (*forward_map)[e];
|
deba@1991
|
1385 |
} else {
|
deba@1991
|
1386 |
return (*backward_map)[e];
|
deba@1991
|
1387 |
}
|
marci@992
|
1388 |
}
|
marci@992
|
1389 |
|
deba@1991
|
1390 |
typename MapTraits<ForwardMap>::ReturnValue
|
deba@1991
|
1391 |
operator[](const Key& e) {
|
deba@1991
|
1392 |
if (Parent::direction(e)) {
|
deba@1991
|
1393 |
return (*forward_map)[e];
|
deba@1991
|
1394 |
} else {
|
deba@1991
|
1395 |
return (*backward_map)[e];
|
deba@1991
|
1396 |
}
|
marci@992
|
1397 |
}
|
deba@1991
|
1398 |
|
deba@1991
|
1399 |
void setForwardMap(ForwardMap& _forward_map) {
|
deba@1991
|
1400 |
forward_map = &_forward_map;
|
deba@1991
|
1401 |
}
|
deba@1991
|
1402 |
|
deba@1991
|
1403 |
void setBackwardMap(BackwardMap& _backward_map) {
|
deba@1991
|
1404 |
backward_map = &_backward_map;
|
deba@1991
|
1405 |
}
|
deba@1991
|
1406 |
|
deba@1991
|
1407 |
protected:
|
deba@1991
|
1408 |
|
deba@1991
|
1409 |
ForwardMap* forward_map;
|
deba@1991
|
1410 |
BackwardMap* backward_map;
|
deba@1991
|
1411 |
|
marci@992
|
1412 |
};
|
marci@992
|
1413 |
|
marci@992
|
1414 |
};
|
marci@569
|
1415 |
|
deba@1991
|
1416 |
/// \brief Just gives back an undir graph adaptor
|
klao@1951
|
1417 |
///
|
deba@1991
|
1418 |
/// Just gives back an undir graph adaptor
|
marci@650
|
1419 |
template<typename Graph>
|
deba@1991
|
1420 |
UndirGraphAdaptor<const Graph>
|
deba@1991
|
1421 |
undirGraphAdaptor(const Graph& graph) {
|
deba@1991
|
1422 |
return UndirGraphAdaptor<const Graph>(graph);
|
deba@1991
|
1423 |
}
|
marci@650
|
1424 |
|
marci@650
|
1425 |
template<typename Graph, typename Number,
|
marci@650
|
1426 |
typename CapacityMap, typename FlowMap>
|
marci@658
|
1427 |
class ResForwardFilter {
|
marci@650
|
1428 |
const CapacityMap* capacity;
|
marci@650
|
1429 |
const FlowMap* flow;
|
marci@650
|
1430 |
public:
|
deba@1991
|
1431 |
typedef typename Graph::Edge Key;
|
deba@1991
|
1432 |
typedef bool Value;
|
deba@1991
|
1433 |
|
deba@1991
|
1434 |
ResForwardFilter(const CapacityMap& _capacity, const FlowMap& _flow)
|
deba@1991
|
1435 |
: capacity(&_capacity), flow(&_flow) { }
|
deba@1991
|
1436 |
ResForwardFilter() : capacity(0), flow(0) { }
|
deba@1991
|
1437 |
void setCapacity(const CapacityMap& _capacity) { capacity = &_capacity; }
|
deba@1991
|
1438 |
void setFlow(const FlowMap& _flow) { flow = &_flow; }
|
marci@650
|
1439 |
bool operator[](const typename Graph::Edge& e) const {
|
marci@738
|
1440 |
return (Number((*flow)[e]) < Number((*capacity)[e]));
|
marci@650
|
1441 |
}
|
marci@650
|
1442 |
};
|
marci@650
|
1443 |
|
marci@650
|
1444 |
template<typename Graph, typename Number,
|
marci@650
|
1445 |
typename CapacityMap, typename FlowMap>
|
marci@658
|
1446 |
class ResBackwardFilter {
|
marci@650
|
1447 |
const CapacityMap* capacity;
|
marci@650
|
1448 |
const FlowMap* flow;
|
marci@650
|
1449 |
public:
|
deba@1991
|
1450 |
typedef typename Graph::Edge Key;
|
deba@1991
|
1451 |
typedef bool Value;
|
deba@1991
|
1452 |
|
deba@1991
|
1453 |
ResBackwardFilter(const CapacityMap& _capacity, const FlowMap& _flow)
|
deba@1991
|
1454 |
: capacity(&_capacity), flow(&_flow) { }
|
deba@1991
|
1455 |
ResBackwardFilter() : capacity(0), flow(0) { }
|
deba@1991
|
1456 |
void setCapacity(const CapacityMap& _capacity) { capacity = &_capacity; }
|
deba@1991
|
1457 |
void setFlow(const FlowMap& _flow) { flow = &_flow; }
|
marci@650
|
1458 |
bool operator[](const typename Graph::Edge& e) const {
|
marci@738
|
1459 |
return (Number(0) < Number((*flow)[e]));
|
marci@650
|
1460 |
}
|
marci@650
|
1461 |
};
|
marci@650
|
1462 |
|
marci@653
|
1463 |
|
klao@1951
|
1464 |
///\brief An adaptor for composing the residual
|
klao@1951
|
1465 |
///graph for directed flow and circulation problems.
|
klao@1951
|
1466 |
///\ingroup graph_adaptors
|
klao@1951
|
1467 |
///
|
klao@1951
|
1468 |
///An adaptor for composing the residual graph for
|
klao@1951
|
1469 |
///directed flow and circulation problems.
|
klao@1952
|
1470 |
///Let \f$ G=(V, A) \f$ be a directed graph and let \f$ F \f$ be a
|
klao@1951
|
1471 |
///number type. Let moreover
|
klao@1952
|
1472 |
///\f$ f,c:A\to F \f$, be functions on the edge-set.
|
klao@1952
|
1473 |
///In the appications of ResGraphAdaptor, \f$ f \f$ usually stands for a flow
|
klao@1952
|
1474 |
///and \f$ c \f$ for a capacity function.
|
klao@1951
|
1475 |
///Suppose that a graph instange \c g of type
|
klao@1952
|
1476 |
///\c ListGraph implements \f$ G \f$.
|
klao@1951
|
1477 |
///\code
|
klao@1951
|
1478 |
/// ListGraph g;
|
klao@1951
|
1479 |
///\endcode
|
klao@1951
|
1480 |
///Then RevGraphAdaptor implements the graph structure with node-set
|
klao@1952
|
1481 |
///\f$ V \f$ and edge-set \f$ A_{forward}\cup A_{backward} \f$, where
|
klao@1952
|
1482 |
///\f$ A_{forward}=\{uv : uv\in A, f(uv)<c(uv)\} \f$ and
|
klao@1952
|
1483 |
///\f$ A_{backward}=\{vu : uv\in A, f(uv)>0\} \f$,
|
klao@1951
|
1484 |
///i.e. the so called residual graph.
|
klao@1952
|
1485 |
///When we take the union \f$ A_{forward}\cup A_{backward} \f$,
|
klao@1951
|
1486 |
///multilicities are counted, i.e. if an edge is in both
|
klao@1952
|
1487 |
///\f$ A_{forward} \f$ and \f$ A_{backward} \f$, then in the adaptor it
|
klao@1951
|
1488 |
///appears twice.
|
klao@1951
|
1489 |
///The following code shows how
|
klao@1951
|
1490 |
///such an instance can be constructed.
|
klao@1951
|
1491 |
///\code
|
klao@1951
|
1492 |
///typedef ListGraph Graph;
|
klao@1951
|
1493 |
///Graph::EdgeMap<int> f(g);
|
klao@1951
|
1494 |
///Graph::EdgeMap<int> c(g);
|
deba@1991
|
1495 |
///ResGraphAdaptor<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > ga(g);
|
klao@1951
|
1496 |
///\endcode
|
klao@1951
|
1497 |
///\author Marton Makai
|
klao@1951
|
1498 |
///
|
marci@650
|
1499 |
template<typename Graph, typename Number,
|
marci@650
|
1500 |
typename CapacityMap, typename FlowMap>
|
alpar@1401
|
1501 |
class ResGraphAdaptor :
|
deba@1991
|
1502 |
public EdgeSubGraphAdaptor<
|
deba@1991
|
1503 |
UndirGraphAdaptor<Graph>,
|
deba@1991
|
1504 |
typename UndirGraphAdaptor<Graph>::template CombinedEdgeMap<
|
marci@658
|
1505 |
ResForwardFilter<Graph, Number, CapacityMap, FlowMap>,
|
deba@1991
|
1506 |
ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> > > {
|
marci@650
|
1507 |
public:
|
deba@1991
|
1508 |
|
deba@1991
|
1509 |
typedef UndirGraphAdaptor<Graph> UGraph;
|
deba@1991
|
1510 |
|
deba@1991
|
1511 |
typedef ResForwardFilter<Graph, Number, CapacityMap, FlowMap>
|
deba@1991
|
1512 |
ForwardFilter;
|
deba@1991
|
1513 |
|
deba@1991
|
1514 |
typedef ResBackwardFilter<Graph, Number, CapacityMap, FlowMap>
|
deba@1991
|
1515 |
BackwardFilter;
|
deba@1991
|
1516 |
|
deba@1991
|
1517 |
typedef typename UGraph::
|
deba@1991
|
1518 |
template CombinedEdgeMap<ForwardFilter, BackwardFilter>
|
deba@1991
|
1519 |
EdgeFilter;
|
deba@1991
|
1520 |
|
deba@1991
|
1521 |
typedef EdgeSubGraphAdaptor<UGraph, EdgeFilter> Parent;
|
deba@1991
|
1522 |
|
marci@650
|
1523 |
protected:
|
deba@1991
|
1524 |
|
marci@650
|
1525 |
const CapacityMap* capacity;
|
marci@650
|
1526 |
FlowMap* flow;
|
deba@1991
|
1527 |
|
deba@1991
|
1528 |
UGraph ugraph;
|
deba@1991
|
1529 |
ForwardFilter forward_filter;
|
deba@1991
|
1530 |
BackwardFilter backward_filter;
|
deba@1991
|
1531 |
EdgeFilter edge_filter;
|
deba@1991
|
1532 |
|
marci@658
|
1533 |
void setCapacityMap(const CapacityMap& _capacity) {
|
marci@658
|
1534 |
capacity=&_capacity;
|
marci@658
|
1535 |
forward_filter.setCapacity(_capacity);
|
marci@658
|
1536 |
backward_filter.setCapacity(_capacity);
|
marci@658
|
1537 |
}
|
deba@1991
|
1538 |
|
marci@658
|
1539 |
void setFlowMap(FlowMap& _flow) {
|
marci@658
|
1540 |
flow=&_flow;
|
marci@658
|
1541 |
forward_filter.setFlow(_flow);
|
marci@658
|
1542 |
backward_filter.setFlow(_flow);
|
marci@658
|
1543 |
}
|
deba@1991
|
1544 |
|
marci@650
|
1545 |
public:
|
deba@1991
|
1546 |
|
alpar@1401
|
1547 |
ResGraphAdaptor(Graph& _graph, const CapacityMap& _capacity,
|
deba@1991
|
1548 |
FlowMap& _flow)
|
deba@1991
|
1549 |
: Parent(), capacity(&_capacity), flow(&_flow),
|
deba@1991
|
1550 |
ugraph(_graph),
|
deba@1991
|
1551 |
forward_filter(_capacity, _flow),
|
deba@1991
|
1552 |
backward_filter(_capacity, _flow),
|
deba@1991
|
1553 |
edge_filter(forward_filter, backward_filter) {
|
deba@1991
|
1554 |
Parent::setGraph(ugraph);
|
deba@1991
|
1555 |
Parent::setEdgeFilterMap(edge_filter);
|
marci@650
|
1556 |
}
|
marci@650
|
1557 |
|
marci@660
|
1558 |
typedef typename Parent::Edge Edge;
|
marci@660
|
1559 |
|
marci@660
|
1560 |
void augment(const Edge& e, Number a) const {
|
deba@1991
|
1561 |
if (UGraph::direction(e)) {
|
marci@650
|
1562 |
flow->set(e, (*flow)[e]+a);
|
deba@1991
|
1563 |
} else {
|
marci@650
|
1564 |
flow->set(e, (*flow)[e]-a);
|
deba@1991
|
1565 |
}
|
marci@650
|
1566 |
}
|
marci@650
|
1567 |
|
deba@1991
|
1568 |
static bool forward(const Edge& e) {
|
deba@1991
|
1569 |
return UGraph::direction(e);
|
deba@1991
|
1570 |
}
|
deba@1991
|
1571 |
|
deba@1991
|
1572 |
static bool backward(const Edge& e) {
|
deba@1991
|
1573 |
return !UGraph::direction(e);
|
deba@1991
|
1574 |
}
|
deba@1991
|
1575 |
|
deba@1991
|
1576 |
static Edge forward(const typename Graph::Edge& e) {
|
deba@1991
|
1577 |
return UGraph::direct(e, true);
|
deba@1991
|
1578 |
}
|
deba@1991
|
1579 |
|
deba@1991
|
1580 |
static Edge backward(const typename Graph::Edge& e) {
|
deba@1991
|
1581 |
return UGraph::direct(e, false);
|
deba@1991
|
1582 |
}
|
deba@1991
|
1583 |
|
deba@1991
|
1584 |
|
klao@1951
|
1585 |
/// \brief Residual capacity map.
|
klao@1951
|
1586 |
///
|
klao@1951
|
1587 |
/// In generic residual graphs the residual capacity can be obtained
|
klao@1951
|
1588 |
/// as a map.
|
marci@660
|
1589 |
class ResCap {
|
marci@660
|
1590 |
protected:
|
deba@1991
|
1591 |
const ResGraphAdaptor* res_graph;
|
marci@660
|
1592 |
public:
|
alpar@987
|
1593 |
typedef Number Value;
|
alpar@987
|
1594 |
typedef Edge Key;
|
deba@1991
|
1595 |
ResCap(const ResGraphAdaptor& _res_graph)
|
deba@1991
|
1596 |
: res_graph(&_res_graph) {}
|
deba@1991
|
1597 |
|
marci@660
|
1598 |
Number operator[](const Edge& e) const {
|
deba@1991
|
1599 |
if (ResGraphAdaptor::direction(e))
|
marci@660
|
1600 |
return (*(res_graph->capacity))[e]-(*(res_graph->flow))[e];
|
marci@660
|
1601 |
else
|
marci@660
|
1602 |
return (*(res_graph->flow))[e];
|
marci@660
|
1603 |
}
|
deba@1991
|
1604 |
|
marci@660
|
1605 |
};
|
marci@660
|
1606 |
|
marci@650
|
1607 |
};
|
marci@650
|
1608 |
|
marci@650
|
1609 |
|
marci@998
|
1610 |
|
marci@998
|
1611 |
template <typename _Graph, typename FirstOutEdgesMap>
|
alpar@1401
|
1612 |
class ErasingFirstGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
|
marci@998
|
1613 |
public:
|
marci@998
|
1614 |
typedef _Graph Graph;
|
alpar@1401
|
1615 |
typedef GraphAdaptorBase<_Graph> Parent;
|
marci@998
|
1616 |
protected:
|
marci@998
|
1617 |
FirstOutEdgesMap* first_out_edges;
|
alpar@1401
|
1618 |
ErasingFirstGraphAdaptorBase() : Parent(),
|
marci@998
|
1619 |
first_out_edges(0) { }
|
marci@998
|
1620 |
|
marci@998
|
1621 |
void setFirstOutEdgesMap(FirstOutEdgesMap& _first_out_edges) {
|
marci@998
|
1622 |
first_out_edges=&_first_out_edges;
|
marci@998
|
1623 |
}
|
marci@998
|
1624 |
|
marci@998
|
1625 |
public:
|
marci@998
|
1626 |
|
marci@998
|
1627 |
typedef typename Parent::Node Node;
|
marci@998
|
1628 |
typedef typename Parent::Edge Edge;
|
marci@998
|
1629 |
|
marci@998
|
1630 |
void firstOut(Edge& i, const Node& n) const {
|
marci@998
|
1631 |
i=(*first_out_edges)[n];
|
marci@998
|
1632 |
}
|
marci@998
|
1633 |
|
marci@998
|
1634 |
void erase(const Edge& e) const {
|
marci@998
|
1635 |
Node n=source(e);
|
marci@998
|
1636 |
Edge f=e;
|
marci@998
|
1637 |
Parent::nextOut(f);
|
marci@998
|
1638 |
first_out_edges->set(n, f);
|
marci@998
|
1639 |
}
|
marci@998
|
1640 |
};
|
marci@998
|
1641 |
|
marci@998
|
1642 |
|
klao@1951
|
1643 |
///\brief For blocking flows.
|
klao@1951
|
1644 |
///\ingroup graph_adaptors
|
klao@1951
|
1645 |
///
|
klao@1951
|
1646 |
///\warning Graph adaptors are in even more
|
klao@1951
|
1647 |
///experimental state than the other
|
klao@1951
|
1648 |
///parts of the lib. Use them at you own risk.
|
klao@1951
|
1649 |
///
|
klao@1951
|
1650 |
///This graph adaptor is used for on-the-fly
|
klao@1951
|
1651 |
///Dinits blocking flow computations.
|
klao@1951
|
1652 |
///For each node, an out-edge is stored which is used when the
|
klao@1951
|
1653 |
///\code
|
klao@1951
|
1654 |
///OutEdgeIt& first(OutEdgeIt&, const Node&)
|
klao@1951
|
1655 |
///\endcode
|
klao@1951
|
1656 |
///is called.
|
klao@1951
|
1657 |
///
|
klao@1951
|
1658 |
///\author Marton Makai
|
klao@1951
|
1659 |
///
|
marci@998
|
1660 |
template <typename _Graph, typename FirstOutEdgesMap>
|
alpar@1401
|
1661 |
class ErasingFirstGraphAdaptor :
|
deba@1979
|
1662 |
public GraphAdaptorExtender<
|
alpar@1401
|
1663 |
ErasingFirstGraphAdaptorBase<_Graph, FirstOutEdgesMap> > {
|
marci@650
|
1664 |
public:
|
marci@998
|
1665 |
typedef _Graph Graph;
|
deba@1979
|
1666 |
typedef GraphAdaptorExtender<
|
alpar@1401
|
1667 |
ErasingFirstGraphAdaptorBase<_Graph, FirstOutEdgesMap> > Parent;
|
alpar@1401
|
1668 |
ErasingFirstGraphAdaptor(Graph& _graph,
|
marci@998
|
1669 |
FirstOutEdgesMap& _first_out_edges) {
|
marci@998
|
1670 |
setGraph(_graph);
|
marci@998
|
1671 |
setFirstOutEdgesMap(_first_out_edges);
|
marci@998
|
1672 |
}
|
marci@1019
|
1673 |
|
marci@998
|
1674 |
};
|
marci@556
|
1675 |
|
deba@1989
|
1676 |
// template <typename _Graph>
|
deba@1989
|
1677 |
// class SplitGraphAdaptorBase
|
deba@1989
|
1678 |
// : public GraphAdaptorBase<_Graph> {
|
deba@1989
|
1679 |
// public:
|
deba@1989
|
1680 |
// typedef GraphAdaptorBase<_Graph> Parent;
|
deba@1697
|
1681 |
|
deba@1989
|
1682 |
// class Node;
|
deba@1989
|
1683 |
// class Edge;
|
deba@1989
|
1684 |
// template <typename T> class NodeMap;
|
deba@1989
|
1685 |
// template <typename T> class EdgeMap;
|
deba@1697
|
1686 |
|
deba@1697
|
1687 |
|
deba@1989
|
1688 |
// class Node : public Parent::Node {
|
deba@1989
|
1689 |
// friend class SplitGraphAdaptorBase;
|
deba@1989
|
1690 |
// template <typename T> friend class NodeMap;
|
deba@1989
|
1691 |
// typedef typename Parent::Node NodeParent;
|
deba@1989
|
1692 |
// private:
|
deba@1697
|
1693 |
|
deba@1989
|
1694 |
// bool entry;
|
deba@1989
|
1695 |
// Node(typename Parent::Node _node, bool _entry)
|
deba@1989
|
1696 |
// : Parent::Node(_node), entry(_entry) {}
|
deba@1697
|
1697 |
|
deba@1989
|
1698 |
// public:
|
deba@1989
|
1699 |
// Node() {}
|
deba@1989
|
1700 |
// Node(Invalid) : NodeParent(INVALID), entry(true) {}
|
deba@1697
|
1701 |
|
deba@1989
|
1702 |
// bool operator==(const Node& node) const {
|
deba@1989
|
1703 |
// return NodeParent::operator==(node) && entry == node.entry;
|
deba@1989
|
1704 |
// }
|
deba@1697
|
1705 |
|
deba@1989
|
1706 |
// bool operator!=(const Node& node) const {
|
deba@1989
|
1707 |
// return !(*this == node);
|
deba@1989
|
1708 |
// }
|
deba@1697
|
1709 |
|
deba@1989
|
1710 |
// bool operator<(const Node& node) const {
|
deba@1989
|
1711 |
// return NodeParent::operator<(node) ||
|
deba@1989
|
1712 |
// (NodeParent::operator==(node) && entry < node.entry);
|
deba@1989
|
1713 |
// }
|
deba@1989
|
1714 |
// };
|
deba@1697
|
1715 |
|
deba@1989
|
1716 |
// /// \todo May we want VARIANT/union type
|
deba@1989
|
1717 |
// class Edge : public Parent::Edge {
|
deba@1989
|
1718 |
// friend class SplitGraphAdaptorBase;
|
deba@1989
|
1719 |
// template <typename T> friend class EdgeMap;
|
deba@1989
|
1720 |
// private:
|
deba@1989
|
1721 |
// typedef typename Parent::Edge EdgeParent;
|
deba@1989
|
1722 |
// typedef typename Parent::Node NodeParent;
|
deba@1989
|
1723 |
// NodeParent bind;
|
deba@1697
|
1724 |
|
deba@1989
|
1725 |
// Edge(const EdgeParent& edge, const NodeParent& node)
|
deba@1989
|
1726 |
// : EdgeParent(edge), bind(node) {}
|
deba@1989
|
1727 |
// public:
|
deba@1989
|
1728 |
// Edge() {}
|
deba@1989
|
1729 |
// Edge(Invalid) : EdgeParent(INVALID), bind(INVALID) {}
|
deba@1697
|
1730 |
|
deba@1989
|
1731 |
// bool operator==(const Edge& edge) const {
|
deba@1989
|
1732 |
// return EdgeParent::operator==(edge) && bind == edge.bind;
|
deba@1989
|
1733 |
// }
|
deba@1697
|
1734 |
|
deba@1989
|
1735 |
// bool operator!=(const Edge& edge) const {
|
deba@1989
|
1736 |
// return !(*this == edge);
|
deba@1989
|
1737 |
// }
|
deba@1697
|
1738 |
|
deba@1989
|
1739 |
// bool operator<(const Edge& edge) const {
|
deba@1989
|
1740 |
// return EdgeParent::operator<(edge) ||
|
deba@1989
|
1741 |
// (EdgeParent::operator==(edge) && bind < edge.bind);
|
deba@1989
|
1742 |
// }
|
deba@1989
|
1743 |
// };
|
deba@1697
|
1744 |
|
deba@1989
|
1745 |
// void first(Node& node) const {
|
deba@1989
|
1746 |
// Parent::first(node);
|
deba@1989
|
1747 |
// node.entry = true;
|
deba@1989
|
1748 |
// }
|
deba@1697
|
1749 |
|
deba@1989
|
1750 |
// void next(Node& node) const {
|
deba@1989
|
1751 |
// if (node.entry) {
|
deba@1989
|
1752 |
// node.entry = false;
|
deba@1989
|
1753 |
// } else {
|
deba@1989
|
1754 |
// node.entry = true;
|
deba@1989
|
1755 |
// Parent::next(node);
|
deba@1989
|
1756 |
// }
|
deba@1989
|
1757 |
// }
|
deba@1697
|
1758 |
|
deba@1989
|
1759 |
// void first(Edge& edge) const {
|
deba@1989
|
1760 |
// Parent::first(edge);
|
deba@1989
|
1761 |
// if ((typename Parent::Edge&)edge == INVALID) {
|
deba@1989
|
1762 |
// Parent::first(edge.bind);
|
deba@1989
|
1763 |
// } else {
|
deba@1989
|
1764 |
// edge.bind = INVALID;
|
deba@1989
|
1765 |
// }
|
deba@1989
|
1766 |
// }
|
deba@1697
|
1767 |
|
deba@1989
|
1768 |
// void next(Edge& edge) const {
|
deba@1989
|
1769 |
// if ((typename Parent::Edge&)edge != INVALID) {
|
deba@1989
|
1770 |
// Parent::next(edge);
|
deba@1989
|
1771 |
// if ((typename Parent::Edge&)edge == INVALID) {
|
deba@1989
|
1772 |
// Parent::first(edge.bind);
|
deba@1989
|
1773 |
// }
|
deba@1989
|
1774 |
// } else {
|
deba@1989
|
1775 |
// Parent::next(edge.bind);
|
deba@1989
|
1776 |
// }
|
deba@1989
|
1777 |
// }
|
deba@1697
|
1778 |
|
deba@1989
|
1779 |
// void firstIn(Edge& edge, const Node& node) const {
|
deba@1989
|
1780 |
// if (node.entry) {
|
deba@1989
|
1781 |
// Parent::firstIn(edge, node);
|
deba@1989
|
1782 |
// edge.bind = INVALID;
|
deba@1989
|
1783 |
// } else {
|
deba@1989
|
1784 |
// (typename Parent::Edge&)edge = INVALID;
|
deba@1989
|
1785 |
// edge.bind = node;
|
deba@1989
|
1786 |
// }
|
deba@1989
|
1787 |
// }
|
deba@1697
|
1788 |
|
deba@1989
|
1789 |
// void nextIn(Edge& edge) const {
|
deba@1989
|
1790 |
// if ((typename Parent::Edge&)edge != INVALID) {
|
deba@1989
|
1791 |
// Parent::nextIn(edge);
|
deba@1989
|
1792 |
// } else {
|
deba@1989
|
1793 |
// edge.bind = INVALID;
|
deba@1989
|
1794 |
// }
|
deba@1989
|
1795 |
// }
|
deba@1697
|
1796 |
|
deba@1989
|
1797 |
// void firstOut(Edge& edge, const Node& node) const {
|
deba@1989
|
1798 |
// if (!node.entry) {
|
deba@1989
|
1799 |
// Parent::firstOut(edge, node);
|
deba@1989
|
1800 |
// edge.bind = INVALID;
|
deba@1989
|
1801 |
// } else {
|
deba@1989
|
1802 |
// (typename Parent::Edge&)edge = INVALID;
|
deba@1989
|
1803 |
// edge.bind = node;
|
deba@1989
|
1804 |
// }
|
deba@1989
|
1805 |
// }
|
deba@1697
|
1806 |
|
deba@1989
|
1807 |
// void nextOut(Edge& edge) const {
|
deba@1989
|
1808 |
// if ((typename Parent::Edge&)edge != INVALID) {
|
deba@1989
|
1809 |
// Parent::nextOut(edge);
|
deba@1989
|
1810 |
// } else {
|
deba@1989
|
1811 |
// edge.bind = INVALID;
|
deba@1989
|
1812 |
// }
|
deba@1989
|
1813 |
// }
|
deba@1697
|
1814 |
|
deba@1989
|
1815 |
// Node source(const Edge& edge) const {
|
deba@1989
|
1816 |
// if ((typename Parent::Edge&)edge != INVALID) {
|
deba@1989
|
1817 |
// return Node(Parent::source(edge), false);
|
deba@1989
|
1818 |
// } else {
|
deba@1989
|
1819 |
// return Node(edge.bind, true);
|
deba@1989
|
1820 |
// }
|
deba@1989
|
1821 |
// }
|
deba@1697
|
1822 |
|
deba@1989
|
1823 |
// Node target(const Edge& edge) const {
|
deba@1989
|
1824 |
// if ((typename Parent::Edge&)edge != INVALID) {
|
deba@1989
|
1825 |
// return Node(Parent::target(edge), true);
|
deba@1989
|
1826 |
// } else {
|
deba@1989
|
1827 |
// return Node(edge.bind, false);
|
deba@1989
|
1828 |
// }
|
deba@1989
|
1829 |
// }
|
deba@1697
|
1830 |
|
deba@1989
|
1831 |
// static bool entryNode(const Node& node) {
|
deba@1989
|
1832 |
// return node.entry;
|
deba@1989
|
1833 |
// }
|
deba@1697
|
1834 |
|
deba@1989
|
1835 |
// static bool exitNode(const Node& node) {
|
deba@1989
|
1836 |
// return !node.entry;
|
deba@1989
|
1837 |
// }
|
deba@1697
|
1838 |
|
deba@1989
|
1839 |
// static Node getEntry(const typename Parent::Node& node) {
|
deba@1989
|
1840 |
// return Node(node, true);
|
deba@1989
|
1841 |
// }
|
deba@1697
|
1842 |
|
deba@1989
|
1843 |
// static Node getExit(const typename Parent::Node& node) {
|
deba@1989
|
1844 |
// return Node(node, false);
|
deba@1989
|
1845 |
// }
|
deba@1697
|
1846 |
|
deba@1989
|
1847 |
// static bool originalEdge(const Edge& edge) {
|
deba@1989
|
1848 |
// return (typename Parent::Edge&)edge != INVALID;
|
deba@1989
|
1849 |
// }
|
deba@1697
|
1850 |
|
deba@1989
|
1851 |
// static bool bindingEdge(const Edge& edge) {
|
deba@1989
|
1852 |
// return edge.bind != INVALID;
|
deba@1989
|
1853 |
// }
|
deba@1697
|
1854 |
|
deba@1989
|
1855 |
// static Node getBindedNode(const Edge& edge) {
|
deba@1989
|
1856 |
// return edge.bind;
|
deba@1989
|
1857 |
// }
|
deba@1697
|
1858 |
|
deba@1989
|
1859 |
// int nodeNum() const {
|
deba@1989
|
1860 |
// return Parent::nodeNum() * 2;
|
deba@1989
|
1861 |
// }
|
deba@1697
|
1862 |
|
deba@1989
|
1863 |
// typedef True EdgeNumTag;
|
deba@1697
|
1864 |
|
deba@1989
|
1865 |
// int edgeNum() const {
|
deba@1989
|
1866 |
// return countEdges() + Parent::nodeNum();
|
deba@1989
|
1867 |
// }
|
deba@1697
|
1868 |
|
deba@1989
|
1869 |
// Edge findEdge(const Node& source, const Node& target,
|
deba@1989
|
1870 |
// const Edge& prev = INVALID) const {
|
deba@1989
|
1871 |
// if (exitNode(source) && entryNode(target)) {
|
deba@1989
|
1872 |
// return Parent::findEdge(source, target, prev);
|
deba@1989
|
1873 |
// } else {
|
deba@1989
|
1874 |
// if (prev == INVALID && entryNode(source) && exitNode(target) &&
|
deba@1989
|
1875 |
// (typename Parent::Node&)source == (typename Parent::Node&)target) {
|
deba@1989
|
1876 |
// return Edge(INVALID, source);
|
deba@1989
|
1877 |
// } else {
|
deba@1989
|
1878 |
// return INVALID;
|
deba@1989
|
1879 |
// }
|
deba@1989
|
1880 |
// }
|
deba@1989
|
1881 |
// }
|
deba@1697
|
1882 |
|
deba@1989
|
1883 |
// template <typename T>
|
deba@1989
|
1884 |
// class NodeMap : public MapBase<Node, T> {
|
deba@1989
|
1885 |
// typedef typename Parent::template NodeMap<T> NodeImpl;
|
deba@1989
|
1886 |
// public:
|
deba@1989
|
1887 |
// NodeMap(const SplitGraphAdaptorBase& _graph)
|
deba@1989
|
1888 |
// : entry(_graph), exit(_graph) {}
|
deba@1989
|
1889 |
// NodeMap(const SplitGraphAdaptorBase& _graph, const T& t)
|
deba@1989
|
1890 |
// : entry(_graph, t), exit(_graph, t) {}
|
deba@1697
|
1891 |
|
deba@1989
|
1892 |
// void set(const Node& key, const T& val) {
|
deba@1989
|
1893 |
// if (key.entry) { entry.set(key, val); }
|
deba@1989
|
1894 |
// else {exit.set(key, val); }
|
deba@1989
|
1895 |
// }
|
deba@1697
|
1896 |
|
deba@1989
|
1897 |
// typename MapTraits<NodeImpl>::ReturnValue
|
deba@1989
|
1898 |
// operator[](const Node& key) {
|
deba@1989
|
1899 |
// if (key.entry) { return entry[key]; }
|
deba@1989
|
1900 |
// else { return exit[key]; }
|
deba@1989
|
1901 |
// }
|
deba@1697
|
1902 |
|
deba@1989
|
1903 |
// typename MapTraits<NodeImpl>::ConstReturnValue
|
deba@1989
|
1904 |
// operator[](const Node& key) const {
|
deba@1989
|
1905 |
// if (key.entry) { return entry[key]; }
|
deba@1989
|
1906 |
// else { return exit[key]; }
|
deba@1989
|
1907 |
// }
|
deba@1697
|
1908 |
|
deba@1989
|
1909 |
// private:
|
deba@1989
|
1910 |
// NodeImpl entry, exit;
|
deba@1989
|
1911 |
// };
|
deba@1697
|
1912 |
|
deba@1989
|
1913 |
// template <typename T>
|
deba@1989
|
1914 |
// class EdgeMap : public MapBase<Edge, T> {
|
deba@1989
|
1915 |
// typedef typename Parent::template NodeMap<T> NodeImpl;
|
deba@1989
|
1916 |
// typedef typename Parent::template EdgeMap<T> EdgeImpl;
|
deba@1989
|
1917 |
// public:
|
deba@1989
|
1918 |
// EdgeMap(const SplitGraphAdaptorBase& _graph)
|
deba@1989
|
1919 |
// : bind(_graph), orig(_graph) {}
|
deba@1989
|
1920 |
// EdgeMap(const SplitGraphAdaptorBase& _graph, const T& t)
|
deba@1989
|
1921 |
// : bind(_graph, t), orig(_graph, t) {}
|
deba@1697
|
1922 |
|
deba@1989
|
1923 |
// void set(const Edge& key, const T& val) {
|
deba@1989
|
1924 |
// if ((typename Parent::Edge&)key != INVALID) { orig.set(key, val); }
|
deba@1989
|
1925 |
// else {bind.set(key.bind, val); }
|
deba@1989
|
1926 |
// }
|
deba@1697
|
1927 |
|
deba@1989
|
1928 |
// typename MapTraits<EdgeImpl>::ReturnValue
|
deba@1989
|
1929 |
// operator[](const Edge& key) {
|
deba@1989
|
1930 |
// if ((typename Parent::Edge&)key != INVALID) { return orig[key]; }
|
deba@1989
|
1931 |
// else {return bind[key.bind]; }
|
deba@1989
|
1932 |
// }
|
deba@1697
|
1933 |
|
deba@1989
|
1934 |
// typename MapTraits<EdgeImpl>::ConstReturnValue
|
deba@1989
|
1935 |
// operator[](const Edge& key) const {
|
deba@1989
|
1936 |
// if ((typename Parent::Edge&)key != INVALID) { return orig[key]; }
|
deba@1989
|
1937 |
// else {return bind[key.bind]; }
|
deba@1989
|
1938 |
// }
|
deba@1697
|
1939 |
|
deba@1989
|
1940 |
// private:
|
deba@1989
|
1941 |
// typename Parent::template NodeMap<T> bind;
|
deba@1989
|
1942 |
// typename Parent::template EdgeMap<T> orig;
|
deba@1989
|
1943 |
// };
|
deba@1697
|
1944 |
|
deba@1989
|
1945 |
// template <typename EntryMap, typename ExitMap>
|
deba@1989
|
1946 |
// class CombinedNodeMap : public MapBase<Node, typename EntryMap::Value> {
|
deba@1989
|
1947 |
// public:
|
deba@1989
|
1948 |
// typedef MapBase<Node, typename EntryMap::Value> Parent;
|
deba@1697
|
1949 |
|
deba@1989
|
1950 |
// typedef typename Parent::Key Key;
|
deba@1989
|
1951 |
// typedef typename Parent::Value Value;
|
deba@1697
|
1952 |
|
deba@1989
|
1953 |
// CombinedNodeMap(EntryMap& _entryMap, ExitMap& _exitMap)
|
deba@1989
|
1954 |
// : entryMap(_entryMap), exitMap(_exitMap) {}
|
deba@1697
|
1955 |
|
deba@1989
|
1956 |
// Value& operator[](const Key& key) {
|
deba@1989
|
1957 |
// if (key.entry) {
|
deba@1989
|
1958 |
// return entryMap[key];
|
deba@1989
|
1959 |
// } else {
|
deba@1989
|
1960 |
// return exitMap[key];
|
deba@1989
|
1961 |
// }
|
deba@1989
|
1962 |
// }
|
deba@1697
|
1963 |
|
deba@1989
|
1964 |
// Value operator[](const Key& key) const {
|
deba@1989
|
1965 |
// if (key.entry) {
|
deba@1989
|
1966 |
// return entryMap[key];
|
deba@1989
|
1967 |
// } else {
|
deba@1989
|
1968 |
// return exitMap[key];
|
deba@1989
|
1969 |
// }
|
deba@1989
|
1970 |
// }
|
deba@1697
|
1971 |
|
deba@1989
|
1972 |
// void set(const Key& key, const Value& value) {
|
deba@1989
|
1973 |
// if (key.entry) {
|
deba@1989
|
1974 |
// entryMap.set(key, value);
|
deba@1989
|
1975 |
// } else {
|
deba@1989
|
1976 |
// exitMap.set(key, value);
|
deba@1989
|
1977 |
// }
|
deba@1989
|
1978 |
// }
|
deba@1697
|
1979 |
|
deba@1989
|
1980 |
// private:
|
deba@1697
|
1981 |
|
deba@1989
|
1982 |
// EntryMap& entryMap;
|
deba@1989
|
1983 |
// ExitMap& exitMap;
|
deba@1697
|
1984 |
|
deba@1989
|
1985 |
// };
|
deba@1697
|
1986 |
|
deba@1989
|
1987 |
// template <typename EdgeMap, typename NodeMap>
|
deba@1989
|
1988 |
// class CombinedEdgeMap : public MapBase<Edge, typename EdgeMap::Value> {
|
deba@1989
|
1989 |
// public:
|
deba@1989
|
1990 |
// typedef MapBase<Edge, typename EdgeMap::Value> Parent;
|
deba@1697
|
1991 |
|
deba@1989
|
1992 |
// typedef typename Parent::Key Key;
|
deba@1989
|
1993 |
// typedef typename Parent::Value Value;
|
deba@1697
|
1994 |
|
deba@1989
|
1995 |
// CombinedEdgeMap(EdgeMap& _edgeMap, NodeMap& _nodeMap)
|
deba@1989
|
1996 |
// : edgeMap(_edgeMap), nodeMap(_nodeMap) {}
|
deba@1697
|
1997 |
|
deba@1989
|
1998 |
// void set(const Edge& edge, const Value& val) {
|
deba@1989
|
1999 |
// if (SplitGraphAdaptorBase::originalEdge(edge)) {
|
deba@1989
|
2000 |
// edgeMap.set(edge, val);
|
deba@1989
|
2001 |
// } else {
|
deba@1989
|
2002 |
// nodeMap.set(SplitGraphAdaptorBase::bindedNode(edge), val);
|
deba@1989
|
2003 |
// }
|
deba@1989
|
2004 |
// }
|
deba@1697
|
2005 |
|
deba@1989
|
2006 |
// Value operator[](const Key& edge) const {
|
deba@1989
|
2007 |
// if (SplitGraphAdaptorBase::originalEdge(edge)) {
|
deba@1989
|
2008 |
// return edgeMap[edge];
|
deba@1989
|
2009 |
// } else {
|
deba@1989
|
2010 |
// return nodeMap[SplitGraphAdaptorBase::bindedNode(edge)];
|
deba@1989
|
2011 |
// }
|
deba@1989
|
2012 |
// }
|
deba@1697
|
2013 |
|
deba@1989
|
2014 |
// Value& operator[](const Key& edge) {
|
deba@1989
|
2015 |
// if (SplitGraphAdaptorBase::originalEdge(edge)) {
|
deba@1989
|
2016 |
// return edgeMap[edge];
|
deba@1989
|
2017 |
// } else {
|
deba@1989
|
2018 |
// return nodeMap[SplitGraphAdaptorBase::bindedNode(edge)];
|
deba@1989
|
2019 |
// }
|
deba@1989
|
2020 |
// }
|
deba@1697
|
2021 |
|
deba@1989
|
2022 |
// private:
|
deba@1989
|
2023 |
// EdgeMap& edgeMap;
|
deba@1989
|
2024 |
// NodeMap& nodeMap;
|
deba@1989
|
2025 |
// };
|
deba@1697
|
2026 |
|
deba@1989
|
2027 |
// };
|
deba@1697
|
2028 |
|
deba@1989
|
2029 |
// template <typename _Graph>
|
deba@1989
|
2030 |
// class SplitGraphAdaptor
|
deba@1989
|
2031 |
// : public GraphAdaptorExtender<SplitGraphAdaptorBase<_Graph> > {
|
deba@1989
|
2032 |
// public:
|
deba@1989
|
2033 |
// typedef GraphAdaptorExtender<SplitGraphAdaptorBase<_Graph> > Parent;
|
deba@1697
|
2034 |
|
deba@1989
|
2035 |
// SplitGraphAdaptor(_Graph& graph) {
|
deba@1989
|
2036 |
// Parent::setGraph(graph);
|
deba@1989
|
2037 |
// }
|
deba@1697
|
2038 |
|
deba@1697
|
2039 |
|
deba@1989
|
2040 |
// };
|
deba@1697
|
2041 |
|
alpar@921
|
2042 |
} //namespace lemon
|
marci@556
|
2043 |
|
alpar@1401
|
2044 |
#endif //LEMON_GRAPH_ADAPTOR_H
|
marci@556
|
2045 |
|