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