| 1 |
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
| 2 |
2 |
*
|
| 3 |
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
| 4 |
4 |
*
|
| 5 |
5 |
* Copyright (C) 2003-2009
|
| 6 |
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
| 7 |
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
| 8 |
8 |
*
|
| 9 |
9 |
* Permission to use, modify and distribute this software is granted
|
| 10 |
10 |
* provided that this copyright notice appears in all copies. For
|
| 11 |
11 |
* precise terms see the accompanying LICENSE file.
|
| 12 |
12 |
*
|
| 13 |
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
| 14 |
14 |
* express or implied, and with no claim as to its suitability for any
|
| 15 |
15 |
* purpose.
|
| 16 |
16 |
*
|
| 17 |
17 |
*/
|
| 18 |
18 |
|
| 19 |
19 |
#ifndef LEMON_ADAPTORS_H
|
| 20 |
20 |
#define LEMON_ADAPTORS_H
|
| 21 |
21 |
|
| 22 |
22 |
/// \ingroup graph_adaptors
|
| 23 |
23 |
/// \file
|
| 24 |
24 |
/// \brief Adaptor classes for digraphs and graphs
|
| 25 |
25 |
///
|
| 26 |
26 |
/// This file contains several useful adaptors for digraphs and graphs.
|
| 27 |
27 |
|
| 28 |
28 |
#include <lemon/core.h>
|
| 29 |
29 |
#include <lemon/maps.h>
|
| 30 |
30 |
#include <lemon/bits/variant.h>
|
| 31 |
31 |
|
| 32 |
32 |
#include <lemon/bits/graph_adaptor_extender.h>
|
| 33 |
33 |
#include <lemon/tolerance.h>
|
| 34 |
34 |
|
| 35 |
35 |
#include <algorithm>
|
| 36 |
36 |
|
| 37 |
37 |
namespace lemon {
|
| 38 |
38 |
|
| 39 |
|
template<typename _Digraph>
|
|
39 |
#ifdef _MSC_VER
|
|
40 |
#define LEMON_SCOPE_FIX(OUTER, NESTED) OUTER::NESTED
|
|
41 |
#else
|
|
42 |
#define LEMON_SCOPE_FIX(OUTER, NESTED) typename OUTER::template NESTED
|
|
43 |
#endif
|
|
44 |
|
|
45 |
template<typename DGR>
|
| 40 |
46 |
class DigraphAdaptorBase {
|
| 41 |
47 |
public:
|
| 42 |
|
typedef _Digraph Digraph;
|
|
48 |
typedef DGR Digraph;
|
| 43 |
49 |
typedef DigraphAdaptorBase Adaptor;
|
| 44 |
|
typedef Digraph ParentDigraph;
|
| 45 |
50 |
|
| 46 |
51 |
protected:
|
| 47 |
|
Digraph* _digraph;
|
|
52 |
DGR* _digraph;
|
| 48 |
53 |
DigraphAdaptorBase() : _digraph(0) { }
|
| 49 |
|
void setDigraph(Digraph& digraph) { _digraph = &digraph; }
|
|
54 |
void initialize(DGR& digraph) { _digraph = &digraph; }
|
| 50 |
55 |
|
| 51 |
56 |
public:
|
| 52 |
|
DigraphAdaptorBase(Digraph& digraph) : _digraph(&digraph) { }
|
| 53 |
|
|
| 54 |
|
typedef typename Digraph::Node Node;
|
| 55 |
|
typedef typename Digraph::Arc Arc;
|
|
57 |
DigraphAdaptorBase(DGR& digraph) : _digraph(&digraph) { }
|
|
58 |
|
|
59 |
typedef typename DGR::Node Node;
|
|
60 |
typedef typename DGR::Arc Arc;
|
| 56 |
61 |
|
| 57 |
62 |
void first(Node& i) const { _digraph->first(i); }
|
| 58 |
63 |
void first(Arc& i) const { _digraph->first(i); }
|
| 59 |
64 |
void firstIn(Arc& i, const Node& n) const { _digraph->firstIn(i, n); }
|
| 60 |
65 |
void firstOut(Arc& i, const Node& n ) const { _digraph->firstOut(i, n); }
|
| 61 |
66 |
|
| 62 |
67 |
void next(Node& i) const { _digraph->next(i); }
|
| 63 |
68 |
void next(Arc& i) const { _digraph->next(i); }
|
| 64 |
69 |
void nextIn(Arc& i) const { _digraph->nextIn(i); }
|
| 65 |
70 |
void nextOut(Arc& i) const { _digraph->nextOut(i); }
|
| 66 |
71 |
|
| 67 |
72 |
Node source(const Arc& a) const { return _digraph->source(a); }
|
| 68 |
73 |
Node target(const Arc& a) const { return _digraph->target(a); }
|
| 69 |
74 |
|
| 70 |
|
typedef NodeNumTagIndicator<Digraph> NodeNumTag;
|
|
75 |
typedef NodeNumTagIndicator<DGR> NodeNumTag;
|
| 71 |
76 |
int nodeNum() const { return _digraph->nodeNum(); }
|
| 72 |
77 |
|
| 73 |
|
typedef ArcNumTagIndicator<Digraph> ArcNumTag;
|
|
78 |
typedef ArcNumTagIndicator<DGR> ArcNumTag;
|
| 74 |
79 |
int arcNum() const { return _digraph->arcNum(); }
|
| 75 |
80 |
|
| 76 |
|
typedef FindArcTagIndicator<Digraph> FindArcTag;
|
|
81 |
typedef FindArcTagIndicator<DGR> FindArcTag;
|
| 77 |
82 |
Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) const {
|
| 78 |
83 |
return _digraph->findArc(u, v, prev);
|
| 79 |
84 |
}
|
| 80 |
85 |
|
| 81 |
86 |
Node addNode() { return _digraph->addNode(); }
|
| 82 |
87 |
Arc addArc(const Node& u, const Node& v) { return _digraph->addArc(u, v); }
|
| 83 |
88 |
|
| 84 |
89 |
void erase(const Node& n) { _digraph->erase(n); }
|
| 85 |
90 |
void erase(const Arc& a) { _digraph->erase(a); }
|
| 86 |
91 |
|
| 87 |
92 |
void clear() { _digraph->clear(); }
|
| 88 |
93 |
|
| 89 |
94 |
int id(const Node& n) const { return _digraph->id(n); }
|
| 90 |
95 |
int id(const Arc& a) const { return _digraph->id(a); }
|
| 91 |
96 |
|
| 92 |
97 |
Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
|
| 93 |
98 |
Arc arcFromId(int ix) const { return _digraph->arcFromId(ix); }
|
| 94 |
99 |
|
| 95 |
100 |
int maxNodeId() const { return _digraph->maxNodeId(); }
|
| 96 |
101 |
int maxArcId() const { return _digraph->maxArcId(); }
|
| 97 |
102 |
|
| 98 |
|
typedef typename ItemSetTraits<Digraph, Node>::ItemNotifier NodeNotifier;
|
|
103 |
typedef typename ItemSetTraits<DGR, Node>::ItemNotifier NodeNotifier;
|
| 99 |
104 |
NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
|
| 100 |
105 |
|
| 101 |
|
typedef typename ItemSetTraits<Digraph, Arc>::ItemNotifier ArcNotifier;
|
|
106 |
typedef typename ItemSetTraits<DGR, Arc>::ItemNotifier ArcNotifier;
|
| 102 |
107 |
ArcNotifier& notifier(Arc) const { return _digraph->notifier(Arc()); }
|
| 103 |
108 |
|
| 104 |
|
template <typename _Value>
|
| 105 |
|
class NodeMap : public Digraph::template NodeMap<_Value> {
|
|
109 |
template <typename V>
|
|
110 |
class NodeMap : public DGR::template NodeMap<V> {
|
| 106 |
111 |
public:
|
| 107 |
112 |
|
| 108 |
|
typedef typename Digraph::template NodeMap<_Value> Parent;
|
|
113 |
typedef typename DGR::template NodeMap<V> Parent;
|
| 109 |
114 |
|
| 110 |
115 |
explicit NodeMap(const Adaptor& adaptor)
|
| 111 |
116 |
: Parent(*adaptor._digraph) {}
|
| 112 |
117 |
|
| 113 |
|
NodeMap(const Adaptor& adaptor, const _Value& value)
|
|
118 |
NodeMap(const Adaptor& adaptor, const V& value)
|
| 114 |
119 |
: Parent(*adaptor._digraph, value) { }
|
| 115 |
120 |
|
| 116 |
121 |
private:
|
| 117 |
122 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 118 |
123 |
return operator=<NodeMap>(cmap);
|
| 119 |
124 |
}
|
| 120 |
125 |
|
| 121 |
126 |
template <typename CMap>
|
| 122 |
127 |
NodeMap& operator=(const CMap& cmap) {
|
| 123 |
128 |
Parent::operator=(cmap);
|
| 124 |
129 |
return *this;
|
| 125 |
130 |
}
|
| 126 |
131 |
|
| 127 |
132 |
};
|
| 128 |
133 |
|
| 129 |
|
template <typename _Value>
|
| 130 |
|
class ArcMap : public Digraph::template ArcMap<_Value> {
|
|
134 |
template <typename V>
|
|
135 |
class ArcMap : public DGR::template ArcMap<V> {
|
| 131 |
136 |
public:
|
| 132 |
137 |
|
| 133 |
|
typedef typename Digraph::template ArcMap<_Value> Parent;
|
| 134 |
|
|
| 135 |
|
explicit ArcMap(const Adaptor& adaptor)
|
|
138 |
typedef typename DGR::template ArcMap<V> Parent;
|
|
139 |
|
|
140 |
explicit ArcMap(const DigraphAdaptorBase<DGR>& adaptor)
|
| 136 |
141 |
: Parent(*adaptor._digraph) {}
|
| 137 |
142 |
|
| 138 |
|
ArcMap(const Adaptor& adaptor, const _Value& value)
|
|
143 |
ArcMap(const DigraphAdaptorBase<DGR>& adaptor, const V& value)
|
| 139 |
144 |
: Parent(*adaptor._digraph, value) {}
|
| 140 |
145 |
|
| 141 |
146 |
private:
|
| 142 |
147 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 143 |
148 |
return operator=<ArcMap>(cmap);
|
| 144 |
149 |
}
|
| 145 |
150 |
|
| 146 |
151 |
template <typename CMap>
|
| 147 |
152 |
ArcMap& operator=(const CMap& cmap) {
|
| 148 |
153 |
Parent::operator=(cmap);
|
| 149 |
154 |
return *this;
|
| 150 |
155 |
}
|
| 151 |
156 |
|
| 152 |
157 |
};
|
| 153 |
158 |
|
| 154 |
159 |
};
|
| 155 |
160 |
|
| 156 |
|
template<typename _Graph>
|
|
161 |
template<typename GR>
|
| 157 |
162 |
class GraphAdaptorBase {
|
| 158 |
163 |
public:
|
| 159 |
|
typedef _Graph Graph;
|
| 160 |
|
typedef Graph ParentGraph;
|
|
164 |
typedef GR Graph;
|
| 161 |
165 |
|
| 162 |
166 |
protected:
|
| 163 |
|
Graph* _graph;
|
|
167 |
GR* _graph;
|
| 164 |
168 |
|
| 165 |
169 |
GraphAdaptorBase() : _graph(0) {}
|
| 166 |
170 |
|
| 167 |
|
void setGraph(Graph& graph) { _graph = &graph; }
|
|
171 |
void initialize(GR& graph) { _graph = &graph; }
|
| 168 |
172 |
|
| 169 |
173 |
public:
|
| 170 |
|
GraphAdaptorBase(Graph& graph) : _graph(&graph) {}
|
| 171 |
|
|
| 172 |
|
typedef typename Graph::Node Node;
|
| 173 |
|
typedef typename Graph::Arc Arc;
|
| 174 |
|
typedef typename Graph::Edge Edge;
|
|
174 |
GraphAdaptorBase(GR& graph) : _graph(&graph) {}
|
|
175 |
|
|
176 |
typedef typename GR::Node Node;
|
|
177 |
typedef typename GR::Arc Arc;
|
|
178 |
typedef typename GR::Edge Edge;
|
| 175 |
179 |
|
| 176 |
180 |
void first(Node& i) const { _graph->first(i); }
|
| 177 |
181 |
void first(Arc& i) const { _graph->first(i); }
|
| 178 |
182 |
void first(Edge& i) const { _graph->first(i); }
|
| 179 |
183 |
void firstIn(Arc& i, const Node& n) const { _graph->firstIn(i, n); }
|
| 180 |
184 |
void firstOut(Arc& i, const Node& n ) const { _graph->firstOut(i, n); }
|
| 181 |
185 |
void firstInc(Edge &i, bool &d, const Node &n) const {
|
| 182 |
186 |
_graph->firstInc(i, d, n);
|
| 183 |
187 |
}
|
| 184 |
188 |
|
| 185 |
189 |
void next(Node& i) const { _graph->next(i); }
|
| 186 |
190 |
void next(Arc& i) const { _graph->next(i); }
|
| 187 |
191 |
void next(Edge& i) const { _graph->next(i); }
|
| 188 |
192 |
void nextIn(Arc& i) const { _graph->nextIn(i); }
|
| 189 |
193 |
void nextOut(Arc& i) const { _graph->nextOut(i); }
|
| 190 |
194 |
void nextInc(Edge &i, bool &d) const { _graph->nextInc(i, d); }
|
| 191 |
195 |
|
| 192 |
196 |
Node u(const Edge& e) const { return _graph->u(e); }
|
| 193 |
197 |
Node v(const Edge& e) const { return _graph->v(e); }
|
| 194 |
198 |
|
| 195 |
199 |
Node source(const Arc& a) const { return _graph->source(a); }
|
| 196 |
200 |
Node target(const Arc& a) const { return _graph->target(a); }
|
| 197 |
201 |
|
| 198 |
202 |
typedef NodeNumTagIndicator<Graph> NodeNumTag;
|
| 199 |
203 |
int nodeNum() const { return _graph->nodeNum(); }
|
| 200 |
204 |
|
| 201 |
205 |
typedef ArcNumTagIndicator<Graph> ArcNumTag;
|
| 202 |
206 |
int arcNum() const { return _graph->arcNum(); }
|
| 203 |
207 |
|
| 204 |
208 |
typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
|
| 205 |
209 |
int edgeNum() const { return _graph->edgeNum(); }
|
| 206 |
210 |
|
| 207 |
211 |
typedef FindArcTagIndicator<Graph> FindArcTag;
|
| 208 |
212 |
Arc findArc(const Node& u, const Node& v,
|
| 209 |
213 |
const Arc& prev = INVALID) const {
|
| 210 |
214 |
return _graph->findArc(u, v, prev);
|
| 211 |
215 |
}
|
| 212 |
216 |
|
| 213 |
217 |
typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
|
| 214 |
218 |
Edge findEdge(const Node& u, const Node& v,
|
| 215 |
219 |
const Edge& prev = INVALID) const {
|
| 216 |
220 |
return _graph->findEdge(u, v, prev);
|
| 217 |
221 |
}
|
| 218 |
222 |
|
| 219 |
223 |
Node addNode() { return _graph->addNode(); }
|
| 220 |
224 |
Edge addEdge(const Node& u, const Node& v) { return _graph->addEdge(u, v); }
|
| 221 |
225 |
|
| 222 |
226 |
void erase(const Node& i) { _graph->erase(i); }
|
| 223 |
227 |
void erase(const Edge& i) { _graph->erase(i); }
|
| 224 |
228 |
|
| 225 |
229 |
void clear() { _graph->clear(); }
|
| 226 |
230 |
|
| 227 |
231 |
bool direction(const Arc& a) const { return _graph->direction(a); }
|
| 228 |
232 |
Arc direct(const Edge& e, bool d) const { return _graph->direct(e, d); }
|
| 229 |
233 |
|
| 230 |
234 |
int id(const Node& v) const { return _graph->id(v); }
|
| 231 |
235 |
int id(const Arc& a) const { return _graph->id(a); }
|
| 232 |
236 |
int id(const Edge& e) const { return _graph->id(e); }
|
| 233 |
237 |
|
| 234 |
238 |
Node nodeFromId(int ix) const { return _graph->nodeFromId(ix); }
|
| 235 |
239 |
Arc arcFromId(int ix) const { return _graph->arcFromId(ix); }
|
| 236 |
240 |
Edge edgeFromId(int ix) const { return _graph->edgeFromId(ix); }
|
| 237 |
241 |
|
| 238 |
242 |
int maxNodeId() const { return _graph->maxNodeId(); }
|
| 239 |
243 |
int maxArcId() const { return _graph->maxArcId(); }
|
| 240 |
244 |
int maxEdgeId() const { return _graph->maxEdgeId(); }
|
| 241 |
245 |
|
| 242 |
|
typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
|
|
246 |
typedef typename ItemSetTraits<GR, Node>::ItemNotifier NodeNotifier;
|
| 243 |
247 |
NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
|
| 244 |
248 |
|
| 245 |
|
typedef typename ItemSetTraits<Graph, Arc>::ItemNotifier ArcNotifier;
|
|
249 |
typedef typename ItemSetTraits<GR, Arc>::ItemNotifier ArcNotifier;
|
| 246 |
250 |
ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
|
| 247 |
251 |
|
| 248 |
|
typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
|
|
252 |
typedef typename ItemSetTraits<GR, Edge>::ItemNotifier EdgeNotifier;
|
| 249 |
253 |
EdgeNotifier& notifier(Edge) const { return _graph->notifier(Edge()); }
|
| 250 |
254 |
|
| 251 |
|
template <typename _Value>
|
| 252 |
|
class NodeMap : public Graph::template NodeMap<_Value> {
|
|
255 |
template <typename V>
|
|
256 |
class NodeMap : public GR::template NodeMap<V> {
|
| 253 |
257 |
public:
|
| 254 |
|
typedef typename Graph::template NodeMap<_Value> Parent;
|
| 255 |
|
explicit NodeMap(const GraphAdaptorBase<Graph>& adapter)
|
|
258 |
typedef typename GR::template NodeMap<V> Parent;
|
|
259 |
explicit NodeMap(const GraphAdaptorBase<GR>& adapter)
|
| 256 |
260 |
: Parent(*adapter._graph) {}
|
| 257 |
|
NodeMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
|
|
261 |
NodeMap(const GraphAdaptorBase<GR>& adapter, const V& value)
|
| 258 |
262 |
: Parent(*adapter._graph, value) {}
|
| 259 |
263 |
|
| 260 |
264 |
private:
|
| 261 |
265 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 262 |
266 |
return operator=<NodeMap>(cmap);
|
| 263 |
267 |
}
|
| 264 |
268 |
|
| 265 |
269 |
template <typename CMap>
|
| 266 |
270 |
NodeMap& operator=(const CMap& cmap) {
|
| 267 |
271 |
Parent::operator=(cmap);
|
| 268 |
272 |
return *this;
|
| 269 |
273 |
}
|
| 270 |
274 |
|
| 271 |
275 |
};
|
| 272 |
276 |
|
| 273 |
|
template <typename _Value>
|
| 274 |
|
class ArcMap : public Graph::template ArcMap<_Value> {
|
|
277 |
template <typename V>
|
|
278 |
class ArcMap : public GR::template ArcMap<V> {
|
| 275 |
279 |
public:
|
| 276 |
|
typedef typename Graph::template ArcMap<_Value> Parent;
|
| 277 |
|
explicit ArcMap(const GraphAdaptorBase<Graph>& adapter)
|
|
280 |
typedef typename GR::template ArcMap<V> Parent;
|
|
281 |
explicit ArcMap(const GraphAdaptorBase<GR>& adapter)
|
| 278 |
282 |
: Parent(*adapter._graph) {}
|
| 279 |
|
ArcMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
|
|
283 |
ArcMap(const GraphAdaptorBase<GR>& adapter, const V& value)
|
| 280 |
284 |
: Parent(*adapter._graph, value) {}
|
| 281 |
285 |
|
| 282 |
286 |
private:
|
| 283 |
287 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 284 |
288 |
return operator=<ArcMap>(cmap);
|
| 285 |
289 |
}
|
| 286 |
290 |
|
| 287 |
291 |
template <typename CMap>
|
| 288 |
292 |
ArcMap& operator=(const CMap& cmap) {
|
| 289 |
293 |
Parent::operator=(cmap);
|
| 290 |
294 |
return *this;
|
| 291 |
295 |
}
|
| 292 |
296 |
};
|
| 293 |
297 |
|
| 294 |
|
template <typename _Value>
|
| 295 |
|
class EdgeMap : public Graph::template EdgeMap<_Value> {
|
|
298 |
template <typename V>
|
|
299 |
class EdgeMap : public GR::template EdgeMap<V> {
|
| 296 |
300 |
public:
|
| 297 |
|
typedef typename Graph::template EdgeMap<_Value> Parent;
|
| 298 |
|
explicit EdgeMap(const GraphAdaptorBase<Graph>& adapter)
|
|
301 |
typedef typename GR::template EdgeMap<V> Parent;
|
|
302 |
explicit EdgeMap(const GraphAdaptorBase<GR>& adapter)
|
| 299 |
303 |
: Parent(*adapter._graph) {}
|
| 300 |
|
EdgeMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
|
|
304 |
EdgeMap(const GraphAdaptorBase<GR>& adapter, const V& value)
|
| 301 |
305 |
: Parent(*adapter._graph, value) {}
|
| 302 |
306 |
|
| 303 |
307 |
private:
|
| 304 |
308 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
| 305 |
309 |
return operator=<EdgeMap>(cmap);
|
| 306 |
310 |
}
|
| 307 |
311 |
|
| 308 |
312 |
template <typename CMap>
|
| 309 |
313 |
EdgeMap& operator=(const CMap& cmap) {
|
| 310 |
314 |
Parent::operator=(cmap);
|
| 311 |
315 |
return *this;
|
| 312 |
316 |
}
|
| 313 |
317 |
};
|
| 314 |
318 |
|
| 315 |
319 |
};
|
| 316 |
320 |
|
| 317 |
|
template <typename _Digraph>
|
| 318 |
|
class ReverseDigraphBase : public DigraphAdaptorBase<_Digraph> {
|
|
321 |
template <typename DGR>
|
|
322 |
class ReverseDigraphBase : public DigraphAdaptorBase<DGR> {
|
| 319 |
323 |
public:
|
| 320 |
|
typedef _Digraph Digraph;
|
| 321 |
|
typedef DigraphAdaptorBase<_Digraph> Parent;
|
|
324 |
typedef DGR Digraph;
|
|
325 |
typedef DigraphAdaptorBase<DGR> Parent;
|
| 322 |
326 |
protected:
|
| 323 |
327 |
ReverseDigraphBase() : Parent() { }
|
| 324 |
328 |
public:
|
| 325 |
329 |
typedef typename Parent::Node Node;
|
| 326 |
330 |
typedef typename Parent::Arc Arc;
|
| 327 |
331 |
|
| 328 |
332 |
void firstIn(Arc& a, const Node& n) const { Parent::firstOut(a, n); }
|
| 329 |
333 |
void firstOut(Arc& a, const Node& n ) const { Parent::firstIn(a, n); }
|
| 330 |
334 |
|
| 331 |
335 |
void nextIn(Arc& a) const { Parent::nextOut(a); }
|
| 332 |
336 |
void nextOut(Arc& a) const { Parent::nextIn(a); }
|
| 333 |
337 |
|
| 334 |
338 |
Node source(const Arc& a) const { return Parent::target(a); }
|
| 335 |
339 |
Node target(const Arc& a) const { return Parent::source(a); }
|
| 336 |
340 |
|
| 337 |
341 |
Arc addArc(const Node& u, const Node& v) { return Parent::addArc(v, u); }
|
| 338 |
342 |
|
| 339 |
|
typedef FindArcTagIndicator<Digraph> FindArcTag;
|
|
343 |
typedef FindArcTagIndicator<DGR> FindArcTag;
|
| 340 |
344 |
Arc findArc(const Node& u, const Node& v,
|
| 341 |
345 |
const Arc& prev = INVALID) const {
|
| 342 |
346 |
return Parent::findArc(v, u, prev);
|
| 343 |
347 |
}
|
| 344 |
348 |
|
| 345 |
349 |
};
|
| 346 |
350 |
|
| 347 |
351 |
/// \ingroup graph_adaptors
|
| 348 |
352 |
///
|
| 349 |
353 |
/// \brief Adaptor class for reversing the orientation of the arcs in
|
| 350 |
354 |
/// a digraph.
|
| 351 |
355 |
///
|
| 352 |
356 |
/// ReverseDigraph can be used for reversing the arcs in a digraph.
|
| 353 |
357 |
/// It conforms to the \ref concepts::Digraph "Digraph" concept.
|
| 354 |
358 |
///
|
| 355 |
359 |
/// The adapted digraph can also be modified through this adaptor
|
| 356 |
360 |
/// by adding or removing nodes or arcs, unless the \c GR template
|
| 357 |
361 |
/// parameter is set to be \c const.
|
| 358 |
362 |
///
|
| 359 |
|
/// \tparam GR The type of the adapted digraph.
|
|
363 |
/// \tparam DGR The type of the adapted digraph.
|
| 360 |
364 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept.
|
| 361 |
365 |
/// It can also be specified to be \c const.
|
| 362 |
366 |
///
|
| 363 |
367 |
/// \note The \c Node and \c Arc types of this adaptor and the adapted
|
| 364 |
368 |
/// digraph are convertible to each other.
|
| 365 |
|
template<typename GR>
|
|
369 |
template<typename DGR>
|
| 366 |
370 |
#ifdef DOXYGEN
|
| 367 |
371 |
class ReverseDigraph {
|
| 368 |
372 |
#else
|
| 369 |
373 |
class ReverseDigraph :
|
| 370 |
|
public DigraphAdaptorExtender<ReverseDigraphBase<GR> > {
|
|
374 |
public DigraphAdaptorExtender<ReverseDigraphBase<DGR> > {
|
| 371 |
375 |
#endif
|
| 372 |
376 |
public:
|
| 373 |
377 |
/// The type of the adapted digraph.
|
| 374 |
|
typedef GR Digraph;
|
| 375 |
|
typedef DigraphAdaptorExtender<ReverseDigraphBase<GR> > Parent;
|
|
378 |
typedef DGR Digraph;
|
|
379 |
typedef DigraphAdaptorExtender<ReverseDigraphBase<DGR> > Parent;
|
| 376 |
380 |
protected:
|
| 377 |
381 |
ReverseDigraph() { }
|
| 378 |
382 |
public:
|
| 379 |
383 |
|
| 380 |
384 |
/// \brief Constructor
|
| 381 |
385 |
///
|
| 382 |
386 |
/// Creates a reverse digraph adaptor for the given digraph.
|
| 383 |
|
explicit ReverseDigraph(Digraph& digraph) {
|
| 384 |
|
Parent::setDigraph(digraph);
|
|
387 |
explicit ReverseDigraph(DGR& digraph) {
|
|
388 |
Parent::initialize(digraph);
|
| 385 |
389 |
}
|
| 386 |
390 |
};
|
| 387 |
391 |
|
| 388 |
392 |
/// \brief Returns a read-only ReverseDigraph adaptor
|
| 389 |
393 |
///
|
| 390 |
394 |
/// This function just returns a read-only \ref ReverseDigraph adaptor.
|
| 391 |
395 |
/// \ingroup graph_adaptors
|
| 392 |
396 |
/// \relates ReverseDigraph
|
| 393 |
|
template<typename GR>
|
| 394 |
|
ReverseDigraph<const GR> reverseDigraph(const GR& digraph) {
|
| 395 |
|
return ReverseDigraph<const GR>(digraph);
|
|
397 |
template<typename DGR>
|
|
398 |
ReverseDigraph<const DGR> reverseDigraph(const DGR& digraph) {
|
|
399 |
return ReverseDigraph<const DGR>(digraph);
|
| 396 |
400 |
}
|
| 397 |
401 |
|
| 398 |
402 |
|
| 399 |
|
template <typename _Digraph, typename _NodeFilterMap,
|
| 400 |
|
typename _ArcFilterMap, bool _checked = true>
|
| 401 |
|
class SubDigraphBase : public DigraphAdaptorBase<_Digraph> {
|
|
403 |
template <typename DGR, typename NF, typename AF, bool ch = true>
|
|
404 |
class SubDigraphBase : public DigraphAdaptorBase<DGR> {
|
| 402 |
405 |
public:
|
| 403 |
|
typedef _Digraph Digraph;
|
| 404 |
|
typedef _NodeFilterMap NodeFilterMap;
|
| 405 |
|
typedef _ArcFilterMap ArcFilterMap;
|
|
406 |
typedef DGR Digraph;
|
|
407 |
typedef NF NodeFilterMap;
|
|
408 |
typedef AF ArcFilterMap;
|
| 406 |
409 |
|
| 407 |
410 |
typedef SubDigraphBase Adaptor;
|
| 408 |
|
typedef DigraphAdaptorBase<_Digraph> Parent;
|
|
411 |
typedef DigraphAdaptorBase<DGR> Parent;
|
| 409 |
412 |
protected:
|
| 410 |
|
NodeFilterMap* _node_filter;
|
| 411 |
|
ArcFilterMap* _arc_filter;
|
|
413 |
NF* _node_filter;
|
|
414 |
AF* _arc_filter;
|
| 412 |
415 |
SubDigraphBase()
|
| 413 |
416 |
: Parent(), _node_filter(0), _arc_filter(0) { }
|
| 414 |
417 |
|
| 415 |
|
void setNodeFilterMap(NodeFilterMap& node_filter) {
|
|
418 |
void initialize(DGR& digraph, NF& node_filter, AF& arc_filter) {
|
|
419 |
Parent::initialize(digraph);
|
| 416 |
420 |
_node_filter = &node_filter;
|
| 417 |
|
}
|
| 418 |
|
void setArcFilterMap(ArcFilterMap& arc_filter) {
|
| 419 |
|
_arc_filter = &arc_filter;
|
|
421 |
_arc_filter = &arc_filter;
|
| 420 |
422 |
}
|
| 421 |
423 |
|
| 422 |
424 |
public:
|
| 423 |
425 |
|
| 424 |
426 |
typedef typename Parent::Node Node;
|
| 425 |
427 |
typedef typename Parent::Arc Arc;
|
| 426 |
428 |
|
| 427 |
429 |
void first(Node& i) const {
|
| 428 |
430 |
Parent::first(i);
|
| 429 |
431 |
while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
|
| 430 |
432 |
}
|
| 431 |
433 |
|
| 432 |
434 |
void first(Arc& i) const {
|
| 433 |
435 |
Parent::first(i);
|
| 434 |
436 |
while (i != INVALID && (!(*_arc_filter)[i]
|
| 435 |
437 |
|| !(*_node_filter)[Parent::source(i)]
|
| 436 |
438 |
|| !(*_node_filter)[Parent::target(i)]))
|
| 437 |
439 |
Parent::next(i);
|
| 438 |
440 |
}
|
| 439 |
441 |
|
| 440 |
442 |
void firstIn(Arc& i, const Node& n) const {
|
| 441 |
443 |
Parent::firstIn(i, n);
|
| 442 |
444 |
while (i != INVALID && (!(*_arc_filter)[i]
|
| 443 |
445 |
|| !(*_node_filter)[Parent::source(i)]))
|
| 444 |
446 |
Parent::nextIn(i);
|
| 445 |
447 |
}
|
| 446 |
448 |
|
| 447 |
449 |
void firstOut(Arc& i, const Node& n) const {
|
| 448 |
450 |
Parent::firstOut(i, n);
|
| 449 |
451 |
while (i != INVALID && (!(*_arc_filter)[i]
|
| 450 |
452 |
|| !(*_node_filter)[Parent::target(i)]))
|
| 451 |
453 |
Parent::nextOut(i);
|
| 452 |
454 |
}
|
| 453 |
455 |
|
| 454 |
456 |
void next(Node& i) const {
|
| 455 |
457 |
Parent::next(i);
|
| 456 |
458 |
while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
|
| 457 |
459 |
}
|
| 458 |
460 |
|
| 459 |
461 |
void next(Arc& i) const {
|
| 460 |
462 |
Parent::next(i);
|
| 461 |
463 |
while (i != INVALID && (!(*_arc_filter)[i]
|
| 462 |
464 |
|| !(*_node_filter)[Parent::source(i)]
|
| 463 |
465 |
|| !(*_node_filter)[Parent::target(i)]))
|
| 464 |
466 |
Parent::next(i);
|
| 465 |
467 |
}
|
| 466 |
468 |
|
| 467 |
469 |
void nextIn(Arc& i) const {
|
| 468 |
470 |
Parent::nextIn(i);
|
| 469 |
471 |
while (i != INVALID && (!(*_arc_filter)[i]
|
| 470 |
472 |
|| !(*_node_filter)[Parent::source(i)]))
|
| 471 |
473 |
Parent::nextIn(i);
|
| 472 |
474 |
}
|
| 473 |
475 |
|
| 474 |
476 |
void nextOut(Arc& i) const {
|
| 475 |
477 |
Parent::nextOut(i);
|
| 476 |
478 |
while (i != INVALID && (!(*_arc_filter)[i]
|
| 477 |
479 |
|| !(*_node_filter)[Parent::target(i)]))
|
| 478 |
480 |
Parent::nextOut(i);
|
| 479 |
481 |
}
|
| 480 |
482 |
|
| 481 |
483 |
void status(const Node& n, bool v) const { _node_filter->set(n, v); }
|
| 482 |
484 |
void status(const Arc& a, bool v) const { _arc_filter->set(a, v); }
|
| 483 |
485 |
|
| 484 |
486 |
bool status(const Node& n) const { return (*_node_filter)[n]; }
|
| 485 |
487 |
bool status(const Arc& a) const { return (*_arc_filter)[a]; }
|
| 486 |
488 |
|
| 487 |
489 |
typedef False NodeNumTag;
|
| 488 |
490 |
typedef False ArcNumTag;
|
| 489 |
491 |
|
| 490 |
|
typedef FindArcTagIndicator<Digraph> FindArcTag;
|
|
492 |
typedef FindArcTagIndicator<DGR> FindArcTag;
|
| 491 |
493 |
Arc findArc(const Node& source, const Node& target,
|
| 492 |
494 |
const Arc& prev = INVALID) const {
|
| 493 |
495 |
if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
|
| 494 |
496 |
return INVALID;
|
| 495 |
497 |
}
|
| 496 |
498 |
Arc arc = Parent::findArc(source, target, prev);
|
| 497 |
499 |
while (arc != INVALID && !(*_arc_filter)[arc]) {
|
| 498 |
500 |
arc = Parent::findArc(source, target, arc);
|
| 499 |
501 |
}
|
| 500 |
502 |
return arc;
|
| 501 |
503 |
}
|
| 502 |
504 |
|
| 503 |
|
template <typename _Value>
|
| 504 |
|
class NodeMap : public SubMapExtender<Adaptor,
|
| 505 |
|
typename Parent::template NodeMap<_Value> > {
|
|
505 |
public:
|
|
506 |
|
|
507 |
template <typename V>
|
|
508 |
class NodeMap
|
|
509 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
|
|
510 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> {
|
| 506 |
511 |
public:
|
| 507 |
|
typedef _Value Value;
|
| 508 |
|
typedef SubMapExtender<Adaptor, typename Parent::
|
| 509 |
|
template NodeMap<Value> > MapParent;
|
| 510 |
|
|
| 511 |
|
NodeMap(const Adaptor& adaptor)
|
| 512 |
|
: MapParent(adaptor) {}
|
| 513 |
|
NodeMap(const Adaptor& adaptor, const Value& value)
|
| 514 |
|
: MapParent(adaptor, value) {}
|
|
512 |
typedef V Value;
|
|
513 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
|
|
514 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent;
|
|
515 |
|
|
516 |
NodeMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor)
|
|
517 |
: Parent(adaptor) {}
|
|
518 |
NodeMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor, const V& value)
|
|
519 |
: Parent(adaptor, value) {}
|
| 515 |
520 |
|
| 516 |
521 |
private:
|
| 517 |
522 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 518 |
523 |
return operator=<NodeMap>(cmap);
|
| 519 |
524 |
}
|
| 520 |
525 |
|
| 521 |
526 |
template <typename CMap>
|
| 522 |
527 |
NodeMap& operator=(const CMap& cmap) {
|
| 523 |
|
MapParent::operator=(cmap);
|
|
528 |
Parent::operator=(cmap);
|
| 524 |
529 |
return *this;
|
| 525 |
530 |
}
|
| 526 |
531 |
};
|
| 527 |
532 |
|
| 528 |
|
template <typename _Value>
|
| 529 |
|
class ArcMap : public SubMapExtender<Adaptor,
|
| 530 |
|
typename Parent::template ArcMap<_Value> > {
|
|
533 |
template <typename V>
|
|
534 |
class ArcMap
|
|
535 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
|
|
536 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> {
|
| 531 |
537 |
public:
|
| 532 |
|
typedef _Value Value;
|
| 533 |
|
typedef SubMapExtender<Adaptor, typename Parent::
|
| 534 |
|
template ArcMap<Value> > MapParent;
|
| 535 |
|
|
| 536 |
|
ArcMap(const Adaptor& adaptor)
|
| 537 |
|
: MapParent(adaptor) {}
|
| 538 |
|
ArcMap(const Adaptor& adaptor, const Value& value)
|
| 539 |
|
: MapParent(adaptor, value) {}
|
|
538 |
typedef V Value;
|
|
539 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
|
|
540 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> Parent;
|
|
541 |
|
|
542 |
ArcMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor)
|
|
543 |
: Parent(adaptor) {}
|
|
544 |
ArcMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor, const V& value)
|
|
545 |
: Parent(adaptor, value) {}
|
| 540 |
546 |
|
| 541 |
547 |
private:
|
| 542 |
548 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 543 |
549 |
return operator=<ArcMap>(cmap);
|
| 544 |
550 |
}
|
| 545 |
551 |
|
| 546 |
552 |
template <typename CMap>
|
| 547 |
553 |
ArcMap& operator=(const CMap& cmap) {
|
| 548 |
|
MapParent::operator=(cmap);
|
|
554 |
Parent::operator=(cmap);
|
| 549 |
555 |
return *this;
|
| 550 |
556 |
}
|
| 551 |
557 |
};
|
| 552 |
558 |
|
| 553 |
559 |
};
|
| 554 |
560 |
|
| 555 |
|
template <typename _Digraph, typename _NodeFilterMap, typename _ArcFilterMap>
|
| 556 |
|
class SubDigraphBase<_Digraph, _NodeFilterMap, _ArcFilterMap, false>
|
| 557 |
|
: public DigraphAdaptorBase<_Digraph> {
|
|
561 |
template <typename DGR, typename NF, typename AF>
|
|
562 |
class SubDigraphBase<DGR, NF, AF, false>
|
|
563 |
: public DigraphAdaptorBase<DGR> {
|
| 558 |
564 |
public:
|
| 559 |
|
typedef _Digraph Digraph;
|
| 560 |
|
typedef _NodeFilterMap NodeFilterMap;
|
| 561 |
|
typedef _ArcFilterMap ArcFilterMap;
|
|
565 |
typedef DGR Digraph;
|
|
566 |
typedef NF NodeFilterMap;
|
|
567 |
typedef AF ArcFilterMap;
|
| 562 |
568 |
|
| 563 |
569 |
typedef SubDigraphBase Adaptor;
|
| 564 |
570 |
typedef DigraphAdaptorBase<Digraph> Parent;
|
| 565 |
571 |
protected:
|
| 566 |
|
NodeFilterMap* _node_filter;
|
| 567 |
|
ArcFilterMap* _arc_filter;
|
|
572 |
NF* _node_filter;
|
|
573 |
AF* _arc_filter;
|
| 568 |
574 |
SubDigraphBase()
|
| 569 |
575 |
: Parent(), _node_filter(0), _arc_filter(0) { }
|
| 570 |
576 |
|
| 571 |
|
void setNodeFilterMap(NodeFilterMap& node_filter) {
|
|
577 |
void initialize(DGR& digraph, NF& node_filter, AF& arc_filter) {
|
|
578 |
Parent::initialize(digraph);
|
| 572 |
579 |
_node_filter = &node_filter;
|
| 573 |
|
}
|
| 574 |
|
void setArcFilterMap(ArcFilterMap& arc_filter) {
|
| 575 |
|
_arc_filter = &arc_filter;
|
|
580 |
_arc_filter = &arc_filter;
|
| 576 |
581 |
}
|
| 577 |
582 |
|
| 578 |
583 |
public:
|
| 579 |
584 |
|
| 580 |
585 |
typedef typename Parent::Node Node;
|
| 581 |
586 |
typedef typename Parent::Arc Arc;
|
| 582 |
587 |
|
| 583 |
588 |
void first(Node& i) const {
|
| 584 |
589 |
Parent::first(i);
|
| 585 |
590 |
while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
|
| 586 |
591 |
}
|
| 587 |
592 |
|
| 588 |
593 |
void first(Arc& i) const {
|
| 589 |
594 |
Parent::first(i);
|
| 590 |
595 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
|
| 591 |
596 |
}
|
| 592 |
597 |
|
| 593 |
598 |
void firstIn(Arc& i, const Node& n) const {
|
| 594 |
599 |
Parent::firstIn(i, n);
|
| 595 |
600 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
|
| 596 |
601 |
}
|
| 597 |
602 |
|
| 598 |
603 |
void firstOut(Arc& i, const Node& n) const {
|
| 599 |
604 |
Parent::firstOut(i, n);
|
| 600 |
605 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
|
| 601 |
606 |
}
|
| 602 |
607 |
|
| 603 |
608 |
void next(Node& i) const {
|
| 604 |
609 |
Parent::next(i);
|
| 605 |
610 |
while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
|
| 606 |
611 |
}
|
| 607 |
612 |
void next(Arc& i) const {
|
| 608 |
613 |
Parent::next(i);
|
| 609 |
614 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
|
| 610 |
615 |
}
|
| 611 |
616 |
void nextIn(Arc& i) const {
|
| 612 |
617 |
Parent::nextIn(i);
|
| 613 |
618 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
|
| 614 |
619 |
}
|
| 615 |
620 |
|
| 616 |
621 |
void nextOut(Arc& i) const {
|
| 617 |
622 |
Parent::nextOut(i);
|
| 618 |
623 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
|
| 619 |
624 |
}
|
| 620 |
625 |
|
| 621 |
626 |
void status(const Node& n, bool v) const { _node_filter->set(n, v); }
|
| 622 |
627 |
void status(const Arc& a, bool v) const { _arc_filter->set(a, v); }
|
| 623 |
628 |
|
| 624 |
629 |
bool status(const Node& n) const { return (*_node_filter)[n]; }
|
| 625 |
630 |
bool status(const Arc& a) const { return (*_arc_filter)[a]; }
|
| 626 |
631 |
|
| 627 |
632 |
typedef False NodeNumTag;
|
| 628 |
633 |
typedef False ArcNumTag;
|
| 629 |
634 |
|
| 630 |
|
typedef FindArcTagIndicator<Digraph> FindArcTag;
|
|
635 |
typedef FindArcTagIndicator<DGR> FindArcTag;
|
| 631 |
636 |
Arc findArc(const Node& source, const Node& target,
|
| 632 |
637 |
const Arc& prev = INVALID) const {
|
| 633 |
638 |
if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
|
| 634 |
639 |
return INVALID;
|
| 635 |
640 |
}
|
| 636 |
641 |
Arc arc = Parent::findArc(source, target, prev);
|
| 637 |
642 |
while (arc != INVALID && !(*_arc_filter)[arc]) {
|
| 638 |
643 |
arc = Parent::findArc(source, target, arc);
|
| 639 |
644 |
}
|
| 640 |
645 |
return arc;
|
| 641 |
646 |
}
|
| 642 |
647 |
|
| 643 |
|
template <typename _Value>
|
| 644 |
|
class NodeMap : public SubMapExtender<Adaptor,
|
| 645 |
|
typename Parent::template NodeMap<_Value> > {
|
|
648 |
template <typename V>
|
|
649 |
class NodeMap
|
|
650 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
|
|
651 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> {
|
| 646 |
652 |
public:
|
| 647 |
|
typedef _Value Value;
|
| 648 |
|
typedef SubMapExtender<Adaptor, typename Parent::
|
| 649 |
|
template NodeMap<Value> > MapParent;
|
| 650 |
|
|
| 651 |
|
NodeMap(const Adaptor& adaptor)
|
| 652 |
|
: MapParent(adaptor) {}
|
| 653 |
|
NodeMap(const Adaptor& adaptor, const Value& value)
|
| 654 |
|
: MapParent(adaptor, value) {}
|
|
653 |
typedef V Value;
|
|
654 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
|
|
655 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent;
|
|
656 |
|
|
657 |
NodeMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor)
|
|
658 |
: Parent(adaptor) {}
|
|
659 |
NodeMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor, const V& value)
|
|
660 |
: Parent(adaptor, value) {}
|
| 655 |
661 |
|
| 656 |
662 |
private:
|
| 657 |
663 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 658 |
664 |
return operator=<NodeMap>(cmap);
|
| 659 |
665 |
}
|
| 660 |
666 |
|
| 661 |
667 |
template <typename CMap>
|
| 662 |
668 |
NodeMap& operator=(const CMap& cmap) {
|
| 663 |
|
MapParent::operator=(cmap);
|
|
669 |
Parent::operator=(cmap);
|
| 664 |
670 |
return *this;
|
| 665 |
671 |
}
|
| 666 |
672 |
};
|
| 667 |
673 |
|
| 668 |
|
template <typename _Value>
|
| 669 |
|
class ArcMap : public SubMapExtender<Adaptor,
|
| 670 |
|
typename Parent::template ArcMap<_Value> > {
|
|
674 |
template <typename V>
|
|
675 |
class ArcMap
|
|
676 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
|
|
677 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> {
|
| 671 |
678 |
public:
|
| 672 |
|
typedef _Value Value;
|
| 673 |
|
typedef SubMapExtender<Adaptor, typename Parent::
|
| 674 |
|
template ArcMap<Value> > MapParent;
|
| 675 |
|
|
| 676 |
|
ArcMap(const Adaptor& adaptor)
|
| 677 |
|
: MapParent(adaptor) {}
|
| 678 |
|
ArcMap(const Adaptor& adaptor, const Value& value)
|
| 679 |
|
: MapParent(adaptor, value) {}
|
|
679 |
typedef V Value;
|
|
680 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
|
|
681 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> Parent;
|
|
682 |
|
|
683 |
ArcMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor)
|
|
684 |
: Parent(adaptor) {}
|
|
685 |
ArcMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor, const V& value)
|
|
686 |
: Parent(adaptor, value) {}
|
| 680 |
687 |
|
| 681 |
688 |
private:
|
| 682 |
689 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 683 |
690 |
return operator=<ArcMap>(cmap);
|
| 684 |
691 |
}
|
| 685 |
692 |
|
| 686 |
693 |
template <typename CMap>
|
| 687 |
694 |
ArcMap& operator=(const CMap& cmap) {
|
| 688 |
|
MapParent::operator=(cmap);
|
|
695 |
Parent::operator=(cmap);
|
| 689 |
696 |
return *this;
|
| 690 |
697 |
}
|
| 691 |
698 |
};
|
| 692 |
699 |
|
| 693 |
700 |
};
|
| 694 |
701 |
|
| 695 |
702 |
/// \ingroup graph_adaptors
|
| 696 |
703 |
///
|
| 697 |
704 |
/// \brief Adaptor class for hiding nodes and arcs in a digraph
|
| 698 |
705 |
///
|
| 699 |
706 |
/// SubDigraph can be used for hiding nodes and arcs in a digraph.
|
| 700 |
707 |
/// A \c bool node map and a \c bool arc map must be specified, which
|
| 701 |
708 |
/// define the filters for nodes and arcs.
|
| 702 |
709 |
/// Only the nodes and arcs with \c true filter value are
|
| 703 |
710 |
/// shown in the subdigraph. The arcs that are incident to hidden
|
| 704 |
711 |
/// nodes are also filtered out.
|
| 705 |
712 |
/// This adaptor conforms to the \ref concepts::Digraph "Digraph" concept.
|
| 706 |
713 |
///
|
| 707 |
714 |
/// The adapted digraph can also be modified through this adaptor
|
| 708 |
715 |
/// by adding or removing nodes or arcs, unless the \c GR template
|
| 709 |
716 |
/// parameter is set to be \c const.
|
| 710 |
717 |
///
|
| 711 |
|
/// \tparam GR The type of the adapted digraph.
|
|
718 |
/// \tparam DGR The type of the adapted digraph.
|
| 712 |
719 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept.
|
| 713 |
720 |
/// It can also be specified to be \c const.
|
| 714 |
721 |
/// \tparam NF The type of the node filter map.
|
| 715 |
722 |
/// It must be a \c bool (or convertible) node map of the
|
| 716 |
723 |
/// adapted digraph. The default type is
|
| 717 |
|
/// \ref concepts::Digraph::NodeMap "GR::NodeMap<bool>".
|
|
724 |
/// \ref concepts::Digraph::NodeMap "DGR::NodeMap<bool>".
|
| 718 |
725 |
/// \tparam AF The type of the arc filter map.
|
| 719 |
726 |
/// It must be \c bool (or convertible) arc map of the
|
| 720 |
727 |
/// adapted digraph. The default type is
|
| 721 |
|
/// \ref concepts::Digraph::ArcMap "GR::ArcMap<bool>".
|
|
728 |
/// \ref concepts::Digraph::ArcMap "DGR::ArcMap<bool>".
|
| 722 |
729 |
///
|
| 723 |
730 |
/// \note The \c Node and \c Arc types of this adaptor and the adapted
|
| 724 |
731 |
/// digraph are convertible to each other.
|
| 725 |
732 |
///
|
| 726 |
733 |
/// \see FilterNodes
|
| 727 |
734 |
/// \see FilterArcs
|
| 728 |
735 |
#ifdef DOXYGEN
|
| 729 |
|
template<typename GR, typename NF, typename AF>
|
|
736 |
template<typename DGR, typename NF, typename AF>
|
| 730 |
737 |
class SubDigraph {
|
| 731 |
738 |
#else
|
| 732 |
|
template<typename GR,
|
| 733 |
|
typename NF = typename GR::template NodeMap<bool>,
|
| 734 |
|
typename AF = typename GR::template ArcMap<bool> >
|
|
739 |
template<typename DGR,
|
|
740 |
typename NF = typename DGR::template NodeMap<bool>,
|
|
741 |
typename AF = typename DGR::template ArcMap<bool> >
|
| 735 |
742 |
class SubDigraph :
|
| 736 |
|
public DigraphAdaptorExtender<SubDigraphBase<GR, NF, AF, true> > {
|
|
743 |
public DigraphAdaptorExtender<SubDigraphBase<DGR, NF, AF, true> > {
|
| 737 |
744 |
#endif
|
| 738 |
745 |
public:
|
| 739 |
746 |
/// The type of the adapted digraph.
|
| 740 |
|
typedef GR Digraph;
|
|
747 |
typedef DGR Digraph;
|
| 741 |
748 |
/// The type of the node filter map.
|
| 742 |
749 |
typedef NF NodeFilterMap;
|
| 743 |
750 |
/// The type of the arc filter map.
|
| 744 |
751 |
typedef AF ArcFilterMap;
|
| 745 |
752 |
|
| 746 |
|
typedef DigraphAdaptorExtender<SubDigraphBase<GR, NF, AF, true> >
|
|
753 |
typedef DigraphAdaptorExtender<SubDigraphBase<DGR, NF, AF, true> >
|
| 747 |
754 |
Parent;
|
| 748 |
755 |
|
| 749 |
756 |
typedef typename Parent::Node Node;
|
| 750 |
757 |
typedef typename Parent::Arc Arc;
|
| 751 |
758 |
|
| 752 |
759 |
protected:
|
| 753 |
760 |
SubDigraph() { }
|
| 754 |
761 |
public:
|
| 755 |
762 |
|
| 756 |
763 |
/// \brief Constructor
|
| 757 |
764 |
///
|
| 758 |
765 |
/// Creates a subdigraph for the given digraph with the
|
| 759 |
766 |
/// given node and arc filter maps.
|
| 760 |
|
SubDigraph(Digraph& digraph, NodeFilterMap& node_filter,
|
| 761 |
|
ArcFilterMap& arc_filter) {
|
| 762 |
|
setDigraph(digraph);
|
| 763 |
|
setNodeFilterMap(node_filter);
|
| 764 |
|
setArcFilterMap(arc_filter);
|
|
767 |
SubDigraph(DGR& digraph, NF& node_filter, AF& arc_filter) {
|
|
768 |
Parent::initialize(digraph, node_filter, arc_filter);
|
| 765 |
769 |
}
|
| 766 |
770 |
|
| 767 |
771 |
/// \brief Sets the status of the given node
|
| 768 |
772 |
///
|
| 769 |
773 |
/// This function sets the status of the given node.
|
| 770 |
774 |
/// It is done by simply setting the assigned value of \c n
|
| 771 |
775 |
/// to \c v in the node filter map.
|
| 772 |
776 |
void status(const Node& n, bool v) const { Parent::status(n, v); }
|
| 773 |
777 |
|
| 774 |
778 |
/// \brief Sets the status of the given arc
|
| 775 |
779 |
///
|
| 776 |
780 |
/// This function sets the status of the given arc.
|
| 777 |
781 |
/// It is done by simply setting the assigned value of \c a
|
| 778 |
782 |
/// to \c v in the arc filter map.
|
| 779 |
783 |
void status(const Arc& a, bool v) const { Parent::status(a, v); }
|
| 780 |
784 |
|
| 781 |
785 |
/// \brief Returns the status of the given node
|
| 782 |
786 |
///
|
| 783 |
787 |
/// This function returns the status of the given node.
|
| 784 |
788 |
/// It is \c true if the given node is enabled (i.e. not hidden).
|
| 785 |
789 |
bool status(const Node& n) const { return Parent::status(n); }
|
| 786 |
790 |
|
| 787 |
791 |
/// \brief Returns the status of the given arc
|
| 788 |
792 |
///
|
| 789 |
793 |
/// This function returns the status of the given arc.
|
| 790 |
794 |
/// It is \c true if the given arc is enabled (i.e. not hidden).
|
| 791 |
795 |
bool status(const Arc& a) const { return Parent::status(a); }
|
| 792 |
796 |
|
| 793 |
797 |
/// \brief Disables the given node
|
| 794 |
798 |
///
|
| 795 |
799 |
/// This function disables the given node in the subdigraph,
|
| 796 |
800 |
/// so the iteration jumps over it.
|
| 797 |
801 |
/// It is the same as \ref status() "status(n, false)".
|
| 798 |
802 |
void disable(const Node& n) const { Parent::status(n, false); }
|
| 799 |
803 |
|
| 800 |
804 |
/// \brief Disables the given arc
|
| 801 |
805 |
///
|
| 802 |
806 |
/// This function disables the given arc in the subdigraph,
|
| 803 |
807 |
/// so the iteration jumps over it.
|
| 804 |
808 |
/// It is the same as \ref status() "status(a, false)".
|
| 805 |
809 |
void disable(const Arc& a) const { Parent::status(a, false); }
|
| 806 |
810 |
|
| 807 |
811 |
/// \brief Enables the given node
|
| 808 |
812 |
///
|
| 809 |
813 |
/// This function enables the given node in the subdigraph.
|
| 810 |
814 |
/// It is the same as \ref status() "status(n, true)".
|
| 811 |
815 |
void enable(const Node& n) const { Parent::status(n, true); }
|
| 812 |
816 |
|
| 813 |
817 |
/// \brief Enables the given arc
|
| 814 |
818 |
///
|
| 815 |
819 |
/// This function enables the given arc in the subdigraph.
|
| 816 |
820 |
/// It is the same as \ref status() "status(a, true)".
|
| 817 |
821 |
void enable(const Arc& a) const { Parent::status(a, true); }
|
| 818 |
822 |
|
| 819 |
823 |
};
|
| 820 |
824 |
|
| 821 |
825 |
/// \brief Returns a read-only SubDigraph adaptor
|
| 822 |
826 |
///
|
| 823 |
827 |
/// This function just returns a read-only \ref SubDigraph adaptor.
|
| 824 |
828 |
/// \ingroup graph_adaptors
|
| 825 |
829 |
/// \relates SubDigraph
|
| 826 |
|
template<typename GR, typename NF, typename AF>
|
| 827 |
|
SubDigraph<const GR, NF, AF>
|
| 828 |
|
subDigraph(const GR& digraph,
|
| 829 |
|
NF& node_filter_map, AF& arc_filter_map) {
|
| 830 |
|
return SubDigraph<const GR, NF, AF>
|
| 831 |
|
(digraph, node_filter_map, arc_filter_map);
|
|
830 |
template<typename DGR, typename NF, typename AF>
|
|
831 |
SubDigraph<const DGR, NF, AF>
|
|
832 |
subDigraph(const DGR& digraph,
|
|
833 |
NF& node_filter, AF& arc_filter) {
|
|
834 |
return SubDigraph<const DGR, NF, AF>
|
|
835 |
(digraph, node_filter, arc_filter);
|
| 832 |
836 |
}
|
| 833 |
837 |
|
| 834 |
|
template<typename GR, typename NF, typename AF>
|
| 835 |
|
SubDigraph<const GR, const NF, AF>
|
| 836 |
|
subDigraph(const GR& digraph,
|
| 837 |
|
const NF& node_filter_map, AF& arc_filter_map) {
|
| 838 |
|
return SubDigraph<const GR, const NF, AF>
|
| 839 |
|
(digraph, node_filter_map, arc_filter_map);
|
|
838 |
template<typename DGR, typename NF, typename AF>
|
|
839 |
SubDigraph<const DGR, const NF, AF>
|
|
840 |
subDigraph(const DGR& digraph,
|
|
841 |
const NF& node_filter, AF& arc_filter) {
|
|
842 |
return SubDigraph<const DGR, const NF, AF>
|
|
843 |
(digraph, node_filter, arc_filter);
|
| 840 |
844 |
}
|
| 841 |
845 |
|
| 842 |
|
template<typename GR, typename NF, typename AF>
|
| 843 |
|
SubDigraph<const GR, NF, const AF>
|
| 844 |
|
subDigraph(const GR& digraph,
|
| 845 |
|
NF& node_filter_map, const AF& arc_filter_map) {
|
| 846 |
|
return SubDigraph<const GR, NF, const AF>
|
| 847 |
|
(digraph, node_filter_map, arc_filter_map);
|
|
846 |
template<typename DGR, typename NF, typename AF>
|
|
847 |
SubDigraph<const DGR, NF, const AF>
|
|
848 |
subDigraph(const DGR& digraph,
|
|
849 |
NF& node_filter, const AF& arc_filter) {
|
|
850 |
return SubDigraph<const DGR, NF, const AF>
|
|
851 |
(digraph, node_filter, arc_filter);
|
| 848 |
852 |
}
|
| 849 |
853 |
|
| 850 |
|
template<typename GR, typename NF, typename AF>
|
| 851 |
|
SubDigraph<const GR, const NF, const AF>
|
| 852 |
|
subDigraph(const GR& digraph,
|
| 853 |
|
const NF& node_filter_map, const AF& arc_filter_map) {
|
| 854 |
|
return SubDigraph<const GR, const NF, const AF>
|
| 855 |
|
(digraph, node_filter_map, arc_filter_map);
|
|
854 |
template<typename DGR, typename NF, typename AF>
|
|
855 |
SubDigraph<const DGR, const NF, const AF>
|
|
856 |
subDigraph(const DGR& digraph,
|
|
857 |
const NF& node_filter, const AF& arc_filter) {
|
|
858 |
return SubDigraph<const DGR, const NF, const AF>
|
|
859 |
(digraph, node_filter, arc_filter);
|
| 856 |
860 |
}
|
| 857 |
861 |
|
| 858 |
862 |
|
| 859 |
|
template <typename _Graph, typename _NodeFilterMap,
|
| 860 |
|
typename _EdgeFilterMap, bool _checked = true>
|
| 861 |
|
class SubGraphBase : public GraphAdaptorBase<_Graph> {
|
|
863 |
template <typename GR, typename NF, typename EF, bool ch = true>
|
|
864 |
class SubGraphBase : public GraphAdaptorBase<GR> {
|
| 862 |
865 |
public:
|
| 863 |
|
typedef _Graph Graph;
|
| 864 |
|
typedef _NodeFilterMap NodeFilterMap;
|
| 865 |
|
typedef _EdgeFilterMap EdgeFilterMap;
|
|
866 |
typedef GR Graph;
|
|
867 |
typedef NF NodeFilterMap;
|
|
868 |
typedef EF EdgeFilterMap;
|
| 866 |
869 |
|
| 867 |
870 |
typedef SubGraphBase Adaptor;
|
| 868 |
|
typedef GraphAdaptorBase<_Graph> Parent;
|
|
871 |
typedef GraphAdaptorBase<GR> Parent;
|
| 869 |
872 |
protected:
|
| 870 |
873 |
|
| 871 |
|
NodeFilterMap* _node_filter_map;
|
| 872 |
|
EdgeFilterMap* _edge_filter_map;
|
|
874 |
NF* _node_filter;
|
|
875 |
EF* _edge_filter;
|
| 873 |
876 |
|
| 874 |
877 |
SubGraphBase()
|
| 875 |
|
: Parent(), _node_filter_map(0), _edge_filter_map(0) { }
|
| 876 |
|
|
| 877 |
|
void setNodeFilterMap(NodeFilterMap& node_filter_map) {
|
| 878 |
|
_node_filter_map=&node_filter_map;
|
| 879 |
|
}
|
| 880 |
|
void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
|
| 881 |
|
_edge_filter_map=&edge_filter_map;
|
|
878 |
: Parent(), _node_filter(0), _edge_filter(0) { }
|
|
879 |
|
|
880 |
void initialize(GR& graph, NF& node_filter, EF& edge_filter) {
|
|
881 |
Parent::initialize(graph);
|
|
882 |
_node_filter = &node_filter;
|
|
883 |
_edge_filter = &edge_filter;
|
| 882 |
884 |
}
|
| 883 |
885 |
|
| 884 |
886 |
public:
|
| 885 |
887 |
|
| 886 |
888 |
typedef typename Parent::Node Node;
|
| 887 |
889 |
typedef typename Parent::Arc Arc;
|
| 888 |
890 |
typedef typename Parent::Edge Edge;
|
| 889 |
891 |
|
| 890 |
892 |
void first(Node& i) const {
|
| 891 |
893 |
Parent::first(i);
|
| 892 |
|
while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
|
|
894 |
while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
|
| 893 |
895 |
}
|
| 894 |
896 |
|
| 895 |
897 |
void first(Arc& i) const {
|
| 896 |
898 |
Parent::first(i);
|
| 897 |
|
while (i!=INVALID && (!(*_edge_filter_map)[i]
|
| 898 |
|
|| !(*_node_filter_map)[Parent::source(i)]
|
| 899 |
|
|| !(*_node_filter_map)[Parent::target(i)]))
|
|
899 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
|
900 |
|| !(*_node_filter)[Parent::source(i)]
|
|
901 |
|| !(*_node_filter)[Parent::target(i)]))
|
| 900 |
902 |
Parent::next(i);
|
| 901 |
903 |
}
|
| 902 |
904 |
|
| 903 |
905 |
void first(Edge& i) const {
|
| 904 |
906 |
Parent::first(i);
|
| 905 |
|
while (i!=INVALID && (!(*_edge_filter_map)[i]
|
| 906 |
|
|| !(*_node_filter_map)[Parent::u(i)]
|
| 907 |
|
|| !(*_node_filter_map)[Parent::v(i)]))
|
|
907 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
|
908 |
|| !(*_node_filter)[Parent::u(i)]
|
|
909 |
|| !(*_node_filter)[Parent::v(i)]))
|
| 908 |
910 |
Parent::next(i);
|
| 909 |
911 |
}
|
| 910 |
912 |
|
| 911 |
913 |
void firstIn(Arc& i, const Node& n) const {
|
| 912 |
914 |
Parent::firstIn(i, n);
|
| 913 |
|
while (i!=INVALID && (!(*_edge_filter_map)[i]
|
| 914 |
|
|| !(*_node_filter_map)[Parent::source(i)]))
|
|
915 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
|
916 |
|| !(*_node_filter)[Parent::source(i)]))
|
| 915 |
917 |
Parent::nextIn(i);
|
| 916 |
918 |
}
|
| 917 |
919 |
|
| 918 |
920 |
void firstOut(Arc& i, const Node& n) const {
|
| 919 |
921 |
Parent::firstOut(i, n);
|
| 920 |
|
while (i!=INVALID && (!(*_edge_filter_map)[i]
|
| 921 |
|
|| !(*_node_filter_map)[Parent::target(i)]))
|
|
922 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
|
923 |
|| !(*_node_filter)[Parent::target(i)]))
|
| 922 |
924 |
Parent::nextOut(i);
|
| 923 |
925 |
}
|
| 924 |
926 |
|
| 925 |
927 |
void firstInc(Edge& i, bool& d, const Node& n) const {
|
| 926 |
928 |
Parent::firstInc(i, d, n);
|
| 927 |
|
while (i!=INVALID && (!(*_edge_filter_map)[i]
|
| 928 |
|
|| !(*_node_filter_map)[Parent::u(i)]
|
| 929 |
|
|| !(*_node_filter_map)[Parent::v(i)]))
|
|
929 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
|
930 |
|| !(*_node_filter)[Parent::u(i)]
|
|
931 |
|| !(*_node_filter)[Parent::v(i)]))
|
| 930 |
932 |
Parent::nextInc(i, d);
|
| 931 |
933 |
}
|
| 932 |
934 |
|
| 933 |
935 |
void next(Node& i) const {
|
| 934 |
936 |
Parent::next(i);
|
| 935 |
|
while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
|
|
937 |
while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
|
| 936 |
938 |
}
|
| 937 |
939 |
|
| 938 |
940 |
void next(Arc& i) const {
|
| 939 |
941 |
Parent::next(i);
|
| 940 |
|
while (i!=INVALID && (!(*_edge_filter_map)[i]
|
| 941 |
|
|| !(*_node_filter_map)[Parent::source(i)]
|
| 942 |
|
|| !(*_node_filter_map)[Parent::target(i)]))
|
|
942 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
|
943 |
|| !(*_node_filter)[Parent::source(i)]
|
|
944 |
|| !(*_node_filter)[Parent::target(i)]))
|
| 943 |
945 |
Parent::next(i);
|
| 944 |
946 |
}
|
| 945 |
947 |
|
| 946 |
948 |
void next(Edge& i) const {
|
| 947 |
949 |
Parent::next(i);
|
| 948 |
|
while (i!=INVALID && (!(*_edge_filter_map)[i]
|
| 949 |
|
|| !(*_node_filter_map)[Parent::u(i)]
|
| 950 |
|
|| !(*_node_filter_map)[Parent::v(i)]))
|
|
950 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
|
951 |
|| !(*_node_filter)[Parent::u(i)]
|
|
952 |
|| !(*_node_filter)[Parent::v(i)]))
|
| 951 |
953 |
Parent::next(i);
|
| 952 |
954 |
}
|
| 953 |
955 |
|
| 954 |
956 |
void nextIn(Arc& i) const {
|
| 955 |
957 |
Parent::nextIn(i);
|
| 956 |
|
while (i!=INVALID && (!(*_edge_filter_map)[i]
|
| 957 |
|
|| !(*_node_filter_map)[Parent::source(i)]))
|
|
958 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
|
959 |
|| !(*_node_filter)[Parent::source(i)]))
|
| 958 |
960 |
Parent::nextIn(i);
|
| 959 |
961 |
}
|
| 960 |
962 |
|
| 961 |
963 |
void nextOut(Arc& i) const {
|
| 962 |
964 |
Parent::nextOut(i);
|
| 963 |
|
while (i!=INVALID && (!(*_edge_filter_map)[i]
|
| 964 |
|
|| !(*_node_filter_map)[Parent::target(i)]))
|
|
965 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
|
966 |
|| !(*_node_filter)[Parent::target(i)]))
|
| 965 |
967 |
Parent::nextOut(i);
|
| 966 |
968 |
}
|
| 967 |
969 |
|
| 968 |
970 |
void nextInc(Edge& i, bool& d) const {
|
| 969 |
971 |
Parent::nextInc(i, d);
|
| 970 |
|
while (i!=INVALID && (!(*_edge_filter_map)[i]
|
| 971 |
|
|| !(*_node_filter_map)[Parent::u(i)]
|
| 972 |
|
|| !(*_node_filter_map)[Parent::v(i)]))
|
|
972 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
|
973 |
|| !(*_node_filter)[Parent::u(i)]
|
|
974 |
|| !(*_node_filter)[Parent::v(i)]))
|
| 973 |
975 |
Parent::nextInc(i, d);
|
| 974 |
976 |
}
|
| 975 |
977 |
|
| 976 |
|
void status(const Node& n, bool v) const { _node_filter_map->set(n, v); }
|
| 977 |
|
void status(const Edge& e, bool v) const { _edge_filter_map->set(e, v); }
|
| 978 |
|
|
| 979 |
|
bool status(const Node& n) const { return (*_node_filter_map)[n]; }
|
| 980 |
|
bool status(const Edge& e) const { return (*_edge_filter_map)[e]; }
|
|
978 |
void status(const Node& n, bool v) const { _node_filter->set(n, v); }
|
|
979 |
void status(const Edge& e, bool v) const { _edge_filter->set(e, v); }
|
|
980 |
|
|
981 |
bool status(const Node& n) const { return (*_node_filter)[n]; }
|
|
982 |
bool status(const Edge& e) const { return (*_edge_filter)[e]; }
|
| 981 |
983 |
|
| 982 |
984 |
typedef False NodeNumTag;
|
| 983 |
985 |
typedef False ArcNumTag;
|
| 984 |
986 |
typedef False EdgeNumTag;
|
| 985 |
987 |
|
| 986 |
988 |
typedef FindArcTagIndicator<Graph> FindArcTag;
|
| 987 |
989 |
Arc findArc(const Node& u, const Node& v,
|
| 988 |
990 |
const Arc& prev = INVALID) const {
|
| 989 |
|
if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
|
|
991 |
if (!(*_node_filter)[u] || !(*_node_filter)[v]) {
|
| 990 |
992 |
return INVALID;
|
| 991 |
993 |
}
|
| 992 |
994 |
Arc arc = Parent::findArc(u, v, prev);
|
| 993 |
|
while (arc != INVALID && !(*_edge_filter_map)[arc]) {
|
|
995 |
while (arc != INVALID && !(*_edge_filter)[arc]) {
|
| 994 |
996 |
arc = Parent::findArc(u, v, arc);
|
| 995 |
997 |
}
|
| 996 |
998 |
return arc;
|
| 997 |
999 |
}
|
| 998 |
1000 |
|
| 999 |
1001 |
typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
|
| 1000 |
1002 |
Edge findEdge(const Node& u, const Node& v,
|
| 1001 |
1003 |
const Edge& prev = INVALID) const {
|
| 1002 |
|
if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
|
|
1004 |
if (!(*_node_filter)[u] || !(*_node_filter)[v]) {
|
| 1003 |
1005 |
return INVALID;
|
| 1004 |
1006 |
}
|
| 1005 |
1007 |
Edge edge = Parent::findEdge(u, v, prev);
|
| 1006 |
|
while (edge != INVALID && !(*_edge_filter_map)[edge]) {
|
|
1008 |
while (edge != INVALID && !(*_edge_filter)[edge]) {
|
| 1007 |
1009 |
edge = Parent::findEdge(u, v, edge);
|
| 1008 |
1010 |
}
|
| 1009 |
1011 |
return edge;
|
| 1010 |
1012 |
}
|
| 1011 |
1013 |
|
| 1012 |
|
template <typename _Value>
|
| 1013 |
|
class NodeMap : public SubMapExtender<Adaptor,
|
| 1014 |
|
typename Parent::template NodeMap<_Value> > {
|
|
1014 |
template <typename V>
|
|
1015 |
class NodeMap
|
|
1016 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
|
|
1017 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> {
|
| 1015 |
1018 |
public:
|
| 1016 |
|
typedef _Value Value;
|
| 1017 |
|
typedef SubMapExtender<Adaptor, typename Parent::
|
| 1018 |
|
template NodeMap<Value> > MapParent;
|
| 1019 |
|
|
| 1020 |
|
NodeMap(const Adaptor& adaptor)
|
| 1021 |
|
: MapParent(adaptor) {}
|
| 1022 |
|
NodeMap(const Adaptor& adaptor, const Value& value)
|
| 1023 |
|
: MapParent(adaptor, value) {}
|
|
1019 |
typedef V Value;
|
|
1020 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
|
|
1021 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent;
|
|
1022 |
|
|
1023 |
NodeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor)
|
|
1024 |
: Parent(adaptor) {}
|
|
1025 |
NodeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor, const V& value)
|
|
1026 |
: Parent(adaptor, value) {}
|
| 1024 |
1027 |
|
| 1025 |
1028 |
private:
|
| 1026 |
1029 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 1027 |
1030 |
return operator=<NodeMap>(cmap);
|
| 1028 |
1031 |
}
|
| 1029 |
1032 |
|
| 1030 |
1033 |
template <typename CMap>
|
| 1031 |
1034 |
NodeMap& operator=(const CMap& cmap) {
|
| 1032 |
|
MapParent::operator=(cmap);
|
|
1035 |
Parent::operator=(cmap);
|
| 1033 |
1036 |
return *this;
|
| 1034 |
1037 |
}
|
| 1035 |
1038 |
};
|
| 1036 |
1039 |
|
| 1037 |
|
template <typename _Value>
|
| 1038 |
|
class ArcMap : public SubMapExtender<Adaptor,
|
| 1039 |
|
typename Parent::template ArcMap<_Value> > {
|
|
1040 |
template <typename V>
|
|
1041 |
class ArcMap
|
|
1042 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
|
|
1043 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> {
|
| 1040 |
1044 |
public:
|
| 1041 |
|
typedef _Value Value;
|
| 1042 |
|
typedef SubMapExtender<Adaptor, typename Parent::
|
| 1043 |
|
template ArcMap<Value> > MapParent;
|
| 1044 |
|
|
| 1045 |
|
ArcMap(const Adaptor& adaptor)
|
| 1046 |
|
: MapParent(adaptor) {}
|
| 1047 |
|
ArcMap(const Adaptor& adaptor, const Value& value)
|
| 1048 |
|
: MapParent(adaptor, value) {}
|
|
1045 |
typedef V Value;
|
|
1046 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
|
|
1047 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent;
|
|
1048 |
|
|
1049 |
ArcMap(const SubGraphBase<GR, NF, EF, ch>& adaptor)
|
|
1050 |
: Parent(adaptor) {}
|
|
1051 |
ArcMap(const SubGraphBase<GR, NF, EF, ch>& adaptor, const V& value)
|
|
1052 |
: Parent(adaptor, value) {}
|
| 1049 |
1053 |
|
| 1050 |
1054 |
private:
|
| 1051 |
1055 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 1052 |
1056 |
return operator=<ArcMap>(cmap);
|
| 1053 |
1057 |
}
|
| 1054 |
1058 |
|
| 1055 |
1059 |
template <typename CMap>
|
| 1056 |
1060 |
ArcMap& operator=(const CMap& cmap) {
|
| 1057 |
|
MapParent::operator=(cmap);
|
|
1061 |
Parent::operator=(cmap);
|
| 1058 |
1062 |
return *this;
|
| 1059 |
1063 |
}
|
| 1060 |
1064 |
};
|
| 1061 |
1065 |
|
| 1062 |
|
template <typename _Value>
|
| 1063 |
|
class EdgeMap : public SubMapExtender<Adaptor,
|
| 1064 |
|
typename Parent::template EdgeMap<_Value> > {
|
|
1066 |
template <typename V>
|
|
1067 |
class EdgeMap
|
|
1068 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
|
|
1069 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> {
|
| 1065 |
1070 |
public:
|
| 1066 |
|
typedef _Value Value;
|
| 1067 |
|
typedef SubMapExtender<Adaptor, typename Parent::
|
| 1068 |
|
template EdgeMap<Value> > MapParent;
|
| 1069 |
|
|
| 1070 |
|
EdgeMap(const Adaptor& adaptor)
|
| 1071 |
|
: MapParent(adaptor) {}
|
| 1072 |
|
|
| 1073 |
|
EdgeMap(const Adaptor& adaptor, const Value& value)
|
| 1074 |
|
: MapParent(adaptor, value) {}
|
|
1071 |
typedef V Value;
|
|
1072 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
|
|
1073 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent;
|
|
1074 |
|
|
1075 |
EdgeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor)
|
|
1076 |
: Parent(adaptor) {}
|
|
1077 |
|
|
1078 |
EdgeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor, const V& value)
|
|
1079 |
: Parent(adaptor, value) {}
|
| 1075 |
1080 |
|
| 1076 |
1081 |
private:
|
| 1077 |
1082 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
| 1078 |
1083 |
return operator=<EdgeMap>(cmap);
|
| 1079 |
1084 |
}
|
| 1080 |
1085 |
|
| 1081 |
1086 |
template <typename CMap>
|
| 1082 |
1087 |
EdgeMap& operator=(const CMap& cmap) {
|
| 1083 |
|
MapParent::operator=(cmap);
|
|
1088 |
Parent::operator=(cmap);
|
| 1084 |
1089 |
return *this;
|
| 1085 |
1090 |
}
|
| 1086 |
1091 |
};
|
| 1087 |
1092 |
|
| 1088 |
1093 |
};
|
| 1089 |
1094 |
|
| 1090 |
|
template <typename _Graph, typename _NodeFilterMap, typename _EdgeFilterMap>
|
| 1091 |
|
class SubGraphBase<_Graph, _NodeFilterMap, _EdgeFilterMap, false>
|
| 1092 |
|
: public GraphAdaptorBase<_Graph> {
|
|
1095 |
template <typename GR, typename NF, typename EF>
|
|
1096 |
class SubGraphBase<GR, NF, EF, false>
|
|
1097 |
: public GraphAdaptorBase<GR> {
|
| 1093 |
1098 |
public:
|
| 1094 |
|
typedef _Graph Graph;
|
| 1095 |
|
typedef _NodeFilterMap NodeFilterMap;
|
| 1096 |
|
typedef _EdgeFilterMap EdgeFilterMap;
|
|
1099 |
typedef GR Graph;
|
|
1100 |
typedef NF NodeFilterMap;
|
|
1101 |
typedef EF EdgeFilterMap;
|
| 1097 |
1102 |
|
| 1098 |
1103 |
typedef SubGraphBase Adaptor;
|
| 1099 |
|
typedef GraphAdaptorBase<_Graph> Parent;
|
|
1104 |
typedef GraphAdaptorBase<GR> Parent;
|
| 1100 |
1105 |
protected:
|
| 1101 |
|
NodeFilterMap* _node_filter_map;
|
| 1102 |
|
EdgeFilterMap* _edge_filter_map;
|
| 1103 |
|
SubGraphBase() : Parent(),
|
| 1104 |
|
_node_filter_map(0), _edge_filter_map(0) { }
|
| 1105 |
|
|
| 1106 |
|
void setNodeFilterMap(NodeFilterMap& node_filter_map) {
|
| 1107 |
|
_node_filter_map=&node_filter_map;
|
| 1108 |
|
}
|
| 1109 |
|
void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
|
| 1110 |
|
_edge_filter_map=&edge_filter_map;
|
|
1106 |
NF* _node_filter;
|
|
1107 |
EF* _edge_filter;
|
|
1108 |
SubGraphBase()
|
|
1109 |
: Parent(), _node_filter(0), _edge_filter(0) { }
|
|
1110 |
|
|
1111 |
void initialize(GR& graph, NF& node_filter, EF& edge_filter) {
|
|
1112 |
Parent::initialize(graph);
|
|
1113 |
_node_filter = &node_filter;
|
|
1114 |
_edge_filter = &edge_filter;
|
| 1111 |
1115 |
}
|
| 1112 |
1116 |
|
| 1113 |
1117 |
public:
|
| 1114 |
1118 |
|
| 1115 |
1119 |
typedef typename Parent::Node Node;
|
| 1116 |
1120 |
typedef typename Parent::Arc Arc;
|
| 1117 |
1121 |
typedef typename Parent::Edge Edge;
|
| 1118 |
1122 |
|
| 1119 |
1123 |
void first(Node& i) const {
|
| 1120 |
1124 |
Parent::first(i);
|
| 1121 |
|
while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
|
|
1125 |
while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
|
| 1122 |
1126 |
}
|
| 1123 |
1127 |
|
| 1124 |
1128 |
void first(Arc& i) const {
|
| 1125 |
1129 |
Parent::first(i);
|
| 1126 |
|
while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
|
|
1130 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::next(i);
|
| 1127 |
1131 |
}
|
| 1128 |
1132 |
|
| 1129 |
1133 |
void first(Edge& i) const {
|
| 1130 |
1134 |
Parent::first(i);
|
| 1131 |
|
while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
|
|
1135 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::next(i);
|
| 1132 |
1136 |
}
|
| 1133 |
1137 |
|
| 1134 |
1138 |
void firstIn(Arc& i, const Node& n) const {
|
| 1135 |
1139 |
Parent::firstIn(i, n);
|
| 1136 |
|
while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextIn(i);
|
|
1140 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextIn(i);
|
| 1137 |
1141 |
}
|
| 1138 |
1142 |
|
| 1139 |
1143 |
void firstOut(Arc& i, const Node& n) const {
|
| 1140 |
1144 |
Parent::firstOut(i, n);
|
| 1141 |
|
while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextOut(i);
|
|
1145 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextOut(i);
|
| 1142 |
1146 |
}
|
| 1143 |
1147 |
|
| 1144 |
1148 |
void firstInc(Edge& i, bool& d, const Node& n) const {
|
| 1145 |
1149 |
Parent::firstInc(i, d, n);
|
| 1146 |
|
while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d);
|
|
1150 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextInc(i, d);
|
| 1147 |
1151 |
}
|
| 1148 |
1152 |
|
| 1149 |
1153 |
void next(Node& i) const {
|
| 1150 |
1154 |
Parent::next(i);
|
| 1151 |
|
while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
|
|
1155 |
while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
|
| 1152 |
1156 |
}
|
| 1153 |
1157 |
void next(Arc& i) const {
|
| 1154 |
1158 |
Parent::next(i);
|
| 1155 |
|
while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
|
|
1159 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::next(i);
|
| 1156 |
1160 |
}
|
| 1157 |
1161 |
void next(Edge& i) const {
|
| 1158 |
1162 |
Parent::next(i);
|
| 1159 |
|
while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
|
|
1163 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::next(i);
|
| 1160 |
1164 |
}
|
| 1161 |
1165 |
void nextIn(Arc& i) const {
|
| 1162 |
1166 |
Parent::nextIn(i);
|
| 1163 |
|
while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextIn(i);
|
|
1167 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextIn(i);
|
| 1164 |
1168 |
}
|
| 1165 |
1169 |
|
| 1166 |
1170 |
void nextOut(Arc& i) const {
|
| 1167 |
1171 |
Parent::nextOut(i);
|
| 1168 |
|
while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextOut(i);
|
|
1172 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextOut(i);
|
| 1169 |
1173 |
}
|
| 1170 |
1174 |
void nextInc(Edge& i, bool& d) const {
|
| 1171 |
1175 |
Parent::nextInc(i, d);
|
| 1172 |
|
while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d);
|
|
1176 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextInc(i, d);
|
| 1173 |
1177 |
}
|
| 1174 |
1178 |
|
| 1175 |
|
void status(const Node& n, bool v) const { _node_filter_map->set(n, v); }
|
| 1176 |
|
void status(const Edge& e, bool v) const { _edge_filter_map->set(e, v); }
|
| 1177 |
|
|
| 1178 |
|
bool status(const Node& n) const { return (*_node_filter_map)[n]; }
|
| 1179 |
|
bool status(const Edge& e) const { return (*_edge_filter_map)[e]; }
|
|
1179 |
void status(const Node& n, bool v) const { _node_filter->set(n, v); }
|
|
1180 |
void status(const Edge& e, bool v) const { _edge_filter->set(e, v); }
|
|
1181 |
|
|
1182 |
bool status(const Node& n) const { return (*_node_filter)[n]; }
|
|
1183 |
bool status(const Edge& e) const { return (*_edge_filter)[e]; }
|
| 1180 |
1184 |
|
| 1181 |
1185 |
typedef False NodeNumTag;
|
| 1182 |
1186 |
typedef False ArcNumTag;
|
| 1183 |
1187 |
typedef False EdgeNumTag;
|
| 1184 |
1188 |
|
| 1185 |
1189 |
typedef FindArcTagIndicator<Graph> FindArcTag;
|
| 1186 |
1190 |
Arc findArc(const Node& u, const Node& v,
|
| 1187 |
1191 |
const Arc& prev = INVALID) const {
|
| 1188 |
1192 |
Arc arc = Parent::findArc(u, v, prev);
|
| 1189 |
|
while (arc != INVALID && !(*_edge_filter_map)[arc]) {
|
|
1193 |
while (arc != INVALID && !(*_edge_filter)[arc]) {
|
| 1190 |
1194 |
arc = Parent::findArc(u, v, arc);
|
| 1191 |
1195 |
}
|
| 1192 |
1196 |
return arc;
|
| 1193 |
1197 |
}
|
| 1194 |
1198 |
|
| 1195 |
1199 |
typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
|
| 1196 |
1200 |
Edge findEdge(const Node& u, const Node& v,
|
| 1197 |
1201 |
const Edge& prev = INVALID) const {
|
| 1198 |
1202 |
Edge edge = Parent::findEdge(u, v, prev);
|
| 1199 |
|
while (edge != INVALID && !(*_edge_filter_map)[edge]) {
|
|
1203 |
while (edge != INVALID && !(*_edge_filter)[edge]) {
|
| 1200 |
1204 |
edge = Parent::findEdge(u, v, edge);
|
| 1201 |
1205 |
}
|
| 1202 |
1206 |
return edge;
|
| 1203 |
1207 |
}
|
| 1204 |
1208 |
|
| 1205 |
|
template <typename _Value>
|
| 1206 |
|
class NodeMap : public SubMapExtender<Adaptor,
|
| 1207 |
|
typename Parent::template NodeMap<_Value> > {
|
|
1209 |
template <typename V>
|
|
1210 |
class NodeMap
|
|
1211 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
|
|
1212 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> {
|
| 1208 |
1213 |
public:
|
| 1209 |
|
typedef _Value Value;
|
| 1210 |
|
typedef SubMapExtender<Adaptor, typename Parent::
|
| 1211 |
|
template NodeMap<Value> > MapParent;
|
| 1212 |
|
|
| 1213 |
|
NodeMap(const Adaptor& adaptor)
|
| 1214 |
|
: MapParent(adaptor) {}
|
| 1215 |
|
NodeMap(const Adaptor& adaptor, const Value& value)
|
| 1216 |
|
: MapParent(adaptor, value) {}
|
|
1214 |
typedef V Value;
|
|
1215 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>,
|
|
1216 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent;
|
|
1217 |
|
|
1218 |
NodeMap(const SubGraphBase<GR, NF, EF, false>& adaptor)
|
|
1219 |
: Parent(adaptor) {}
|
|
1220 |
NodeMap(const SubGraphBase<GR, NF, EF, false>& adaptor, const V& value)
|
|
1221 |
: Parent(adaptor, value) {}
|
| 1217 |
1222 |
|
| 1218 |
1223 |
private:
|
| 1219 |
1224 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 1220 |
1225 |
return operator=<NodeMap>(cmap);
|
| 1221 |
1226 |
}
|
| 1222 |
1227 |
|
| 1223 |
1228 |
template <typename CMap>
|
| 1224 |
1229 |
NodeMap& operator=(const CMap& cmap) {
|
| 1225 |
|
MapParent::operator=(cmap);
|
|
1230 |
Parent::operator=(cmap);
|
| 1226 |
1231 |
return *this;
|
| 1227 |
1232 |
}
|
| 1228 |
1233 |
};
|
| 1229 |
1234 |
|
| 1230 |
|
template <typename _Value>
|
| 1231 |
|
class ArcMap : public SubMapExtender<Adaptor,
|
| 1232 |
|
typename Parent::template ArcMap<_Value> > {
|
|
1235 |
template <typename V>
|
|
1236 |
class ArcMap
|
|
1237 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
|
|
1238 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> {
|
| 1233 |
1239 |
public:
|
| 1234 |
|
typedef _Value Value;
|
| 1235 |
|
typedef SubMapExtender<Adaptor, typename Parent::
|
| 1236 |
|
template ArcMap<Value> > MapParent;
|
| 1237 |
|
|
| 1238 |
|
ArcMap(const Adaptor& adaptor)
|
| 1239 |
|
: MapParent(adaptor) {}
|
| 1240 |
|
ArcMap(const Adaptor& adaptor, const Value& value)
|
| 1241 |
|
: MapParent(adaptor, value) {}
|
|
1240 |
typedef V Value;
|
|
1241 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>,
|
|
1242 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent;
|
|
1243 |
|
|
1244 |
ArcMap(const SubGraphBase<GR, NF, EF, false>& adaptor)
|
|
1245 |
: Parent(adaptor) {}
|
|
1246 |
ArcMap(const SubGraphBase<GR, NF, EF, false>& adaptor, const V& value)
|
|
1247 |
: Parent(adaptor, value) {}
|
| 1242 |
1248 |
|
| 1243 |
1249 |
private:
|
| 1244 |
1250 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 1245 |
1251 |
return operator=<ArcMap>(cmap);
|
| 1246 |
1252 |
}
|
| 1247 |
1253 |
|
| 1248 |
1254 |
template <typename CMap>
|
| 1249 |
1255 |
ArcMap& operator=(const CMap& cmap) {
|
| 1250 |
|
MapParent::operator=(cmap);
|
|
1256 |
Parent::operator=(cmap);
|
| 1251 |
1257 |
return *this;
|
| 1252 |
1258 |
}
|
| 1253 |
1259 |
};
|
| 1254 |
1260 |
|
| 1255 |
|
template <typename _Value>
|
| 1256 |
|
class EdgeMap : public SubMapExtender<Adaptor,
|
| 1257 |
|
typename Parent::template EdgeMap<_Value> > {
|
|
1261 |
template <typename V>
|
|
1262 |
class EdgeMap
|
|
1263 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
|
|
1264 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> {
|
| 1258 |
1265 |
public:
|
| 1259 |
|
typedef _Value Value;
|
| 1260 |
|
typedef SubMapExtender<Adaptor, typename Parent::
|
| 1261 |
|
template EdgeMap<Value> > MapParent;
|
| 1262 |
|
|
| 1263 |
|
EdgeMap(const Adaptor& adaptor)
|
| 1264 |
|
: MapParent(adaptor) {}
|
| 1265 |
|
|
| 1266 |
|
EdgeMap(const Adaptor& adaptor, const _Value& value)
|
| 1267 |
|
: MapParent(adaptor, value) {}
|
|
1266 |
typedef V Value;
|
|
1267 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>,
|
|
1268 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent;
|
|
1269 |
|
|
1270 |
EdgeMap(const SubGraphBase<GR, NF, EF, false>& adaptor)
|
|
1271 |
: Parent(adaptor) {}
|
|
1272 |
|
|
1273 |
EdgeMap(const SubGraphBase<GR, NF, EF, false>& adaptor, const V& value)
|
|
1274 |
: Parent(adaptor, value) {}
|
| 1268 |
1275 |
|
| 1269 |
1276 |
private:
|
| 1270 |
1277 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
| 1271 |
1278 |
return operator=<EdgeMap>(cmap);
|
| 1272 |
1279 |
}
|
| 1273 |
1280 |
|
| 1274 |
1281 |
template <typename CMap>
|
| 1275 |
1282 |
EdgeMap& operator=(const CMap& cmap) {
|
| 1276 |
|
MapParent::operator=(cmap);
|
|
1283 |
Parent::operator=(cmap);
|
| 1277 |
1284 |
return *this;
|
| 1278 |
1285 |
}
|
| 1279 |
1286 |
};
|
| 1280 |
1287 |
|
| 1281 |
1288 |
};
|
| 1282 |
1289 |
|
| 1283 |
1290 |
/// \ingroup graph_adaptors
|
| 1284 |
1291 |
///
|
| 1285 |
1292 |
/// \brief Adaptor class for hiding nodes and edges in an undirected
|
| 1286 |
1293 |
/// graph.
|
| 1287 |
1294 |
///
|
| 1288 |
1295 |
/// SubGraph can be used for hiding nodes and edges in a graph.
|
| 1289 |
1296 |
/// A \c bool node map and a \c bool edge map must be specified, which
|
| 1290 |
1297 |
/// define the filters for nodes and edges.
|
| 1291 |
1298 |
/// Only the nodes and edges with \c true filter value are
|
| 1292 |
1299 |
/// shown in the subgraph. The edges that are incident to hidden
|
| 1293 |
1300 |
/// nodes are also filtered out.
|
| 1294 |
1301 |
/// This adaptor conforms to the \ref concepts::Graph "Graph" concept.
|
| 1295 |
1302 |
///
|
| 1296 |
1303 |
/// The adapted graph can also be modified through this adaptor
|
| 1297 |
1304 |
/// by adding or removing nodes or edges, unless the \c GR template
|
| 1298 |
1305 |
/// parameter is set to be \c const.
|
| 1299 |
1306 |
///
|
| 1300 |
1307 |
/// \tparam GR The type of the adapted graph.
|
| 1301 |
1308 |
/// It must conform to the \ref concepts::Graph "Graph" concept.
|
| 1302 |
1309 |
/// It can also be specified to be \c const.
|
| 1303 |
1310 |
/// \tparam NF The type of the node filter map.
|
| 1304 |
1311 |
/// It must be a \c bool (or convertible) node map of the
|
| 1305 |
1312 |
/// adapted graph. The default type is
|
| 1306 |
1313 |
/// \ref concepts::Graph::NodeMap "GR::NodeMap<bool>".
|
| 1307 |
1314 |
/// \tparam EF The type of the edge filter map.
|
| 1308 |
1315 |
/// It must be a \c bool (or convertible) edge map of the
|
| 1309 |
1316 |
/// adapted graph. The default type is
|
| 1310 |
1317 |
/// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>".
|
| 1311 |
1318 |
///
|
| 1312 |
1319 |
/// \note The \c Node, \c Edge and \c Arc types of this adaptor and the
|
| 1313 |
1320 |
/// adapted graph are convertible to each other.
|
| 1314 |
1321 |
///
|
| 1315 |
1322 |
/// \see FilterNodes
|
| 1316 |
1323 |
/// \see FilterEdges
|
| 1317 |
1324 |
#ifdef DOXYGEN
|
| 1318 |
1325 |
template<typename GR, typename NF, typename EF>
|
| 1319 |
1326 |
class SubGraph {
|
| 1320 |
1327 |
#else
|
| 1321 |
1328 |
template<typename GR,
|
| 1322 |
1329 |
typename NF = typename GR::template NodeMap<bool>,
|
| 1323 |
1330 |
typename EF = typename GR::template EdgeMap<bool> >
|
| 1324 |
1331 |
class SubGraph :
|
| 1325 |
1332 |
public GraphAdaptorExtender<SubGraphBase<GR, NF, EF, true> > {
|
| 1326 |
1333 |
#endif
|
| 1327 |
1334 |
public:
|
| 1328 |
1335 |
/// The type of the adapted graph.
|
| 1329 |
1336 |
typedef GR Graph;
|
| 1330 |
1337 |
/// The type of the node filter map.
|
| 1331 |
1338 |
typedef NF NodeFilterMap;
|
| 1332 |
1339 |
/// The type of the edge filter map.
|
| 1333 |
1340 |
typedef EF EdgeFilterMap;
|
| 1334 |
1341 |
|
| 1335 |
|
typedef GraphAdaptorExtender< SubGraphBase<GR, NF, EF, true> >
|
|
1342 |
typedef GraphAdaptorExtender<SubGraphBase<GR, NF, EF, true> >
|
| 1336 |
1343 |
Parent;
|
| 1337 |
1344 |
|
| 1338 |
1345 |
typedef typename Parent::Node Node;
|
| 1339 |
1346 |
typedef typename Parent::Edge Edge;
|
| 1340 |
1347 |
|
| 1341 |
1348 |
protected:
|
| 1342 |
1349 |
SubGraph() { }
|
| 1343 |
1350 |
public:
|
| 1344 |
1351 |
|
| 1345 |
1352 |
/// \brief Constructor
|
| 1346 |
1353 |
///
|
| 1347 |
1354 |
/// Creates a subgraph for the given graph with the given node
|
| 1348 |
1355 |
/// and edge filter maps.
|
| 1349 |
|
SubGraph(Graph& graph, NodeFilterMap& node_filter_map,
|
| 1350 |
|
EdgeFilterMap& edge_filter_map) {
|
| 1351 |
|
setGraph(graph);
|
| 1352 |
|
setNodeFilterMap(node_filter_map);
|
| 1353 |
|
setEdgeFilterMap(edge_filter_map);
|
|
1356 |
SubGraph(GR& graph, NF& node_filter, EF& edge_filter) {
|
|
1357 |
initialize(graph, node_filter, edge_filter);
|
| 1354 |
1358 |
}
|
| 1355 |
1359 |
|
| 1356 |
1360 |
/// \brief Sets the status of the given node
|
| 1357 |
1361 |
///
|
| 1358 |
1362 |
/// This function sets the status of the given node.
|
| 1359 |
1363 |
/// It is done by simply setting the assigned value of \c n
|
| 1360 |
1364 |
/// to \c v in the node filter map.
|
| 1361 |
1365 |
void status(const Node& n, bool v) const { Parent::status(n, v); }
|
| 1362 |
1366 |
|
| 1363 |
1367 |
/// \brief Sets the status of the given edge
|
| 1364 |
1368 |
///
|
| 1365 |
1369 |
/// This function sets the status of the given edge.
|
| 1366 |
1370 |
/// It is done by simply setting the assigned value of \c e
|
| 1367 |
1371 |
/// to \c v in the edge filter map.
|
| 1368 |
1372 |
void status(const Edge& e, bool v) const { Parent::status(e, v); }
|
| 1369 |
1373 |
|
| 1370 |
1374 |
/// \brief Returns the status of the given node
|
| 1371 |
1375 |
///
|
| 1372 |
1376 |
/// This function returns the status of the given node.
|
| 1373 |
1377 |
/// It is \c true if the given node is enabled (i.e. not hidden).
|
| 1374 |
1378 |
bool status(const Node& n) const { return Parent::status(n); }
|
| 1375 |
1379 |
|
| 1376 |
1380 |
/// \brief Returns the status of the given edge
|
| 1377 |
1381 |
///
|
| 1378 |
1382 |
/// This function returns the status of the given edge.
|
| 1379 |
1383 |
/// It is \c true if the given edge is enabled (i.e. not hidden).
|
| 1380 |
1384 |
bool status(const Edge& e) const { return Parent::status(e); }
|
| 1381 |
1385 |
|
| 1382 |
1386 |
/// \brief Disables the given node
|
| 1383 |
1387 |
///
|
| 1384 |
1388 |
/// This function disables the given node in the subdigraph,
|
| 1385 |
1389 |
/// so the iteration jumps over it.
|
| 1386 |
1390 |
/// It is the same as \ref status() "status(n, false)".
|
| 1387 |
1391 |
void disable(const Node& n) const { Parent::status(n, false); }
|
| 1388 |
1392 |
|
| 1389 |
1393 |
/// \brief Disables the given edge
|
| 1390 |
1394 |
///
|
| 1391 |
1395 |
/// This function disables the given edge in the subgraph,
|
| 1392 |
1396 |
/// so the iteration jumps over it.
|
| 1393 |
1397 |
/// It is the same as \ref status() "status(e, false)".
|
| 1394 |
1398 |
void disable(const Edge& e) const { Parent::status(e, false); }
|
| 1395 |
1399 |
|
| 1396 |
1400 |
/// \brief Enables the given node
|
| 1397 |
1401 |
///
|
| 1398 |
1402 |
/// This function enables the given node in the subdigraph.
|
| 1399 |
1403 |
/// It is the same as \ref status() "status(n, true)".
|
| 1400 |
1404 |
void enable(const Node& n) const { Parent::status(n, true); }
|
| 1401 |
1405 |
|
| 1402 |
1406 |
/// \brief Enables the given edge
|
| 1403 |
1407 |
///
|
| 1404 |
1408 |
/// This function enables the given edge in the subgraph.
|
| 1405 |
1409 |
/// It is the same as \ref status() "status(e, true)".
|
| 1406 |
1410 |
void enable(const Edge& e) const { Parent::status(e, true); }
|
| 1407 |
1411 |
|
| 1408 |
1412 |
};
|
| 1409 |
1413 |
|
| 1410 |
1414 |
/// \brief Returns a read-only SubGraph adaptor
|
| 1411 |
1415 |
///
|
| 1412 |
1416 |
/// This function just returns a read-only \ref SubGraph adaptor.
|
| 1413 |
1417 |
/// \ingroup graph_adaptors
|
| 1414 |
1418 |
/// \relates SubGraph
|
| 1415 |
1419 |
template<typename GR, typename NF, typename EF>
|
| 1416 |
1420 |
SubGraph<const GR, NF, EF>
|
| 1417 |
|
subGraph(const GR& graph,
|
| 1418 |
|
NF& node_filter_map, EF& edge_filter_map) {
|
|
1421 |
subGraph(const GR& graph, NF& node_filter, EF& edge_filter) {
|
| 1419 |
1422 |
return SubGraph<const GR, NF, EF>
|
| 1420 |
|
(graph, node_filter_map, edge_filter_map);
|
|
1423 |
(graph, node_filter, edge_filter);
|
| 1421 |
1424 |
}
|
| 1422 |
1425 |
|
| 1423 |
1426 |
template<typename GR, typename NF, typename EF>
|
| 1424 |
1427 |
SubGraph<const GR, const NF, EF>
|
| 1425 |
|
subGraph(const GR& graph,
|
| 1426 |
|
const NF& node_filter_map, EF& edge_filter_map) {
|
|
1428 |
subGraph(const GR& graph, const NF& node_filter, EF& edge_filter) {
|
| 1427 |
1429 |
return SubGraph<const GR, const NF, EF>
|
| 1428 |
|
(graph, node_filter_map, edge_filter_map);
|
|
1430 |
(graph, node_filter, edge_filter);
|
| 1429 |
1431 |
}
|
| 1430 |
1432 |
|
| 1431 |
1433 |
template<typename GR, typename NF, typename EF>
|
| 1432 |
1434 |
SubGraph<const GR, NF, const EF>
|
| 1433 |
|
subGraph(const GR& graph,
|
| 1434 |
|
NF& node_filter_map, const EF& edge_filter_map) {
|
|
1435 |
subGraph(const GR& graph, NF& node_filter, const EF& edge_filter) {
|
| 1435 |
1436 |
return SubGraph<const GR, NF, const EF>
|
| 1436 |
|
(graph, node_filter_map, edge_filter_map);
|
|
1437 |
(graph, node_filter, edge_filter);
|
| 1437 |
1438 |
}
|
| 1438 |
1439 |
|
| 1439 |
1440 |
template<typename GR, typename NF, typename EF>
|
| 1440 |
1441 |
SubGraph<const GR, const NF, const EF>
|
| 1441 |
|
subGraph(const GR& graph,
|
| 1442 |
|
const NF& node_filter_map, const EF& edge_filter_map) {
|
|
1442 |
subGraph(const GR& graph, const NF& node_filter, const EF& edge_filter) {
|
| 1443 |
1443 |
return SubGraph<const GR, const NF, const EF>
|
| 1444 |
|
(graph, node_filter_map, edge_filter_map);
|
|
1444 |
(graph, node_filter, edge_filter);
|
| 1445 |
1445 |
}
|
| 1446 |
1446 |
|
| 1447 |
1447 |
|
| 1448 |
1448 |
/// \ingroup graph_adaptors
|
| 1449 |
1449 |
///
|
| 1450 |
1450 |
/// \brief Adaptor class for hiding nodes in a digraph or a graph.
|
| 1451 |
1451 |
///
|
| 1452 |
1452 |
/// FilterNodes adaptor can be used for hiding nodes in a digraph or a
|
| 1453 |
1453 |
/// graph. A \c bool node map must be specified, which defines the filter
|
| 1454 |
1454 |
/// for the nodes. Only the nodes with \c true filter value and the
|
| 1455 |
1455 |
/// arcs/edges incident to nodes both with \c true filter value are shown
|
| 1456 |
1456 |
/// in the subgraph. This adaptor conforms to the \ref concepts::Digraph
|
| 1457 |
1457 |
/// "Digraph" concept or the \ref concepts::Graph "Graph" concept
|
| 1458 |
1458 |
/// depending on the \c GR template parameter.
|
| 1459 |
1459 |
///
|
| 1460 |
1460 |
/// The adapted (di)graph can also be modified through this adaptor
|
| 1461 |
1461 |
/// by adding or removing nodes or arcs/edges, unless the \c GR template
|
| 1462 |
1462 |
/// parameter is set to be \c const.
|
| 1463 |
1463 |
///
|
| 1464 |
1464 |
/// \tparam GR The type of the adapted digraph or graph.
|
| 1465 |
1465 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept
|
| 1466 |
1466 |
/// or the \ref concepts::Graph "Graph" concept.
|
| 1467 |
1467 |
/// It can also be specified to be \c const.
|
| 1468 |
1468 |
/// \tparam NF The type of the node filter map.
|
| 1469 |
1469 |
/// It must be a \c bool (or convertible) node map of the
|
| 1470 |
1470 |
/// adapted (di)graph. The default type is
|
| 1471 |
1471 |
/// \ref concepts::Graph::NodeMap "GR::NodeMap<bool>".
|
| 1472 |
1472 |
///
|
| 1473 |
1473 |
/// \note The \c Node and <tt>Arc/Edge</tt> types of this adaptor and the
|
| 1474 |
1474 |
/// adapted (di)graph are convertible to each other.
|
| 1475 |
1475 |
#ifdef DOXYGEN
|
| 1476 |
1476 |
template<typename GR, typename NF>
|
| 1477 |
1477 |
class FilterNodes {
|
| 1478 |
1478 |
#else
|
| 1479 |
1479 |
template<typename GR,
|
| 1480 |
1480 |
typename NF = typename GR::template NodeMap<bool>,
|
| 1481 |
1481 |
typename Enable = void>
|
| 1482 |
1482 |
class FilterNodes :
|
| 1483 |
1483 |
public DigraphAdaptorExtender<
|
| 1484 |
|
SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, bool>, true> > {
|
|
1484 |
SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >,
|
|
1485 |
true> > {
|
| 1485 |
1486 |
#endif
|
| 1486 |
1487 |
public:
|
| 1487 |
1488 |
|
| 1488 |
1489 |
typedef GR Digraph;
|
| 1489 |
1490 |
typedef NF NodeFilterMap;
|
| 1490 |
1491 |
|
| 1491 |
1492 |
typedef DigraphAdaptorExtender<
|
| 1492 |
|
SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, bool>, true> >
|
| 1493 |
|
Parent;
|
|
1493 |
SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >,
|
|
1494 |
true> > Parent;
|
| 1494 |
1495 |
|
| 1495 |
1496 |
typedef typename Parent::Node Node;
|
| 1496 |
1497 |
|
| 1497 |
1498 |
protected:
|
| 1498 |
|
ConstMap<typename Digraph::Arc, bool> const_true_map;
|
| 1499 |
|
|
| 1500 |
|
FilterNodes() : const_true_map(true) {
|
| 1501 |
|
Parent::setArcFilterMap(const_true_map);
|
| 1502 |
|
}
|
|
1499 |
ConstMap<typename Digraph::Arc, Const<bool, true> > const_true_map;
|
|
1500 |
|
|
1501 |
FilterNodes() : const_true_map() {}
|
| 1503 |
1502 |
|
| 1504 |
1503 |
public:
|
| 1505 |
1504 |
|
| 1506 |
1505 |
/// \brief Constructor
|
| 1507 |
1506 |
///
|
| 1508 |
1507 |
/// Creates a subgraph for the given digraph or graph with the
|
| 1509 |
1508 |
/// given node filter map.
|
| 1510 |
|
FilterNodes(GR& graph, NodeFilterMap& node_filter) :
|
| 1511 |
|
Parent(), const_true_map(true)
|
|
1509 |
FilterNodes(GR& graph, NF& node_filter)
|
|
1510 |
: Parent(), const_true_map()
|
| 1512 |
1511 |
{
|
| 1513 |
|
Parent::setDigraph(graph);
|
| 1514 |
|
Parent::setNodeFilterMap(node_filter);
|
| 1515 |
|
Parent::setArcFilterMap(const_true_map);
|
|
1512 |
Parent::initialize(graph, node_filter, const_true_map);
|
| 1516 |
1513 |
}
|
| 1517 |
1514 |
|
| 1518 |
1515 |
/// \brief Sets the status of the given node
|
| 1519 |
1516 |
///
|
| 1520 |
1517 |
/// This function sets the status of the given node.
|
| 1521 |
1518 |
/// It is done by simply setting the assigned value of \c n
|
| 1522 |
1519 |
/// to \c v in the node filter map.
|
| 1523 |
1520 |
void status(const Node& n, bool v) const { Parent::status(n, v); }
|
| 1524 |
1521 |
|
| 1525 |
1522 |
/// \brief Returns the status of the given node
|
| 1526 |
1523 |
///
|
| 1527 |
1524 |
/// This function returns the status of the given node.
|
| 1528 |
1525 |
/// It is \c true if the given node is enabled (i.e. not hidden).
|
| 1529 |
1526 |
bool status(const Node& n) const { return Parent::status(n); }
|
| 1530 |
1527 |
|
| 1531 |
1528 |
/// \brief Disables the given node
|
| 1532 |
1529 |
///
|
| 1533 |
1530 |
/// This function disables the given node, so the iteration
|
| 1534 |
1531 |
/// jumps over it.
|
| 1535 |
1532 |
/// It is the same as \ref status() "status(n, false)".
|
| 1536 |
1533 |
void disable(const Node& n) const { Parent::status(n, false); }
|
| 1537 |
1534 |
|
| 1538 |
1535 |
/// \brief Enables the given node
|
| 1539 |
1536 |
///
|
| 1540 |
1537 |
/// This function enables the given node.
|
| 1541 |
1538 |
/// It is the same as \ref status() "status(n, true)".
|
| 1542 |
1539 |
void enable(const Node& n) const { Parent::status(n, true); }
|
| 1543 |
1540 |
|
| 1544 |
1541 |
};
|
| 1545 |
1542 |
|
| 1546 |
1543 |
template<typename GR, typename NF>
|
| 1547 |
1544 |
class FilterNodes<GR, NF,
|
| 1548 |
1545 |
typename enable_if<UndirectedTagIndicator<GR> >::type> :
|
| 1549 |
1546 |
public GraphAdaptorExtender<
|
| 1550 |
|
SubGraphBase<GR, NF, ConstMap<typename GR::Edge, bool>, true> > {
|
|
1547 |
SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >,
|
|
1548 |
true> > {
|
| 1551 |
1549 |
|
| 1552 |
1550 |
public:
|
| 1553 |
1551 |
typedef GR Graph;
|
| 1554 |
1552 |
typedef NF NodeFilterMap;
|
| 1555 |
1553 |
typedef GraphAdaptorExtender<
|
| 1556 |
|
SubGraphBase<GR, NF, ConstMap<typename GR::Edge, bool>, true> >
|
| 1557 |
|
Parent;
|
|
1554 |
SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >,
|
|
1555 |
true> > Parent;
|
| 1558 |
1556 |
|
| 1559 |
1557 |
typedef typename Parent::Node Node;
|
| 1560 |
1558 |
protected:
|
| 1561 |
|
ConstMap<typename Graph::Edge, bool> const_true_map;
|
| 1562 |
|
|
| 1563 |
|
FilterNodes() : const_true_map(true) {
|
| 1564 |
|
Parent::setEdgeFilterMap(const_true_map);
|
| 1565 |
|
}
|
|
1559 |
ConstMap<typename GR::Edge, Const<bool, true> > const_true_map;
|
|
1560 |
|
|
1561 |
FilterNodes() : const_true_map() {}
|
| 1566 |
1562 |
|
| 1567 |
1563 |
public:
|
| 1568 |
1564 |
|
| 1569 |
|
FilterNodes(Graph& _graph, NodeFilterMap& node_filter_map) :
|
| 1570 |
|
Parent(), const_true_map(true) {
|
| 1571 |
|
Parent::setGraph(_graph);
|
| 1572 |
|
Parent::setNodeFilterMap(node_filter_map);
|
| 1573 |
|
Parent::setEdgeFilterMap(const_true_map);
|
|
1565 |
FilterNodes(GR& graph, NodeFilterMap& node_filter) :
|
|
1566 |
Parent(), const_true_map() {
|
|
1567 |
Parent::initialize(graph, node_filter, const_true_map);
|
| 1574 |
1568 |
}
|
| 1575 |
1569 |
|
| 1576 |
1570 |
void status(const Node& n, bool v) const { Parent::status(n, v); }
|
| 1577 |
1571 |
bool status(const Node& n) const { return Parent::status(n); }
|
| 1578 |
1572 |
void disable(const Node& n) const { Parent::status(n, false); }
|
| 1579 |
1573 |
void enable(const Node& n) const { Parent::status(n, true); }
|
| 1580 |
1574 |
|
| 1581 |
1575 |
};
|
| 1582 |
1576 |
|
| 1583 |
1577 |
|
| 1584 |
1578 |
/// \brief Returns a read-only FilterNodes adaptor
|
| 1585 |
1579 |
///
|
| 1586 |
1580 |
/// This function just returns a read-only \ref FilterNodes adaptor.
|
| 1587 |
1581 |
/// \ingroup graph_adaptors
|
| 1588 |
1582 |
/// \relates FilterNodes
|
| 1589 |
1583 |
template<typename GR, typename NF>
|
| 1590 |
1584 |
FilterNodes<const GR, NF>
|
| 1591 |
|
filterNodes(const GR& graph, NF& node_filter_map) {
|
| 1592 |
|
return FilterNodes<const GR, NF>(graph, node_filter_map);
|
|
1585 |
filterNodes(const GR& graph, NF& node_filter) {
|
|
1586 |
return FilterNodes<const GR, NF>(graph, node_filter);
|
| 1593 |
1587 |
}
|
| 1594 |
1588 |
|
| 1595 |
1589 |
template<typename GR, typename NF>
|
| 1596 |
1590 |
FilterNodes<const GR, const NF>
|
| 1597 |
|
filterNodes(const GR& graph, const NF& node_filter_map) {
|
| 1598 |
|
return FilterNodes<const GR, const NF>(graph, node_filter_map);
|
|
1591 |
filterNodes(const GR& graph, const NF& node_filter) {
|
|
1592 |
return FilterNodes<const GR, const NF>(graph, node_filter);
|
| 1599 |
1593 |
}
|
| 1600 |
1594 |
|
| 1601 |
1595 |
/// \ingroup graph_adaptors
|
| 1602 |
1596 |
///
|
| 1603 |
1597 |
/// \brief Adaptor class for hiding arcs in a digraph.
|
| 1604 |
1598 |
///
|
| 1605 |
1599 |
/// FilterArcs adaptor can be used for hiding arcs in a digraph.
|
| 1606 |
1600 |
/// A \c bool arc map must be specified, which defines the filter for
|
| 1607 |
1601 |
/// the arcs. Only the arcs with \c true filter value are shown in the
|
| 1608 |
1602 |
/// subdigraph. This adaptor conforms to the \ref concepts::Digraph
|
| 1609 |
1603 |
/// "Digraph" concept.
|
| 1610 |
1604 |
///
|
| 1611 |
1605 |
/// The adapted digraph can also be modified through this adaptor
|
| 1612 |
1606 |
/// by adding or removing nodes or arcs, unless the \c GR template
|
| 1613 |
1607 |
/// parameter is set to be \c const.
|
| 1614 |
1608 |
///
|
| 1615 |
|
/// \tparam GR The type of the adapted digraph.
|
|
1609 |
/// \tparam DGR The type of the adapted digraph.
|
| 1616 |
1610 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept.
|
| 1617 |
1611 |
/// It can also be specified to be \c const.
|
| 1618 |
1612 |
/// \tparam AF The type of the arc filter map.
|
| 1619 |
1613 |
/// It must be a \c bool (or convertible) arc map of the
|
| 1620 |
1614 |
/// adapted digraph. The default type is
|
| 1621 |
|
/// \ref concepts::Digraph::ArcMap "GR::ArcMap<bool>".
|
|
1615 |
/// \ref concepts::Digraph::ArcMap "DGR::ArcMap<bool>".
|
| 1622 |
1616 |
///
|
| 1623 |
1617 |
/// \note The \c Node and \c Arc types of this adaptor and the adapted
|
| 1624 |
1618 |
/// digraph are convertible to each other.
|
| 1625 |
1619 |
#ifdef DOXYGEN
|
| 1626 |
|
template<typename GR,
|
|
1620 |
template<typename DGR,
|
| 1627 |
1621 |
typename AF>
|
| 1628 |
1622 |
class FilterArcs {
|
| 1629 |
1623 |
#else
|
| 1630 |
|
template<typename GR,
|
| 1631 |
|
typename AF = typename GR::template ArcMap<bool> >
|
|
1624 |
template<typename DGR,
|
|
1625 |
typename AF = typename DGR::template ArcMap<bool> >
|
| 1632 |
1626 |
class FilterArcs :
|
| 1633 |
1627 |
public DigraphAdaptorExtender<
|
| 1634 |
|
SubDigraphBase<GR, ConstMap<typename GR::Node, bool>, AF, false> > {
|
|
1628 |
SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >,
|
|
1629 |
AF, false> > {
|
| 1635 |
1630 |
#endif
|
| 1636 |
1631 |
public:
|
| 1637 |
1632 |
/// The type of the adapted digraph.
|
| 1638 |
|
typedef GR Digraph;
|
|
1633 |
typedef DGR Digraph;
|
| 1639 |
1634 |
/// The type of the arc filter map.
|
| 1640 |
1635 |
typedef AF ArcFilterMap;
|
| 1641 |
1636 |
|
| 1642 |
1637 |
typedef DigraphAdaptorExtender<
|
| 1643 |
|
SubDigraphBase<GR, ConstMap<typename GR::Node, bool>, AF, false> >
|
| 1644 |
|
Parent;
|
|
1638 |
SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >,
|
|
1639 |
AF, false> > Parent;
|
| 1645 |
1640 |
|
| 1646 |
1641 |
typedef typename Parent::Arc Arc;
|
| 1647 |
1642 |
|
| 1648 |
1643 |
protected:
|
| 1649 |
|
ConstMap<typename Digraph::Node, bool> const_true_map;
|
| 1650 |
|
|
| 1651 |
|
FilterArcs() : const_true_map(true) {
|
| 1652 |
|
Parent::setNodeFilterMap(const_true_map);
|
| 1653 |
|
}
|
|
1644 |
ConstMap<typename DGR::Node, Const<bool, true> > const_true_map;
|
|
1645 |
|
|
1646 |
FilterArcs() : const_true_map() {}
|
| 1654 |
1647 |
|
| 1655 |
1648 |
public:
|
| 1656 |
1649 |
|
| 1657 |
1650 |
/// \brief Constructor
|
| 1658 |
1651 |
///
|
| 1659 |
1652 |
/// Creates a subdigraph for the given digraph with the given arc
|
| 1660 |
1653 |
/// filter map.
|
| 1661 |
|
FilterArcs(Digraph& digraph, ArcFilterMap& arc_filter)
|
| 1662 |
|
: Parent(), const_true_map(true) {
|
| 1663 |
|
Parent::setDigraph(digraph);
|
| 1664 |
|
Parent::setNodeFilterMap(const_true_map);
|
| 1665 |
|
Parent::setArcFilterMap(arc_filter);
|
|
1654 |
FilterArcs(DGR& digraph, ArcFilterMap& arc_filter)
|
|
1655 |
: Parent(), const_true_map() {
|
|
1656 |
Parent::initialize(digraph, const_true_map, arc_filter);
|
| 1666 |
1657 |
}
|
| 1667 |
1658 |
|
| 1668 |
1659 |
/// \brief Sets the status of the given arc
|
| 1669 |
1660 |
///
|
| 1670 |
1661 |
/// This function sets the status of the given arc.
|
| 1671 |
1662 |
/// It is done by simply setting the assigned value of \c a
|
| 1672 |
1663 |
/// to \c v in the arc filter map.
|
| 1673 |
1664 |
void status(const Arc& a, bool v) const { Parent::status(a, v); }
|
| 1674 |
1665 |
|
| 1675 |
1666 |
/// \brief Returns the status of the given arc
|
| 1676 |
1667 |
///
|
| 1677 |
1668 |
/// This function returns the status of the given arc.
|
| 1678 |
1669 |
/// It is \c true if the given arc is enabled (i.e. not hidden).
|
| 1679 |
1670 |
bool status(const Arc& a) const { return Parent::status(a); }
|
| 1680 |
1671 |
|
| 1681 |
1672 |
/// \brief Disables the given arc
|
| 1682 |
1673 |
///
|
| 1683 |
1674 |
/// This function disables the given arc in the subdigraph,
|
| 1684 |
1675 |
/// so the iteration jumps over it.
|
| 1685 |
1676 |
/// It is the same as \ref status() "status(a, false)".
|
| 1686 |
1677 |
void disable(const Arc& a) const { Parent::status(a, false); }
|
| 1687 |
1678 |
|
| 1688 |
1679 |
/// \brief Enables the given arc
|
| 1689 |
1680 |
///
|
| 1690 |
1681 |
/// This function enables the given arc in the subdigraph.
|
| 1691 |
1682 |
/// It is the same as \ref status() "status(a, true)".
|
| 1692 |
1683 |
void enable(const Arc& a) const { Parent::status(a, true); }
|
| 1693 |
1684 |
|
| 1694 |
1685 |
};
|
| 1695 |
1686 |
|
| 1696 |
1687 |
/// \brief Returns a read-only FilterArcs adaptor
|
| 1697 |
1688 |
///
|
| 1698 |
1689 |
/// This function just returns a read-only \ref FilterArcs adaptor.
|
| 1699 |
1690 |
/// \ingroup graph_adaptors
|
| 1700 |
1691 |
/// \relates FilterArcs
|
| 1701 |
|
template<typename GR, typename AF>
|
| 1702 |
|
FilterArcs<const GR, AF>
|
| 1703 |
|
filterArcs(const GR& digraph, AF& arc_filter_map) {
|
| 1704 |
|
return FilterArcs<const GR, AF>(digraph, arc_filter_map);
|
|
1692 |
template<typename DGR, typename AF>
|
|
1693 |
FilterArcs<const DGR, AF>
|
|
1694 |
filterArcs(const DGR& digraph, AF& arc_filter) {
|
|
1695 |
return FilterArcs<const DGR, AF>(digraph, arc_filter);
|
| 1705 |
1696 |
}
|
| 1706 |
1697 |
|
| 1707 |
|
template<typename GR, typename AF>
|
| 1708 |
|
FilterArcs<const GR, const AF>
|
| 1709 |
|
filterArcs(const GR& digraph, const AF& arc_filter_map) {
|
| 1710 |
|
return FilterArcs<const GR, const AF>(digraph, arc_filter_map);
|
|
1698 |
template<typename DGR, typename AF>
|
|
1699 |
FilterArcs<const DGR, const AF>
|
|
1700 |
filterArcs(const DGR& digraph, const AF& arc_filter) {
|
|
1701 |
return FilterArcs<const DGR, const AF>(digraph, arc_filter);
|
| 1711 |
1702 |
}
|
| 1712 |
1703 |
|
| 1713 |
1704 |
/// \ingroup graph_adaptors
|
| 1714 |
1705 |
///
|
| 1715 |
1706 |
/// \brief Adaptor class for hiding edges in a graph.
|
| 1716 |
1707 |
///
|
| 1717 |
1708 |
/// FilterEdges adaptor can be used for hiding edges in a graph.
|
| 1718 |
1709 |
/// A \c bool edge map must be specified, which defines the filter for
|
| 1719 |
1710 |
/// the edges. Only the edges with \c true filter value are shown in the
|
| 1720 |
1711 |
/// subgraph. This adaptor conforms to the \ref concepts::Graph
|
| 1721 |
1712 |
/// "Graph" concept.
|
| 1722 |
1713 |
///
|
| 1723 |
1714 |
/// The adapted graph can also be modified through this adaptor
|
| 1724 |
1715 |
/// by adding or removing nodes or edges, unless the \c GR template
|
| 1725 |
1716 |
/// parameter is set to be \c const.
|
| 1726 |
1717 |
///
|
| 1727 |
1718 |
/// \tparam GR The type of the adapted graph.
|
| 1728 |
1719 |
/// It must conform to the \ref concepts::Graph "Graph" concept.
|
| 1729 |
1720 |
/// It can also be specified to be \c const.
|
| 1730 |
1721 |
/// \tparam EF The type of the edge filter map.
|
| 1731 |
1722 |
/// It must be a \c bool (or convertible) edge map of the
|
| 1732 |
1723 |
/// adapted graph. The default type is
|
| 1733 |
1724 |
/// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>".
|
| 1734 |
1725 |
///
|
| 1735 |
1726 |
/// \note The \c Node, \c Edge and \c Arc types of this adaptor and the
|
| 1736 |
1727 |
/// adapted graph are convertible to each other.
|
| 1737 |
1728 |
#ifdef DOXYGEN
|
| 1738 |
1729 |
template<typename GR,
|
| 1739 |
1730 |
typename EF>
|
| 1740 |
1731 |
class FilterEdges {
|
| 1741 |
1732 |
#else
|
| 1742 |
1733 |
template<typename GR,
|
| 1743 |
1734 |
typename EF = typename GR::template EdgeMap<bool> >
|
| 1744 |
1735 |
class FilterEdges :
|
| 1745 |
1736 |
public GraphAdaptorExtender<
|
| 1746 |
|
SubGraphBase<GR, ConstMap<typename GR::Node,bool>, EF, false> > {
|
|
1737 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >,
|
|
1738 |
EF, false> > {
|
| 1747 |
1739 |
#endif
|
| 1748 |
1740 |
public:
|
| 1749 |
1741 |
/// The type of the adapted graph.
|
| 1750 |
1742 |
typedef GR Graph;
|
| 1751 |
1743 |
/// The type of the edge filter map.
|
| 1752 |
1744 |
typedef EF EdgeFilterMap;
|
| 1753 |
1745 |
|
| 1754 |
1746 |
typedef GraphAdaptorExtender<
|
| 1755 |
|
SubGraphBase<GR, ConstMap<typename GR::Node,bool>, EF, false> >
|
| 1756 |
|
Parent;
|
|
1747 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >,
|
|
1748 |
EF, false> > Parent;
|
| 1757 |
1749 |
|
| 1758 |
1750 |
typedef typename Parent::Edge Edge;
|
| 1759 |
1751 |
|
| 1760 |
1752 |
protected:
|
| 1761 |
|
ConstMap<typename Graph::Node, bool> const_true_map;
|
|
1753 |
ConstMap<typename GR::Node, Const<bool, true> > const_true_map;
|
| 1762 |
1754 |
|
| 1763 |
1755 |
FilterEdges() : const_true_map(true) {
|
| 1764 |
1756 |
Parent::setNodeFilterMap(const_true_map);
|
| 1765 |
1757 |
}
|
| 1766 |
1758 |
|
| 1767 |
1759 |
public:
|
| 1768 |
1760 |
|
| 1769 |
1761 |
/// \brief Constructor
|
| 1770 |
1762 |
///
|
| 1771 |
1763 |
/// Creates a subgraph for the given graph with the given edge
|
| 1772 |
1764 |
/// filter map.
|
| 1773 |
|
FilterEdges(Graph& graph, EdgeFilterMap& edge_filter_map) :
|
| 1774 |
|
Parent(), const_true_map(true) {
|
| 1775 |
|
Parent::setGraph(graph);
|
| 1776 |
|
Parent::setNodeFilterMap(const_true_map);
|
| 1777 |
|
Parent::setEdgeFilterMap(edge_filter_map);
|
|
1765 |
FilterEdges(GR& graph, EF& edge_filter)
|
|
1766 |
: Parent(), const_true_map() {
|
|
1767 |
Parent::initialize(graph, const_true_map, edge_filter);
|
| 1778 |
1768 |
}
|
| 1779 |
1769 |
|
| 1780 |
1770 |
/// \brief Sets the status of the given edge
|
| 1781 |
1771 |
///
|
| 1782 |
1772 |
/// This function sets the status of the given edge.
|
| 1783 |
1773 |
/// It is done by simply setting the assigned value of \c e
|
| 1784 |
1774 |
/// to \c v in the edge filter map.
|
| 1785 |
1775 |
void status(const Edge& e, bool v) const { Parent::status(e, v); }
|
| 1786 |
1776 |
|
| 1787 |
1777 |
/// \brief Returns the status of the given edge
|
| 1788 |
1778 |
///
|
| 1789 |
1779 |
/// This function returns the status of the given edge.
|
| 1790 |
1780 |
/// It is \c true if the given edge is enabled (i.e. not hidden).
|
| 1791 |
1781 |
bool status(const Edge& e) const { return Parent::status(e); }
|
| 1792 |
1782 |
|
| 1793 |
1783 |
/// \brief Disables the given edge
|
| 1794 |
1784 |
///
|
| 1795 |
1785 |
/// This function disables the given edge in the subgraph,
|
| 1796 |
1786 |
/// so the iteration jumps over it.
|
| 1797 |
1787 |
/// It is the same as \ref status() "status(e, false)".
|
| 1798 |
1788 |
void disable(const Edge& e) const { Parent::status(e, false); }
|
| 1799 |
1789 |
|
| 1800 |
1790 |
/// \brief Enables the given edge
|
| 1801 |
1791 |
///
|
| 1802 |
1792 |
/// This function enables the given edge in the subgraph.
|
| 1803 |
1793 |
/// It is the same as \ref status() "status(e, true)".
|
| 1804 |
1794 |
void enable(const Edge& e) const { Parent::status(e, true); }
|
| 1805 |
1795 |
|
| 1806 |
1796 |
};
|
| 1807 |
1797 |
|
| 1808 |
1798 |
/// \brief Returns a read-only FilterEdges adaptor
|
| 1809 |
1799 |
///
|
| 1810 |
1800 |
/// This function just returns a read-only \ref FilterEdges adaptor.
|
| 1811 |
1801 |
/// \ingroup graph_adaptors
|
| 1812 |
1802 |
/// \relates FilterEdges
|
| 1813 |
1803 |
template<typename GR, typename EF>
|
| 1814 |
1804 |
FilterEdges<const GR, EF>
|
| 1815 |
|
filterEdges(const GR& graph, EF& edge_filter_map) {
|
| 1816 |
|
return FilterEdges<const GR, EF>(graph, edge_filter_map);
|
|
1805 |
filterEdges(const GR& graph, EF& edge_filter) {
|
|
1806 |
return FilterEdges<const GR, EF>(graph, edge_filter);
|
| 1817 |
1807 |
}
|
| 1818 |
1808 |
|
| 1819 |
1809 |
template<typename GR, typename EF>
|
| 1820 |
1810 |
FilterEdges<const GR, const EF>
|
| 1821 |
|
filterEdges(const GR& graph, const EF& edge_filter_map) {
|
| 1822 |
|
return FilterEdges<const GR, const EF>(graph, edge_filter_map);
|
|
1811 |
filterEdges(const GR& graph, const EF& edge_filter) {
|
|
1812 |
return FilterEdges<const GR, const EF>(graph, edge_filter);
|
| 1823 |
1813 |
}
|
| 1824 |
1814 |
|
| 1825 |
1815 |
|
| 1826 |
|
template <typename _Digraph>
|
|
1816 |
template <typename DGR>
|
| 1827 |
1817 |
class UndirectorBase {
|
| 1828 |
1818 |
public:
|
| 1829 |
|
typedef _Digraph Digraph;
|
|
1819 |
typedef DGR Digraph;
|
| 1830 |
1820 |
typedef UndirectorBase Adaptor;
|
| 1831 |
1821 |
|
| 1832 |
1822 |
typedef True UndirectedTag;
|
| 1833 |
1823 |
|
| 1834 |
1824 |
typedef typename Digraph::Arc Edge;
|
| 1835 |
1825 |
typedef typename Digraph::Node Node;
|
| 1836 |
1826 |
|
| 1837 |
1827 |
class Arc : public Edge {
|
| 1838 |
1828 |
friend class UndirectorBase;
|
| 1839 |
1829 |
protected:
|
| 1840 |
1830 |
bool _forward;
|
| 1841 |
1831 |
|
| 1842 |
1832 |
Arc(const Edge& edge, bool forward) :
|
| 1843 |
1833 |
Edge(edge), _forward(forward) {}
|
| 1844 |
1834 |
|
| 1845 |
1835 |
public:
|
| 1846 |
1836 |
Arc() {}
|
| 1847 |
1837 |
|
| 1848 |
1838 |
Arc(Invalid) : Edge(INVALID), _forward(true) {}
|
| 1849 |
1839 |
|
| 1850 |
1840 |
bool operator==(const Arc &other) const {
|
| 1851 |
1841 |
return _forward == other._forward &&
|
| 1852 |
1842 |
static_cast<const Edge&>(*this) == static_cast<const Edge&>(other);
|
| 1853 |
1843 |
}
|
| 1854 |
1844 |
bool operator!=(const Arc &other) const {
|
| 1855 |
1845 |
return _forward != other._forward ||
|
| 1856 |
1846 |
static_cast<const Edge&>(*this) != static_cast<const Edge&>(other);
|
| 1857 |
1847 |
}
|
| 1858 |
1848 |
bool operator<(const Arc &other) const {
|
| 1859 |
1849 |
return _forward < other._forward ||
|
| 1860 |
1850 |
(_forward == other._forward &&
|
| 1861 |
1851 |
static_cast<const Edge&>(*this) < static_cast<const Edge&>(other));
|
| 1862 |
1852 |
}
|
| 1863 |
1853 |
};
|
| 1864 |
1854 |
|
| 1865 |
1855 |
void first(Node& n) const {
|
| 1866 |
1856 |
_digraph->first(n);
|
| 1867 |
1857 |
}
|
| 1868 |
1858 |
|
| 1869 |
1859 |
void next(Node& n) const {
|
| 1870 |
1860 |
_digraph->next(n);
|
| 1871 |
1861 |
}
|
| 1872 |
1862 |
|
| 1873 |
1863 |
void first(Arc& a) const {
|
| 1874 |
1864 |
_digraph->first(a);
|
| 1875 |
1865 |
a._forward = true;
|
| 1876 |
1866 |
}
|
| 1877 |
1867 |
|
| ... |
... |
@@ -2017,290 +2007,291 @@
|
| 2017 |
2007 |
|
| 2018 |
2008 |
typedef ArcNumTag EdgeNumTag;
|
| 2019 |
2009 |
int edgeNum() const { return _digraph->arcNum(); }
|
| 2020 |
2010 |
|
| 2021 |
2011 |
typedef FindArcTagIndicator<Digraph> FindArcTag;
|
| 2022 |
2012 |
Arc findArc(Node s, Node t, Arc p = INVALID) const {
|
| 2023 |
2013 |
if (p == INVALID) {
|
| 2024 |
2014 |
Edge arc = _digraph->findArc(s, t);
|
| 2025 |
2015 |
if (arc != INVALID) return direct(arc, true);
|
| 2026 |
2016 |
arc = _digraph->findArc(t, s);
|
| 2027 |
2017 |
if (arc != INVALID) return direct(arc, false);
|
| 2028 |
2018 |
} else if (direction(p)) {
|
| 2029 |
2019 |
Edge arc = _digraph->findArc(s, t, p);
|
| 2030 |
2020 |
if (arc != INVALID) return direct(arc, true);
|
| 2031 |
2021 |
arc = _digraph->findArc(t, s);
|
| 2032 |
2022 |
if (arc != INVALID) return direct(arc, false);
|
| 2033 |
2023 |
} else {
|
| 2034 |
2024 |
Edge arc = _digraph->findArc(t, s, p);
|
| 2035 |
2025 |
if (arc != INVALID) return direct(arc, false);
|
| 2036 |
2026 |
}
|
| 2037 |
2027 |
return INVALID;
|
| 2038 |
2028 |
}
|
| 2039 |
2029 |
|
| 2040 |
2030 |
typedef FindArcTag FindEdgeTag;
|
| 2041 |
2031 |
Edge findEdge(Node s, Node t, Edge p = INVALID) const {
|
| 2042 |
2032 |
if (s != t) {
|
| 2043 |
2033 |
if (p == INVALID) {
|
| 2044 |
2034 |
Edge arc = _digraph->findArc(s, t);
|
| 2045 |
2035 |
if (arc != INVALID) return arc;
|
| 2046 |
2036 |
arc = _digraph->findArc(t, s);
|
| 2047 |
2037 |
if (arc != INVALID) return arc;
|
| 2048 |
2038 |
} else if (_digraph->source(p) == s) {
|
| 2049 |
2039 |
Edge arc = _digraph->findArc(s, t, p);
|
| 2050 |
2040 |
if (arc != INVALID) return arc;
|
| 2051 |
2041 |
arc = _digraph->findArc(t, s);
|
| 2052 |
2042 |
if (arc != INVALID) return arc;
|
| 2053 |
2043 |
} else {
|
| 2054 |
2044 |
Edge arc = _digraph->findArc(t, s, p);
|
| 2055 |
2045 |
if (arc != INVALID) return arc;
|
| 2056 |
2046 |
}
|
| 2057 |
2047 |
} else {
|
| 2058 |
2048 |
return _digraph->findArc(s, t, p);
|
| 2059 |
2049 |
}
|
| 2060 |
2050 |
return INVALID;
|
| 2061 |
2051 |
}
|
| 2062 |
2052 |
|
| 2063 |
2053 |
private:
|
| 2064 |
2054 |
|
| 2065 |
|
template <typename _Value>
|
|
2055 |
template <typename V>
|
| 2066 |
2056 |
class ArcMapBase {
|
| 2067 |
2057 |
private:
|
| 2068 |
2058 |
|
| 2069 |
|
typedef typename Digraph::template ArcMap<_Value> MapImpl;
|
|
2059 |
typedef typename DGR::template ArcMap<V> MapImpl;
|
| 2070 |
2060 |
|
| 2071 |
2061 |
public:
|
| 2072 |
2062 |
|
| 2073 |
2063 |
typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag;
|
| 2074 |
2064 |
|
| 2075 |
|
typedef _Value Value;
|
|
2065 |
typedef V Value;
|
| 2076 |
2066 |
typedef Arc Key;
|
| 2077 |
2067 |
typedef typename MapTraits<MapImpl>::ConstReturnValue ConstReturnValue;
|
| 2078 |
2068 |
typedef typename MapTraits<MapImpl>::ReturnValue ReturnValue;
|
| 2079 |
2069 |
typedef typename MapTraits<MapImpl>::ConstReturnValue ConstReference;
|
| 2080 |
2070 |
typedef typename MapTraits<MapImpl>::ReturnValue Reference;
|
| 2081 |
2071 |
|
| 2082 |
|
ArcMapBase(const Adaptor& adaptor) :
|
|
2072 |
ArcMapBase(const UndirectorBase<DGR>& adaptor) :
|
| 2083 |
2073 |
_forward(*adaptor._digraph), _backward(*adaptor._digraph) {}
|
| 2084 |
2074 |
|
| 2085 |
|
ArcMapBase(const Adaptor& adaptor, const Value& v)
|
| 2086 |
|
: _forward(*adaptor._digraph, v), _backward(*adaptor._digraph, v) {}
|
| 2087 |
|
|
| 2088 |
|
void set(const Arc& a, const Value& v) {
|
|
2075 |
ArcMapBase(const UndirectorBase<DGR>& adaptor, const V& value)
|
|
2076 |
: _forward(*adaptor._digraph, value),
|
|
2077 |
_backward(*adaptor._digraph, value) {}
|
|
2078 |
|
|
2079 |
void set(const Arc& a, const V& value) {
|
| 2089 |
2080 |
if (direction(a)) {
|
| 2090 |
|
_forward.set(a, v);
|
|
2081 |
_forward.set(a, value);
|
| 2091 |
2082 |
} else {
|
| 2092 |
|
_backward.set(a, v);
|
|
2083 |
_backward.set(a, value);
|
| 2093 |
2084 |
}
|
| 2094 |
2085 |
}
|
| 2095 |
2086 |
|
| 2096 |
2087 |
ConstReturnValue operator[](const Arc& a) const {
|
| 2097 |
2088 |
if (direction(a)) {
|
| 2098 |
2089 |
return _forward[a];
|
| 2099 |
2090 |
} else {
|
| 2100 |
2091 |
return _backward[a];
|
| 2101 |
2092 |
}
|
| 2102 |
2093 |
}
|
| 2103 |
2094 |
|
| 2104 |
2095 |
ReturnValue operator[](const Arc& a) {
|
| 2105 |
2096 |
if (direction(a)) {
|
| 2106 |
2097 |
return _forward[a];
|
| 2107 |
2098 |
} else {
|
| 2108 |
2099 |
return _backward[a];
|
| 2109 |
2100 |
}
|
| 2110 |
2101 |
}
|
| 2111 |
2102 |
|
| 2112 |
2103 |
protected:
|
| 2113 |
2104 |
|
| 2114 |
2105 |
MapImpl _forward, _backward;
|
| 2115 |
2106 |
|
| 2116 |
2107 |
};
|
| 2117 |
2108 |
|
| 2118 |
2109 |
public:
|
| 2119 |
2110 |
|
| 2120 |
|
template <typename _Value>
|
| 2121 |
|
class NodeMap : public Digraph::template NodeMap<_Value> {
|
|
2111 |
template <typename V>
|
|
2112 |
class NodeMap : public DGR::template NodeMap<V> {
|
| 2122 |
2113 |
public:
|
| 2123 |
2114 |
|
| 2124 |
|
typedef _Value Value;
|
| 2125 |
|
typedef typename Digraph::template NodeMap<Value> Parent;
|
| 2126 |
|
|
| 2127 |
|
explicit NodeMap(const Adaptor& adaptor)
|
|
2115 |
typedef V Value;
|
|
2116 |
typedef typename DGR::template NodeMap<Value> Parent;
|
|
2117 |
|
|
2118 |
explicit NodeMap(const UndirectorBase<DGR>& adaptor)
|
| 2128 |
2119 |
: Parent(*adaptor._digraph) {}
|
| 2129 |
2120 |
|
| 2130 |
|
NodeMap(const Adaptor& adaptor, const _Value& value)
|
|
2121 |
NodeMap(const UndirectorBase<DGR>& adaptor, const V& value)
|
| 2131 |
2122 |
: Parent(*adaptor._digraph, value) { }
|
| 2132 |
2123 |
|
| 2133 |
2124 |
private:
|
| 2134 |
2125 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 2135 |
2126 |
return operator=<NodeMap>(cmap);
|
| 2136 |
2127 |
}
|
| 2137 |
2128 |
|
| 2138 |
2129 |
template <typename CMap>
|
| 2139 |
2130 |
NodeMap& operator=(const CMap& cmap) {
|
| 2140 |
2131 |
Parent::operator=(cmap);
|
| 2141 |
2132 |
return *this;
|
| 2142 |
2133 |
}
|
| 2143 |
2134 |
|
| 2144 |
2135 |
};
|
| 2145 |
2136 |
|
| 2146 |
|
template <typename _Value>
|
|
2137 |
template <typename V>
|
| 2147 |
2138 |
class ArcMap
|
| 2148 |
|
: public SubMapExtender<Adaptor, ArcMapBase<_Value> >
|
|
2139 |
: public SubMapExtender<UndirectorBase<DGR>, ArcMapBase<V> >
|
| 2149 |
2140 |
{
|
| 2150 |
2141 |
public:
|
| 2151 |
|
typedef _Value Value;
|
| 2152 |
|
typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
|
| 2153 |
|
|
| 2154 |
|
explicit ArcMap(const Adaptor& adaptor)
|
|
2142 |
typedef V Value;
|
|
2143 |
typedef SubMapExtender<Adaptor, ArcMapBase<V> > Parent;
|
|
2144 |
|
|
2145 |
explicit ArcMap(const UndirectorBase<DGR>& adaptor)
|
| 2155 |
2146 |
: Parent(adaptor) {}
|
| 2156 |
2147 |
|
| 2157 |
|
ArcMap(const Adaptor& adaptor, const Value& value)
|
|
2148 |
ArcMap(const UndirectorBase<DGR>& adaptor, const V& value)
|
| 2158 |
2149 |
: Parent(adaptor, value) {}
|
| 2159 |
2150 |
|
| 2160 |
2151 |
private:
|
| 2161 |
2152 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 2162 |
2153 |
return operator=<ArcMap>(cmap);
|
| 2163 |
2154 |
}
|
| 2164 |
2155 |
|
| 2165 |
2156 |
template <typename CMap>
|
| 2166 |
2157 |
ArcMap& operator=(const CMap& cmap) {
|
| 2167 |
2158 |
Parent::operator=(cmap);
|
| 2168 |
2159 |
return *this;
|
| 2169 |
2160 |
}
|
| 2170 |
2161 |
};
|
| 2171 |
2162 |
|
| 2172 |
|
template <typename _Value>
|
| 2173 |
|
class EdgeMap : public Digraph::template ArcMap<_Value> {
|
|
2163 |
template <typename V>
|
|
2164 |
class EdgeMap : public Digraph::template ArcMap<V> {
|
| 2174 |
2165 |
public:
|
| 2175 |
2166 |
|
| 2176 |
|
typedef _Value Value;
|
| 2177 |
|
typedef typename Digraph::template ArcMap<Value> Parent;
|
| 2178 |
|
|
| 2179 |
|
explicit EdgeMap(const Adaptor& adaptor)
|
|
2167 |
typedef V Value;
|
|
2168 |
typedef typename Digraph::template ArcMap<V> Parent;
|
|
2169 |
|
|
2170 |
explicit EdgeMap(const UndirectorBase<DGR>& adaptor)
|
| 2180 |
2171 |
: Parent(*adaptor._digraph) {}
|
| 2181 |
2172 |
|
| 2182 |
|
EdgeMap(const Adaptor& adaptor, const Value& value)
|
|
2173 |
EdgeMap(const UndirectorBase<DGR>& adaptor, const V& value)
|
| 2183 |
2174 |
: Parent(*adaptor._digraph, value) {}
|
| 2184 |
2175 |
|
| 2185 |
2176 |
private:
|
| 2186 |
2177 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
| 2187 |
2178 |
return operator=<EdgeMap>(cmap);
|
| 2188 |
2179 |
}
|
| 2189 |
2180 |
|
| 2190 |
2181 |
template <typename CMap>
|
| 2191 |
2182 |
EdgeMap& operator=(const CMap& cmap) {
|
| 2192 |
2183 |
Parent::operator=(cmap);
|
| 2193 |
2184 |
return *this;
|
| 2194 |
2185 |
}
|
| 2195 |
2186 |
|
| 2196 |
2187 |
};
|
| 2197 |
2188 |
|
| 2198 |
|
typedef typename ItemSetTraits<Digraph, Node>::ItemNotifier NodeNotifier;
|
|
2189 |
typedef typename ItemSetTraits<DGR, Node>::ItemNotifier NodeNotifier;
|
| 2199 |
2190 |
NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
|
| 2200 |
2191 |
|
| 2201 |
|
typedef typename ItemSetTraits<Digraph, Edge>::ItemNotifier EdgeNotifier;
|
|
2192 |
typedef typename ItemSetTraits<DGR, Edge>::ItemNotifier EdgeNotifier;
|
| 2202 |
2193 |
EdgeNotifier& notifier(Edge) const { return _digraph->notifier(Edge()); }
|
| 2203 |
2194 |
|
| 2204 |
2195 |
protected:
|
| 2205 |
2196 |
|
| 2206 |
2197 |
UndirectorBase() : _digraph(0) {}
|
| 2207 |
2198 |
|
| 2208 |
|
Digraph* _digraph;
|
| 2209 |
|
|
| 2210 |
|
void setDigraph(Digraph& digraph) {
|
|
2199 |
DGR* _digraph;
|
|
2200 |
|
|
2201 |
void initialize(DGR& digraph) {
|
| 2211 |
2202 |
_digraph = &digraph;
|
| 2212 |
2203 |
}
|
| 2213 |
2204 |
|
| 2214 |
2205 |
};
|
| 2215 |
2206 |
|
| 2216 |
2207 |
/// \ingroup graph_adaptors
|
| 2217 |
2208 |
///
|
| 2218 |
2209 |
/// \brief Adaptor class for viewing a digraph as an undirected graph.
|
| 2219 |
2210 |
///
|
| 2220 |
2211 |
/// Undirector adaptor can be used for viewing a digraph as an undirected
|
| 2221 |
2212 |
/// graph. All arcs of the underlying digraph are showed in the
|
| 2222 |
2213 |
/// adaptor as an edge (and also as a pair of arcs, of course).
|
| 2223 |
2214 |
/// This adaptor conforms to the \ref concepts::Graph "Graph" concept.
|
| 2224 |
2215 |
///
|
| 2225 |
2216 |
/// The adapted digraph can also be modified through this adaptor
|
| 2226 |
2217 |
/// by adding or removing nodes or edges, unless the \c GR template
|
| 2227 |
2218 |
/// parameter is set to be \c const.
|
| 2228 |
2219 |
///
|
| 2229 |
|
/// \tparam GR The type of the adapted digraph.
|
|
2220 |
/// \tparam DGR The type of the adapted digraph.
|
| 2230 |
2221 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept.
|
| 2231 |
2222 |
/// It can also be specified to be \c const.
|
| 2232 |
2223 |
///
|
| 2233 |
2224 |
/// \note The \c Node type of this adaptor and the adapted digraph are
|
| 2234 |
2225 |
/// convertible to each other, moreover the \c Edge type of the adaptor
|
| 2235 |
2226 |
/// and the \c Arc type of the adapted digraph are also convertible to
|
| 2236 |
2227 |
/// each other.
|
| 2237 |
2228 |
/// (Thus the \c Arc type of the adaptor is convertible to the \c Arc type
|
| 2238 |
2229 |
/// of the adapted digraph.)
|
| 2239 |
|
template<typename GR>
|
|
2230 |
template<typename DGR>
|
| 2240 |
2231 |
#ifdef DOXYGEN
|
| 2241 |
2232 |
class Undirector {
|
| 2242 |
2233 |
#else
|
| 2243 |
2234 |
class Undirector :
|
| 2244 |
|
public GraphAdaptorExtender<UndirectorBase<GR> > {
|
|
2235 |
public GraphAdaptorExtender<UndirectorBase<DGR> > {
|
| 2245 |
2236 |
#endif
|
| 2246 |
2237 |
public:
|
| 2247 |
2238 |
/// The type of the adapted digraph.
|
| 2248 |
|
typedef GR Digraph;
|
| 2249 |
|
typedef GraphAdaptorExtender<UndirectorBase<GR> > Parent;
|
|
2239 |
typedef DGR Digraph;
|
|
2240 |
typedef GraphAdaptorExtender<UndirectorBase<DGR> > Parent;
|
| 2250 |
2241 |
protected:
|
| 2251 |
2242 |
Undirector() { }
|
| 2252 |
2243 |
public:
|
| 2253 |
2244 |
|
| 2254 |
2245 |
/// \brief Constructor
|
| 2255 |
2246 |
///
|
| 2256 |
2247 |
/// Creates an undirected graph from the given digraph.
|
| 2257 |
|
Undirector(Digraph& digraph) {
|
| 2258 |
|
setDigraph(digraph);
|
|
2248 |
Undirector(DGR& digraph) {
|
|
2249 |
initialize(digraph);
|
| 2259 |
2250 |
}
|
| 2260 |
2251 |
|
| 2261 |
2252 |
/// \brief Arc map combined from two original arc maps
|
| 2262 |
2253 |
///
|
| 2263 |
2254 |
/// This map adaptor class adapts two arc maps of the underlying
|
| 2264 |
2255 |
/// digraph to get an arc map of the undirected graph.
|
| 2265 |
2256 |
/// Its value type is inherited from the first arc map type
|
| 2266 |
2257 |
/// (\c %ForwardMap).
|
| 2267 |
2258 |
template <typename ForwardMap, typename BackwardMap>
|
| 2268 |
2259 |
class CombinedArcMap {
|
| 2269 |
2260 |
public:
|
| 2270 |
2261 |
|
| 2271 |
2262 |
/// The key type of the map
|
| 2272 |
2263 |
typedef typename Parent::Arc Key;
|
| 2273 |
2264 |
/// The value type of the map
|
| 2274 |
2265 |
typedef typename ForwardMap::Value Value;
|
| 2275 |
2266 |
|
| 2276 |
2267 |
typedef typename MapTraits<ForwardMap>::ReferenceMapTag ReferenceMapTag;
|
| 2277 |
2268 |
|
| 2278 |
2269 |
typedef typename MapTraits<ForwardMap>::ReturnValue ReturnValue;
|
| 2279 |
2270 |
typedef typename MapTraits<ForwardMap>::ConstReturnValue ConstReturnValue;
|
| 2280 |
2271 |
typedef typename MapTraits<ForwardMap>::ReturnValue Reference;
|
| 2281 |
2272 |
typedef typename MapTraits<ForwardMap>::ConstReturnValue ConstReference;
|
| 2282 |
2273 |
|
| 2283 |
2274 |
/// Constructor
|
| 2284 |
2275 |
CombinedArcMap(ForwardMap& forward, BackwardMap& backward)
|
| 2285 |
2276 |
: _forward(&forward), _backward(&backward) {}
|
| 2286 |
2277 |
|
| 2287 |
2278 |
/// Sets the value associated with the given key.
|
| 2288 |
2279 |
void set(const Key& e, const Value& a) {
|
| 2289 |
2280 |
if (Parent::direction(e)) {
|
| 2290 |
2281 |
_forward->set(e, a);
|
| 2291 |
2282 |
} else {
|
| 2292 |
2283 |
_backward->set(e, a);
|
| 2293 |
2284 |
}
|
| 2294 |
2285 |
}
|
| 2295 |
2286 |
|
| 2296 |
2287 |
/// Returns the value associated with the given key.
|
| 2297 |
2288 |
ConstReturnValue operator[](const Key& e) const {
|
| 2298 |
2289 |
if (Parent::direction(e)) {
|
| 2299 |
2290 |
return (*_forward)[e];
|
| 2300 |
2291 |
} else {
|
| 2301 |
2292 |
return (*_backward)[e];
|
| 2302 |
2293 |
}
|
| 2303 |
2294 |
}
|
| 2304 |
2295 |
|
| 2305 |
2296 |
/// Returns a reference to the value associated with the given key.
|
| 2306 |
2297 |
ReturnValue operator[](const Key& e) {
|
| ... |
... |
@@ -2310,626 +2301,622 @@
|
| 2310 |
2301 |
return (*_backward)[e];
|
| 2311 |
2302 |
}
|
| 2312 |
2303 |
}
|
| 2313 |
2304 |
|
| 2314 |
2305 |
protected:
|
| 2315 |
2306 |
|
| 2316 |
2307 |
ForwardMap* _forward;
|
| 2317 |
2308 |
BackwardMap* _backward;
|
| 2318 |
2309 |
|
| 2319 |
2310 |
};
|
| 2320 |
2311 |
|
| 2321 |
2312 |
/// \brief Returns a combined arc map
|
| 2322 |
2313 |
///
|
| 2323 |
2314 |
/// This function just returns a combined arc map.
|
| 2324 |
2315 |
template <typename ForwardMap, typename BackwardMap>
|
| 2325 |
2316 |
static CombinedArcMap<ForwardMap, BackwardMap>
|
| 2326 |
2317 |
combinedArcMap(ForwardMap& forward, BackwardMap& backward) {
|
| 2327 |
2318 |
return CombinedArcMap<ForwardMap, BackwardMap>(forward, backward);
|
| 2328 |
2319 |
}
|
| 2329 |
2320 |
|
| 2330 |
2321 |
template <typename ForwardMap, typename BackwardMap>
|
| 2331 |
2322 |
static CombinedArcMap<const ForwardMap, BackwardMap>
|
| 2332 |
2323 |
combinedArcMap(const ForwardMap& forward, BackwardMap& backward) {
|
| 2333 |
2324 |
return CombinedArcMap<const ForwardMap,
|
| 2334 |
2325 |
BackwardMap>(forward, backward);
|
| 2335 |
2326 |
}
|
| 2336 |
2327 |
|
| 2337 |
2328 |
template <typename ForwardMap, typename BackwardMap>
|
| 2338 |
2329 |
static CombinedArcMap<ForwardMap, const BackwardMap>
|
| 2339 |
2330 |
combinedArcMap(ForwardMap& forward, const BackwardMap& backward) {
|
| 2340 |
2331 |
return CombinedArcMap<ForwardMap,
|
| 2341 |
2332 |
const BackwardMap>(forward, backward);
|
| 2342 |
2333 |
}
|
| 2343 |
2334 |
|
| 2344 |
2335 |
template <typename ForwardMap, typename BackwardMap>
|
| 2345 |
2336 |
static CombinedArcMap<const ForwardMap, const BackwardMap>
|
| 2346 |
2337 |
combinedArcMap(const ForwardMap& forward, const BackwardMap& backward) {
|
| 2347 |
2338 |
return CombinedArcMap<const ForwardMap,
|
| 2348 |
2339 |
const BackwardMap>(forward, backward);
|
| 2349 |
2340 |
}
|
| 2350 |
2341 |
|
| 2351 |
2342 |
};
|
| 2352 |
2343 |
|
| 2353 |
2344 |
/// \brief Returns a read-only Undirector adaptor
|
| 2354 |
2345 |
///
|
| 2355 |
2346 |
/// This function just returns a read-only \ref Undirector adaptor.
|
| 2356 |
2347 |
/// \ingroup graph_adaptors
|
| 2357 |
2348 |
/// \relates Undirector
|
| 2358 |
|
template<typename GR>
|
| 2359 |
|
Undirector<const GR> undirector(const GR& digraph) {
|
| 2360 |
|
return Undirector<const GR>(digraph);
|
|
2349 |
template<typename DGR>
|
|
2350 |
Undirector<const DGR> undirector(const DGR& digraph) {
|
|
2351 |
return Undirector<const DGR>(digraph);
|
| 2361 |
2352 |
}
|
| 2362 |
2353 |
|
| 2363 |
2354 |
|
| 2364 |
|
template <typename _Graph, typename _DirectionMap>
|
|
2355 |
template <typename GR, typename DM>
|
| 2365 |
2356 |
class OrienterBase {
|
| 2366 |
2357 |
public:
|
| 2367 |
2358 |
|
| 2368 |
|
typedef _Graph Graph;
|
| 2369 |
|
typedef _DirectionMap DirectionMap;
|
| 2370 |
|
|
| 2371 |
|
typedef typename Graph::Node Node;
|
| 2372 |
|
typedef typename Graph::Edge Arc;
|
|
2359 |
typedef GR Graph;
|
|
2360 |
typedef DM DirectionMap;
|
|
2361 |
|
|
2362 |
typedef typename GR::Node Node;
|
|
2363 |
typedef typename GR::Edge Arc;
|
| 2373 |
2364 |
|
| 2374 |
2365 |
void reverseArc(const Arc& arc) {
|
| 2375 |
2366 |
_direction->set(arc, !(*_direction)[arc]);
|
| 2376 |
2367 |
}
|
| 2377 |
2368 |
|
| 2378 |
2369 |
void first(Node& i) const { _graph->first(i); }
|
| 2379 |
2370 |
void first(Arc& i) const { _graph->first(i); }
|
| 2380 |
2371 |
void firstIn(Arc& i, const Node& n) const {
|
| 2381 |
2372 |
bool d = true;
|
| 2382 |
2373 |
_graph->firstInc(i, d, n);
|
| 2383 |
2374 |
while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
|
| 2384 |
2375 |
}
|
| 2385 |
2376 |
void firstOut(Arc& i, const Node& n ) const {
|
| 2386 |
2377 |
bool d = true;
|
| 2387 |
2378 |
_graph->firstInc(i, d, n);
|
| 2388 |
2379 |
while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
|
| 2389 |
2380 |
}
|
| 2390 |
2381 |
|
| 2391 |
2382 |
void next(Node& i) const { _graph->next(i); }
|
| 2392 |
2383 |
void next(Arc& i) const { _graph->next(i); }
|
| 2393 |
2384 |
void nextIn(Arc& i) const {
|
| 2394 |
2385 |
bool d = !(*_direction)[i];
|
| 2395 |
2386 |
_graph->nextInc(i, d);
|
| 2396 |
2387 |
while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
|
| 2397 |
2388 |
}
|
| 2398 |
2389 |
void nextOut(Arc& i) const {
|
| 2399 |
2390 |
bool d = (*_direction)[i];
|
| 2400 |
2391 |
_graph->nextInc(i, d);
|
| 2401 |
2392 |
while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
|
| 2402 |
2393 |
}
|
| 2403 |
2394 |
|
| 2404 |
2395 |
Node source(const Arc& e) const {
|
| 2405 |
2396 |
return (*_direction)[e] ? _graph->u(e) : _graph->v(e);
|
| 2406 |
2397 |
}
|
| 2407 |
2398 |
Node target(const Arc& e) const {
|
| 2408 |
2399 |
return (*_direction)[e] ? _graph->v(e) : _graph->u(e);
|
| 2409 |
2400 |
}
|
| 2410 |
2401 |
|
| 2411 |
2402 |
typedef NodeNumTagIndicator<Graph> NodeNumTag;
|
| 2412 |
2403 |
int nodeNum() const { return _graph->nodeNum(); }
|
| 2413 |
2404 |
|
| 2414 |
2405 |
typedef EdgeNumTagIndicator<Graph> ArcNumTag;
|
| 2415 |
2406 |
int arcNum() const { return _graph->edgeNum(); }
|
| 2416 |
2407 |
|
| 2417 |
2408 |
typedef FindEdgeTagIndicator<Graph> FindArcTag;
|
| 2418 |
2409 |
Arc findArc(const Node& u, const Node& v,
|
| 2419 |
2410 |
const Arc& prev = INVALID) const {
|
| 2420 |
2411 |
Arc arc = _graph->findEdge(u, v, prev);
|
| 2421 |
2412 |
while (arc != INVALID && source(arc) != u) {
|
| 2422 |
2413 |
arc = _graph->findEdge(u, v, arc);
|
| 2423 |
2414 |
}
|
| 2424 |
2415 |
return arc;
|
| 2425 |
2416 |
}
|
| 2426 |
2417 |
|
| 2427 |
2418 |
Node addNode() {
|
| 2428 |
2419 |
return Node(_graph->addNode());
|
| 2429 |
2420 |
}
|
| 2430 |
2421 |
|
| 2431 |
2422 |
Arc addArc(const Node& u, const Node& v) {
|
| 2432 |
2423 |
Arc arc = _graph->addEdge(u, v);
|
| 2433 |
2424 |
_direction->set(arc, _graph->u(arc) == u);
|
| 2434 |
2425 |
return arc;
|
| 2435 |
2426 |
}
|
| 2436 |
2427 |
|
| 2437 |
2428 |
void erase(const Node& i) { _graph->erase(i); }
|
| 2438 |
2429 |
void erase(const Arc& i) { _graph->erase(i); }
|
| 2439 |
2430 |
|
| 2440 |
2431 |
void clear() { _graph->clear(); }
|
| 2441 |
2432 |
|
| 2442 |
2433 |
int id(const Node& v) const { return _graph->id(v); }
|
| 2443 |
2434 |
int id(const Arc& e) const { return _graph->id(e); }
|
| 2444 |
2435 |
|
| 2445 |
2436 |
Node nodeFromId(int idx) const { return _graph->nodeFromId(idx); }
|
| 2446 |
2437 |
Arc arcFromId(int idx) const { return _graph->edgeFromId(idx); }
|
| 2447 |
2438 |
|
| 2448 |
2439 |
int maxNodeId() const { return _graph->maxNodeId(); }
|
| 2449 |
2440 |
int maxArcId() const { return _graph->maxEdgeId(); }
|
| 2450 |
2441 |
|
| 2451 |
|
typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
|
|
2442 |
typedef typename ItemSetTraits<GR, Node>::ItemNotifier NodeNotifier;
|
| 2452 |
2443 |
NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
|
| 2453 |
2444 |
|
| 2454 |
|
typedef typename ItemSetTraits<Graph, Arc>::ItemNotifier ArcNotifier;
|
|
2445 |
typedef typename ItemSetTraits<GR, Arc>::ItemNotifier ArcNotifier;
|
| 2455 |
2446 |
ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
|
| 2456 |
2447 |
|
| 2457 |
|
template <typename _Value>
|
| 2458 |
|
class NodeMap : public _Graph::template NodeMap<_Value> {
|
|
2448 |
template <typename V>
|
|
2449 |
class NodeMap : public GR::template NodeMap<V> {
|
| 2459 |
2450 |
public:
|
| 2460 |
2451 |
|
| 2461 |
|
typedef typename _Graph::template NodeMap<_Value> Parent;
|
| 2462 |
|
|
| 2463 |
|
explicit NodeMap(const OrienterBase& adapter)
|
|
2452 |
typedef typename GR::template NodeMap<V> Parent;
|
|
2453 |
|
|
2454 |
explicit NodeMap(const OrienterBase<GR, DM>& adapter)
|
| 2464 |
2455 |
: Parent(*adapter._graph) {}
|
| 2465 |
2456 |
|
| 2466 |
|
NodeMap(const OrienterBase& adapter, const _Value& value)
|
|
2457 |
NodeMap(const OrienterBase<GR, DM>& adapter, const V& value)
|
| 2467 |
2458 |
: Parent(*adapter._graph, value) {}
|
| 2468 |
2459 |
|
| 2469 |
2460 |
private:
|
| 2470 |
2461 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 2471 |
2462 |
return operator=<NodeMap>(cmap);
|
| 2472 |
2463 |
}
|
| 2473 |
2464 |
|
| 2474 |
2465 |
template <typename CMap>
|
| 2475 |
2466 |
NodeMap& operator=(const CMap& cmap) {
|
| 2476 |
2467 |
Parent::operator=(cmap);
|
| 2477 |
2468 |
return *this;
|
| 2478 |
2469 |
}
|
| 2479 |
2470 |
|
| 2480 |
2471 |
};
|
| 2481 |
2472 |
|
| 2482 |
|
template <typename _Value>
|
| 2483 |
|
class ArcMap : public _Graph::template EdgeMap<_Value> {
|
|
2473 |
template <typename V>
|
|
2474 |
class ArcMap : public GR::template EdgeMap<V> {
|
| 2484 |
2475 |
public:
|
| 2485 |
2476 |
|
| 2486 |
|
typedef typename Graph::template EdgeMap<_Value> Parent;
|
| 2487 |
|
|
| 2488 |
|
explicit ArcMap(const OrienterBase& adapter)
|
|
2477 |
typedef typename Graph::template EdgeMap<V> Parent;
|
|
2478 |
|
|
2479 |
explicit ArcMap(const OrienterBase<GR, DM>& adapter)
|
| 2489 |
2480 |
: Parent(*adapter._graph) { }
|
| 2490 |
2481 |
|
| 2491 |
|
ArcMap(const OrienterBase& adapter, const _Value& value)
|
|
2482 |
ArcMap(const OrienterBase<GR, DM>& adapter, const V& value)
|
| 2492 |
2483 |
: Parent(*adapter._graph, value) { }
|
| 2493 |
2484 |
|
| 2494 |
2485 |
private:
|
| 2495 |
2486 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 2496 |
2487 |
return operator=<ArcMap>(cmap);
|
| 2497 |
2488 |
}
|
| 2498 |
2489 |
|
| 2499 |
2490 |
template <typename CMap>
|
| 2500 |
2491 |
ArcMap& operator=(const CMap& cmap) {
|
| 2501 |
2492 |
Parent::operator=(cmap);
|
| 2502 |
2493 |
return *this;
|
| 2503 |
2494 |
}
|
| 2504 |
2495 |
};
|
| 2505 |
2496 |
|
| 2506 |
2497 |
|
| 2507 |
2498 |
|
| 2508 |
2499 |
protected:
|
| 2509 |
2500 |
Graph* _graph;
|
| 2510 |
|
DirectionMap* _direction;
|
| 2511 |
|
|
| 2512 |
|
void setDirectionMap(DirectionMap& direction) {
|
|
2501 |
DM* _direction;
|
|
2502 |
|
|
2503 |
void initialize(GR& graph, DM& direction) {
|
|
2504 |
_graph = &graph;
|
| 2513 |
2505 |
_direction = &direction;
|
| 2514 |
2506 |
}
|
| 2515 |
2507 |
|
| 2516 |
|
void setGraph(Graph& graph) {
|
| 2517 |
|
_graph = &graph;
|
| 2518 |
|
}
|
| 2519 |
|
|
| 2520 |
2508 |
};
|
| 2521 |
2509 |
|
| 2522 |
2510 |
/// \ingroup graph_adaptors
|
| 2523 |
2511 |
///
|
| 2524 |
2512 |
/// \brief Adaptor class for orienting the edges of a graph to get a digraph
|
| 2525 |
2513 |
///
|
| 2526 |
2514 |
/// Orienter adaptor can be used for orienting the edges of a graph to
|
| 2527 |
2515 |
/// get a digraph. A \c bool edge map of the underlying graph must be
|
| 2528 |
2516 |
/// specified, which define the direction of the arcs in the adaptor.
|
| 2529 |
2517 |
/// The arcs can be easily reversed by the \c reverseArc() member function
|
| 2530 |
2518 |
/// of the adaptor.
|
| 2531 |
2519 |
/// This class conforms to the \ref concepts::Digraph "Digraph" concept.
|
| 2532 |
2520 |
///
|
| 2533 |
2521 |
/// The adapted graph can also be modified through this adaptor
|
| 2534 |
2522 |
/// by adding or removing nodes or arcs, unless the \c GR template
|
| 2535 |
2523 |
/// parameter is set to be \c const.
|
| 2536 |
2524 |
///
|
| 2537 |
2525 |
/// \tparam GR The type of the adapted graph.
|
| 2538 |
2526 |
/// It must conform to the \ref concepts::Graph "Graph" concept.
|
| 2539 |
2527 |
/// It can also be specified to be \c const.
|
| 2540 |
2528 |
/// \tparam DM The type of the direction map.
|
| 2541 |
2529 |
/// It must be a \c bool (or convertible) edge map of the
|
| 2542 |
2530 |
/// adapted graph. The default type is
|
| 2543 |
2531 |
/// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>".
|
| 2544 |
2532 |
///
|
| 2545 |
2533 |
/// \note The \c Node type of this adaptor and the adapted graph are
|
| 2546 |
2534 |
/// convertible to each other, moreover the \c Arc type of the adaptor
|
| 2547 |
2535 |
/// and the \c Edge type of the adapted graph are also convertible to
|
| 2548 |
2536 |
/// each other.
|
| 2549 |
2537 |
#ifdef DOXYGEN
|
| 2550 |
2538 |
template<typename GR,
|
| 2551 |
2539 |
typename DM>
|
| 2552 |
2540 |
class Orienter {
|
| 2553 |
2541 |
#else
|
| 2554 |
2542 |
template<typename GR,
|
| 2555 |
2543 |
typename DM = typename GR::template EdgeMap<bool> >
|
| 2556 |
2544 |
class Orienter :
|
| 2557 |
2545 |
public DigraphAdaptorExtender<OrienterBase<GR, DM> > {
|
| 2558 |
2546 |
#endif
|
| 2559 |
2547 |
public:
|
| 2560 |
2548 |
|
| 2561 |
2549 |
/// The type of the adapted graph.
|
| 2562 |
2550 |
typedef GR Graph;
|
| 2563 |
2551 |
/// The type of the direction edge map.
|
| 2564 |
2552 |
typedef DM DirectionMap;
|
| 2565 |
2553 |
|
| 2566 |
2554 |
typedef DigraphAdaptorExtender<OrienterBase<GR, DM> > Parent;
|
| 2567 |
2555 |
typedef typename Parent::Arc Arc;
|
| 2568 |
2556 |
protected:
|
| 2569 |
2557 |
Orienter() { }
|
| 2570 |
2558 |
public:
|
| 2571 |
2559 |
|
| 2572 |
2560 |
/// \brief Constructor
|
| 2573 |
2561 |
///
|
| 2574 |
2562 |
/// Constructor of the adaptor.
|
| 2575 |
|
Orienter(Graph& graph, DirectionMap& direction) {
|
| 2576 |
|
setGraph(graph);
|
| 2577 |
|
setDirectionMap(direction);
|
|
2563 |
Orienter(GR& graph, DM& direction) {
|
|
2564 |
Parent::initialize(graph, direction);
|
| 2578 |
2565 |
}
|
| 2579 |
2566 |
|
| 2580 |
2567 |
/// \brief Reverses the given arc
|
| 2581 |
2568 |
///
|
| 2582 |
2569 |
/// This function reverses the given arc.
|
| 2583 |
2570 |
/// It is done by simply negate the assigned value of \c a
|
| 2584 |
2571 |
/// in the direction map.
|
| 2585 |
2572 |
void reverseArc(const Arc& a) {
|
| 2586 |
2573 |
Parent::reverseArc(a);
|
| 2587 |
2574 |
}
|
| 2588 |
2575 |
};
|
| 2589 |
2576 |
|
| 2590 |
2577 |
/// \brief Returns a read-only Orienter adaptor
|
| 2591 |
2578 |
///
|
| 2592 |
2579 |
/// This function just returns a read-only \ref Orienter adaptor.
|
| 2593 |
2580 |
/// \ingroup graph_adaptors
|
| 2594 |
2581 |
/// \relates Orienter
|
| 2595 |
2582 |
template<typename GR, typename DM>
|
| 2596 |
2583 |
Orienter<const GR, DM>
|
| 2597 |
|
orienter(const GR& graph, DM& direction_map) {
|
| 2598 |
|
return Orienter<const GR, DM>(graph, direction_map);
|
|
2584 |
orienter(const GR& graph, DM& direction) {
|
|
2585 |
return Orienter<const GR, DM>(graph, direction);
|
| 2599 |
2586 |
}
|
| 2600 |
2587 |
|
| 2601 |
2588 |
template<typename GR, typename DM>
|
| 2602 |
2589 |
Orienter<const GR, const DM>
|
| 2603 |
|
orienter(const GR& graph, const DM& direction_map) {
|
| 2604 |
|
return Orienter<const GR, const DM>(graph, direction_map);
|
|
2590 |
orienter(const GR& graph, const DM& direction) {
|
|
2591 |
return Orienter<const GR, const DM>(graph, direction);
|
| 2605 |
2592 |
}
|
| 2606 |
2593 |
|
| 2607 |
2594 |
namespace _adaptor_bits {
|
| 2608 |
2595 |
|
| 2609 |
|
template<typename Digraph,
|
| 2610 |
|
typename CapacityMap,
|
| 2611 |
|
typename FlowMap,
|
| 2612 |
|
typename Tolerance>
|
|
2596 |
template <typename DGR, typename CM, typename FM, typename TL>
|
| 2613 |
2597 |
class ResForwardFilter {
|
| 2614 |
2598 |
public:
|
| 2615 |
2599 |
|
| 2616 |
|
typedef typename Digraph::Arc Key;
|
|
2600 |
typedef typename DGR::Arc Key;
|
| 2617 |
2601 |
typedef bool Value;
|
| 2618 |
2602 |
|
| 2619 |
2603 |
private:
|
| 2620 |
2604 |
|
| 2621 |
|
const CapacityMap* _capacity;
|
| 2622 |
|
const FlowMap* _flow;
|
| 2623 |
|
Tolerance _tolerance;
|
|
2605 |
const CM* _capacity;
|
|
2606 |
const FM* _flow;
|
|
2607 |
TL _tolerance;
|
|
2608 |
|
| 2624 |
2609 |
public:
|
| 2625 |
2610 |
|
| 2626 |
|
ResForwardFilter(const CapacityMap& capacity, const FlowMap& flow,
|
| 2627 |
|
const Tolerance& tolerance = Tolerance())
|
|
2611 |
ResForwardFilter(const CM& capacity, const FM& flow,
|
|
2612 |
const TL& tolerance = TL())
|
| 2628 |
2613 |
: _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
|
| 2629 |
2614 |
|
| 2630 |
|
bool operator[](const typename Digraph::Arc& a) const {
|
|
2615 |
bool operator[](const typename DGR::Arc& a) const {
|
| 2631 |
2616 |
return _tolerance.positive((*_capacity)[a] - (*_flow)[a]);
|
| 2632 |
2617 |
}
|
| 2633 |
2618 |
};
|
| 2634 |
2619 |
|
| 2635 |
|
template<typename Digraph,
|
| 2636 |
|
typename CapacityMap,
|
| 2637 |
|
typename FlowMap,
|
| 2638 |
|
typename Tolerance>
|
|
2620 |
template<typename DGR,typename CM, typename FM, typename TL>
|
| 2639 |
2621 |
class ResBackwardFilter {
|
| 2640 |
2622 |
public:
|
| 2641 |
2623 |
|
| 2642 |
|
typedef typename Digraph::Arc Key;
|
|
2624 |
typedef typename DGR::Arc Key;
|
| 2643 |
2625 |
typedef bool Value;
|
| 2644 |
2626 |
|
| 2645 |
2627 |
private:
|
| 2646 |
2628 |
|
| 2647 |
|
const CapacityMap* _capacity;
|
| 2648 |
|
const FlowMap* _flow;
|
| 2649 |
|
Tolerance _tolerance;
|
|
2629 |
const CM* _capacity;
|
|
2630 |
const FM* _flow;
|
|
2631 |
TL _tolerance;
|
| 2650 |
2632 |
|
| 2651 |
2633 |
public:
|
| 2652 |
2634 |
|
| 2653 |
|
ResBackwardFilter(const CapacityMap& capacity, const FlowMap& flow,
|
| 2654 |
|
const Tolerance& tolerance = Tolerance())
|
|
2635 |
ResBackwardFilter(const CM& capacity, const FM& flow,
|
|
2636 |
const TL& tolerance = TL())
|
| 2655 |
2637 |
: _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
|
| 2656 |
2638 |
|
| 2657 |
|
bool operator[](const typename Digraph::Arc& a) const {
|
|
2639 |
bool operator[](const typename DGR::Arc& a) const {
|
| 2658 |
2640 |
return _tolerance.positive((*_flow)[a]);
|
| 2659 |
2641 |
}
|
| 2660 |
2642 |
};
|
| 2661 |
2643 |
|
| 2662 |
2644 |
}
|
| 2663 |
2645 |
|
| 2664 |
2646 |
/// \ingroup graph_adaptors
|
| 2665 |
2647 |
///
|
| 2666 |
2648 |
/// \brief Adaptor class for composing the residual digraph for directed
|
| 2667 |
2649 |
/// flow and circulation problems.
|
| 2668 |
2650 |
///
|
| 2669 |
2651 |
/// ResidualDigraph can be used for composing the \e residual digraph
|
| 2670 |
2652 |
/// for directed flow and circulation problems. Let \f$ G=(V, A) \f$
|
| 2671 |
2653 |
/// be a directed graph and let \f$ F \f$ be a number type.
|
| 2672 |
2654 |
/// Let \f$ flow, cap: A\to F \f$ be functions on the arcs.
|
| 2673 |
2655 |
/// This adaptor implements a digraph structure with node set \f$ V \f$
|
| 2674 |
2656 |
/// and arc set \f$ A_{forward}\cup A_{backward} \f$,
|
| 2675 |
2657 |
/// where \f$ A_{forward}=\{uv : uv\in A, flow(uv)<cap(uv)\} \f$ and
|
| 2676 |
2658 |
/// \f$ A_{backward}=\{vu : uv\in A, flow(uv)>0\} \f$, i.e. the so
|
| 2677 |
2659 |
/// called residual digraph.
|
| 2678 |
2660 |
/// When the union \f$ A_{forward}\cup A_{backward} \f$ is taken,
|
| 2679 |
2661 |
/// multiplicities are counted, i.e. the adaptor has exactly
|
| 2680 |
2662 |
/// \f$ |A_{forward}| + |A_{backward}|\f$ arcs (it may have parallel
|
| 2681 |
2663 |
/// arcs).
|
| 2682 |
2664 |
/// This class conforms to the \ref concepts::Digraph "Digraph" concept.
|
| 2683 |
2665 |
///
|
| 2684 |
|
/// \tparam GR The type of the adapted digraph.
|
|
2666 |
/// \tparam DGR The type of the adapted digraph.
|
| 2685 |
2667 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept.
|
| 2686 |
2668 |
/// It is implicitly \c const.
|
| 2687 |
2669 |
/// \tparam CM The type of the capacity map.
|
| 2688 |
2670 |
/// It must be an arc map of some numerical type, which defines
|
| 2689 |
2671 |
/// the capacities in the flow problem. It is implicitly \c const.
|
| 2690 |
2672 |
/// The default type is
|
| 2691 |
2673 |
/// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
|
| 2692 |
2674 |
/// \tparam FM The type of the flow map.
|
| 2693 |
2675 |
/// It must be an arc map of some numerical type, which defines
|
| 2694 |
2676 |
/// the flow values in the flow problem. The default type is \c CM.
|
| 2695 |
2677 |
/// \tparam TL The tolerance type for handling inexact computation.
|
| 2696 |
2678 |
/// The default tolerance type depends on the value type of the
|
| 2697 |
2679 |
/// capacity map.
|
| 2698 |
2680 |
///
|
| 2699 |
2681 |
/// \note This adaptor is implemented using Undirector and FilterArcs
|
| 2700 |
2682 |
/// adaptors.
|
| 2701 |
2683 |
///
|
| 2702 |
2684 |
/// \note The \c Node type of this adaptor and the adapted digraph are
|
| 2703 |
2685 |
/// convertible to each other, moreover the \c Arc type of the adaptor
|
| 2704 |
2686 |
/// is convertible to the \c Arc type of the adapted digraph.
|
| 2705 |
2687 |
#ifdef DOXYGEN
|
| 2706 |
|
template<typename GR, typename CM, typename FM, typename TL>
|
|
2688 |
template<typename DGR, typename CM, typename FM, typename TL>
|
| 2707 |
2689 |
class ResidualDigraph
|
| 2708 |
2690 |
#else
|
| 2709 |
|
template<typename GR,
|
| 2710 |
|
typename CM = typename GR::template ArcMap<int>,
|
|
2691 |
template<typename DGR,
|
|
2692 |
typename CM = typename DGR::template ArcMap<int>,
|
| 2711 |
2693 |
typename FM = CM,
|
| 2712 |
2694 |
typename TL = Tolerance<typename CM::Value> >
|
| 2713 |
|
class ResidualDigraph :
|
| 2714 |
|
public FilterArcs<
|
| 2715 |
|
Undirector<const GR>,
|
| 2716 |
|
typename Undirector<const GR>::template CombinedArcMap<
|
| 2717 |
|
_adaptor_bits::ResForwardFilter<const GR, CM, FM, TL>,
|
| 2718 |
|
_adaptor_bits::ResBackwardFilter<const GR, CM, FM, TL> > >
|
|
2695 |
class ResidualDigraph
|
|
2696 |
: public SubDigraph<
|
|
2697 |
Undirector<const DGR>,
|
|
2698 |
ConstMap<typename DGR::Node, Const<bool, true> >,
|
|
2699 |
typename Undirector<const DGR>::template CombinedArcMap<
|
|
2700 |
_adaptor_bits::ResForwardFilter<const DGR, CM, FM, TL>,
|
|
2701 |
_adaptor_bits::ResBackwardFilter<const DGR, CM, FM, TL> > >
|
| 2719 |
2702 |
#endif
|
| 2720 |
2703 |
{
|
| 2721 |
2704 |
public:
|
| 2722 |
2705 |
|
| 2723 |
2706 |
/// The type of the underlying digraph.
|
| 2724 |
|
typedef GR Digraph;
|
|
2707 |
typedef DGR Digraph;
|
| 2725 |
2708 |
/// The type of the capacity map.
|
| 2726 |
2709 |
typedef CM CapacityMap;
|
| 2727 |
2710 |
/// The type of the flow map.
|
| 2728 |
2711 |
typedef FM FlowMap;
|
| 2729 |
2712 |
/// The tolerance type.
|
| 2730 |
2713 |
typedef TL Tolerance;
|
| 2731 |
2714 |
|
| 2732 |
2715 |
typedef typename CapacityMap::Value Value;
|
| 2733 |
2716 |
typedef ResidualDigraph Adaptor;
|
| 2734 |
2717 |
|
| 2735 |
2718 |
protected:
|
| 2736 |
2719 |
|
| 2737 |
2720 |
typedef Undirector<const Digraph> Undirected;
|
| 2738 |
2721 |
|
| 2739 |
|
typedef _adaptor_bits::ResForwardFilter<const Digraph, CapacityMap,
|
| 2740 |
|
FlowMap, Tolerance> ForwardFilter;
|
| 2741 |
|
|
| 2742 |
|
typedef _adaptor_bits::ResBackwardFilter<const Digraph, CapacityMap,
|
| 2743 |
|
FlowMap, Tolerance> BackwardFilter;
|
|
2722 |
typedef ConstMap<typename DGR::Node, Const<bool, true> > NodeFilter;
|
|
2723 |
|
|
2724 |
typedef _adaptor_bits::ResForwardFilter<const DGR, CM,
|
|
2725 |
FM, TL> ForwardFilter;
|
|
2726 |
|
|
2727 |
typedef _adaptor_bits::ResBackwardFilter<const DGR, CM,
|
|
2728 |
FM, TL> BackwardFilter;
|
| 2744 |
2729 |
|
| 2745 |
2730 |
typedef typename Undirected::
|
| 2746 |
2731 |
template CombinedArcMap<ForwardFilter, BackwardFilter> ArcFilter;
|
| 2747 |
2732 |
|
| 2748 |
|
typedef FilterArcs<Undirected, ArcFilter> Parent;
|
|
2733 |
typedef SubDigraph<Undirected, NodeFilter, ArcFilter> Parent;
|
| 2749 |
2734 |
|
| 2750 |
2735 |
const CapacityMap* _capacity;
|
| 2751 |
2736 |
FlowMap* _flow;
|
| 2752 |
2737 |
|
| 2753 |
2738 |
Undirected _graph;
|
|
2739 |
NodeFilter _node_filter;
|
| 2754 |
2740 |
ForwardFilter _forward_filter;
|
| 2755 |
2741 |
BackwardFilter _backward_filter;
|
| 2756 |
2742 |
ArcFilter _arc_filter;
|
| 2757 |
2743 |
|
| 2758 |
2744 |
public:
|
| 2759 |
2745 |
|
| 2760 |
2746 |
/// \brief Constructor
|
| 2761 |
2747 |
///
|
| 2762 |
2748 |
/// Constructor of the residual digraph adaptor. The parameters are the
|
| 2763 |
2749 |
/// digraph, the capacity map, the flow map, and a tolerance object.
|
| 2764 |
|
ResidualDigraph(const Digraph& digraph, const CapacityMap& capacity,
|
| 2765 |
|
FlowMap& flow, const Tolerance& tolerance = Tolerance())
|
| 2766 |
|
: Parent(), _capacity(&capacity), _flow(&flow), _graph(digraph),
|
|
2750 |
ResidualDigraph(const DGR& digraph, const CM& capacity,
|
|
2751 |
FM& flow, const TL& tolerance = Tolerance())
|
|
2752 |
: Parent(), _capacity(&capacity), _flow(&flow),
|
|
2753 |
_graph(digraph), _node_filter(),
|
| 2767 |
2754 |
_forward_filter(capacity, flow, tolerance),
|
| 2768 |
2755 |
_backward_filter(capacity, flow, tolerance),
|
| 2769 |
2756 |
_arc_filter(_forward_filter, _backward_filter)
|
| 2770 |
2757 |
{
|
| 2771 |
|
Parent::setDigraph(_graph);
|
| 2772 |
|
Parent::setArcFilterMap(_arc_filter);
|
|
2758 |
Parent::initialize(_graph, _node_filter, _arc_filter);
|
| 2773 |
2759 |
}
|
| 2774 |
2760 |
|
| 2775 |
2761 |
typedef typename Parent::Arc Arc;
|
| 2776 |
2762 |
|
| 2777 |
2763 |
/// \brief Returns the residual capacity of the given arc.
|
| 2778 |
2764 |
///
|
| 2779 |
2765 |
/// Returns the residual capacity of the given arc.
|
| 2780 |
2766 |
Value residualCapacity(const Arc& a) const {
|
| 2781 |
2767 |
if (Undirected::direction(a)) {
|
| 2782 |
2768 |
return (*_capacity)[a] - (*_flow)[a];
|
| 2783 |
2769 |
} else {
|
| 2784 |
2770 |
return (*_flow)[a];
|
| 2785 |
2771 |
}
|
| 2786 |
2772 |
}
|
| 2787 |
2773 |
|
| 2788 |
2774 |
/// \brief Augments on the given arc in the residual digraph.
|
| 2789 |
2775 |
///
|
| 2790 |
2776 |
/// Augments on the given arc in the residual digraph. It increases
|
| 2791 |
2777 |
/// or decreases the flow value on the original arc according to the
|
| 2792 |
2778 |
/// direction of the residual arc.
|
| 2793 |
2779 |
void augment(const Arc& a, const Value& v) const {
|
| 2794 |
2780 |
if (Undirected::direction(a)) {
|
| 2795 |
2781 |
_flow->set(a, (*_flow)[a] + v);
|
| 2796 |
2782 |
} else {
|
| 2797 |
2783 |
_flow->set(a, (*_flow)[a] - v);
|
| 2798 |
2784 |
}
|
| 2799 |
2785 |
}
|
| 2800 |
2786 |
|
| 2801 |
2787 |
/// \brief Returns \c true if the given residual arc is a forward arc.
|
| 2802 |
2788 |
///
|
| 2803 |
2789 |
/// Returns \c true if the given residual arc has the same orientation
|
| 2804 |
2790 |
/// as the original arc, i.e. it is a so called forward arc.
|
| 2805 |
2791 |
static bool forward(const Arc& a) {
|
| 2806 |
2792 |
return Undirected::direction(a);
|
| 2807 |
2793 |
}
|
| 2808 |
2794 |
|
| 2809 |
2795 |
/// \brief Returns \c true if the given residual arc is a backward arc.
|
| 2810 |
2796 |
///
|
| 2811 |
2797 |
/// Returns \c true if the given residual arc has the opposite orientation
|
| 2812 |
2798 |
/// than the original arc, i.e. it is a so called backward arc.
|
| 2813 |
2799 |
static bool backward(const Arc& a) {
|
| 2814 |
2800 |
return !Undirected::direction(a);
|
| 2815 |
2801 |
}
|
| 2816 |
2802 |
|
| 2817 |
2803 |
/// \brief Returns the forward oriented residual arc.
|
| 2818 |
2804 |
///
|
| 2819 |
2805 |
/// Returns the forward oriented residual arc related to the given
|
| 2820 |
2806 |
/// arc of the underlying digraph.
|
| 2821 |
2807 |
static Arc forward(const typename Digraph::Arc& a) {
|
| 2822 |
2808 |
return Undirected::direct(a, true);
|
| 2823 |
2809 |
}
|
| 2824 |
2810 |
|
| 2825 |
2811 |
/// \brief Returns the backward oriented residual arc.
|
| 2826 |
2812 |
///
|
| 2827 |
2813 |
/// Returns the backward oriented residual arc related to the given
|
| 2828 |
2814 |
/// arc of the underlying digraph.
|
| 2829 |
2815 |
static Arc backward(const typename Digraph::Arc& a) {
|
| 2830 |
2816 |
return Undirected::direct(a, false);
|
| 2831 |
2817 |
}
|
| 2832 |
2818 |
|
| 2833 |
2819 |
/// \brief Residual capacity map.
|
| 2834 |
2820 |
///
|
| 2835 |
2821 |
/// This map adaptor class can be used for obtaining the residual
|
| 2836 |
2822 |
/// capacities as an arc map of the residual digraph.
|
| 2837 |
2823 |
/// Its value type is inherited from the capacity map.
|
| 2838 |
2824 |
class ResidualCapacity {
|
| 2839 |
2825 |
protected:
|
| 2840 |
2826 |
const Adaptor* _adaptor;
|
| 2841 |
2827 |
public:
|
| 2842 |
2828 |
/// The key type of the map
|
| 2843 |
2829 |
typedef Arc Key;
|
| 2844 |
2830 |
/// The value type of the map
|
| 2845 |
2831 |
typedef typename CapacityMap::Value Value;
|
| 2846 |
2832 |
|
| 2847 |
2833 |
/// Constructor
|
| 2848 |
|
ResidualCapacity(const Adaptor& adaptor) : _adaptor(&adaptor) {}
|
|
2834 |
ResidualCapacity(const ResidualDigraph<DGR, CM, FM, TL>& adaptor)
|
|
2835 |
: _adaptor(&adaptor) {}
|
| 2849 |
2836 |
|
| 2850 |
2837 |
/// Returns the value associated with the given residual arc
|
| 2851 |
2838 |
Value operator[](const Arc& a) const {
|
| 2852 |
2839 |
return _adaptor->residualCapacity(a);
|
| 2853 |
2840 |
}
|
| 2854 |
2841 |
|
| 2855 |
2842 |
};
|
| 2856 |
2843 |
|
| 2857 |
2844 |
/// \brief Returns a residual capacity map
|
| 2858 |
2845 |
///
|
| 2859 |
2846 |
/// This function just returns a residual capacity map.
|
| 2860 |
2847 |
ResidualCapacity residualCapacity() const {
|
| 2861 |
2848 |
return ResidualCapacity(*this);
|
| 2862 |
2849 |
}
|
| 2863 |
2850 |
|
| 2864 |
2851 |
};
|
| 2865 |
2852 |
|
| 2866 |
2853 |
/// \brief Returns a (read-only) Residual adaptor
|
| 2867 |
2854 |
///
|
| 2868 |
|
/// This function just returns a (read-only) \ref Residual adaptor.
|
|
2855 |
/// This function just returns a (read-only) \ref ResidualDigraph adaptor.
|
| 2869 |
2856 |
/// \ingroup graph_adaptors
|
| 2870 |
|
/// \relates Residual
|
| 2871 |
|
template<typename GR, typename CM, typename FM>
|
| 2872 |
|
ResidualDigraph<GR, CM, FM>
|
| 2873 |
|
residualDigraph(const GR& digraph, const CM& capacity_map, FM& flow_map) {
|
| 2874 |
|
return ResidualDigraph<GR, CM, FM> (digraph, capacity_map, flow_map);
|
|
2857 |
/// \relates ResidualDigraph
|
|
2858 |
template<typename DGR, typename CM, typename FM>
|
|
2859 |
ResidualDigraph<DGR, CM, FM>
|
|
2860 |
residualDigraph(const DGR& digraph, const CM& capacity_map, FM& flow_map) {
|
|
2861 |
return ResidualDigraph<DGR, CM, FM> (digraph, capacity_map, flow_map);
|
| 2875 |
2862 |
}
|
| 2876 |
2863 |
|
| 2877 |
2864 |
|
| 2878 |
|
template <typename _Digraph>
|
|
2865 |
template <typename DGR>
|
| 2879 |
2866 |
class SplitNodesBase {
|
| 2880 |
2867 |
public:
|
| 2881 |
2868 |
|
| 2882 |
|
typedef _Digraph Digraph;
|
| 2883 |
|
typedef DigraphAdaptorBase<const _Digraph> Parent;
|
|
2869 |
typedef DGR Digraph;
|
|
2870 |
typedef DigraphAdaptorBase<const DGR> Parent;
|
| 2884 |
2871 |
typedef SplitNodesBase Adaptor;
|
| 2885 |
2872 |
|
| 2886 |
|
typedef typename Digraph::Node DigraphNode;
|
| 2887 |
|
typedef typename Digraph::Arc DigraphArc;
|
|
2873 |
typedef typename DGR::Node DigraphNode;
|
|
2874 |
typedef typename DGR::Arc DigraphArc;
|
| 2888 |
2875 |
|
| 2889 |
2876 |
class Node;
|
| 2890 |
2877 |
class Arc;
|
| 2891 |
2878 |
|
| 2892 |
2879 |
private:
|
| 2893 |
2880 |
|
| 2894 |
2881 |
template <typename T> class NodeMapBase;
|
| 2895 |
2882 |
template <typename T> class ArcMapBase;
|
| 2896 |
2883 |
|
| 2897 |
2884 |
public:
|
| 2898 |
2885 |
|
| 2899 |
2886 |
class Node : public DigraphNode {
|
| 2900 |
2887 |
friend class SplitNodesBase;
|
| 2901 |
2888 |
template <typename T> friend class NodeMapBase;
|
| 2902 |
2889 |
private:
|
| 2903 |
2890 |
|
| 2904 |
2891 |
bool _in;
|
| 2905 |
2892 |
Node(DigraphNode node, bool in)
|
| 2906 |
2893 |
: DigraphNode(node), _in(in) {}
|
| 2907 |
2894 |
|
| 2908 |
2895 |
public:
|
| 2909 |
2896 |
|
| 2910 |
2897 |
Node() {}
|
| 2911 |
2898 |
Node(Invalid) : DigraphNode(INVALID), _in(true) {}
|
| 2912 |
2899 |
|
| 2913 |
2900 |
bool operator==(const Node& node) const {
|
| 2914 |
2901 |
return DigraphNode::operator==(node) && _in == node._in;
|
| 2915 |
2902 |
}
|
| 2916 |
2903 |
|
| 2917 |
2904 |
bool operator!=(const Node& node) const {
|
| 2918 |
2905 |
return !(*this == node);
|
| 2919 |
2906 |
}
|
| 2920 |
2907 |
|
| 2921 |
2908 |
bool operator<(const Node& node) const {
|
| 2922 |
2909 |
return DigraphNode::operator<(node) ||
|
| 2923 |
2910 |
(DigraphNode::operator==(node) && _in < node._in);
|
| 2924 |
2911 |
}
|
| 2925 |
2912 |
};
|
| 2926 |
2913 |
|
| 2927 |
2914 |
class Arc {
|
| 2928 |
2915 |
friend class SplitNodesBase;
|
| 2929 |
2916 |
template <typename T> friend class ArcMapBase;
|
| 2930 |
2917 |
private:
|
| 2931 |
2918 |
typedef BiVariant<DigraphArc, DigraphNode> ArcImpl;
|
| 2932 |
2919 |
|
| 2933 |
2920 |
explicit Arc(const DigraphArc& arc) : _item(arc) {}
|
| 2934 |
2921 |
explicit Arc(const DigraphNode& node) : _item(node) {}
|
| 2935 |
2922 |
|
| ... |
... |
@@ -3103,503 +3090,505 @@
|
| 3103 |
3090 |
|
| 3104 |
3091 |
static bool bindArc(const Arc& e) {
|
| 3105 |
3092 |
return e._item.secondState();
|
| 3106 |
3093 |
}
|
| 3107 |
3094 |
|
| 3108 |
3095 |
static Node inNode(const DigraphNode& n) {
|
| 3109 |
3096 |
return Node(n, true);
|
| 3110 |
3097 |
}
|
| 3111 |
3098 |
|
| 3112 |
3099 |
static Node outNode(const DigraphNode& n) {
|
| 3113 |
3100 |
return Node(n, false);
|
| 3114 |
3101 |
}
|
| 3115 |
3102 |
|
| 3116 |
3103 |
static Arc arc(const DigraphNode& n) {
|
| 3117 |
3104 |
return Arc(n);
|
| 3118 |
3105 |
}
|
| 3119 |
3106 |
|
| 3120 |
3107 |
static Arc arc(const DigraphArc& e) {
|
| 3121 |
3108 |
return Arc(e);
|
| 3122 |
3109 |
}
|
| 3123 |
3110 |
|
| 3124 |
3111 |
typedef True NodeNumTag;
|
| 3125 |
3112 |
int nodeNum() const {
|
| 3126 |
3113 |
return 2 * countNodes(*_digraph);
|
| 3127 |
3114 |
}
|
| 3128 |
3115 |
|
| 3129 |
3116 |
typedef True ArcNumTag;
|
| 3130 |
3117 |
int arcNum() const {
|
| 3131 |
3118 |
return countArcs(*_digraph) + countNodes(*_digraph);
|
| 3132 |
3119 |
}
|
| 3133 |
3120 |
|
| 3134 |
3121 |
typedef True FindArcTag;
|
| 3135 |
3122 |
Arc findArc(const Node& u, const Node& v,
|
| 3136 |
3123 |
const Arc& prev = INVALID) const {
|
| 3137 |
3124 |
if (inNode(u) && outNode(v)) {
|
| 3138 |
3125 |
if (static_cast<const DigraphNode&>(u) ==
|
| 3139 |
3126 |
static_cast<const DigraphNode&>(v) && prev == INVALID) {
|
| 3140 |
3127 |
return Arc(u);
|
| 3141 |
3128 |
}
|
| 3142 |
3129 |
}
|
| 3143 |
3130 |
else if (outNode(u) && inNode(v)) {
|
| 3144 |
3131 |
return Arc(::lemon::findArc(*_digraph, u, v, prev));
|
| 3145 |
3132 |
}
|
| 3146 |
3133 |
return INVALID;
|
| 3147 |
3134 |
}
|
| 3148 |
3135 |
|
| 3149 |
3136 |
private:
|
| 3150 |
3137 |
|
| 3151 |
|
template <typename _Value>
|
|
3138 |
template <typename V>
|
| 3152 |
3139 |
class NodeMapBase
|
| 3153 |
|
: public MapTraits<typename Parent::template NodeMap<_Value> > {
|
| 3154 |
|
typedef typename Parent::template NodeMap<_Value> NodeImpl;
|
|
3140 |
: public MapTraits<typename Parent::template NodeMap<V> > {
|
|
3141 |
typedef typename Parent::template NodeMap<V> NodeImpl;
|
| 3155 |
3142 |
public:
|
| 3156 |
3143 |
typedef Node Key;
|
| 3157 |
|
typedef _Value Value;
|
|
3144 |
typedef V Value;
|
| 3158 |
3145 |
typedef typename MapTraits<NodeImpl>::ReferenceMapTag ReferenceMapTag;
|
| 3159 |
3146 |
typedef typename MapTraits<NodeImpl>::ReturnValue ReturnValue;
|
| 3160 |
3147 |
typedef typename MapTraits<NodeImpl>::ConstReturnValue ConstReturnValue;
|
| 3161 |
3148 |
typedef typename MapTraits<NodeImpl>::ReturnValue Reference;
|
| 3162 |
3149 |
typedef typename MapTraits<NodeImpl>::ConstReturnValue ConstReference;
|
| 3163 |
3150 |
|
| 3164 |
|
NodeMapBase(const Adaptor& adaptor)
|
|
3151 |
NodeMapBase(const SplitNodesBase<DGR>& adaptor)
|
| 3165 |
3152 |
: _in_map(*adaptor._digraph), _out_map(*adaptor._digraph) {}
|
| 3166 |
|
NodeMapBase(const Adaptor& adaptor, const Value& value)
|
|
3153 |
NodeMapBase(const SplitNodesBase<DGR>& adaptor, const V& value)
|
| 3167 |
3154 |
: _in_map(*adaptor._digraph, value),
|
| 3168 |
3155 |
_out_map(*adaptor._digraph, value) {}
|
| 3169 |
3156 |
|
| 3170 |
|
void set(const Node& key, const Value& val) {
|
| 3171 |
|
if (Adaptor::inNode(key)) { _in_map.set(key, val); }
|
|
3157 |
void set(const Node& key, const V& val) {
|
|
3158 |
if (SplitNodesBase<DGR>::inNode(key)) { _in_map.set(key, val); }
|
| 3172 |
3159 |
else {_out_map.set(key, val); }
|
| 3173 |
3160 |
}
|
| 3174 |
3161 |
|
| 3175 |
3162 |
ReturnValue operator[](const Node& key) {
|
| 3176 |
|
if (Adaptor::inNode(key)) { return _in_map[key]; }
|
|
3163 |
if (SplitNodesBase<DGR>::inNode(key)) { return _in_map[key]; }
|
| 3177 |
3164 |
else { return _out_map[key]; }
|
| 3178 |
3165 |
}
|
| 3179 |
3166 |
|
| 3180 |
3167 |
ConstReturnValue operator[](const Node& key) const {
|
| 3181 |
3168 |
if (Adaptor::inNode(key)) { return _in_map[key]; }
|
| 3182 |
3169 |
else { return _out_map[key]; }
|
| 3183 |
3170 |
}
|
| 3184 |
3171 |
|
| 3185 |
3172 |
private:
|
| 3186 |
3173 |
NodeImpl _in_map, _out_map;
|
| 3187 |
3174 |
};
|
| 3188 |
3175 |
|
| 3189 |
|
template <typename _Value>
|
|
3176 |
template <typename V>
|
| 3190 |
3177 |
class ArcMapBase
|
| 3191 |
|
: public MapTraits<typename Parent::template ArcMap<_Value> > {
|
| 3192 |
|
typedef typename Parent::template ArcMap<_Value> ArcImpl;
|
| 3193 |
|
typedef typename Parent::template NodeMap<_Value> NodeImpl;
|
|
3178 |
: public MapTraits<typename Parent::template ArcMap<V> > {
|
|
3179 |
typedef typename Parent::template ArcMap<V> ArcImpl;
|
|
3180 |
typedef typename Parent::template NodeMap<V> NodeImpl;
|
| 3194 |
3181 |
public:
|
| 3195 |
3182 |
typedef Arc Key;
|
| 3196 |
|
typedef _Value Value;
|
|
3183 |
typedef V Value;
|
| 3197 |
3184 |
typedef typename MapTraits<ArcImpl>::ReferenceMapTag ReferenceMapTag;
|
| 3198 |
3185 |
typedef typename MapTraits<ArcImpl>::ReturnValue ReturnValue;
|
| 3199 |
3186 |
typedef typename MapTraits<ArcImpl>::ConstReturnValue ConstReturnValue;
|
| 3200 |
3187 |
typedef typename MapTraits<ArcImpl>::ReturnValue Reference;
|
| 3201 |
3188 |
typedef typename MapTraits<ArcImpl>::ConstReturnValue ConstReference;
|
| 3202 |
3189 |
|
| 3203 |
|
ArcMapBase(const Adaptor& adaptor)
|
|
3190 |
ArcMapBase(const SplitNodesBase<DGR>& adaptor)
|
| 3204 |
3191 |
: _arc_map(*adaptor._digraph), _node_map(*adaptor._digraph) {}
|
| 3205 |
|
ArcMapBase(const Adaptor& adaptor, const Value& value)
|
|
3192 |
ArcMapBase(const SplitNodesBase<DGR>& adaptor, const V& value)
|
| 3206 |
3193 |
: _arc_map(*adaptor._digraph, value),
|
| 3207 |
3194 |
_node_map(*adaptor._digraph, value) {}
|
| 3208 |
3195 |
|
| 3209 |
|
void set(const Arc& key, const Value& val) {
|
| 3210 |
|
if (Adaptor::origArc(key)) {
|
|
3196 |
void set(const Arc& key, const V& val) {
|
|
3197 |
if (SplitNodesBase<DGR>::origArc(key)) {
|
| 3211 |
3198 |
_arc_map.set(key._item.first(), val);
|
| 3212 |
3199 |
} else {
|
| 3213 |
3200 |
_node_map.set(key._item.second(), val);
|
| 3214 |
3201 |
}
|
| 3215 |
3202 |
}
|
| 3216 |
3203 |
|
| 3217 |
3204 |
ReturnValue operator[](const Arc& key) {
|
| 3218 |
|
if (Adaptor::origArc(key)) {
|
|
3205 |
if (SplitNodesBase<DGR>::origArc(key)) {
|
| 3219 |
3206 |
return _arc_map[key._item.first()];
|
| 3220 |
3207 |
} else {
|
| 3221 |
3208 |
return _node_map[key._item.second()];
|
| 3222 |
3209 |
}
|
| 3223 |
3210 |
}
|
| 3224 |
3211 |
|
| 3225 |
3212 |
ConstReturnValue operator[](const Arc& key) const {
|
| 3226 |
|
if (Adaptor::origArc(key)) {
|
|
3213 |
if (SplitNodesBase<DGR>::origArc(key)) {
|
| 3227 |
3214 |
return _arc_map[key._item.first()];
|
| 3228 |
3215 |
} else {
|
| 3229 |
3216 |
return _node_map[key._item.second()];
|
| 3230 |
3217 |
}
|
| 3231 |
3218 |
}
|
| 3232 |
3219 |
|
| 3233 |
3220 |
private:
|
| 3234 |
3221 |
ArcImpl _arc_map;
|
| 3235 |
3222 |
NodeImpl _node_map;
|
| 3236 |
3223 |
};
|
| 3237 |
3224 |
|
| 3238 |
3225 |
public:
|
| 3239 |
3226 |
|
| 3240 |
|
template <typename _Value>
|
|
3227 |
template <typename V>
|
| 3241 |
3228 |
class NodeMap
|
| 3242 |
|
: public SubMapExtender<Adaptor, NodeMapBase<_Value> >
|
|
3229 |
: public SubMapExtender<SplitNodesBase<DGR>, NodeMapBase<V> >
|
| 3243 |
3230 |
{
|
| 3244 |
3231 |
public:
|
| 3245 |
|
typedef _Value Value;
|
| 3246 |
|
typedef SubMapExtender<Adaptor, NodeMapBase<Value> > Parent;
|
| 3247 |
|
|
| 3248 |
|
NodeMap(const Adaptor& adaptor)
|
|
3232 |
typedef V Value;
|
|
3233 |
typedef SubMapExtender<SplitNodesBase<DGR>, NodeMapBase<Value> > Parent;
|
|
3234 |
|
|
3235 |
NodeMap(const SplitNodesBase<DGR>& adaptor)
|
| 3249 |
3236 |
: Parent(adaptor) {}
|
| 3250 |
3237 |
|
| 3251 |
|
NodeMap(const Adaptor& adaptor, const Value& value)
|
|
3238 |
NodeMap(const SplitNodesBase<DGR>& adaptor, const V& value)
|
| 3252 |
3239 |
: Parent(adaptor, value) {}
|
| 3253 |
3240 |
|
| 3254 |
3241 |
private:
|
| 3255 |
3242 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 3256 |
3243 |
return operator=<NodeMap>(cmap);
|
| 3257 |
3244 |
}
|
| 3258 |
3245 |
|
| 3259 |
3246 |
template <typename CMap>
|
| 3260 |
3247 |
NodeMap& operator=(const CMap& cmap) {
|
| 3261 |
3248 |
Parent::operator=(cmap);
|
| 3262 |
3249 |
return *this;
|
| 3263 |
3250 |
}
|
| 3264 |
3251 |
};
|
| 3265 |
3252 |
|
| 3266 |
|
template <typename _Value>
|
|
3253 |
template <typename V>
|
| 3267 |
3254 |
class ArcMap
|
| 3268 |
|
: public SubMapExtender<Adaptor, ArcMapBase<_Value> >
|
|
3255 |
: public SubMapExtender<SplitNodesBase<DGR>, ArcMapBase<V> >
|
| 3269 |
3256 |
{
|
| 3270 |
3257 |
public:
|
| 3271 |
|
typedef _Value Value;
|
| 3272 |
|
typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
|
| 3273 |
|
|
| 3274 |
|
ArcMap(const Adaptor& adaptor)
|
|
3258 |
typedef V Value;
|
|
3259 |
typedef SubMapExtender<SplitNodesBase<DGR>, ArcMapBase<Value> > Parent;
|
|
3260 |
|
|
3261 |
ArcMap(const SplitNodesBase<DGR>& adaptor)
|
| 3275 |
3262 |
: Parent(adaptor) {}
|
| 3276 |
3263 |
|
| 3277 |
|
ArcMap(const Adaptor& adaptor, const Value& value)
|
|
3264 |
ArcMap(const SplitNodesBase<DGR>& adaptor, const V& value)
|
| 3278 |
3265 |
: Parent(adaptor, value) {}
|
| 3279 |
3266 |
|
| 3280 |
3267 |
private:
|
| 3281 |
3268 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 3282 |
3269 |
return operator=<ArcMap>(cmap);
|
| 3283 |
3270 |
}
|
| 3284 |
3271 |
|
| 3285 |
3272 |
template <typename CMap>
|
| 3286 |
3273 |
ArcMap& operator=(const CMap& cmap) {
|
| 3287 |
3274 |
Parent::operator=(cmap);
|
| 3288 |
3275 |
return *this;
|
| 3289 |
3276 |
}
|
| 3290 |
3277 |
};
|
| 3291 |
3278 |
|
| 3292 |
3279 |
protected:
|
| 3293 |
3280 |
|
| 3294 |
3281 |
SplitNodesBase() : _digraph(0) {}
|
| 3295 |
3282 |
|
| 3296 |
|
Digraph* _digraph;
|
| 3297 |
|
|
| 3298 |
|
void setDigraph(Digraph& digraph) {
|
|
3283 |
DGR* _digraph;
|
|
3284 |
|
|
3285 |
void initialize(Digraph& digraph) {
|
| 3299 |
3286 |
_digraph = &digraph;
|
| 3300 |
3287 |
}
|
| 3301 |
3288 |
|
| 3302 |
3289 |
};
|
| 3303 |
3290 |
|
| 3304 |
3291 |
/// \ingroup graph_adaptors
|
| 3305 |
3292 |
///
|
| 3306 |
3293 |
/// \brief Adaptor class for splitting the nodes of a digraph.
|
| 3307 |
3294 |
///
|
| 3308 |
3295 |
/// SplitNodes adaptor can be used for splitting each node into an
|
| 3309 |
3296 |
/// \e in-node and an \e out-node in a digraph. Formaly, the adaptor
|
| 3310 |
3297 |
/// replaces each node \f$ u \f$ in the digraph with two nodes,
|
| 3311 |
3298 |
/// namely node \f$ u_{in} \f$ and node \f$ u_{out} \f$.
|
| 3312 |
3299 |
/// If there is a \f$ (v, u) \f$ arc in the original digraph, then the
|
| 3313 |
3300 |
/// new target of the arc will be \f$ u_{in} \f$ and similarly the
|
| 3314 |
3301 |
/// source of each original \f$ (u, v) \f$ arc will be \f$ u_{out} \f$.
|
| 3315 |
3302 |
/// The adaptor adds an additional \e bind \e arc from \f$ u_{in} \f$
|
| 3316 |
3303 |
/// to \f$ u_{out} \f$ for each node \f$ u \f$ of the original digraph.
|
| 3317 |
3304 |
///
|
| 3318 |
3305 |
/// The aim of this class is running an algorithm with respect to node
|
| 3319 |
3306 |
/// costs or capacities if the algorithm considers only arc costs or
|
| 3320 |
3307 |
/// capacities directly.
|
| 3321 |
3308 |
/// In this case you can use \c SplitNodes adaptor, and set the node
|
| 3322 |
3309 |
/// costs/capacities of the original digraph to the \e bind \e arcs
|
| 3323 |
3310 |
/// in the adaptor.
|
| 3324 |
3311 |
///
|
| 3325 |
|
/// \tparam GR The type of the adapted digraph.
|
|
3312 |
/// \tparam DGR The type of the adapted digraph.
|
| 3326 |
3313 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept.
|
| 3327 |
3314 |
/// It is implicitly \c const.
|
| 3328 |
3315 |
///
|
| 3329 |
3316 |
/// \note The \c Node type of this adaptor is converible to the \c Node
|
| 3330 |
3317 |
/// type of the adapted digraph.
|
| 3331 |
|
template <typename GR>
|
|
3318 |
template <typename DGR>
|
| 3332 |
3319 |
#ifdef DOXYGEN
|
| 3333 |
3320 |
class SplitNodes {
|
| 3334 |
3321 |
#else
|
| 3335 |
3322 |
class SplitNodes
|
| 3336 |
|
: public DigraphAdaptorExtender<SplitNodesBase<const GR> > {
|
|
3323 |
: public DigraphAdaptorExtender<SplitNodesBase<const DGR> > {
|
| 3337 |
3324 |
#endif
|
| 3338 |
3325 |
public:
|
| 3339 |
|
typedef GR Digraph;
|
| 3340 |
|
typedef DigraphAdaptorExtender<SplitNodesBase<const GR> > Parent;
|
| 3341 |
|
|
| 3342 |
|
typedef typename Digraph::Node DigraphNode;
|
| 3343 |
|
typedef typename Digraph::Arc DigraphArc;
|
|
3326 |
typedef DGR Digraph;
|
|
3327 |
typedef DigraphAdaptorExtender<SplitNodesBase<const DGR> > Parent;
|
|
3328 |
|
|
3329 |
typedef typename DGR::Node DigraphNode;
|
|
3330 |
typedef typename DGR::Arc DigraphArc;
|
| 3344 |
3331 |
|
| 3345 |
3332 |
typedef typename Parent::Node Node;
|
| 3346 |
3333 |
typedef typename Parent::Arc Arc;
|
| 3347 |
3334 |
|
| 3348 |
3335 |
/// \brief Constructor
|
| 3349 |
3336 |
///
|
| 3350 |
3337 |
/// Constructor of the adaptor.
|
| 3351 |
|
SplitNodes(const Digraph& g) {
|
| 3352 |
|
Parent::setDigraph(g);
|
|
3338 |
SplitNodes(const DGR& g) {
|
|
3339 |
Parent::initialize(g);
|
| 3353 |
3340 |
}
|
| 3354 |
3341 |
|
| 3355 |
3342 |
/// \brief Returns \c true if the given node is an in-node.
|
| 3356 |
3343 |
///
|
| 3357 |
3344 |
/// Returns \c true if the given node is an in-node.
|
| 3358 |
3345 |
static bool inNode(const Node& n) {
|
| 3359 |
3346 |
return Parent::inNode(n);
|
| 3360 |
3347 |
}
|
| 3361 |
3348 |
|
| 3362 |
3349 |
/// \brief Returns \c true if the given node is an out-node.
|
| 3363 |
3350 |
///
|
| 3364 |
3351 |
/// Returns \c true if the given node is an out-node.
|
| 3365 |
3352 |
static bool outNode(const Node& n) {
|
| 3366 |
3353 |
return Parent::outNode(n);
|
| 3367 |
3354 |
}
|
| 3368 |
3355 |
|
| 3369 |
3356 |
/// \brief Returns \c true if the given arc is an original arc.
|
| 3370 |
3357 |
///
|
| 3371 |
3358 |
/// Returns \c true if the given arc is one of the arcs in the
|
| 3372 |
3359 |
/// original digraph.
|
| 3373 |
3360 |
static bool origArc(const Arc& a) {
|
| 3374 |
3361 |
return Parent::origArc(a);
|
| 3375 |
3362 |
}
|
| 3376 |
3363 |
|
| 3377 |
3364 |
/// \brief Returns \c true if the given arc is a bind arc.
|
| 3378 |
3365 |
///
|
| 3379 |
3366 |
/// Returns \c true if the given arc is a bind arc, i.e. it connects
|
| 3380 |
3367 |
/// an in-node and an out-node.
|
| 3381 |
3368 |
static bool bindArc(const Arc& a) {
|
| 3382 |
3369 |
return Parent::bindArc(a);
|
| 3383 |
3370 |
}
|
| 3384 |
3371 |
|
| 3385 |
3372 |
/// \brief Returns the in-node created from the given original node.
|
| 3386 |
3373 |
///
|
| 3387 |
3374 |
/// Returns the in-node created from the given original node.
|
| 3388 |
3375 |
static Node inNode(const DigraphNode& n) {
|
| 3389 |
3376 |
return Parent::inNode(n);
|
| 3390 |
3377 |
}
|
| 3391 |
3378 |
|
| 3392 |
3379 |
/// \brief Returns the out-node created from the given original node.
|
| 3393 |
3380 |
///
|
| 3394 |
3381 |
/// Returns the out-node created from the given original node.
|
| 3395 |
3382 |
static Node outNode(const DigraphNode& n) {
|
| 3396 |
3383 |
return Parent::outNode(n);
|
| 3397 |
3384 |
}
|
| 3398 |
3385 |
|
| 3399 |
3386 |
/// \brief Returns the bind arc that corresponds to the given
|
| 3400 |
3387 |
/// original node.
|
| 3401 |
3388 |
///
|
| 3402 |
3389 |
/// Returns the bind arc in the adaptor that corresponds to the given
|
| 3403 |
3390 |
/// original node, i.e. the arc connecting the in-node and out-node
|
| 3404 |
3391 |
/// of \c n.
|
| 3405 |
3392 |
static Arc arc(const DigraphNode& n) {
|
| 3406 |
3393 |
return Parent::arc(n);
|
| 3407 |
3394 |
}
|
| 3408 |
3395 |
|
| 3409 |
3396 |
/// \brief Returns the arc that corresponds to the given original arc.
|
| 3410 |
3397 |
///
|
| 3411 |
3398 |
/// Returns the arc in the adaptor that corresponds to the given
|
| 3412 |
3399 |
/// original arc.
|
| 3413 |
3400 |
static Arc arc(const DigraphArc& a) {
|
| 3414 |
3401 |
return Parent::arc(a);
|
| 3415 |
3402 |
}
|
| 3416 |
3403 |
|
| 3417 |
3404 |
/// \brief Node map combined from two original node maps
|
| 3418 |
3405 |
///
|
| 3419 |
3406 |
/// This map adaptor class adapts two node maps of the original digraph
|
| 3420 |
3407 |
/// to get a node map of the split digraph.
|
| 3421 |
3408 |
/// Its value type is inherited from the first node map type
|
| 3422 |
3409 |
/// (\c InNodeMap).
|
| 3423 |
3410 |
template <typename InNodeMap, typename OutNodeMap>
|
| 3424 |
3411 |
class CombinedNodeMap {
|
| 3425 |
3412 |
public:
|
| 3426 |
3413 |
|
| 3427 |
3414 |
/// The key type of the map
|
| 3428 |
3415 |
typedef Node Key;
|
| 3429 |
3416 |
/// The value type of the map
|
| 3430 |
3417 |
typedef typename InNodeMap::Value Value;
|
| 3431 |
3418 |
|
| 3432 |
3419 |
typedef typename MapTraits<InNodeMap>::ReferenceMapTag ReferenceMapTag;
|
| 3433 |
3420 |
typedef typename MapTraits<InNodeMap>::ReturnValue ReturnValue;
|
| 3434 |
3421 |
typedef typename MapTraits<InNodeMap>::ConstReturnValue ConstReturnValue;
|
| 3435 |
3422 |
typedef typename MapTraits<InNodeMap>::ReturnValue Reference;
|
| 3436 |
3423 |
typedef typename MapTraits<InNodeMap>::ConstReturnValue ConstReference;
|
| 3437 |
3424 |
|
| 3438 |
3425 |
/// Constructor
|
| 3439 |
3426 |
CombinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map)
|
| 3440 |
3427 |
: _in_map(in_map), _out_map(out_map) {}
|
| 3441 |
3428 |
|
| 3442 |
3429 |
/// Returns the value associated with the given key.
|
| 3443 |
3430 |
Value operator[](const Key& key) const {
|
| 3444 |
|
if (Parent::inNode(key)) {
|
|
3431 |
if (SplitNodesBase<const DGR>::inNode(key)) {
|
| 3445 |
3432 |
return _in_map[key];
|
| 3446 |
3433 |
} else {
|
| 3447 |
3434 |
return _out_map[key];
|
| 3448 |
3435 |
}
|
| 3449 |
3436 |
}
|
| 3450 |
3437 |
|
| 3451 |
3438 |
/// Returns a reference to the value associated with the given key.
|
| 3452 |
3439 |
Value& operator[](const Key& key) {
|
| 3453 |
|
if (Parent::inNode(key)) {
|
|
3440 |
if (SplitNodesBase<const DGR>::inNode(key)) {
|
| 3454 |
3441 |
return _in_map[key];
|
| 3455 |
3442 |
} else {
|
| 3456 |
3443 |
return _out_map[key];
|
| 3457 |
3444 |
}
|
| 3458 |
3445 |
}
|
| 3459 |
3446 |
|
| 3460 |
3447 |
/// Sets the value associated with the given key.
|
| 3461 |
3448 |
void set(const Key& key, const Value& value) {
|
| 3462 |
|
if (Parent::inNode(key)) {
|
|
3449 |
if (SplitNodesBase<const DGR>::inNode(key)) {
|
| 3463 |
3450 |
_in_map.set(key, value);
|
| 3464 |
3451 |
} else {
|
| 3465 |
3452 |
_out_map.set(key, value);
|
| 3466 |
3453 |
}
|
| 3467 |
3454 |
}
|
| 3468 |
3455 |
|
| 3469 |
3456 |
private:
|
| 3470 |
3457 |
|
| 3471 |
3458 |
InNodeMap& _in_map;
|
| 3472 |
3459 |
OutNodeMap& _out_map;
|
| 3473 |
3460 |
|
| 3474 |
3461 |
};
|
| 3475 |
3462 |
|
| 3476 |
3463 |
|
| 3477 |
3464 |
/// \brief Returns a combined node map
|
| 3478 |
3465 |
///
|
| 3479 |
3466 |
/// This function just returns a combined node map.
|
| 3480 |
3467 |
template <typename InNodeMap, typename OutNodeMap>
|
| 3481 |
3468 |
static CombinedNodeMap<InNodeMap, OutNodeMap>
|
| 3482 |
3469 |
combinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map) {
|
| 3483 |
3470 |
return CombinedNodeMap<InNodeMap, OutNodeMap>(in_map, out_map);
|
| 3484 |
3471 |
}
|
| 3485 |
3472 |
|
| 3486 |
3473 |
template <typename InNodeMap, typename OutNodeMap>
|
| 3487 |
3474 |
static CombinedNodeMap<const InNodeMap, OutNodeMap>
|
| 3488 |
3475 |
combinedNodeMap(const InNodeMap& in_map, OutNodeMap& out_map) {
|
| 3489 |
3476 |
return CombinedNodeMap<const InNodeMap, OutNodeMap>(in_map, out_map);
|
| 3490 |
3477 |
}
|
| 3491 |
3478 |
|
| 3492 |
3479 |
template <typename InNodeMap, typename OutNodeMap>
|
| 3493 |
3480 |
static CombinedNodeMap<InNodeMap, const OutNodeMap>
|
| 3494 |
3481 |
combinedNodeMap(InNodeMap& in_map, const OutNodeMap& out_map) {
|
| 3495 |
3482 |
return CombinedNodeMap<InNodeMap, const OutNodeMap>(in_map, out_map);
|
| 3496 |
3483 |
}
|
| 3497 |
3484 |
|
| 3498 |
3485 |
template <typename InNodeMap, typename OutNodeMap>
|
| 3499 |
3486 |
static CombinedNodeMap<const InNodeMap, const OutNodeMap>
|
| 3500 |
3487 |
combinedNodeMap(const InNodeMap& in_map, const OutNodeMap& out_map) {
|
| 3501 |
3488 |
return CombinedNodeMap<const InNodeMap,
|
| 3502 |
3489 |
const OutNodeMap>(in_map, out_map);
|
| 3503 |
3490 |
}
|
| 3504 |
3491 |
|
| 3505 |
3492 |
/// \brief Arc map combined from an arc map and a node map of the
|
| 3506 |
3493 |
/// original digraph.
|
| 3507 |
3494 |
///
|
| 3508 |
3495 |
/// This map adaptor class adapts an arc map and a node map of the
|
| 3509 |
3496 |
/// original digraph to get an arc map of the split digraph.
|
| 3510 |
3497 |
/// Its value type is inherited from the original arc map type
|
| 3511 |
3498 |
/// (\c ArcMap).
|
| 3512 |
3499 |
template <typename ArcMap, typename NodeMap>
|
| 3513 |
3500 |
class CombinedArcMap {
|
| 3514 |
3501 |
public:
|
| 3515 |
3502 |
|
| 3516 |
3503 |
/// The key type of the map
|
| 3517 |
3504 |
typedef Arc Key;
|
| 3518 |
3505 |
/// The value type of the map
|
| 3519 |
3506 |
typedef typename ArcMap::Value Value;
|
| 3520 |
3507 |
|
| 3521 |
3508 |
typedef typename MapTraits<ArcMap>::ReferenceMapTag ReferenceMapTag;
|
| 3522 |
3509 |
typedef typename MapTraits<ArcMap>::ReturnValue ReturnValue;
|
| 3523 |
3510 |
typedef typename MapTraits<ArcMap>::ConstReturnValue ConstReturnValue;
|
| 3524 |
3511 |
typedef typename MapTraits<ArcMap>::ReturnValue Reference;
|
| 3525 |
3512 |
typedef typename MapTraits<ArcMap>::ConstReturnValue ConstReference;
|
| 3526 |
3513 |
|
| 3527 |
3514 |
/// Constructor
|
| 3528 |
3515 |
CombinedArcMap(ArcMap& arc_map, NodeMap& node_map)
|
| 3529 |
3516 |
: _arc_map(arc_map), _node_map(node_map) {}
|
| 3530 |
3517 |
|
| 3531 |
3518 |
/// Returns the value associated with the given key.
|
| 3532 |
3519 |
Value operator[](const Key& arc) const {
|
| 3533 |
|
if (Parent::origArc(arc)) {
|
|
3520 |
if (SplitNodesBase<const DGR>::origArc(arc)) {
|
| 3534 |
3521 |
return _arc_map[arc];
|
| 3535 |
3522 |
} else {
|
| 3536 |
3523 |
return _node_map[arc];
|
| 3537 |
3524 |
}
|
| 3538 |
3525 |
}
|
| 3539 |
3526 |
|
| 3540 |
3527 |
/// Returns a reference to the value associated with the given key.
|
| 3541 |
3528 |
Value& operator[](const Key& arc) {
|
| 3542 |
|
if (Parent::origArc(arc)) {
|
|
3529 |
if (SplitNodesBase<const DGR>::origArc(arc)) {
|
| 3543 |
3530 |
return _arc_map[arc];
|
| 3544 |
3531 |
} else {
|
| 3545 |
3532 |
return _node_map[arc];
|
| 3546 |
3533 |
}
|
| 3547 |
3534 |
}
|
| 3548 |
3535 |
|
| 3549 |
3536 |
/// Sets the value associated with the given key.
|
| 3550 |
3537 |
void set(const Arc& arc, const Value& val) {
|
| 3551 |
|
if (Parent::origArc(arc)) {
|
|
3538 |
if (SplitNodesBase<const DGR>::origArc(arc)) {
|
| 3552 |
3539 |
_arc_map.set(arc, val);
|
| 3553 |
3540 |
} else {
|
| 3554 |
3541 |
_node_map.set(arc, val);
|
| 3555 |
3542 |
}
|
| 3556 |
3543 |
}
|
| 3557 |
3544 |
|
| 3558 |
3545 |
private:
|
| 3559 |
3546 |
ArcMap& _arc_map;
|
| 3560 |
3547 |
NodeMap& _node_map;
|
| 3561 |
3548 |
};
|
| 3562 |
3549 |
|
| 3563 |
3550 |
/// \brief Returns a combined arc map
|
| 3564 |
3551 |
///
|
| 3565 |
3552 |
/// This function just returns a combined arc map.
|
| 3566 |
3553 |
template <typename ArcMap, typename NodeMap>
|
| 3567 |
3554 |
static CombinedArcMap<ArcMap, NodeMap>
|
| 3568 |
3555 |
combinedArcMap(ArcMap& arc_map, NodeMap& node_map) {
|
| 3569 |
3556 |
return CombinedArcMap<ArcMap, NodeMap>(arc_map, node_map);
|
| 3570 |
3557 |
}
|
| 3571 |
3558 |
|
| 3572 |
3559 |
template <typename ArcMap, typename NodeMap>
|
| 3573 |
3560 |
static CombinedArcMap<const ArcMap, NodeMap>
|
| 3574 |
3561 |
combinedArcMap(const ArcMap& arc_map, NodeMap& node_map) {
|
| 3575 |
3562 |
return CombinedArcMap<const ArcMap, NodeMap>(arc_map, node_map);
|
| 3576 |
3563 |
}
|
| 3577 |
3564 |
|
| 3578 |
3565 |
template <typename ArcMap, typename NodeMap>
|
| 3579 |
3566 |
static CombinedArcMap<ArcMap, const NodeMap>
|
| 3580 |
3567 |
combinedArcMap(ArcMap& arc_map, const NodeMap& node_map) {
|
| 3581 |
3568 |
return CombinedArcMap<ArcMap, const NodeMap>(arc_map, node_map);
|
| 3582 |
3569 |
}
|
| 3583 |
3570 |
|
| 3584 |
3571 |
template <typename ArcMap, typename NodeMap>
|
| 3585 |
3572 |
static CombinedArcMap<const ArcMap, const NodeMap>
|
| 3586 |
3573 |
combinedArcMap(const ArcMap& arc_map, const NodeMap& node_map) {
|
| 3587 |
3574 |
return CombinedArcMap<const ArcMap, const NodeMap>(arc_map, node_map);
|
| 3588 |
3575 |
}
|
| 3589 |
3576 |
|
| 3590 |
3577 |
};
|
| 3591 |
3578 |
|
| 3592 |
3579 |
/// \brief Returns a (read-only) SplitNodes adaptor
|
| 3593 |
3580 |
///
|
| 3594 |
3581 |
/// This function just returns a (read-only) \ref SplitNodes adaptor.
|
| 3595 |
3582 |
/// \ingroup graph_adaptors
|
| 3596 |
3583 |
/// \relates SplitNodes
|
| 3597 |
|
template<typename GR>
|
| 3598 |
|
SplitNodes<GR>
|
| 3599 |
|
splitNodes(const GR& digraph) {
|
| 3600 |
|
return SplitNodes<GR>(digraph);
|
|
3584 |
template<typename DGR>
|
|
3585 |
SplitNodes<DGR>
|
|
3586 |
splitNodes(const DGR& digraph) {
|
|
3587 |
return SplitNodes<DGR>(digraph);
|
| 3601 |
3588 |
}
|
| 3602 |
3589 |
|
|
3590 |
#undef LEMON_SCOPE_FIX
|
|
3591 |
|
| 3603 |
3592 |
} //namespace lemon
|
| 3604 |
3593 |
|
| 3605 |
3594 |
#endif //LEMON_ADAPTORS_H
|