| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
///\ingroup graph_concepts |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief The concept of graph components. |
| 22 | 22 |
|
| 23 | 23 |
#ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
| 24 | 24 |
#define LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/core.h> |
| 27 | 27 |
#include <lemon/concepts/maps.h> |
| 28 | 28 |
|
| 29 | 29 |
#include <lemon/bits/alteration_notifier.h> |
| 30 | 30 |
|
| 31 | 31 |
namespace lemon {
|
| 32 | 32 |
namespace concepts {
|
| 33 | 33 |
|
| 34 | 34 |
/// \brief Concept class for \c Node, \c Arc and \c Edge types. |
| 35 | 35 |
/// |
| 36 | 36 |
/// This class describes the concept of \c Node, \c Arc and \c Edge |
| 37 | 37 |
/// subtypes of digraph and graph types. |
| 38 | 38 |
/// |
| 39 | 39 |
/// \note This class is a template class so that we can use it to |
| 40 | 40 |
/// create graph skeleton classes. The reason for this is that \c Node |
| 41 | 41 |
/// and \c Arc (or \c Edge) types should \e not derive from the same |
| 42 | 42 |
/// base class. For \c Node you should instantiate it with character |
| 43 | 43 |
/// \c 'n', for \c Arc with \c 'a' and for \c Edge with \c 'e'. |
| 44 | 44 |
#ifndef DOXYGEN |
| 45 | 45 |
template <char sel = '0'> |
| 46 | 46 |
#endif |
| 47 | 47 |
class GraphItem {
|
| 48 | 48 |
public: |
| 49 | 49 |
/// \brief Default constructor. |
| 50 | 50 |
/// |
| 51 | 51 |
/// Default constructor. |
| 52 | 52 |
/// \warning The default constructor is not required to set |
| 53 | 53 |
/// the item to some well-defined value. So you should consider it |
| 54 | 54 |
/// as uninitialized. |
| 55 | 55 |
GraphItem() {}
|
| 56 | 56 |
|
| 57 | 57 |
/// \brief Copy constructor. |
| 58 | 58 |
/// |
| 59 | 59 |
/// Copy constructor. |
| 60 | 60 |
GraphItem(const GraphItem &) {}
|
| 61 | 61 |
|
| 62 | 62 |
/// \brief Constructor for conversion from \c INVALID. |
| 63 | 63 |
/// |
| 64 | 64 |
/// Constructor for conversion from \c INVALID. |
| 65 | 65 |
/// It initializes the item to be invalid. |
| 66 | 66 |
/// \sa Invalid for more details. |
| 67 | 67 |
GraphItem(Invalid) {}
|
| 68 | 68 |
|
| 69 | 69 |
/// \brief Assignment operator. |
| 70 | 70 |
/// |
| 71 | 71 |
/// Assignment operator for the item. |
| 72 | 72 |
GraphItem& operator=(const GraphItem&) { return *this; }
|
| 73 | 73 |
|
| 74 |
/// \brief Assignment operator for INVALID. |
|
| 75 |
/// |
|
| 76 |
/// This operator makes the item invalid. |
|
| 77 |
GraphItem& operator=(Invalid) { return *this; }
|
|
| 78 |
|
|
| 74 | 79 |
/// \brief Equality operator. |
| 75 | 80 |
/// |
| 76 | 81 |
/// Equality operator. |
| 77 | 82 |
bool operator==(const GraphItem&) const { return false; }
|
| 78 | 83 |
|
| 79 | 84 |
/// \brief Inequality operator. |
| 80 | 85 |
/// |
| 81 | 86 |
/// Inequality operator. |
| 82 | 87 |
bool operator!=(const GraphItem&) const { return false; }
|
| 83 | 88 |
|
| 84 | 89 |
/// \brief Ordering operator. |
| 85 | 90 |
/// |
| 86 | 91 |
/// This operator defines an ordering of the items. |
| 87 | 92 |
/// It makes possible to use graph item types as key types in |
| 88 | 93 |
/// associative containers (e.g. \c std::map). |
| 89 | 94 |
/// |
| 90 | 95 |
/// \note This operator only have to define some strict ordering of |
| 91 | 96 |
/// the items; this order has nothing to do with the iteration |
| 92 | 97 |
/// ordering of the items. |
| 93 | 98 |
bool operator<(const GraphItem&) const { return false; }
|
| 94 | 99 |
|
| 95 | 100 |
template<typename _GraphItem> |
| 96 | 101 |
struct Constraints {
|
| 97 | 102 |
void constraints() {
|
| 98 | 103 |
_GraphItem i1; |
| 104 |
i1=INVALID; |
|
| 99 | 105 |
_GraphItem i2 = i1; |
| 100 | 106 |
_GraphItem i3 = INVALID; |
| 101 | 107 |
|
| 102 | 108 |
i1 = i2 = i3; |
| 103 | 109 |
|
| 104 | 110 |
bool b; |
| 105 | 111 |
b = (ia == ib) && (ia != ib); |
| 106 | 112 |
b = (ia == INVALID) && (ib != INVALID); |
| 107 | 113 |
b = (ia < ib); |
| 108 | 114 |
} |
| 109 | 115 |
|
| 110 | 116 |
const _GraphItem &ia; |
| 111 | 117 |
const _GraphItem &ib; |
| 112 | 118 |
}; |
| 113 | 119 |
}; |
| 114 | 120 |
|
| 115 | 121 |
/// \brief Base skeleton class for directed graphs. |
| 116 | 122 |
/// |
| 117 | 123 |
/// This class describes the base interface of directed graph types. |
| 118 | 124 |
/// All digraph %concepts have to conform to this class. |
| 119 | 125 |
/// It just provides types for nodes and arcs and functions |
| 120 | 126 |
/// to get the source and the target nodes of arcs. |
| 121 | 127 |
class BaseDigraphComponent {
|
| 122 | 128 |
public: |
| 123 | 129 |
|
| 124 | 130 |
typedef BaseDigraphComponent Digraph; |
| 125 | 131 |
|
| 126 | 132 |
/// \brief Node class of the digraph. |
| 127 | 133 |
/// |
| 128 | 134 |
/// This class represents the nodes of the digraph. |
| 129 | 135 |
typedef GraphItem<'n'> Node; |
| 130 | 136 |
|
| 131 | 137 |
/// \brief Arc class of the digraph. |
| 132 | 138 |
/// |
| 133 | 139 |
/// This class represents the arcs of the digraph. |
| 134 | 140 |
typedef GraphItem<'a'> Arc; |
| 135 | 141 |
|
| 136 | 142 |
/// \brief Return the source node of an arc. |
| 137 | 143 |
/// |
| 138 | 144 |
/// This function returns the source node of an arc. |
| 139 | 145 |
Node source(const Arc&) const { return INVALID; }
|
| 140 | 146 |
|
| 141 | 147 |
/// \brief Return the target node of an arc. |
| 142 | 148 |
/// |
| 143 | 149 |
/// This function returns the target node of an arc. |
| 144 | 150 |
Node target(const Arc&) const { return INVALID; }
|
| 145 | 151 |
|
| 146 | 152 |
/// \brief Return the opposite node on the given arc. |
| 147 | 153 |
/// |
| 148 | 154 |
/// This function returns the opposite node on the given arc. |
| 149 | 155 |
Node oppositeNode(const Node&, const Arc&) const {
|
| 150 | 156 |
return INVALID; |
| 151 | 157 |
} |
| 152 | 158 |
|
| 153 | 159 |
template <typename _Digraph> |
| 154 | 160 |
struct Constraints {
|
| 155 | 161 |
typedef typename _Digraph::Node Node; |
| 156 | 162 |
typedef typename _Digraph::Arc Arc; |
| 157 | 163 |
|
| 158 | 164 |
void constraints() {
|
| 159 | 165 |
checkConcept<GraphItem<'n'>, Node>(); |
| 160 | 166 |
checkConcept<GraphItem<'a'>, Arc>(); |
| 161 | 167 |
{
|
| 162 | 168 |
Node n; |
| 163 | 169 |
Arc e(INVALID); |
| 164 | 170 |
n = digraph.source(e); |
| 165 | 171 |
n = digraph.target(e); |
| 166 | 172 |
n = digraph.oppositeNode(n, e); |
| 167 | 173 |
} |
| 168 | 174 |
} |
| 169 | 175 |
|
| 170 | 176 |
const _Digraph& digraph; |
| 171 | 177 |
}; |
| 172 | 178 |
}; |
| 173 | 179 |
|
| 174 | 180 |
/// \brief Base skeleton class for undirected graphs. |
| 175 | 181 |
/// |
| 176 | 182 |
/// This class describes the base interface of undirected graph types. |
| 177 | 183 |
/// All graph %concepts have to conform to this class. |
| 178 | 184 |
/// It extends the interface of \ref BaseDigraphComponent with an |
| 179 | 185 |
/// \c Edge type and functions to get the end nodes of edges, |
| 180 | 186 |
/// to convert from arcs to edges and to get both direction of edges. |
| 181 | 187 |
class BaseGraphComponent : public BaseDigraphComponent {
|
| 182 | 188 |
public: |
| 183 | 189 |
|
| 184 | 190 |
typedef BaseGraphComponent Graph; |
| 185 | 191 |
|
| 186 | 192 |
typedef BaseDigraphComponent::Node Node; |
| 187 | 193 |
typedef BaseDigraphComponent::Arc Arc; |
| 188 | 194 |
|
| 189 | 195 |
/// \brief Undirected edge class of the graph. |
| 190 | 196 |
/// |
| 191 | 197 |
/// This class represents the undirected edges of the graph. |
| 192 | 198 |
/// Undirected graphs can be used as directed graphs, each edge is |
| 193 | 199 |
/// represented by two opposite directed arcs. |
| 194 | 200 |
class Edge : public GraphItem<'e'> {
|
| 195 | 201 |
typedef GraphItem<'e'> Parent; |
| 196 | 202 |
|
| 197 | 203 |
public: |
| 198 | 204 |
/// \brief Default constructor. |
| 199 | 205 |
/// |
| 200 | 206 |
/// Default constructor. |
| 201 | 207 |
/// \warning The default constructor is not required to set |
| 202 | 208 |
/// the item to some well-defined value. So you should consider it |
| 203 | 209 |
/// as uninitialized. |
| 204 | 210 |
Edge() {}
|
| 205 | 211 |
|
| 206 | 212 |
/// \brief Copy constructor. |
| 207 | 213 |
/// |
| 208 | 214 |
/// Copy constructor. |
| 209 | 215 |
Edge(const Edge &) : Parent() {}
|
| 210 | 216 |
|
| 211 | 217 |
/// \brief Constructor for conversion from \c INVALID. |
| 212 | 218 |
/// |
| 213 | 219 |
/// Constructor for conversion from \c INVALID. |
| 214 | 220 |
/// It initializes the item to be invalid. |
| 215 | 221 |
/// \sa Invalid for more details. |
| 216 | 222 |
Edge(Invalid) {}
|
| 217 | 223 |
|
| 218 | 224 |
/// \brief Constructor for conversion from an arc. |
| 219 | 225 |
/// |
| 220 | 226 |
/// Constructor for conversion from an arc. |
| 221 | 227 |
/// Besides the core graph item functionality each arc should |
| 222 | 228 |
/// be convertible to the represented edge. |
| 223 | 229 |
Edge(const Arc&) {}
|
| 224 |
|
|
| 225 |
/// \brief Assign an arc to an edge. |
|
| 226 |
/// |
|
| 227 |
/// This function assigns an arc to an edge. |
|
| 228 |
/// Besides the core graph item functionality each arc should |
|
| 229 |
/// be convertible to the represented edge. |
|
| 230 |
Edge& operator=(const Arc&) { return *this; }
|
|
| 231 |
}; |
|
| 230 |
}; |
|
| 232 | 231 |
|
| 233 | 232 |
/// \brief Return one end node of an edge. |
| 234 | 233 |
/// |
| 235 | 234 |
/// This function returns one end node of an edge. |
| 236 | 235 |
Node u(const Edge&) const { return INVALID; }
|
| 237 | 236 |
|
| 238 | 237 |
/// \brief Return the other end node of an edge. |
| 239 | 238 |
/// |
| 240 | 239 |
/// This function returns the other end node of an edge. |
| 241 | 240 |
Node v(const Edge&) const { return INVALID; }
|
| 242 | 241 |
|
| 243 | 242 |
/// \brief Return a directed arc related to an edge. |
| 244 | 243 |
/// |
| 245 | 244 |
/// This function returns a directed arc from its direction and the |
| 246 | 245 |
/// represented edge. |
| 247 | 246 |
Arc direct(const Edge&, bool) const { return INVALID; }
|
| 248 | 247 |
|
| 249 | 248 |
/// \brief Return a directed arc related to an edge. |
| 250 | 249 |
/// |
| 251 | 250 |
/// This function returns a directed arc from its source node and the |
| 252 | 251 |
/// represented edge. |
| 253 | 252 |
Arc direct(const Edge&, const Node&) const { return INVALID; }
|
| 254 | 253 |
|
| 255 | 254 |
/// \brief Return the direction of the arc. |
| 256 | 255 |
/// |
| 257 | 256 |
/// Returns the direction of the arc. Each arc represents an |
| 258 | 257 |
/// edge with a direction. It gives back the |
| 259 | 258 |
/// direction. |
| 260 | 259 |
bool direction(const Arc&) const { return true; }
|
| 261 | 260 |
|
| 262 | 261 |
/// \brief Return the opposite arc. |
| 263 | 262 |
/// |
| 264 | 263 |
/// This function returns the opposite arc, i.e. the arc representing |
| 265 | 264 |
/// the same edge and has opposite direction. |
| 266 | 265 |
Arc oppositeArc(const Arc&) const { return INVALID; }
|
| 267 | 266 |
|
| 268 | 267 |
template <typename _Graph> |
| 269 | 268 |
struct Constraints {
|
| 270 | 269 |
typedef typename _Graph::Node Node; |
| 271 | 270 |
typedef typename _Graph::Arc Arc; |
| 272 | 271 |
typedef typename _Graph::Edge Edge; |
| 273 | 272 |
|
| 274 | 273 |
void constraints() {
|
| 275 | 274 |
checkConcept<BaseDigraphComponent, _Graph>(); |
| 276 | 275 |
checkConcept<GraphItem<'e'>, Edge>(); |
| 277 | 276 |
{
|
| 278 | 277 |
Node n; |
| 279 | 278 |
Edge ue(INVALID); |
| 280 | 279 |
Arc e; |
| 281 | 280 |
n = graph.u(ue); |
| 282 | 281 |
n = graph.v(ue); |
| 283 | 282 |
e = graph.direct(ue, true); |
| 284 | 283 |
e = graph.direct(ue, false); |
| 285 | 284 |
e = graph.direct(ue, n); |
| 286 | 285 |
e = graph.oppositeArc(e); |
| 287 | 286 |
ue = e; |
| 288 | 287 |
bool d = graph.direction(e); |
| 289 | 288 |
ignore_unused_variable_warning(d); |
| 290 | 289 |
} |
| 291 | 290 |
} |
| 292 | 291 |
|
| 293 | 292 |
const _Graph& graph; |
| 294 | 293 |
}; |
| 295 | 294 |
|
| 296 | 295 |
}; |
| 297 | 296 |
|
| 298 | 297 |
/// \brief Skeleton class for \e idable directed graphs. |
| 299 | 298 |
/// |
| 300 | 299 |
/// This class describes the interface of \e idable directed graphs. |
| 301 | 300 |
/// It extends \ref BaseDigraphComponent with the core ID functions. |
| 302 | 301 |
/// The ids of the items must be unique and immutable. |
| 303 | 302 |
/// This concept is part of the Digraph concept. |
| 304 | 303 |
template <typename BAS = BaseDigraphComponent> |
| 305 | 304 |
class IDableDigraphComponent : public BAS {
|
| 306 | 305 |
public: |
| 307 | 306 |
|
| 308 | 307 |
typedef BAS Base; |
| 309 | 308 |
typedef typename Base::Node Node; |
| 310 | 309 |
typedef typename Base::Arc Arc; |
| 311 | 310 |
|
| 312 | 311 |
/// \brief Return a unique integer id for the given node. |
| 313 | 312 |
/// |
| 314 | 313 |
/// This function returns a unique integer id for the given node. |
| 315 | 314 |
int id(const Node&) const { return -1; }
|
| 316 | 315 |
|
| 317 | 316 |
/// \brief Return the node by its unique id. |
| 318 | 317 |
/// |
| 319 | 318 |
/// This function returns the node by its unique id. |
| 320 | 319 |
/// If the digraph does not contain a node with the given id, |
| 321 | 320 |
/// then the result of the function is undefined. |
| 322 | 321 |
Node nodeFromId(int) const { return INVALID; }
|
| 323 | 322 |
|
| 324 | 323 |
/// \brief Return a unique integer id for the given arc. |
| 325 | 324 |
/// |
| 326 | 325 |
/// This function returns a unique integer id for the given arc. |
| 327 | 326 |
int id(const Arc&) const { return -1; }
|
| 328 | 327 |
|
| 329 | 328 |
/// \brief Return the arc by its unique id. |
| 330 | 329 |
/// |
| 331 | 330 |
/// This function returns the arc by its unique id. |
| 332 | 331 |
/// If the digraph does not contain an arc with the given id, |
| 333 | 332 |
/// then the result of the function is undefined. |
| 334 | 333 |
Arc arcFromId(int) const { return INVALID; }
|
| 335 | 334 |
|
| 336 | 335 |
/// \brief Return an integer greater or equal to the maximum |
| 337 | 336 |
/// node id. |
| 338 | 337 |
/// |
| 339 | 338 |
/// This function returns an integer greater or equal to the |
| 340 | 339 |
/// maximum node id. |
| 341 | 340 |
int maxNodeId() const { return -1; }
|
| 342 | 341 |
|
| 343 | 342 |
/// \brief Return an integer greater or equal to the maximum |
| 344 | 343 |
/// arc id. |
| 345 | 344 |
/// |
| 346 | 345 |
/// This function returns an integer greater or equal to the |
| 347 | 346 |
/// maximum arc id. |
| 348 | 347 |
int maxArcId() const { return -1; }
|
| 349 | 348 |
|
| 350 | 349 |
template <typename _Digraph> |
| 351 | 350 |
struct Constraints {
|
| 352 | 351 |
|
| 353 | 352 |
void constraints() {
|
| 354 | 353 |
checkConcept<Base, _Digraph >(); |
| 355 | 354 |
typename _Digraph::Node node; |
| 355 |
node=INVALID; |
|
| 356 | 356 |
int nid = digraph.id(node); |
| 357 | 357 |
nid = digraph.id(node); |
| 358 | 358 |
node = digraph.nodeFromId(nid); |
| 359 | 359 |
typename _Digraph::Arc arc; |
| 360 |
arc=INVALID; |
|
| 360 | 361 |
int eid = digraph.id(arc); |
| 361 | 362 |
eid = digraph.id(arc); |
| 362 | 363 |
arc = digraph.arcFromId(eid); |
| 363 | 364 |
|
| 364 | 365 |
nid = digraph.maxNodeId(); |
| 365 | 366 |
ignore_unused_variable_warning(nid); |
| 366 | 367 |
eid = digraph.maxArcId(); |
| 367 | 368 |
ignore_unused_variable_warning(eid); |
| 368 | 369 |
} |
| 369 | 370 |
|
| 370 | 371 |
const _Digraph& digraph; |
| 371 | 372 |
}; |
| 372 | 373 |
}; |
| 373 | 374 |
|
| 374 | 375 |
/// \brief Skeleton class for \e idable undirected graphs. |
| 375 | 376 |
/// |
| 376 | 377 |
/// This class describes the interface of \e idable undirected |
| 377 | 378 |
/// graphs. It extends \ref IDableDigraphComponent with the core ID |
| 378 | 379 |
/// functions of undirected graphs. |
| 379 | 380 |
/// The ids of the items must be unique and immutable. |
| 380 | 381 |
/// This concept is part of the Graph concept. |
| 381 | 382 |
template <typename BAS = BaseGraphComponent> |
| 382 | 383 |
class IDableGraphComponent : public IDableDigraphComponent<BAS> {
|
| 383 | 384 |
public: |
| 384 | 385 |
|
| 385 | 386 |
typedef BAS Base; |
| 386 | 387 |
typedef typename Base::Edge Edge; |
| 387 | 388 |
|
| 388 | 389 |
using IDableDigraphComponent<Base>::id; |
| 389 | 390 |
|
| 390 | 391 |
/// \brief Return a unique integer id for the given edge. |
| 391 | 392 |
/// |
| 392 | 393 |
/// This function returns a unique integer id for the given edge. |
| 393 | 394 |
int id(const Edge&) const { return -1; }
|
| 394 | 395 |
|
| 395 | 396 |
/// \brief Return the edge by its unique id. |
| 396 | 397 |
/// |
| 397 | 398 |
/// This function returns the edge by its unique id. |
| 398 | 399 |
/// If the graph does not contain an edge with the given id, |
| 399 | 400 |
/// then the result of the function is undefined. |
| 400 | 401 |
Edge edgeFromId(int) const { return INVALID; }
|
| 401 | 402 |
|
| 402 | 403 |
/// \brief Return an integer greater or equal to the maximum |
| 403 | 404 |
/// edge id. |
| 404 | 405 |
/// |
| 405 | 406 |
/// This function returns an integer greater or equal to the |
| 406 | 407 |
/// maximum edge id. |
| 407 | 408 |
int maxEdgeId() const { return -1; }
|
| 408 | 409 |
|
| 409 | 410 |
template <typename _Graph> |
| 410 | 411 |
struct Constraints {
|
| 411 | 412 |
|
| 412 | 413 |
void constraints() {
|
| 413 | 414 |
checkConcept<IDableDigraphComponent<Base>, _Graph >(); |
| 414 | 415 |
typename _Graph::Edge edge; |
| 415 | 416 |
int ueid = graph.id(edge); |
| 416 | 417 |
ueid = graph.id(edge); |
| 417 | 418 |
edge = graph.edgeFromId(ueid); |
| 418 | 419 |
ueid = graph.maxEdgeId(); |
| 419 | 420 |
ignore_unused_variable_warning(ueid); |
| 420 | 421 |
} |
| 421 | 422 |
|
| 422 | 423 |
const _Graph& graph; |
| 423 | 424 |
}; |
| 424 | 425 |
}; |
| 425 | 426 |
|
| 426 | 427 |
/// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types. |
| 427 | 428 |
/// |
| 428 | 429 |
/// This class describes the concept of \c NodeIt, \c ArcIt and |
| 429 | 430 |
/// \c EdgeIt subtypes of digraph and graph types. |
| 430 | 431 |
template <typename GR, typename Item> |
| 431 | 432 |
class GraphItemIt : public Item {
|
| 432 | 433 |
public: |
| 433 | 434 |
/// \brief Default constructor. |
| 434 | 435 |
/// |
| 435 | 436 |
/// Default constructor. |
| 436 | 437 |
/// \warning The default constructor is not required to set |
| 437 | 438 |
/// the iterator to some well-defined value. So you should consider it |
| 438 | 439 |
/// as uninitialized. |
| 439 | 440 |
GraphItemIt() {}
|
| 440 | 441 |
|
| 441 | 442 |
/// \brief Copy constructor. |
| 442 | 443 |
/// |
| 443 | 444 |
/// Copy constructor. |
| 444 | 445 |
GraphItemIt(const GraphItemIt& it) : Item(it) {}
|
| 445 | 446 |
|
| 446 | 447 |
/// \brief Constructor that sets the iterator to the first item. |
| 447 | 448 |
/// |
| 448 | 449 |
/// Constructor that sets the iterator to the first item. |
| 449 | 450 |
explicit GraphItemIt(const GR&) {}
|
| 450 | 451 |
|
| 451 | 452 |
/// \brief Constructor for conversion from \c INVALID. |
| 452 | 453 |
/// |
| 453 | 454 |
/// Constructor for conversion from \c INVALID. |
| 454 | 455 |
/// It initializes the iterator to be invalid. |
| 455 | 456 |
/// \sa Invalid for more details. |
| 456 | 457 |
GraphItemIt(Invalid) {}
|
| 457 | 458 |
|
| 458 | 459 |
/// \brief Assignment operator. |
| 459 | 460 |
/// |
| 460 | 461 |
/// Assignment operator for the iterator. |
| 461 | 462 |
GraphItemIt& operator=(const GraphItemIt&) { return *this; }
|
| 462 | 463 |
|
| 463 | 464 |
/// \brief Increment the iterator. |
| 464 | 465 |
/// |
| 465 | 466 |
/// This operator increments the iterator, i.e. assigns it to the |
| 466 | 467 |
/// next item. |
| 467 | 468 |
GraphItemIt& operator++() { return *this; }
|
| 468 | 469 |
|
| 469 | 470 |
/// \brief Equality operator |
| 470 | 471 |
/// |
| 471 | 472 |
/// Equality operator. |
| 472 | 473 |
/// Two iterators are equal if and only if they point to the |
| 473 | 474 |
/// same object or both are invalid. |
| 474 | 475 |
bool operator==(const GraphItemIt&) const { return true;}
|
| 475 | 476 |
|
| 476 | 477 |
/// \brief Inequality operator |
| 477 | 478 |
/// |
| 478 | 479 |
/// Inequality operator. |
| 479 | 480 |
/// Two iterators are equal if and only if they point to the |
| 480 | 481 |
/// same object or both are invalid. |
| 481 | 482 |
bool operator!=(const GraphItemIt&) const { return true;}
|
| 482 | 483 |
|
| 483 | 484 |
template<typename _GraphItemIt> |
| 484 | 485 |
struct Constraints {
|
| 485 | 486 |
void constraints() {
|
| 486 | 487 |
checkConcept<GraphItem<>, _GraphItemIt>(); |
| 487 | 488 |
_GraphItemIt it1(g); |
| 488 | 489 |
_GraphItemIt it2; |
| 489 | 490 |
_GraphItemIt it3 = it1; |
| 490 | 491 |
_GraphItemIt it4 = INVALID; |
| 491 | 492 |
|
| 492 | 493 |
it2 = ++it1; |
| 493 | 494 |
++it2 = it1; |
| 494 | 495 |
++(++it1); |
| 495 | 496 |
|
| 496 | 497 |
Item bi = it1; |
| 497 | 498 |
bi = it2; |
| 498 | 499 |
} |
| 499 | 500 |
const GR& g; |
| 500 | 501 |
}; |
| 501 | 502 |
}; |
| 502 | 503 |
|
| 503 | 504 |
/// \brief Concept class for \c InArcIt, \c OutArcIt and |
| 504 | 505 |
/// \c IncEdgeIt types. |
| 505 | 506 |
/// |
| 506 | 507 |
/// This class describes the concept of \c InArcIt, \c OutArcIt |
| 507 | 508 |
/// and \c IncEdgeIt subtypes of digraph and graph types. |
| 508 | 509 |
/// |
| 509 | 510 |
/// \note Since these iterator classes do not inherit from the same |
| 510 | 511 |
/// base class, there is an additional template parameter (selector) |
| 511 | 512 |
/// \c sel. For \c InArcIt you should instantiate it with character |
| 512 | 513 |
/// \c 'i', for \c OutArcIt with \c 'o' and for \c IncEdgeIt with \c 'e'. |
| 513 | 514 |
template <typename GR, |
| 514 | 515 |
typename Item = typename GR::Arc, |
| 515 | 516 |
typename Base = typename GR::Node, |
| 516 | 517 |
char sel = '0'> |
| 517 | 518 |
class GraphIncIt : public Item {
|
| 518 | 519 |
public: |
| 519 | 520 |
/// \brief Default constructor. |
| 520 | 521 |
/// |
| 521 | 522 |
/// Default constructor. |
| 522 | 523 |
/// \warning The default constructor is not required to set |
| 523 | 524 |
/// the iterator to some well-defined value. So you should consider it |
| 524 | 525 |
/// as uninitialized. |
| 525 | 526 |
GraphIncIt() {}
|
| 526 | 527 |
|
| 527 | 528 |
/// \brief Copy constructor. |
| 528 | 529 |
/// |
| 529 | 530 |
/// Copy constructor. |
| 530 | 531 |
GraphIncIt(const GraphIncIt& it) : Item(it) {}
|
| 531 | 532 |
|
| 532 | 533 |
/// \brief Constructor that sets the iterator to the first |
| 533 | 534 |
/// incoming or outgoing arc. |
| 534 | 535 |
/// |
| 535 | 536 |
/// Constructor that sets the iterator to the first arc |
| 536 | 537 |
/// incoming to or outgoing from the given node. |
| 537 | 538 |
explicit GraphIncIt(const GR&, const Base&) {}
|
| 538 | 539 |
|
| 539 | 540 |
/// \brief Constructor for conversion from \c INVALID. |
| 540 | 541 |
/// |
| 541 | 542 |
/// Constructor for conversion from \c INVALID. |
| 542 | 543 |
/// It initializes the iterator to be invalid. |
| 543 | 544 |
/// \sa Invalid for more details. |
| 544 | 545 |
GraphIncIt(Invalid) {}
|
| 545 | 546 |
|
| 546 | 547 |
/// \brief Assignment operator. |
| 547 | 548 |
/// |
| 548 | 549 |
/// Assignment operator for the iterator. |
| 549 | 550 |
GraphIncIt& operator=(const GraphIncIt&) { return *this; }
|
| 550 | 551 |
|
| 551 | 552 |
/// \brief Increment the iterator. |
| 552 | 553 |
/// |
| 553 | 554 |
/// This operator increments the iterator, i.e. assigns it to the |
| 554 | 555 |
/// next arc incoming to or outgoing from the given node. |
| 555 | 556 |
GraphIncIt& operator++() { return *this; }
|
| 556 | 557 |
|
| 557 | 558 |
/// \brief Equality operator |
| 558 | 559 |
/// |
| 559 | 560 |
/// Equality operator. |
| 560 | 561 |
/// Two iterators are equal if and only if they point to the |
| 561 | 562 |
/// same object or both are invalid. |
| 562 | 563 |
bool operator==(const GraphIncIt&) const { return true;}
|
| 563 | 564 |
|
| 564 | 565 |
/// \brief Inequality operator |
| 565 | 566 |
/// |
| 566 | 567 |
/// Inequality operator. |
| 567 | 568 |
/// Two iterators are equal if and only if they point to the |
| 568 | 569 |
/// same object or both are invalid. |
| 569 | 570 |
bool operator!=(const GraphIncIt&) const { return true;}
|
| 570 | 571 |
|
| 571 | 572 |
template <typename _GraphIncIt> |
| 572 | 573 |
struct Constraints {
|
| 573 | 574 |
void constraints() {
|
| 574 | 575 |
checkConcept<GraphItem<sel>, _GraphIncIt>(); |
| 575 | 576 |
_GraphIncIt it1(graph, node); |
| 576 | 577 |
_GraphIncIt it2; |
| 577 | 578 |
_GraphIncIt it3 = it1; |
| 578 | 579 |
_GraphIncIt it4 = INVALID; |
| 579 | 580 |
|
| 580 | 581 |
it2 = ++it1; |
| 581 | 582 |
++it2 = it1; |
| 582 | 583 |
++(++it1); |
| 583 | 584 |
Item e = it1; |
| 584 | 585 |
e = it2; |
| 585 | 586 |
} |
| 586 | 587 |
const Base& node; |
| 587 | 588 |
const GR& graph; |
| 588 | 589 |
}; |
| 589 | 590 |
}; |
| 590 | 591 |
|
| 591 | 592 |
/// \brief Skeleton class for iterable directed graphs. |
| 592 | 593 |
/// |
| 593 | 594 |
/// This class describes the interface of iterable directed |
| 594 | 595 |
/// graphs. It extends \ref BaseDigraphComponent with the core |
| 595 | 596 |
/// iterable interface. |
| 596 | 597 |
/// This concept is part of the Digraph concept. |
| 597 | 598 |
template <typename BAS = BaseDigraphComponent> |
| 598 | 599 |
class IterableDigraphComponent : public BAS {
|
| 599 | 600 |
|
| 600 | 601 |
public: |
| 601 | 602 |
|
| 602 | 603 |
typedef BAS Base; |
| 603 | 604 |
typedef typename Base::Node Node; |
| 604 | 605 |
typedef typename Base::Arc Arc; |
| 605 | 606 |
|
| 606 | 607 |
typedef IterableDigraphComponent Digraph; |
| 607 | 608 |
|
| 608 | 609 |
/// \name Base Iteration |
| 609 | 610 |
/// |
| 610 | 611 |
/// This interface provides functions for iteration on digraph items. |
| 611 | 612 |
/// |
| 612 | 613 |
/// @{
|
| 613 | 614 |
|
| 614 | 615 |
/// \brief Return the first node. |
| 615 | 616 |
/// |
| 616 | 617 |
/// This function gives back the first node in the iteration order. |
| 617 | 618 |
void first(Node&) const {}
|
| 618 | 619 |
|
| 619 | 620 |
/// \brief Return the next node. |
| 620 | 621 |
/// |
| 621 | 622 |
/// This function gives back the next node in the iteration order. |
| 622 | 623 |
void next(Node&) const {}
|
| 623 | 624 |
|
| 624 | 625 |
/// \brief Return the first arc. |
| 625 | 626 |
/// |
| 626 | 627 |
/// This function gives back the first arc in the iteration order. |
| 627 | 628 |
void first(Arc&) const {}
|
| 628 | 629 |
|
| 629 | 630 |
/// \brief Return the next arc. |
| 630 | 631 |
/// |
| 631 | 632 |
/// This function gives back the next arc in the iteration order. |
| 632 | 633 |
void next(Arc&) const {}
|
| 633 | 634 |
|
| 634 | 635 |
/// \brief Return the first arc incomming to the given node. |
| 635 | 636 |
/// |
| 636 | 637 |
/// This function gives back the first arc incomming to the |
| 637 | 638 |
/// given node. |
| 638 | 639 |
void firstIn(Arc&, const Node&) const {}
|
| 639 | 640 |
|
| 640 | 641 |
/// \brief Return the next arc incomming to the given node. |
| 641 | 642 |
/// |
| 642 | 643 |
/// This function gives back the next arc incomming to the |
| 643 | 644 |
/// given node. |
| 644 | 645 |
void nextIn(Arc&) const {}
|
| 645 | 646 |
|
| 646 | 647 |
/// \brief Return the first arc outgoing form the given node. |
| 647 | 648 |
/// |
| 648 | 649 |
/// This function gives back the first arc outgoing form the |
| 649 | 650 |
/// given node. |
| 650 | 651 |
void firstOut(Arc&, const Node&) const {}
|
| 651 | 652 |
|
| 652 | 653 |
/// \brief Return the next arc outgoing form the given node. |
| 653 | 654 |
/// |
| 654 | 655 |
/// This function gives back the next arc outgoing form the |
| 655 | 656 |
/// given node. |
| 656 | 657 |
void nextOut(Arc&) const {}
|
| 657 | 658 |
|
| 658 | 659 |
/// @} |
| 659 | 660 |
|
| 660 | 661 |
/// \name Class Based Iteration |
| 661 | 662 |
/// |
| 662 | 663 |
/// This interface provides iterator classes for digraph items. |
| 663 | 664 |
/// |
| 664 | 665 |
/// @{
|
| 665 | 666 |
|
| 666 | 667 |
/// \brief This iterator goes through each node. |
| 667 | 668 |
/// |
| 668 | 669 |
/// This iterator goes through each node. |
| 669 | 670 |
/// |
| 670 | 671 |
typedef GraphItemIt<Digraph, Node> NodeIt; |
| 671 | 672 |
|
| 672 | 673 |
/// \brief This iterator goes through each arc. |
| 673 | 674 |
/// |
| 674 | 675 |
/// This iterator goes through each arc. |
| 675 | 676 |
/// |
| 676 | 677 |
typedef GraphItemIt<Digraph, Arc> ArcIt; |
| 677 | 678 |
|
| 678 | 679 |
/// \brief This iterator goes trough the incoming arcs of a node. |
| 679 | 680 |
/// |
| 680 | 681 |
/// This iterator goes trough the \e incoming arcs of a certain node |
| 681 | 682 |
/// of a digraph. |
| 682 | 683 |
typedef GraphIncIt<Digraph, Arc, Node, 'i'> InArcIt; |
| 683 | 684 |
|
| 684 | 685 |
/// \brief This iterator goes trough the outgoing arcs of a node. |
| 685 | 686 |
/// |
| 686 | 687 |
/// This iterator goes trough the \e outgoing arcs of a certain node |
| 687 | 688 |
/// of a digraph. |
| 688 | 689 |
typedef GraphIncIt<Digraph, Arc, Node, 'o'> OutArcIt; |
| 689 | 690 |
|
| 690 | 691 |
/// \brief The base node of the iterator. |
| 691 | 692 |
/// |
| 692 | 693 |
/// This function gives back the base node of the iterator. |
| 693 | 694 |
/// It is always the target node of the pointed arc. |
| 694 | 695 |
Node baseNode(const InArcIt&) const { return INVALID; }
|
| 695 | 696 |
|
| 696 | 697 |
/// \brief The running node of the iterator. |
| 697 | 698 |
/// |
| 698 | 699 |
/// This function gives back the running node of the iterator. |
| 699 | 700 |
/// It is always the source node of the pointed arc. |
| 700 | 701 |
Node runningNode(const InArcIt&) const { return INVALID; }
|
| 701 | 702 |
|
| 702 | 703 |
/// \brief The base node of the iterator. |
| 703 | 704 |
/// |
| 704 | 705 |
/// This function gives back the base node of the iterator. |
| 705 | 706 |
/// It is always the source node of the pointed arc. |
| 706 | 707 |
Node baseNode(const OutArcIt&) const { return INVALID; }
|
| 707 | 708 |
|
| 708 | 709 |
/// \brief The running node of the iterator. |
| 709 | 710 |
/// |
| 710 | 711 |
/// This function gives back the running node of the iterator. |
| 711 | 712 |
/// It is always the target node of the pointed arc. |
| 712 | 713 |
Node runningNode(const OutArcIt&) const { return INVALID; }
|
| 713 | 714 |
|
| 714 | 715 |
/// @} |
| 715 | 716 |
|
| 716 | 717 |
template <typename _Digraph> |
| 717 | 718 |
struct Constraints {
|
| 718 | 719 |
void constraints() {
|
| 719 | 720 |
checkConcept<Base, _Digraph>(); |
| 720 | 721 |
|
| 721 | 722 |
{
|
| 722 | 723 |
typename _Digraph::Node node(INVALID); |
| 723 | 724 |
typename _Digraph::Arc arc(INVALID); |
| 724 | 725 |
{
|
| 725 | 726 |
digraph.first(node); |
| 726 | 727 |
digraph.next(node); |
| 727 | 728 |
} |
| 728 | 729 |
{
|
| 729 | 730 |
digraph.first(arc); |
| 730 | 731 |
digraph.next(arc); |
| 731 | 732 |
} |
| 732 | 733 |
{
|
| 733 | 734 |
digraph.firstIn(arc, node); |
| 734 | 735 |
digraph.nextIn(arc); |
| 735 | 736 |
} |
| 736 | 737 |
{
|
| 737 | 738 |
digraph.firstOut(arc, node); |
| 738 | 739 |
digraph.nextOut(arc); |
| 739 | 740 |
} |
| 740 | 741 |
} |
| 741 | 742 |
|
| 742 | 743 |
{
|
| 743 | 744 |
checkConcept<GraphItemIt<_Digraph, typename _Digraph::Arc>, |
| 744 | 745 |
typename _Digraph::ArcIt >(); |
| 745 | 746 |
checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>, |
| 746 | 747 |
typename _Digraph::NodeIt >(); |
| 747 | 748 |
checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, |
| 748 | 749 |
typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>(); |
| 749 | 750 |
checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, |
| 750 | 751 |
typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>(); |
| 751 | 752 |
|
| 752 | 753 |
typename _Digraph::Node n; |
| 753 | 754 |
const typename _Digraph::InArcIt iait(INVALID); |
| 754 | 755 |
const typename _Digraph::OutArcIt oait(INVALID); |
| 755 | 756 |
n = digraph.baseNode(iait); |
| 756 | 757 |
n = digraph.runningNode(iait); |
| 757 | 758 |
n = digraph.baseNode(oait); |
| 758 | 759 |
n = digraph.runningNode(oait); |
| 759 | 760 |
ignore_unused_variable_warning(n); |
| 760 | 761 |
} |
| 761 | 762 |
} |
| 762 | 763 |
|
| 763 | 764 |
const _Digraph& digraph; |
| 764 | 765 |
}; |
| 765 | 766 |
}; |
| 766 | 767 |
|
| 767 | 768 |
/// \brief Skeleton class for iterable undirected graphs. |
| 768 | 769 |
/// |
| 769 | 770 |
/// This class describes the interface of iterable undirected |
| 770 | 771 |
/// graphs. It extends \ref IterableDigraphComponent with the core |
| 771 | 772 |
/// iterable interface of undirected graphs. |
| 772 | 773 |
/// This concept is part of the Graph concept. |
| 773 | 774 |
template <typename BAS = BaseGraphComponent> |
| 774 | 775 |
class IterableGraphComponent : public IterableDigraphComponent<BAS> {
|
| 775 | 776 |
public: |
| 776 | 777 |
|
| 777 | 778 |
typedef BAS Base; |
| 778 | 779 |
typedef typename Base::Node Node; |
| 779 | 780 |
typedef typename Base::Arc Arc; |
| 780 | 781 |
typedef typename Base::Edge Edge; |
| 781 | 782 |
|
| 782 | 783 |
|
| 783 | 784 |
typedef IterableGraphComponent Graph; |
| 784 | 785 |
|
| 785 | 786 |
/// \name Base Iteration |
| 786 | 787 |
/// |
| 787 | 788 |
/// This interface provides functions for iteration on edges. |
| 788 | 789 |
/// |
| 789 | 790 |
/// @{
|
| 790 | 791 |
|
| 791 | 792 |
using IterableDigraphComponent<Base>::first; |
| 792 | 793 |
using IterableDigraphComponent<Base>::next; |
| 793 | 794 |
|
| 794 | 795 |
/// \brief Return the first edge. |
| 795 | 796 |
/// |
| 796 | 797 |
/// This function gives back the first edge in the iteration order. |
| 797 | 798 |
void first(Edge&) const {}
|
| 798 | 799 |
|
| 799 | 800 |
/// \brief Return the next edge. |
| 800 | 801 |
/// |
| 801 | 802 |
/// This function gives back the next edge in the iteration order. |
| 802 | 803 |
void next(Edge&) const {}
|
| 803 | 804 |
|
| 804 | 805 |
/// \brief Return the first edge incident to the given node. |
| 805 | 806 |
/// |
| 806 | 807 |
/// This function gives back the first edge incident to the given |
| 807 | 808 |
/// node. The bool parameter gives back the direction for which the |
| 808 | 809 |
/// source node of the directed arc representing the edge is the |
| 809 | 810 |
/// given node. |
| 810 | 811 |
void firstInc(Edge&, bool&, const Node&) const {}
|
| 811 | 812 |
|
| 812 | 813 |
/// \brief Gives back the next of the edges from the |
| 813 | 814 |
/// given node. |
| 814 | 815 |
/// |
| 815 | 816 |
/// This function gives back the next edge incident to the given |
| 816 | 817 |
/// node. The bool parameter should be used as \c firstInc() use it. |
| 817 | 818 |
void nextInc(Edge&, bool&) const {}
|
| 818 | 819 |
|
| 819 | 820 |
using IterableDigraphComponent<Base>::baseNode; |
| 820 | 821 |
using IterableDigraphComponent<Base>::runningNode; |
| 821 | 822 |
|
| 822 | 823 |
/// @} |
| 823 | 824 |
|
| 824 | 825 |
/// \name Class Based Iteration |
| 825 | 826 |
/// |
| 826 | 827 |
/// This interface provides iterator classes for edges. |
| 827 | 828 |
/// |
| 828 | 829 |
/// @{
|
| 829 | 830 |
|
| 830 | 831 |
/// \brief This iterator goes through each edge. |
| 831 | 832 |
/// |
| 832 | 833 |
/// This iterator goes through each edge. |
| 833 | 834 |
typedef GraphItemIt<Graph, Edge> EdgeIt; |
| 834 | 835 |
|
| 835 | 836 |
/// \brief This iterator goes trough the incident edges of a |
| 836 | 837 |
/// node. |
| 837 | 838 |
/// |
| 838 | 839 |
/// This iterator goes trough the incident edges of a certain |
| 839 | 840 |
/// node of a graph. |
| 840 | 841 |
typedef GraphIncIt<Graph, Edge, Node, 'e'> IncEdgeIt; |
| 841 | 842 |
|
| 842 | 843 |
/// \brief The base node of the iterator. |
| 843 | 844 |
/// |
| 844 | 845 |
/// This function gives back the base node of the iterator. |
| 845 | 846 |
Node baseNode(const IncEdgeIt&) const { return INVALID; }
|
| 846 | 847 |
|
| 847 | 848 |
/// \brief The running node of the iterator. |
| 848 | 849 |
/// |
| 849 | 850 |
/// This function gives back the running node of the iterator. |
| 850 | 851 |
Node runningNode(const IncEdgeIt&) const { return INVALID; }
|
| 851 | 852 |
|
| 852 | 853 |
/// @} |
| 853 | 854 |
|
| 854 | 855 |
template <typename _Graph> |
| 855 | 856 |
struct Constraints {
|
| 856 | 857 |
void constraints() {
|
| 857 | 858 |
checkConcept<IterableDigraphComponent<Base>, _Graph>(); |
| 858 | 859 |
|
| 859 | 860 |
{
|
| 860 | 861 |
typename _Graph::Node node(INVALID); |
| 861 | 862 |
typename _Graph::Edge edge(INVALID); |
| 862 | 863 |
bool dir; |
| 863 | 864 |
{
|
| 864 | 865 |
graph.first(edge); |
| 865 | 866 |
graph.next(edge); |
| 866 | 867 |
} |
| 867 | 868 |
{
|
| 868 | 869 |
graph.firstInc(edge, dir, node); |
| 869 | 870 |
graph.nextInc(edge, dir); |
| 870 | 871 |
} |
| 871 | 872 |
|
| 872 | 873 |
} |
| 873 | 874 |
|
| 874 | 875 |
{
|
| 875 | 876 |
checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>, |
| 876 | 877 |
typename _Graph::EdgeIt >(); |
| 877 | 878 |
checkConcept<GraphIncIt<_Graph, typename _Graph::Edge, |
| 878 | 879 |
typename _Graph::Node, 'e'>, typename _Graph::IncEdgeIt>(); |
| 879 | 880 |
|
| 880 | 881 |
typename _Graph::Node n; |
| 881 | 882 |
const typename _Graph::IncEdgeIt ieit(INVALID); |
| 882 | 883 |
n = graph.baseNode(ieit); |
| 883 | 884 |
n = graph.runningNode(ieit); |
| 884 | 885 |
} |
| 885 | 886 |
} |
| 886 | 887 |
|
| 887 | 888 |
const _Graph& graph; |
| 888 | 889 |
}; |
| 889 | 890 |
}; |
| 890 | 891 |
|
| 891 | 892 |
/// \brief Skeleton class for alterable directed graphs. |
| 892 | 893 |
/// |
| 893 | 894 |
/// This class describes the interface of alterable directed |
| 894 | 895 |
/// graphs. It extends \ref BaseDigraphComponent with the alteration |
| 895 | 896 |
/// notifier interface. It implements |
| 896 | 897 |
/// an observer-notifier pattern for each digraph item. More |
| 897 | 898 |
/// obsevers can be registered into the notifier and whenever an |
| 898 | 899 |
/// alteration occured in the digraph all the observers will be |
| 899 | 900 |
/// notified about it. |
| 900 | 901 |
template <typename BAS = BaseDigraphComponent> |
| 901 | 902 |
class AlterableDigraphComponent : public BAS {
|
| 902 | 903 |
public: |
| 903 | 904 |
|
| 904 | 905 |
typedef BAS Base; |
| 905 | 906 |
typedef typename Base::Node Node; |
| 906 | 907 |
typedef typename Base::Arc Arc; |
| 907 | 908 |
|
| 908 | 909 |
|
| 909 | 910 |
/// Node alteration notifier class. |
| 910 | 911 |
typedef AlterationNotifier<AlterableDigraphComponent, Node> |
| 911 | 912 |
NodeNotifier; |
| 912 | 913 |
/// Arc alteration notifier class. |
| 913 | 914 |
typedef AlterationNotifier<AlterableDigraphComponent, Arc> |
| 914 | 915 |
ArcNotifier; |
| 915 | 916 |
|
| 916 | 917 |
/// \brief Return the node alteration notifier. |
| 917 | 918 |
/// |
| 918 | 919 |
/// This function gives back the node alteration notifier. |
| 919 | 920 |
NodeNotifier& notifier(Node) const {
|
| 920 | 921 |
return NodeNotifier(); |
| 921 | 922 |
} |
| 922 | 923 |
|
| 923 | 924 |
/// \brief Return the arc alteration notifier. |
| 924 | 925 |
/// |
| 925 | 926 |
/// This function gives back the arc alteration notifier. |
| 926 | 927 |
ArcNotifier& notifier(Arc) const {
|
| 927 | 928 |
return ArcNotifier(); |
| 928 | 929 |
} |
| 929 | 930 |
|
| 930 | 931 |
template <typename _Digraph> |
| 931 | 932 |
struct Constraints {
|
| 932 | 933 |
void constraints() {
|
| 933 | 934 |
checkConcept<Base, _Digraph>(); |
| 934 | 935 |
typename _Digraph::NodeNotifier& nn |
| 935 | 936 |
= digraph.notifier(typename _Digraph::Node()); |
| 936 | 937 |
|
| 937 | 938 |
typename _Digraph::ArcNotifier& en |
| 938 | 939 |
= digraph.notifier(typename _Digraph::Arc()); |
| 939 | 940 |
|
| 940 | 941 |
ignore_unused_variable_warning(nn); |
| 941 | 942 |
ignore_unused_variable_warning(en); |
| 942 | 943 |
} |
| 943 | 944 |
|
| 944 | 945 |
const _Digraph& digraph; |
| 945 | 946 |
}; |
| 946 | 947 |
}; |
| 947 | 948 |
|
| 948 | 949 |
/// \brief Skeleton class for alterable undirected graphs. |
| 949 | 950 |
/// |
| 950 | 951 |
/// This class describes the interface of alterable undirected |
| 951 | 952 |
/// graphs. It extends \ref AlterableDigraphComponent with the alteration |
| 952 | 953 |
/// notifier interface of undirected graphs. It implements |
| 953 | 954 |
/// an observer-notifier pattern for the edges. More |
| 954 | 955 |
/// obsevers can be registered into the notifier and whenever an |
| 955 | 956 |
/// alteration occured in the graph all the observers will be |
| 956 | 957 |
/// notified about it. |
| 957 | 958 |
template <typename BAS = BaseGraphComponent> |
| 958 | 959 |
class AlterableGraphComponent : public AlterableDigraphComponent<BAS> {
|
| 959 | 960 |
public: |
| 960 | 961 |
|
| 961 | 962 |
typedef BAS Base; |
| 962 | 963 |
typedef typename Base::Edge Edge; |
| 963 | 964 |
|
| 964 | 965 |
|
| 965 | 966 |
/// Edge alteration notifier class. |
| 966 | 967 |
typedef AlterationNotifier<AlterableGraphComponent, Edge> |
| 967 | 968 |
EdgeNotifier; |
| 968 | 969 |
|
| 969 | 970 |
/// \brief Return the edge alteration notifier. |
| 970 | 971 |
/// |
| 971 | 972 |
/// This function gives back the edge alteration notifier. |
| 972 | 973 |
EdgeNotifier& notifier(Edge) const {
|
| 973 | 974 |
return EdgeNotifier(); |
| 974 | 975 |
} |
| 975 | 976 |
|
| 976 | 977 |
template <typename _Graph> |
| 977 | 978 |
struct Constraints {
|
| 978 | 979 |
void constraints() {
|
| 979 | 980 |
checkConcept<AlterableDigraphComponent<Base>, _Graph>(); |
| 980 | 981 |
typename _Graph::EdgeNotifier& uen |
| 981 | 982 |
= graph.notifier(typename _Graph::Edge()); |
| 982 | 983 |
ignore_unused_variable_warning(uen); |
| 983 | 984 |
} |
| 984 | 985 |
|
| 985 | 986 |
const _Graph& graph; |
| 986 | 987 |
}; |
| 987 | 988 |
}; |
| 988 | 989 |
|
| 989 | 990 |
/// \brief Concept class for standard graph maps. |
| 990 | 991 |
/// |
| 991 | 992 |
/// This class describes the concept of standard graph maps, i.e. |
| 992 | 993 |
/// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and |
| 993 | 994 |
/// graph types, which can be used for associating data to graph items. |
| 994 | 995 |
/// The standard graph maps must conform to the ReferenceMap concept. |
| 995 | 996 |
template <typename GR, typename K, typename V> |
| 996 | 997 |
class GraphMap : public ReferenceMap<K, V, V&, const V&> {
|
| 997 | 998 |
typedef ReferenceMap<K, V, V&, const V&> Parent; |
| 998 | 999 |
|
| 999 | 1000 |
public: |
| 1000 | 1001 |
|
| 1001 | 1002 |
/// The key type of the map. |
| 1002 | 1003 |
typedef K Key; |
| 1003 | 1004 |
/// The value type of the map. |
| 1004 | 1005 |
typedef V Value; |
| 1005 | 1006 |
/// The reference type of the map. |
| 1006 | 1007 |
typedef Value& Reference; |
| 1007 | 1008 |
/// The const reference type of the map. |
| 1008 | 1009 |
typedef const Value& ConstReference; |
| 1009 | 1010 |
|
| 1010 | 1011 |
// The reference map tag. |
| 1011 | 1012 |
typedef True ReferenceMapTag; |
| 1012 | 1013 |
|
| 1013 | 1014 |
/// \brief Construct a new map. |
| 1014 | 1015 |
/// |
| 1015 | 1016 |
/// Construct a new map for the graph. |
| 1016 | 1017 |
explicit GraphMap(const GR&) {}
|
| 1017 | 1018 |
/// \brief Construct a new map with default value. |
| 1018 | 1019 |
/// |
| 1019 | 1020 |
/// Construct a new map for the graph and initalize the values. |
| 1020 | 1021 |
GraphMap(const GR&, const Value&) {}
|
| 1021 | 1022 |
|
| 1022 | 1023 |
private: |
| 1023 | 1024 |
/// \brief Copy constructor. |
| 1024 | 1025 |
/// |
| 1025 | 1026 |
/// Copy Constructor. |
| 1026 | 1027 |
GraphMap(const GraphMap&) : Parent() {}
|
| 1027 | 1028 |
|
| 1028 | 1029 |
/// \brief Assignment operator. |
| 1029 | 1030 |
/// |
| 1030 | 1031 |
/// Assignment operator. It does not mofify the underlying graph, |
| 1031 | 1032 |
/// it just iterates on the current item set and set the map |
| 1032 | 1033 |
/// with the value returned by the assigned map. |
| 1033 | 1034 |
template <typename CMap> |
| 1034 | 1035 |
GraphMap& operator=(const CMap&) {
|
| 1035 | 1036 |
checkConcept<ReadMap<Key, Value>, CMap>(); |
| 1036 | 1037 |
return *this; |
| 1037 | 1038 |
} |
| 1038 | 1039 |
|
| 1039 | 1040 |
public: |
| 1040 | 1041 |
template<typename _Map> |
| 1041 | 1042 |
struct Constraints {
|
| 1042 | 1043 |
void constraints() {
|
| 1043 | 1044 |
checkConcept |
| 1044 | 1045 |
<ReferenceMap<Key, Value, Value&, const Value&>, _Map>(); |
| 1045 | 1046 |
_Map m1(g); |
| 1046 | 1047 |
_Map m2(g,t); |
| 1047 | 1048 |
|
| 1048 | 1049 |
// Copy constructor |
| 1049 | 1050 |
// _Map m3(m); |
| 1050 | 1051 |
|
| 1051 | 1052 |
// Assignment operator |
| 1052 | 1053 |
// ReadMap<Key, Value> cmap; |
| 1053 | 1054 |
// m3 = cmap; |
| 1054 | 1055 |
|
| 1055 | 1056 |
ignore_unused_variable_warning(m1); |
| 1056 | 1057 |
ignore_unused_variable_warning(m2); |
| 1057 | 1058 |
// ignore_unused_variable_warning(m3); |
| 1058 | 1059 |
} |
| 1059 | 1060 |
|
| 1060 | 1061 |
const _Map &m; |
| 1061 | 1062 |
const GR &g; |
| 1062 | 1063 |
const typename GraphMap::Value &t; |
| 1063 | 1064 |
}; |
| 1064 | 1065 |
|
| 1065 | 1066 |
}; |
| 1066 | 1067 |
|
| 1067 | 1068 |
/// \brief Skeleton class for mappable directed graphs. |
| 1068 | 1069 |
/// |
| 1069 | 1070 |
/// This class describes the interface of mappable directed graphs. |
| 1070 | 1071 |
/// It extends \ref BaseDigraphComponent with the standard digraph |
| 1071 | 1072 |
/// map classes, namely \c NodeMap and \c ArcMap. |
| 1072 | 1073 |
/// This concept is part of the Digraph concept. |
| 1073 | 1074 |
template <typename BAS = BaseDigraphComponent> |
| 1074 | 1075 |
class MappableDigraphComponent : public BAS {
|
| 1075 | 1076 |
public: |
| 1076 | 1077 |
|
| 1077 | 1078 |
typedef BAS Base; |
| 1078 | 1079 |
typedef typename Base::Node Node; |
| 1079 | 1080 |
typedef typename Base::Arc Arc; |
| 1080 | 1081 |
|
| 1081 | 1082 |
typedef MappableDigraphComponent Digraph; |
| 1082 | 1083 |
|
| 1083 | 1084 |
/// \brief Standard graph map for the nodes. |
| 1084 | 1085 |
/// |
| 1085 | 1086 |
/// Standard graph map for the nodes. |
| 1086 | 1087 |
/// It conforms to the ReferenceMap concept. |
| 1087 | 1088 |
template <typename V> |
| 1088 | 1089 |
class NodeMap : public GraphMap<MappableDigraphComponent, Node, V> {
|
| 1089 | 1090 |
typedef GraphMap<MappableDigraphComponent, Node, V> Parent; |
| 1090 | 1091 |
|
| 1091 | 1092 |
public: |
| 1092 | 1093 |
/// \brief Construct a new map. |
| 1093 | 1094 |
/// |
| 1094 | 1095 |
/// Construct a new map for the digraph. |
| 1095 | 1096 |
explicit NodeMap(const MappableDigraphComponent& digraph) |
| 1096 | 1097 |
: Parent(digraph) {}
|
| 1097 | 1098 |
|
| 1098 | 1099 |
/// \brief Construct a new map with default value. |
| 1099 | 1100 |
/// |
| 1100 | 1101 |
/// Construct a new map for the digraph and initalize the values. |
| 1101 | 1102 |
NodeMap(const MappableDigraphComponent& digraph, const V& value) |
| 1102 | 1103 |
: Parent(digraph, value) {}
|
| 1103 | 1104 |
|
| 1104 | 1105 |
private: |
| 1105 | 1106 |
/// \brief Copy constructor. |
| 1106 | 1107 |
/// |
| 1107 | 1108 |
/// Copy Constructor. |
| 1108 | 1109 |
NodeMap(const NodeMap& nm) : Parent(nm) {}
|
| 1109 | 1110 |
|
| 1110 | 1111 |
/// \brief Assignment operator. |
| 1111 | 1112 |
/// |
| 1112 | 1113 |
/// Assignment operator. |
| 1113 | 1114 |
template <typename CMap> |
| 1114 | 1115 |
NodeMap& operator=(const CMap&) {
|
| 1115 | 1116 |
checkConcept<ReadMap<Node, V>, CMap>(); |
| 1116 | 1117 |
return *this; |
| 1117 | 1118 |
} |
| 1118 | 1119 |
|
| 1119 | 1120 |
}; |
| 1120 | 1121 |
|
| 1121 | 1122 |
/// \brief Standard graph map for the arcs. |
| 1122 | 1123 |
/// |
| 1123 | 1124 |
/// Standard graph map for the arcs. |
| 1124 | 1125 |
/// It conforms to the ReferenceMap concept. |
| 1125 | 1126 |
template <typename V> |
| 1126 | 1127 |
class ArcMap : public GraphMap<MappableDigraphComponent, Arc, V> {
|
| 1127 | 1128 |
typedef GraphMap<MappableDigraphComponent, Arc, V> Parent; |
0 comments (0 inline)