[209] | 1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
[57] | 2 | * |
---|
[209] | 3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
[57] | 4 | * |
---|
[956] | 5 | * Copyright (C) 2003-2010 |
---|
[57] | 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | ///\ingroup graph_concepts |
---|
| 20 | ///\file |
---|
[833] | 21 | ///\brief The concepts of graph components. |
---|
[57] | 22 | |
---|
[576] | 23 | #ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
---|
| 24 | #define LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
---|
[57] | 25 | |
---|
[220] | 26 | #include <lemon/core.h> |
---|
[57] | 27 | #include <lemon/concepts/maps.h> |
---|
| 28 | |
---|
| 29 | #include <lemon/bits/alteration_notifier.h> |
---|
| 30 | |
---|
| 31 | namespace lemon { |
---|
| 32 | namespace concepts { |
---|
| 33 | |
---|
[626] | 34 | /// \brief Concept class for \c Node, \c Arc and \c Edge types. |
---|
[57] | 35 | /// |
---|
[626] | 36 | /// This class describes the concept of \c Node, \c Arc and \c Edge |
---|
| 37 | /// subtypes of digraph and graph types. |
---|
[57] | 38 | /// |
---|
| 39 | /// \note This class is a template class so that we can use it to |
---|
[626] | 40 | /// create graph skeleton classes. The reason for this is that \c Node |
---|
[956] | 41 | /// and \c Arc (or \c Edge) types should \e not derive from the same |
---|
[626] | 42 | /// base class. For \c Node you should instantiate it with character |
---|
| 43 | /// \c 'n', for \c Arc with \c 'a' and for \c Edge with \c 'e'. |
---|
[57] | 44 | #ifndef DOXYGEN |
---|
[606] | 45 | template <char sel = '0'> |
---|
[57] | 46 | #endif |
---|
| 47 | class GraphItem { |
---|
| 48 | public: |
---|
| 49 | /// \brief Default constructor. |
---|
[209] | 50 | /// |
---|
[626] | 51 | /// Default constructor. |
---|
[57] | 52 | /// \warning The default constructor is not required to set |
---|
| 53 | /// the item to some well-defined value. So you should consider it |
---|
| 54 | /// as uninitialized. |
---|
| 55 | GraphItem() {} |
---|
[626] | 56 | |
---|
[57] | 57 | /// \brief Copy constructor. |
---|
| 58 | /// |
---|
| 59 | /// Copy constructor. |
---|
[626] | 60 | GraphItem(const GraphItem &) {} |
---|
| 61 | |
---|
| 62 | /// \brief Constructor for conversion from \c INVALID. |
---|
[57] | 63 | /// |
---|
[626] | 64 | /// Constructor for conversion from \c INVALID. |
---|
| 65 | /// It initializes the item to be invalid. |
---|
[57] | 66 | /// \sa Invalid for more details. |
---|
| 67 | GraphItem(Invalid) {} |
---|
[626] | 68 | |
---|
| 69 | /// \brief Assignment operator. |
---|
[57] | 70 | /// |
---|
[626] | 71 | /// Assignment operator for the item. |
---|
| 72 | GraphItem& operator=(const GraphItem&) { return *this; } |
---|
| 73 | |
---|
[713] | 74 | /// \brief Assignment operator for INVALID. |
---|
| 75 | /// |
---|
| 76 | /// This operator makes the item invalid. |
---|
| 77 | GraphItem& operator=(Invalid) { return *this; } |
---|
| 78 | |
---|
[57] | 79 | /// \brief Equality operator. |
---|
| 80 | /// |
---|
[626] | 81 | /// Equality operator. |
---|
| 82 | bool operator==(const GraphItem&) const { return false; } |
---|
| 83 | |
---|
[57] | 84 | /// \brief Inequality operator. |
---|
| 85 | /// |
---|
[626] | 86 | /// Inequality operator. |
---|
| 87 | bool operator!=(const GraphItem&) const { return false; } |
---|
| 88 | |
---|
| 89 | /// \brief Ordering operator. |
---|
[57] | 90 | /// |
---|
[626] | 91 | /// This operator defines an ordering of the items. |
---|
[956] | 92 | /// It makes possible to use graph item types as key types in |
---|
[626] | 93 | /// associative containers (e.g. \c std::map). |
---|
[57] | 94 | /// |
---|
[781] | 95 | /// \note This operator only has to define some strict ordering of |
---|
[57] | 96 | /// the items; this order has nothing to do with the iteration |
---|
| 97 | /// ordering of the items. |
---|
[626] | 98 | bool operator<(const GraphItem&) const { return false; } |
---|
[57] | 99 | |
---|
| 100 | template<typename _GraphItem> |
---|
| 101 | struct Constraints { |
---|
[209] | 102 | void constraints() { |
---|
| 103 | _GraphItem i1; |
---|
[713] | 104 | i1=INVALID; |
---|
[209] | 105 | _GraphItem i2 = i1; |
---|
| 106 | _GraphItem i3 = INVALID; |
---|
[57] | 107 | |
---|
[209] | 108 | i1 = i2 = i3; |
---|
| 109 | |
---|
| 110 | bool b; |
---|
[1171] | 111 | ignore_unused_variable_warning(b); |
---|
| 112 | |
---|
[209] | 113 | b = (ia == ib) && (ia != ib); |
---|
| 114 | b = (ia == INVALID) && (ib != INVALID); |
---|
[57] | 115 | b = (ia < ib); |
---|
[209] | 116 | } |
---|
[57] | 117 | |
---|
[209] | 118 | const _GraphItem &ia; |
---|
| 119 | const _GraphItem &ib; |
---|
[1125] | 120 | Constraints() {} |
---|
[57] | 121 | }; |
---|
| 122 | }; |
---|
| 123 | |
---|
[626] | 124 | /// \brief Base skeleton class for directed graphs. |
---|
[209] | 125 | /// |
---|
[626] | 126 | /// This class describes the base interface of directed graph types. |
---|
| 127 | /// All digraph %concepts have to conform to this class. |
---|
[956] | 128 | /// It just provides types for nodes and arcs and functions |
---|
[626] | 129 | /// to get the source and the target nodes of arcs. |
---|
[57] | 130 | class BaseDigraphComponent { |
---|
| 131 | public: |
---|
| 132 | |
---|
| 133 | typedef BaseDigraphComponent Digraph; |
---|
[209] | 134 | |
---|
[57] | 135 | /// \brief Node class of the digraph. |
---|
| 136 | /// |
---|
[626] | 137 | /// This class represents the nodes of the digraph. |
---|
[57] | 138 | typedef GraphItem<'n'> Node; |
---|
| 139 | |
---|
| 140 | /// \brief Arc class of the digraph. |
---|
| 141 | /// |
---|
[626] | 142 | /// This class represents the arcs of the digraph. |
---|
| 143 | typedef GraphItem<'a'> Arc; |
---|
| 144 | |
---|
| 145 | /// \brief Return the source node of an arc. |
---|
[57] | 146 | /// |
---|
[626] | 147 | /// This function returns the source node of an arc. |
---|
| 148 | Node source(const Arc&) const { return INVALID; } |
---|
[57] | 149 | |
---|
[626] | 150 | /// \brief Return the target node of an arc. |
---|
[57] | 151 | /// |
---|
[626] | 152 | /// This function returns the target node of an arc. |
---|
| 153 | Node target(const Arc&) const { return INVALID; } |
---|
| 154 | |
---|
| 155 | /// \brief Return the opposite node on the given arc. |
---|
[57] | 156 | /// |
---|
[626] | 157 | /// This function returns the opposite node on the given arc. |
---|
[57] | 158 | Node oppositeNode(const Node&, const Arc&) const { |
---|
| 159 | return INVALID; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | template <typename _Digraph> |
---|
| 163 | struct Constraints { |
---|
[209] | 164 | typedef typename _Digraph::Node Node; |
---|
| 165 | typedef typename _Digraph::Arc Arc; |
---|
| 166 | |
---|
| 167 | void constraints() { |
---|
| 168 | checkConcept<GraphItem<'n'>, Node>(); |
---|
| 169 | checkConcept<GraphItem<'a'>, Arc>(); |
---|
| 170 | { |
---|
| 171 | Node n; |
---|
| 172 | Arc e(INVALID); |
---|
| 173 | n = digraph.source(e); |
---|
| 174 | n = digraph.target(e); |
---|
[57] | 175 | n = digraph.oppositeNode(n, e); |
---|
[209] | 176 | } |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | const _Digraph& digraph; |
---|
[1125] | 180 | Constraints() {} |
---|
[57] | 181 | }; |
---|
| 182 | }; |
---|
| 183 | |
---|
[626] | 184 | /// \brief Base skeleton class for undirected graphs. |
---|
[209] | 185 | /// |
---|
[626] | 186 | /// This class describes the base interface of undirected graph types. |
---|
| 187 | /// All graph %concepts have to conform to this class. |
---|
| 188 | /// It extends the interface of \ref BaseDigraphComponent with an |
---|
| 189 | /// \c Edge type and functions to get the end nodes of edges, |
---|
| 190 | /// to convert from arcs to edges and to get both direction of edges. |
---|
[57] | 191 | class BaseGraphComponent : public BaseDigraphComponent { |
---|
| 192 | public: |
---|
[664] | 193 | |
---|
| 194 | typedef BaseGraphComponent Graph; |
---|
| 195 | |
---|
[57] | 196 | typedef BaseDigraphComponent::Node Node; |
---|
| 197 | typedef BaseDigraphComponent::Arc Arc; |
---|
[626] | 198 | |
---|
| 199 | /// \brief Undirected edge class of the graph. |
---|
[57] | 200 | /// |
---|
[626] | 201 | /// This class represents the undirected edges of the graph. |
---|
| 202 | /// Undirected graphs can be used as directed graphs, each edge is |
---|
| 203 | /// represented by two opposite directed arcs. |
---|
| 204 | class Edge : public GraphItem<'e'> { |
---|
| 205 | typedef GraphItem<'e'> Parent; |
---|
| 206 | |
---|
[664] | 207 | public: |
---|
[57] | 208 | /// \brief Default constructor. |
---|
[209] | 209 | /// |
---|
[626] | 210 | /// Default constructor. |
---|
[57] | 211 | /// \warning The default constructor is not required to set |
---|
| 212 | /// the item to some well-defined value. So you should consider it |
---|
| 213 | /// as uninitialized. |
---|
| 214 | Edge() {} |
---|
[626] | 215 | |
---|
[57] | 216 | /// \brief Copy constructor. |
---|
| 217 | /// |
---|
| 218 | /// Copy constructor. |
---|
[626] | 219 | Edge(const Edge &) : Parent() {} |
---|
| 220 | |
---|
| 221 | /// \brief Constructor for conversion from \c INVALID. |
---|
[57] | 222 | /// |
---|
[626] | 223 | /// Constructor for conversion from \c INVALID. |
---|
| 224 | /// It initializes the item to be invalid. |
---|
[57] | 225 | /// \sa Invalid for more details. |
---|
| 226 | Edge(Invalid) {} |
---|
[626] | 227 | |
---|
| 228 | /// \brief Constructor for conversion from an arc. |
---|
[57] | 229 | /// |
---|
[626] | 230 | /// Constructor for conversion from an arc. |
---|
[57] | 231 | /// Besides the core graph item functionality each arc should |
---|
[209] | 232 | /// be convertible to the represented edge. |
---|
[57] | 233 | Edge(const Arc&) {} |
---|
[713] | 234 | }; |
---|
[57] | 235 | |
---|
[626] | 236 | /// \brief Return one end node of an edge. |
---|
| 237 | /// |
---|
| 238 | /// This function returns one end node of an edge. |
---|
| 239 | Node u(const Edge&) const { return INVALID; } |
---|
| 240 | |
---|
| 241 | /// \brief Return the other end node of an edge. |
---|
| 242 | /// |
---|
| 243 | /// This function returns the other end node of an edge. |
---|
| 244 | Node v(const Edge&) const { return INVALID; } |
---|
| 245 | |
---|
| 246 | /// \brief Return a directed arc related to an edge. |
---|
| 247 | /// |
---|
| 248 | /// This function returns a directed arc from its direction and the |
---|
| 249 | /// represented edge. |
---|
| 250 | Arc direct(const Edge&, bool) const { return INVALID; } |
---|
| 251 | |
---|
| 252 | /// \brief Return a directed arc related to an edge. |
---|
| 253 | /// |
---|
| 254 | /// This function returns a directed arc from its source node and the |
---|
| 255 | /// represented edge. |
---|
| 256 | Arc direct(const Edge&, const Node&) const { return INVALID; } |
---|
| 257 | |
---|
| 258 | /// \brief Return the direction of the arc. |
---|
[57] | 259 | /// |
---|
| 260 | /// Returns the direction of the arc. Each arc represents an |
---|
| 261 | /// edge with a direction. It gives back the |
---|
| 262 | /// direction. |
---|
| 263 | bool direction(const Arc&) const { return true; } |
---|
| 264 | |
---|
[626] | 265 | /// \brief Return the opposite arc. |
---|
[57] | 266 | /// |
---|
[626] | 267 | /// This function returns the opposite arc, i.e. the arc representing |
---|
| 268 | /// the same edge and has opposite direction. |
---|
| 269 | Arc oppositeArc(const Arc&) const { return INVALID; } |
---|
[209] | 270 | |
---|
[57] | 271 | template <typename _Graph> |
---|
| 272 | struct Constraints { |
---|
[209] | 273 | typedef typename _Graph::Node Node; |
---|
| 274 | typedef typename _Graph::Arc Arc; |
---|
| 275 | typedef typename _Graph::Edge Edge; |
---|
| 276 | |
---|
| 277 | void constraints() { |
---|
[57] | 278 | checkConcept<BaseDigraphComponent, _Graph>(); |
---|
[626] | 279 | checkConcept<GraphItem<'e'>, Edge>(); |
---|
[209] | 280 | { |
---|
| 281 | Node n; |
---|
| 282 | Edge ue(INVALID); |
---|
[57] | 283 | Arc e; |
---|
[209] | 284 | n = graph.u(ue); |
---|
| 285 | n = graph.v(ue); |
---|
[57] | 286 | e = graph.direct(ue, true); |
---|
[626] | 287 | e = graph.direct(ue, false); |
---|
[57] | 288 | e = graph.direct(ue, n); |
---|
| 289 | e = graph.oppositeArc(e); |
---|
| 290 | ue = e; |
---|
| 291 | bool d = graph.direction(e); |
---|
| 292 | ignore_unused_variable_warning(d); |
---|
[209] | 293 | } |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | const _Graph& graph; |
---|
[1125] | 297 | Constraints() {} |
---|
[57] | 298 | }; |
---|
| 299 | |
---|
| 300 | }; |
---|
| 301 | |
---|
[1186] | 302 | /// \brief Base skeleton class for undirected bipartite graphs. |
---|
| 303 | /// |
---|
| 304 | /// This class describes the base interface of undirected |
---|
| 305 | /// bipartite graph types. All bipartite graph %concepts have to |
---|
| 306 | /// conform to this class. It extends the interface of \ref |
---|
| 307 | /// BaseGraphComponent with an \c Edge type and functions to get |
---|
| 308 | /// the end nodes of edges, to convert from arcs to edges and to |
---|
| 309 | /// get both direction of edges. |
---|
| 310 | class BaseBpGraphComponent : public BaseGraphComponent { |
---|
| 311 | public: |
---|
| 312 | |
---|
| 313 | typedef BaseBpGraphComponent BpGraph; |
---|
| 314 | |
---|
| 315 | typedef BaseDigraphComponent::Node Node; |
---|
| 316 | typedef BaseDigraphComponent::Arc Arc; |
---|
| 317 | |
---|
| 318 | /// \brief Class to represent red nodes. |
---|
| 319 | /// |
---|
| 320 | /// This class represents the red nodes of the graph. It does |
---|
| 321 | /// not supposed to be used directly, because the nodes can be |
---|
| 322 | /// represented as Node instances. This class can be used as |
---|
| 323 | /// template parameter for special map classes. |
---|
| 324 | class RedNode : public Node { |
---|
| 325 | typedef Node Parent; |
---|
| 326 | |
---|
| 327 | public: |
---|
| 328 | /// \brief Default constructor. |
---|
| 329 | /// |
---|
| 330 | /// Default constructor. |
---|
| 331 | /// \warning The default constructor is not required to set |
---|
| 332 | /// the item to some well-defined value. So you should consider it |
---|
| 333 | /// as uninitialized. |
---|
| 334 | RedNode() {} |
---|
| 335 | |
---|
| 336 | /// \brief Copy constructor. |
---|
| 337 | /// |
---|
| 338 | /// Copy constructor. |
---|
| 339 | RedNode(const RedNode &) : Parent() {} |
---|
| 340 | |
---|
| 341 | /// \brief Constructor for conversion from \c INVALID. |
---|
| 342 | /// |
---|
| 343 | /// Constructor for conversion from \c INVALID. |
---|
| 344 | /// It initializes the item to be invalid. |
---|
| 345 | /// \sa Invalid for more details. |
---|
| 346 | RedNode(Invalid) {} |
---|
| 347 | |
---|
| 348 | /// \brief Constructor for conversion from a node. |
---|
| 349 | /// |
---|
| 350 | /// Constructor for conversion from a node. The conversion can |
---|
| 351 | /// be invalid, since the Node can be member of the blue |
---|
| 352 | /// set. |
---|
| 353 | RedNode(const Node&) {} |
---|
| 354 | }; |
---|
| 355 | |
---|
| 356 | /// \brief Class to represent blue nodes. |
---|
| 357 | /// |
---|
| 358 | /// This class represents the blue nodes of the graph. It does |
---|
| 359 | /// not supposed to be used directly, because the nodes can be |
---|
| 360 | /// represented as Node instances. This class can be used as |
---|
| 361 | /// template parameter for special map classes. |
---|
| 362 | class BlueNode : public Node { |
---|
| 363 | typedef Node Parent; |
---|
| 364 | |
---|
| 365 | public: |
---|
| 366 | /// \brief Default constructor. |
---|
| 367 | /// |
---|
| 368 | /// Default constructor. |
---|
| 369 | /// \warning The default constructor is not required to set |
---|
| 370 | /// the item to some well-defined value. So you should consider it |
---|
| 371 | /// as uninitialized. |
---|
| 372 | BlueNode() {} |
---|
| 373 | |
---|
| 374 | /// \brief Copy constructor. |
---|
| 375 | /// |
---|
| 376 | /// Copy constructor. |
---|
| 377 | BlueNode(const BlueNode &) : Parent() {} |
---|
| 378 | |
---|
| 379 | /// \brief Constructor for conversion from \c INVALID. |
---|
| 380 | /// |
---|
| 381 | /// Constructor for conversion from \c INVALID. |
---|
| 382 | /// It initializes the item to be invalid. |
---|
| 383 | /// \sa Invalid for more details. |
---|
| 384 | BlueNode(Invalid) {} |
---|
| 385 | |
---|
| 386 | /// \brief Constructor for conversion from a node. |
---|
| 387 | /// |
---|
| 388 | /// Constructor for conversion from a node. The conversion can |
---|
| 389 | /// be invalid, since the Node can be member of the red |
---|
| 390 | /// set. |
---|
| 391 | BlueNode(const Node&) {} |
---|
| 392 | }; |
---|
| 393 | |
---|
| 394 | /// \brief Gives back %true for red nodes. |
---|
| 395 | /// |
---|
| 396 | /// Gives back %true for red nodes. |
---|
| 397 | bool red(const Node&) const { return true; } |
---|
| 398 | |
---|
| 399 | /// \brief Gives back %true for blue nodes. |
---|
| 400 | /// |
---|
| 401 | /// Gives back %true for blue nodes. |
---|
| 402 | bool blue(const Node&) const { return true; } |
---|
| 403 | |
---|
| 404 | /// \brief Gives back the red end node of the edge. |
---|
| 405 | /// |
---|
| 406 | /// Gives back the red end node of the edge. |
---|
| 407 | Node redNode(const Edge&) const { return Node(); } |
---|
| 408 | |
---|
| 409 | /// \brief Gives back the blue end node of the edge. |
---|
| 410 | /// |
---|
| 411 | /// Gives back the blue end node of the edge. |
---|
| 412 | Node blueNode(const Edge&) const { return Node(); } |
---|
| 413 | |
---|
| 414 | template <typename _BpGraph> |
---|
| 415 | struct Constraints { |
---|
| 416 | typedef typename _BpGraph::Node Node; |
---|
| 417 | typedef typename _BpGraph::RedNode RedNode; |
---|
| 418 | typedef typename _BpGraph::BlueNode BlueNode; |
---|
| 419 | typedef typename _BpGraph::Arc Arc; |
---|
| 420 | typedef typename _BpGraph::Edge Edge; |
---|
| 421 | |
---|
| 422 | void constraints() { |
---|
| 423 | checkConcept<BaseGraphComponent, _BpGraph>(); |
---|
| 424 | checkConcept<GraphItem<'n'>, RedNode>(); |
---|
| 425 | checkConcept<GraphItem<'n'>, BlueNode>(); |
---|
| 426 | { |
---|
| 427 | Node n; |
---|
| 428 | RedNode rn = n; |
---|
| 429 | BlueNode bn = bn; |
---|
| 430 | Edge e; |
---|
| 431 | bool b; |
---|
| 432 | b = bpgraph.red(n); |
---|
| 433 | b = bpgraph.blue(n); |
---|
| 434 | ignore_unused_variable_warning(b); |
---|
| 435 | n = bpgraph.redNode(e); |
---|
| 436 | n = bpgraph.blueNode(e); |
---|
| 437 | rn = n; |
---|
| 438 | bn = n; |
---|
| 439 | } |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | const _BpGraph& bpgraph; |
---|
| 443 | }; |
---|
| 444 | |
---|
| 445 | }; |
---|
| 446 | |
---|
[626] | 447 | /// \brief Skeleton class for \e idable directed graphs. |
---|
[209] | 448 | /// |
---|
[626] | 449 | /// This class describes the interface of \e idable directed graphs. |
---|
| 450 | /// It extends \ref BaseDigraphComponent with the core ID functions. |
---|
| 451 | /// The ids of the items must be unique and immutable. |
---|
| 452 | /// This concept is part of the Digraph concept. |
---|
[606] | 453 | template <typename BAS = BaseDigraphComponent> |
---|
| 454 | class IDableDigraphComponent : public BAS { |
---|
[57] | 455 | public: |
---|
| 456 | |
---|
[606] | 457 | typedef BAS Base; |
---|
[57] | 458 | typedef typename Base::Node Node; |
---|
| 459 | typedef typename Base::Arc Arc; |
---|
| 460 | |
---|
[626] | 461 | /// \brief Return a unique integer id for the given node. |
---|
[57] | 462 | /// |
---|
[626] | 463 | /// This function returns a unique integer id for the given node. |
---|
| 464 | int id(const Node&) const { return -1; } |
---|
| 465 | |
---|
| 466 | /// \brief Return the node by its unique id. |
---|
[57] | 467 | /// |
---|
[626] | 468 | /// This function returns the node by its unique id. |
---|
| 469 | /// If the digraph does not contain a node with the given id, |
---|
| 470 | /// then the result of the function is undefined. |
---|
| 471 | Node nodeFromId(int) const { return INVALID; } |
---|
[57] | 472 | |
---|
[626] | 473 | /// \brief Return a unique integer id for the given arc. |
---|
[57] | 474 | /// |
---|
[626] | 475 | /// This function returns a unique integer id for the given arc. |
---|
| 476 | int id(const Arc&) const { return -1; } |
---|
[57] | 477 | |
---|
[626] | 478 | /// \brief Return the arc by its unique id. |
---|
[57] | 479 | /// |
---|
[626] | 480 | /// This function returns the arc by its unique id. |
---|
| 481 | /// If the digraph does not contain an arc with the given id, |
---|
| 482 | /// then the result of the function is undefined. |
---|
| 483 | Arc arcFromId(int) const { return INVALID; } |
---|
| 484 | |
---|
| 485 | /// \brief Return an integer greater or equal to the maximum |
---|
| 486 | /// node id. |
---|
[57] | 487 | /// |
---|
[626] | 488 | /// This function returns an integer greater or equal to the |
---|
| 489 | /// maximum node id. |
---|
| 490 | int maxNodeId() const { return -1; } |
---|
[57] | 491 | |
---|
[626] | 492 | /// \brief Return an integer greater or equal to the maximum |
---|
| 493 | /// arc id. |
---|
[57] | 494 | /// |
---|
[626] | 495 | /// This function returns an integer greater or equal to the |
---|
| 496 | /// maximum arc id. |
---|
| 497 | int maxArcId() const { return -1; } |
---|
[57] | 498 | |
---|
| 499 | template <typename _Digraph> |
---|
| 500 | struct Constraints { |
---|
| 501 | |
---|
[209] | 502 | void constraints() { |
---|
| 503 | checkConcept<Base, _Digraph >(); |
---|
| 504 | typename _Digraph::Node node; |
---|
[713] | 505 | node=INVALID; |
---|
[209] | 506 | int nid = digraph.id(node); |
---|
| 507 | nid = digraph.id(node); |
---|
| 508 | node = digraph.nodeFromId(nid); |
---|
| 509 | typename _Digraph::Arc arc; |
---|
[713] | 510 | arc=INVALID; |
---|
[209] | 511 | int eid = digraph.id(arc); |
---|
| 512 | eid = digraph.id(arc); |
---|
| 513 | arc = digraph.arcFromId(eid); |
---|
[57] | 514 | |
---|
[209] | 515 | nid = digraph.maxNodeId(); |
---|
| 516 | ignore_unused_variable_warning(nid); |
---|
| 517 | eid = digraph.maxArcId(); |
---|
| 518 | ignore_unused_variable_warning(eid); |
---|
| 519 | } |
---|
[57] | 520 | |
---|
[209] | 521 | const _Digraph& digraph; |
---|
[1125] | 522 | Constraints() {} |
---|
[57] | 523 | }; |
---|
| 524 | }; |
---|
| 525 | |
---|
[626] | 526 | /// \brief Skeleton class for \e idable undirected graphs. |
---|
[209] | 527 | /// |
---|
[626] | 528 | /// This class describes the interface of \e idable undirected |
---|
| 529 | /// graphs. It extends \ref IDableDigraphComponent with the core ID |
---|
| 530 | /// functions of undirected graphs. |
---|
| 531 | /// The ids of the items must be unique and immutable. |
---|
| 532 | /// This concept is part of the Graph concept. |
---|
[606] | 533 | template <typename BAS = BaseGraphComponent> |
---|
| 534 | class IDableGraphComponent : public IDableDigraphComponent<BAS> { |
---|
[57] | 535 | public: |
---|
| 536 | |
---|
[606] | 537 | typedef BAS Base; |
---|
[57] | 538 | typedef typename Base::Edge Edge; |
---|
| 539 | |
---|
[606] | 540 | using IDableDigraphComponent<Base>::id; |
---|
[57] | 541 | |
---|
[626] | 542 | /// \brief Return a unique integer id for the given edge. |
---|
[57] | 543 | /// |
---|
[626] | 544 | /// This function returns a unique integer id for the given edge. |
---|
| 545 | int id(const Edge&) const { return -1; } |
---|
| 546 | |
---|
| 547 | /// \brief Return the edge by its unique id. |
---|
[57] | 548 | /// |
---|
[626] | 549 | /// This function returns the edge by its unique id. |
---|
| 550 | /// If the graph does not contain an edge with the given id, |
---|
| 551 | /// then the result of the function is undefined. |
---|
| 552 | Edge edgeFromId(int) const { return INVALID; } |
---|
[57] | 553 | |
---|
[626] | 554 | /// \brief Return an integer greater or equal to the maximum |
---|
| 555 | /// edge id. |
---|
[57] | 556 | /// |
---|
[626] | 557 | /// This function returns an integer greater or equal to the |
---|
| 558 | /// maximum edge id. |
---|
| 559 | int maxEdgeId() const { return -1; } |
---|
[57] | 560 | |
---|
| 561 | template <typename _Graph> |
---|
| 562 | struct Constraints { |
---|
| 563 | |
---|
[209] | 564 | void constraints() { |
---|
| 565 | checkConcept<IDableDigraphComponent<Base>, _Graph >(); |
---|
| 566 | typename _Graph::Edge edge; |
---|
| 567 | int ueid = graph.id(edge); |
---|
| 568 | ueid = graph.id(edge); |
---|
| 569 | edge = graph.edgeFromId(ueid); |
---|
| 570 | ueid = graph.maxEdgeId(); |
---|
| 571 | ignore_unused_variable_warning(ueid); |
---|
| 572 | } |
---|
[57] | 573 | |
---|
[209] | 574 | const _Graph& graph; |
---|
[1125] | 575 | Constraints() {} |
---|
[57] | 576 | }; |
---|
| 577 | }; |
---|
| 578 | |
---|
[1186] | 579 | /// \brief Skeleton class for \e idable undirected bipartite graphs. |
---|
| 580 | /// |
---|
| 581 | /// This class describes the interface of \e idable undirected |
---|
| 582 | /// bipartite graphs. It extends \ref IDableGraphComponent with |
---|
| 583 | /// the core ID functions of undirected bipartite graphs. Beside |
---|
| 584 | /// the regular node ids, this class also provides ids within the |
---|
| 585 | /// the red and blue sets of the nodes. This concept is part of |
---|
| 586 | /// the BpGraph concept. |
---|
| 587 | template <typename BAS = BaseBpGraphComponent> |
---|
| 588 | class IDableBpGraphComponent : public IDableGraphComponent<BAS> { |
---|
| 589 | public: |
---|
| 590 | |
---|
| 591 | typedef BAS Base; |
---|
| 592 | typedef IDableGraphComponent<BAS> Parent; |
---|
| 593 | typedef typename Base::Node Node; |
---|
| 594 | typedef typename Base::RedNode RedNode; |
---|
| 595 | typedef typename Base::BlueNode BlueNode; |
---|
| 596 | |
---|
| 597 | using Parent::id; |
---|
| 598 | |
---|
| 599 | /// \brief Return a unique integer id for the given node in the red set. |
---|
| 600 | /// |
---|
| 601 | /// Return a unique integer id for the given node in the red set. |
---|
| 602 | int redId(const Node&) const { return -1; } |
---|
| 603 | |
---|
| 604 | /// \brief Return the same value as redId(). |
---|
| 605 | /// |
---|
| 606 | /// Return the same value as redId(). |
---|
| 607 | int id(const RedNode&) const { return -1; } |
---|
| 608 | |
---|
| 609 | /// \brief Return a unique integer id for the given node in the blue set. |
---|
| 610 | /// |
---|
| 611 | /// Return a unique integer id for the given node in the blue set. |
---|
| 612 | int blueId(const Node&) const { return -1; } |
---|
| 613 | |
---|
| 614 | /// \brief Return the same value as blueId(). |
---|
| 615 | /// |
---|
| 616 | /// Return the same value as blueId(). |
---|
| 617 | int id(const BlueNode&) const { return -1; } |
---|
| 618 | |
---|
| 619 | /// \brief Return an integer greater or equal to the maximum |
---|
| 620 | /// node id in the red set. |
---|
| 621 | /// |
---|
| 622 | /// Return an integer greater or equal to the maximum |
---|
| 623 | /// node id in the red set. |
---|
| 624 | int maxRedId() const { return -1; } |
---|
| 625 | |
---|
| 626 | /// \brief Return an integer greater or equal to the maximum |
---|
| 627 | /// node id in the blue set. |
---|
| 628 | /// |
---|
| 629 | /// Return an integer greater or equal to the maximum |
---|
| 630 | /// node id in the blue set. |
---|
| 631 | int maxBlueId() const { return -1; } |
---|
| 632 | |
---|
| 633 | template <typename _BpGraph> |
---|
| 634 | struct Constraints { |
---|
| 635 | |
---|
| 636 | void constraints() { |
---|
| 637 | checkConcept<IDableGraphComponent<Base>, _BpGraph>(); |
---|
| 638 | typename _BpGraph::Node node; |
---|
| 639 | typename _BpGraph::RedNode red; |
---|
| 640 | typename _BpGraph::BlueNode blue; |
---|
| 641 | int rid = bpgraph.redId(node); |
---|
| 642 | int bid = bpgraph.blueId(node); |
---|
| 643 | rid = bpgraph.id(red); |
---|
| 644 | bid = bpgraph.id(blue); |
---|
| 645 | rid = bpgraph.maxRedId(); |
---|
| 646 | bid = bpgraph.maxBlueId(); |
---|
| 647 | ignore_unused_variable_warning(rid); |
---|
| 648 | ignore_unused_variable_warning(bid); |
---|
| 649 | } |
---|
| 650 | |
---|
| 651 | const _BpGraph& bpgraph; |
---|
| 652 | }; |
---|
| 653 | }; |
---|
| 654 | |
---|
[626] | 655 | /// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types. |
---|
[57] | 656 | /// |
---|
[956] | 657 | /// This class describes the concept of \c NodeIt, \c ArcIt and |
---|
[626] | 658 | /// \c EdgeIt subtypes of digraph and graph types. |
---|
[606] | 659 | template <typename GR, typename Item> |
---|
| 660 | class GraphItemIt : public Item { |
---|
[57] | 661 | public: |
---|
| 662 | /// \brief Default constructor. |
---|
| 663 | /// |
---|
[626] | 664 | /// Default constructor. |
---|
| 665 | /// \warning The default constructor is not required to set |
---|
| 666 | /// the iterator to some well-defined value. So you should consider it |
---|
| 667 | /// as uninitialized. |
---|
[57] | 668 | GraphItemIt() {} |
---|
[626] | 669 | |
---|
[57] | 670 | /// \brief Copy constructor. |
---|
| 671 | /// |
---|
| 672 | /// Copy constructor. |
---|
[626] | 673 | GraphItemIt(const GraphItemIt& it) : Item(it) {} |
---|
| 674 | |
---|
| 675 | /// \brief Constructor that sets the iterator to the first item. |
---|
[57] | 676 | /// |
---|
[626] | 677 | /// Constructor that sets the iterator to the first item. |
---|
| 678 | explicit GraphItemIt(const GR&) {} |
---|
| 679 | |
---|
| 680 | /// \brief Constructor for conversion from \c INVALID. |
---|
[57] | 681 | /// |
---|
[626] | 682 | /// Constructor for conversion from \c INVALID. |
---|
| 683 | /// It initializes the iterator to be invalid. |
---|
[57] | 684 | /// \sa Invalid for more details. |
---|
| 685 | GraphItemIt(Invalid) {} |
---|
[626] | 686 | |
---|
| 687 | /// \brief Assignment operator. |
---|
[57] | 688 | /// |
---|
[626] | 689 | /// Assignment operator for the iterator. |
---|
| 690 | GraphItemIt& operator=(const GraphItemIt&) { return *this; } |
---|
| 691 | |
---|
| 692 | /// \brief Increment the iterator. |
---|
[57] | 693 | /// |
---|
[626] | 694 | /// This operator increments the iterator, i.e. assigns it to the |
---|
| 695 | /// next item. |
---|
[57] | 696 | GraphItemIt& operator++() { return *this; } |
---|
[956] | 697 | |
---|
[57] | 698 | /// \brief Equality operator |
---|
[209] | 699 | /// |
---|
[626] | 700 | /// Equality operator. |
---|
[57] | 701 | /// Two iterators are equal if and only if they point to the |
---|
| 702 | /// same object or both are invalid. |
---|
| 703 | bool operator==(const GraphItemIt&) const { return true;} |
---|
[626] | 704 | |
---|
[57] | 705 | /// \brief Inequality operator |
---|
[209] | 706 | /// |
---|
[626] | 707 | /// Inequality operator. |
---|
| 708 | /// Two iterators are equal if and only if they point to the |
---|
| 709 | /// same object or both are invalid. |
---|
[57] | 710 | bool operator!=(const GraphItemIt&) const { return true;} |
---|
[209] | 711 | |
---|
[57] | 712 | template<typename _GraphItemIt> |
---|
| 713 | struct Constraints { |
---|
[209] | 714 | void constraints() { |
---|
[626] | 715 | checkConcept<GraphItem<>, _GraphItemIt>(); |
---|
[209] | 716 | _GraphItemIt it1(g); |
---|
| 717 | _GraphItemIt it2; |
---|
[626] | 718 | _GraphItemIt it3 = it1; |
---|
| 719 | _GraphItemIt it4 = INVALID; |
---|
[1157] | 720 | ignore_unused_variable_warning(it3); |
---|
| 721 | ignore_unused_variable_warning(it4); |
---|
[57] | 722 | |
---|
[209] | 723 | it2 = ++it1; |
---|
| 724 | ++it2 = it1; |
---|
| 725 | ++(++it1); |
---|
[57] | 726 | |
---|
[606] | 727 | Item bi = it1; |
---|
[209] | 728 | bi = it2; |
---|
| 729 | } |
---|
[626] | 730 | const GR& g; |
---|
[1125] | 731 | Constraints() {} |
---|
[57] | 732 | }; |
---|
| 733 | }; |
---|
| 734 | |
---|
[956] | 735 | /// \brief Concept class for \c InArcIt, \c OutArcIt and |
---|
[626] | 736 | /// \c IncEdgeIt types. |
---|
[57] | 737 | /// |
---|
[956] | 738 | /// This class describes the concept of \c InArcIt, \c OutArcIt |
---|
[626] | 739 | /// and \c IncEdgeIt subtypes of digraph and graph types. |
---|
| 740 | /// |
---|
| 741 | /// \note Since these iterator classes do not inherit from the same |
---|
| 742 | /// base class, there is an additional template parameter (selector) |
---|
[956] | 743 | /// \c sel. For \c InArcIt you should instantiate it with character |
---|
[626] | 744 | /// \c 'i', for \c OutArcIt with \c 'o' and for \c IncEdgeIt with \c 'e'. |
---|
[606] | 745 | template <typename GR, |
---|
| 746 | typename Item = typename GR::Arc, |
---|
| 747 | typename Base = typename GR::Node, |
---|
| 748 | char sel = '0'> |
---|
| 749 | class GraphIncIt : public Item { |
---|
[57] | 750 | public: |
---|
| 751 | /// \brief Default constructor. |
---|
| 752 | /// |
---|
[626] | 753 | /// Default constructor. |
---|
| 754 | /// \warning The default constructor is not required to set |
---|
| 755 | /// the iterator to some well-defined value. So you should consider it |
---|
| 756 | /// as uninitialized. |
---|
[57] | 757 | GraphIncIt() {} |
---|
[626] | 758 | |
---|
[57] | 759 | /// \brief Copy constructor. |
---|
| 760 | /// |
---|
| 761 | /// Copy constructor. |
---|
[626] | 762 | GraphIncIt(const GraphIncIt& it) : Item(it) {} |
---|
| 763 | |
---|
[956] | 764 | /// \brief Constructor that sets the iterator to the first |
---|
[626] | 765 | /// incoming or outgoing arc. |
---|
[57] | 766 | /// |
---|
[956] | 767 | /// Constructor that sets the iterator to the first arc |
---|
[626] | 768 | /// incoming to or outgoing from the given node. |
---|
| 769 | explicit GraphIncIt(const GR&, const Base&) {} |
---|
| 770 | |
---|
| 771 | /// \brief Constructor for conversion from \c INVALID. |
---|
[57] | 772 | /// |
---|
[626] | 773 | /// Constructor for conversion from \c INVALID. |
---|
| 774 | /// It initializes the iterator to be invalid. |
---|
[57] | 775 | /// \sa Invalid for more details. |
---|
| 776 | GraphIncIt(Invalid) {} |
---|
[626] | 777 | |
---|
| 778 | /// \brief Assignment operator. |
---|
[57] | 779 | /// |
---|
[626] | 780 | /// Assignment operator for the iterator. |
---|
| 781 | GraphIncIt& operator=(const GraphIncIt&) { return *this; } |
---|
| 782 | |
---|
| 783 | /// \brief Increment the iterator. |
---|
[57] | 784 | /// |
---|
[626] | 785 | /// This operator increments the iterator, i.e. assigns it to the |
---|
| 786 | /// next arc incoming to or outgoing from the given node. |
---|
[57] | 787 | GraphIncIt& operator++() { return *this; } |
---|
| 788 | |
---|
| 789 | /// \brief Equality operator |
---|
| 790 | /// |
---|
[626] | 791 | /// Equality operator. |
---|
[57] | 792 | /// Two iterators are equal if and only if they point to the |
---|
| 793 | /// same object or both are invalid. |
---|
| 794 | bool operator==(const GraphIncIt&) const { return true;} |
---|
| 795 | |
---|
| 796 | /// \brief Inequality operator |
---|
| 797 | /// |
---|
[626] | 798 | /// Inequality operator. |
---|
| 799 | /// Two iterators are equal if and only if they point to the |
---|
| 800 | /// same object or both are invalid. |
---|
[57] | 801 | bool operator!=(const GraphIncIt&) const { return true;} |
---|
| 802 | |
---|
| 803 | template <typename _GraphIncIt> |
---|
| 804 | struct Constraints { |
---|
[209] | 805 | void constraints() { |
---|
[606] | 806 | checkConcept<GraphItem<sel>, _GraphIncIt>(); |
---|
[209] | 807 | _GraphIncIt it1(graph, node); |
---|
| 808 | _GraphIncIt it2; |
---|
[626] | 809 | _GraphIncIt it3 = it1; |
---|
| 810 | _GraphIncIt it4 = INVALID; |
---|
[1157] | 811 | ignore_unused_variable_warning(it3); |
---|
| 812 | ignore_unused_variable_warning(it4); |
---|
[57] | 813 | |
---|
[209] | 814 | it2 = ++it1; |
---|
| 815 | ++it2 = it1; |
---|
| 816 | ++(++it1); |
---|
[606] | 817 | Item e = it1; |
---|
[209] | 818 | e = it2; |
---|
| 819 | } |
---|
[626] | 820 | const Base& node; |
---|
| 821 | const GR& graph; |
---|
[1125] | 822 | Constraints() {} |
---|
[57] | 823 | }; |
---|
| 824 | }; |
---|
| 825 | |
---|
[626] | 826 | /// \brief Skeleton class for iterable directed graphs. |
---|
[57] | 827 | /// |
---|
[626] | 828 | /// This class describes the interface of iterable directed |
---|
| 829 | /// graphs. It extends \ref BaseDigraphComponent with the core |
---|
| 830 | /// iterable interface. |
---|
[57] | 831 | /// This concept is part of the Digraph concept. |
---|
[606] | 832 | template <typename BAS = BaseDigraphComponent> |
---|
| 833 | class IterableDigraphComponent : public BAS { |
---|
[57] | 834 | |
---|
| 835 | public: |
---|
[209] | 836 | |
---|
[606] | 837 | typedef BAS Base; |
---|
[57] | 838 | typedef typename Base::Node Node; |
---|
| 839 | typedef typename Base::Arc Arc; |
---|
| 840 | |
---|
| 841 | typedef IterableDigraphComponent Digraph; |
---|
| 842 | |
---|
[631] | 843 | /// \name Base Iteration |
---|
[209] | 844 | /// |
---|
[626] | 845 | /// This interface provides functions for iteration on digraph items. |
---|
[57] | 846 | /// |
---|
[209] | 847 | /// @{ |
---|
[57] | 848 | |
---|
[626] | 849 | /// \brief Return the first node. |
---|
[209] | 850 | /// |
---|
[626] | 851 | /// This function gives back the first node in the iteration order. |
---|
[57] | 852 | void first(Node&) const {} |
---|
| 853 | |
---|
[626] | 854 | /// \brief Return the next node. |
---|
[57] | 855 | /// |
---|
[626] | 856 | /// This function gives back the next node in the iteration order. |
---|
[57] | 857 | void next(Node&) const {} |
---|
| 858 | |
---|
[626] | 859 | /// \brief Return the first arc. |
---|
[57] | 860 | /// |
---|
[626] | 861 | /// This function gives back the first arc in the iteration order. |
---|
[57] | 862 | void first(Arc&) const {} |
---|
| 863 | |
---|
[626] | 864 | /// \brief Return the next arc. |
---|
[57] | 865 | /// |
---|
[626] | 866 | /// This function gives back the next arc in the iteration order. |
---|
[57] | 867 | void next(Arc&) const {} |
---|
| 868 | |
---|
[626] | 869 | /// \brief Return the first arc incomming to the given node. |
---|
[57] | 870 | /// |
---|
[626] | 871 | /// This function gives back the first arc incomming to the |
---|
| 872 | /// given node. |
---|
[57] | 873 | void firstIn(Arc&, const Node&) const {} |
---|
| 874 | |
---|
[626] | 875 | /// \brief Return the next arc incomming to the given node. |
---|
[57] | 876 | /// |
---|
[626] | 877 | /// This function gives back the next arc incomming to the |
---|
| 878 | /// given node. |
---|
[57] | 879 | void nextIn(Arc&) const {} |
---|
| 880 | |
---|
[626] | 881 | /// \brief Return the first arc outgoing form the given node. |
---|
| 882 | /// |
---|
| 883 | /// This function gives back the first arc outgoing form the |
---|
[57] | 884 | /// given node. |
---|
| 885 | void firstOut(Arc&, const Node&) const {} |
---|
| 886 | |
---|
[626] | 887 | /// \brief Return the next arc outgoing form the given node. |
---|
[57] | 888 | /// |
---|
[626] | 889 | /// This function gives back the next arc outgoing form the |
---|
| 890 | /// given node. |
---|
[57] | 891 | void nextOut(Arc&) const {} |
---|
| 892 | |
---|
| 893 | /// @} |
---|
| 894 | |
---|
[631] | 895 | /// \name Class Based Iteration |
---|
[209] | 896 | /// |
---|
[626] | 897 | /// This interface provides iterator classes for digraph items. |
---|
[57] | 898 | /// |
---|
| 899 | /// @{ |
---|
| 900 | |
---|
| 901 | /// \brief This iterator goes through each node. |
---|
| 902 | /// |
---|
| 903 | /// This iterator goes through each node. |
---|
| 904 | /// |
---|
| 905 | typedef GraphItemIt<Digraph, Node> NodeIt; |
---|
| 906 | |
---|
[626] | 907 | /// \brief This iterator goes through each arc. |
---|
[57] | 908 | /// |
---|
[626] | 909 | /// This iterator goes through each arc. |
---|
[57] | 910 | /// |
---|
| 911 | typedef GraphItemIt<Digraph, Arc> ArcIt; |
---|
| 912 | |
---|
| 913 | /// \brief This iterator goes trough the incoming arcs of a node. |
---|
| 914 | /// |
---|
[626] | 915 | /// This iterator goes trough the \e incoming arcs of a certain node |
---|
[57] | 916 | /// of a digraph. |
---|
| 917 | typedef GraphIncIt<Digraph, Arc, Node, 'i'> InArcIt; |
---|
| 918 | |
---|
| 919 | /// \brief This iterator goes trough the outgoing arcs of a node. |
---|
| 920 | /// |
---|
| 921 | /// This iterator goes trough the \e outgoing arcs of a certain node |
---|
| 922 | /// of a digraph. |
---|
| 923 | typedef GraphIncIt<Digraph, Arc, Node, 'o'> OutArcIt; |
---|
| 924 | |
---|
| 925 | /// \brief The base node of the iterator. |
---|
| 926 | /// |
---|
[626] | 927 | /// This function gives back the base node of the iterator. |
---|
| 928 | /// It is always the target node of the pointed arc. |
---|
[57] | 929 | Node baseNode(const InArcIt&) const { return INVALID; } |
---|
| 930 | |
---|
| 931 | /// \brief The running node of the iterator. |
---|
| 932 | /// |
---|
[626] | 933 | /// This function gives back the running node of the iterator. |
---|
| 934 | /// It is always the source node of the pointed arc. |
---|
[57] | 935 | Node runningNode(const InArcIt&) const { return INVALID; } |
---|
| 936 | |
---|
| 937 | /// \brief The base node of the iterator. |
---|
| 938 | /// |
---|
[626] | 939 | /// This function gives back the base node of the iterator. |
---|
| 940 | /// It is always the source node of the pointed arc. |
---|
[57] | 941 | Node baseNode(const OutArcIt&) const { return INVALID; } |
---|
| 942 | |
---|
| 943 | /// \brief The running node of the iterator. |
---|
| 944 | /// |
---|
[626] | 945 | /// This function gives back the running node of the iterator. |
---|
| 946 | /// It is always the target node of the pointed arc. |
---|
[57] | 947 | Node runningNode(const OutArcIt&) const { return INVALID; } |
---|
| 948 | |
---|
| 949 | /// @} |
---|
| 950 | |
---|
[209] | 951 | template <typename _Digraph> |
---|
[57] | 952 | struct Constraints { |
---|
[209] | 953 | void constraints() { |
---|
| 954 | checkConcept<Base, _Digraph>(); |
---|
[57] | 955 | |
---|
| 956 | { |
---|
[209] | 957 | typename _Digraph::Node node(INVALID); |
---|
[57] | 958 | typename _Digraph::Arc arc(INVALID); |
---|
| 959 | { |
---|
| 960 | digraph.first(node); |
---|
| 961 | digraph.next(node); |
---|
| 962 | } |
---|
| 963 | { |
---|
| 964 | digraph.first(arc); |
---|
| 965 | digraph.next(arc); |
---|
| 966 | } |
---|
| 967 | { |
---|
| 968 | digraph.firstIn(arc, node); |
---|
| 969 | digraph.nextIn(arc); |
---|
| 970 | } |
---|
| 971 | { |
---|
| 972 | digraph.firstOut(arc, node); |
---|
| 973 | digraph.nextOut(arc); |
---|
| 974 | } |
---|
[209] | 975 | } |
---|
[57] | 976 | |
---|
| 977 | { |
---|
| 978 | checkConcept<GraphItemIt<_Digraph, typename _Digraph::Arc>, |
---|
| 979 | typename _Digraph::ArcIt >(); |
---|
| 980 | checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>, |
---|
| 981 | typename _Digraph::NodeIt >(); |
---|
[209] | 982 | checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, |
---|
[57] | 983 | typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>(); |
---|
[209] | 984 | checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, |
---|
[57] | 985 | typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>(); |
---|
| 986 | |
---|
| 987 | typename _Digraph::Node n; |
---|
[626] | 988 | const typename _Digraph::InArcIt iait(INVALID); |
---|
| 989 | const typename _Digraph::OutArcIt oait(INVALID); |
---|
| 990 | n = digraph.baseNode(iait); |
---|
| 991 | n = digraph.runningNode(iait); |
---|
| 992 | n = digraph.baseNode(oait); |
---|
| 993 | n = digraph.runningNode(oait); |
---|
[57] | 994 | ignore_unused_variable_warning(n); |
---|
| 995 | } |
---|
| 996 | } |
---|
[209] | 997 | |
---|
| 998 | const _Digraph& digraph; |
---|
[1125] | 999 | Constraints() {} |
---|
[57] | 1000 | }; |
---|
| 1001 | }; |
---|
| 1002 | |
---|
[626] | 1003 | /// \brief Skeleton class for iterable undirected graphs. |
---|
[57] | 1004 | /// |
---|
[626] | 1005 | /// This class describes the interface of iterable undirected |
---|
| 1006 | /// graphs. It extends \ref IterableDigraphComponent with the core |
---|
| 1007 | /// iterable interface of undirected graphs. |
---|
[57] | 1008 | /// This concept is part of the Graph concept. |
---|
[606] | 1009 | template <typename BAS = BaseGraphComponent> |
---|
| 1010 | class IterableGraphComponent : public IterableDigraphComponent<BAS> { |
---|
[57] | 1011 | public: |
---|
| 1012 | |
---|
[606] | 1013 | typedef BAS Base; |
---|
[57] | 1014 | typedef typename Base::Node Node; |
---|
| 1015 | typedef typename Base::Arc Arc; |
---|
| 1016 | typedef typename Base::Edge Edge; |
---|
| 1017 | |
---|
[209] | 1018 | |
---|
[57] | 1019 | typedef IterableGraphComponent Graph; |
---|
| 1020 | |
---|
[631] | 1021 | /// \name Base Iteration |
---|
[209] | 1022 | /// |
---|
[626] | 1023 | /// This interface provides functions for iteration on edges. |
---|
| 1024 | /// |
---|
[209] | 1025 | /// @{ |
---|
[57] | 1026 | |
---|
[606] | 1027 | using IterableDigraphComponent<Base>::first; |
---|
| 1028 | using IterableDigraphComponent<Base>::next; |
---|
[57] | 1029 | |
---|
[626] | 1030 | /// \brief Return the first edge. |
---|
[57] | 1031 | /// |
---|
[626] | 1032 | /// This function gives back the first edge in the iteration order. |
---|
[57] | 1033 | void first(Edge&) const {} |
---|
| 1034 | |
---|
[626] | 1035 | /// \brief Return the next edge. |
---|
[57] | 1036 | /// |
---|
[626] | 1037 | /// This function gives back the next edge in the iteration order. |
---|
[57] | 1038 | void next(Edge&) const {} |
---|
| 1039 | |
---|
[626] | 1040 | /// \brief Return the first edge incident to the given node. |
---|
| 1041 | /// |
---|
[956] | 1042 | /// This function gives back the first edge incident to the given |
---|
[626] | 1043 | /// node. The bool parameter gives back the direction for which the |
---|
[956] | 1044 | /// source node of the directed arc representing the edge is the |
---|
[57] | 1045 | /// given node. |
---|
| 1046 | void firstInc(Edge&, bool&, const Node&) const {} |
---|
| 1047 | |
---|
| 1048 | /// \brief Gives back the next of the edges from the |
---|
| 1049 | /// given node. |
---|
| 1050 | /// |
---|
[956] | 1051 | /// This function gives back the next edge incident to the given |
---|
[626] | 1052 | /// node. The bool parameter should be used as \c firstInc() use it. |
---|
[57] | 1053 | void nextInc(Edge&, bool&) const {} |
---|
| 1054 | |
---|
[606] | 1055 | using IterableDigraphComponent<Base>::baseNode; |
---|
| 1056 | using IterableDigraphComponent<Base>::runningNode; |
---|
[57] | 1057 | |
---|
| 1058 | /// @} |
---|
| 1059 | |
---|
[631] | 1060 | /// \name Class Based Iteration |
---|
[209] | 1061 | /// |
---|
[626] | 1062 | /// This interface provides iterator classes for edges. |
---|
[57] | 1063 | /// |
---|
| 1064 | /// @{ |
---|
| 1065 | |
---|
[626] | 1066 | /// \brief This iterator goes through each edge. |
---|
[57] | 1067 | /// |
---|
[626] | 1068 | /// This iterator goes through each edge. |
---|
[57] | 1069 | typedef GraphItemIt<Graph, Edge> EdgeIt; |
---|
[626] | 1070 | |
---|
| 1071 | /// \brief This iterator goes trough the incident edges of a |
---|
[57] | 1072 | /// node. |
---|
| 1073 | /// |
---|
[626] | 1074 | /// This iterator goes trough the incident edges of a certain |
---|
[57] | 1075 | /// node of a graph. |
---|
[626] | 1076 | typedef GraphIncIt<Graph, Edge, Node, 'e'> IncEdgeIt; |
---|
| 1077 | |
---|
[57] | 1078 | /// \brief The base node of the iterator. |
---|
| 1079 | /// |
---|
[626] | 1080 | /// This function gives back the base node of the iterator. |
---|
[78] | 1081 | Node baseNode(const IncEdgeIt&) const { return INVALID; } |
---|
[57] | 1082 | |
---|
| 1083 | /// \brief The running node of the iterator. |
---|
| 1084 | /// |
---|
[626] | 1085 | /// This function gives back the running node of the iterator. |
---|
[78] | 1086 | Node runningNode(const IncEdgeIt&) const { return INVALID; } |
---|
[57] | 1087 | |
---|
| 1088 | /// @} |
---|
| 1089 | |
---|
[209] | 1090 | template <typename _Graph> |
---|
[57] | 1091 | struct Constraints { |
---|
[209] | 1092 | void constraints() { |
---|
| 1093 | checkConcept<IterableDigraphComponent<Base>, _Graph>(); |
---|
[57] | 1094 | |
---|
| 1095 | { |
---|
| 1096 | typename _Graph::Node node(INVALID); |
---|
| 1097 | typename _Graph::Edge edge(INVALID); |
---|
| 1098 | bool dir; |
---|
| 1099 | { |
---|
| 1100 | graph.first(edge); |
---|
| 1101 | graph.next(edge); |
---|
| 1102 | } |
---|
| 1103 | { |
---|
| 1104 | graph.firstInc(edge, dir, node); |
---|
| 1105 | graph.nextInc(edge, dir); |
---|
| 1106 | } |
---|
[209] | 1107 | |
---|
| 1108 | } |
---|
| 1109 | |
---|
[57] | 1110 | { |
---|
| 1111 | checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>, |
---|
| 1112 | typename _Graph::EdgeIt >(); |
---|
[209] | 1113 | checkConcept<GraphIncIt<_Graph, typename _Graph::Edge, |
---|
[626] | 1114 | typename _Graph::Node, 'e'>, typename _Graph::IncEdgeIt>(); |
---|
[209] | 1115 | |
---|
[57] | 1116 | typename _Graph::Node n; |
---|
[626] | 1117 | const typename _Graph::IncEdgeIt ieit(INVALID); |
---|
| 1118 | n = graph.baseNode(ieit); |
---|
| 1119 | n = graph.runningNode(ieit); |
---|
[57] | 1120 | } |
---|
| 1121 | } |
---|
[209] | 1122 | |
---|
| 1123 | const _Graph& graph; |
---|
[1125] | 1124 | Constraints() {} |
---|
[57] | 1125 | }; |
---|
| 1126 | }; |
---|
| 1127 | |
---|
[1186] | 1128 | /// \brief Skeleton class for iterable undirected bipartite graphs. |
---|
| 1129 | /// |
---|
| 1130 | /// This class describes the interface of iterable undirected |
---|
| 1131 | /// bipartite graphs. It extends \ref IterableGraphComponent with |
---|
| 1132 | /// the core iterable interface of undirected bipartite graphs. |
---|
| 1133 | /// This concept is part of the BpGraph concept. |
---|
| 1134 | template <typename BAS = BaseBpGraphComponent> |
---|
| 1135 | class IterableBpGraphComponent : public IterableGraphComponent<BAS> { |
---|
| 1136 | public: |
---|
| 1137 | |
---|
| 1138 | typedef BAS Base; |
---|
| 1139 | typedef typename Base::Node Node; |
---|
| 1140 | typedef typename Base::Arc Arc; |
---|
| 1141 | typedef typename Base::Edge Edge; |
---|
| 1142 | |
---|
| 1143 | |
---|
| 1144 | typedef IterableBpGraphComponent BpGraph; |
---|
| 1145 | |
---|
| 1146 | /// \name Base Iteration |
---|
| 1147 | /// |
---|
| 1148 | /// This interface provides functions for iteration on red and blue nodes. |
---|
| 1149 | /// |
---|
| 1150 | /// @{ |
---|
| 1151 | |
---|
| 1152 | /// \brief Return the first red node. |
---|
| 1153 | /// |
---|
| 1154 | /// This function gives back the first red node in the iteration order. |
---|
| 1155 | void firstRed(Node&) const {} |
---|
| 1156 | |
---|
| 1157 | /// \brief Return the next red node. |
---|
| 1158 | /// |
---|
| 1159 | /// This function gives back the next red node in the iteration order. |
---|
| 1160 | void nextRed(Node&) const {} |
---|
| 1161 | |
---|
| 1162 | /// \brief Return the first blue node. |
---|
| 1163 | /// |
---|
| 1164 | /// This function gives back the first blue node in the iteration order. |
---|
| 1165 | void firstBlue(Node&) const {} |
---|
| 1166 | |
---|
| 1167 | /// \brief Return the next blue node. |
---|
| 1168 | /// |
---|
| 1169 | /// This function gives back the next blue node in the iteration order. |
---|
| 1170 | void nextBlue(Node&) const {} |
---|
| 1171 | |
---|
| 1172 | |
---|
| 1173 | /// @} |
---|
| 1174 | |
---|
| 1175 | /// \name Class Based Iteration |
---|
| 1176 | /// |
---|
| 1177 | /// This interface provides iterator classes for red and blue nodes. |
---|
| 1178 | /// |
---|
| 1179 | /// @{ |
---|
| 1180 | |
---|
| 1181 | /// \brief This iterator goes through each red node. |
---|
| 1182 | /// |
---|
| 1183 | /// This iterator goes through each red node. |
---|
| 1184 | typedef GraphItemIt<BpGraph, Node> RedIt; |
---|
| 1185 | |
---|
| 1186 | /// \brief This iterator goes through each blue node. |
---|
| 1187 | /// |
---|
| 1188 | /// This iterator goes through each blue node. |
---|
| 1189 | typedef GraphItemIt<BpGraph, Node> BlueIt; |
---|
| 1190 | |
---|
| 1191 | /// @} |
---|
| 1192 | |
---|
| 1193 | template <typename _BpGraph> |
---|
| 1194 | struct Constraints { |
---|
| 1195 | void constraints() { |
---|
| 1196 | checkConcept<IterableGraphComponent<Base>, _BpGraph>(); |
---|
| 1197 | |
---|
| 1198 | typename _BpGraph::Node node(INVALID); |
---|
| 1199 | bpgraph.firstRed(node); |
---|
| 1200 | bpgraph.nextRed(node); |
---|
| 1201 | bpgraph.firstBlue(node); |
---|
| 1202 | bpgraph.nextBlue(node); |
---|
| 1203 | |
---|
| 1204 | checkConcept<GraphItemIt<_BpGraph, typename _BpGraph::Node>, |
---|
| 1205 | typename _BpGraph::RedIt>(); |
---|
| 1206 | checkConcept<GraphItemIt<_BpGraph, typename _BpGraph::Node>, |
---|
| 1207 | typename _BpGraph::BlueIt>(); |
---|
| 1208 | } |
---|
| 1209 | |
---|
| 1210 | const _BpGraph& bpgraph; |
---|
| 1211 | }; |
---|
| 1212 | }; |
---|
| 1213 | |
---|
[626] | 1214 | /// \brief Skeleton class for alterable directed graphs. |
---|
[209] | 1215 | /// |
---|
[626] | 1216 | /// This class describes the interface of alterable directed |
---|
| 1217 | /// graphs. It extends \ref BaseDigraphComponent with the alteration |
---|
| 1218 | /// notifier interface. It implements |
---|
[57] | 1219 | /// an observer-notifier pattern for each digraph item. More |
---|
| 1220 | /// obsevers can be registered into the notifier and whenever an |
---|
[626] | 1221 | /// alteration occured in the digraph all the observers will be |
---|
[57] | 1222 | /// notified about it. |
---|
[606] | 1223 | template <typename BAS = BaseDigraphComponent> |
---|
| 1224 | class AlterableDigraphComponent : public BAS { |
---|
[57] | 1225 | public: |
---|
| 1226 | |
---|
[606] | 1227 | typedef BAS Base; |
---|
[57] | 1228 | typedef typename Base::Node Node; |
---|
| 1229 | typedef typename Base::Arc Arc; |
---|
| 1230 | |
---|
| 1231 | |
---|
[626] | 1232 | /// Node alteration notifier class. |
---|
[209] | 1233 | typedef AlterationNotifier<AlterableDigraphComponent, Node> |
---|
[57] | 1234 | NodeNotifier; |
---|
[626] | 1235 | /// Arc alteration notifier class. |
---|
[209] | 1236 | typedef AlterationNotifier<AlterableDigraphComponent, Arc> |
---|
[57] | 1237 | ArcNotifier; |
---|
[209] | 1238 | |
---|
[1186] | 1239 | mutable NodeNotifier node_notifier; |
---|
| 1240 | mutable ArcNotifier arc_notifier; |
---|
| 1241 | |
---|
[626] | 1242 | /// \brief Return the node alteration notifier. |
---|
[57] | 1243 | /// |
---|
[626] | 1244 | /// This function gives back the node alteration notifier. |
---|
[57] | 1245 | NodeNotifier& notifier(Node) const { |
---|
[1186] | 1246 | return node_notifier; |
---|
[57] | 1247 | } |
---|
[209] | 1248 | |
---|
[626] | 1249 | /// \brief Return the arc alteration notifier. |
---|
[57] | 1250 | /// |
---|
[626] | 1251 | /// This function gives back the arc alteration notifier. |
---|
[57] | 1252 | ArcNotifier& notifier(Arc) const { |
---|
[1186] | 1253 | return arc_notifier; |
---|
[57] | 1254 | } |
---|
| 1255 | |
---|
[209] | 1256 | template <typename _Digraph> |
---|
[57] | 1257 | struct Constraints { |
---|
[209] | 1258 | void constraints() { |
---|
| 1259 | checkConcept<Base, _Digraph>(); |
---|
| 1260 | typename _Digraph::NodeNotifier& nn |
---|
[57] | 1261 | = digraph.notifier(typename _Digraph::Node()); |
---|
| 1262 | |
---|
[209] | 1263 | typename _Digraph::ArcNotifier& en |
---|
[57] | 1264 | = digraph.notifier(typename _Digraph::Arc()); |
---|
[209] | 1265 | |
---|
[57] | 1266 | ignore_unused_variable_warning(nn); |
---|
| 1267 | ignore_unused_variable_warning(en); |
---|
[209] | 1268 | } |
---|
| 1269 | |
---|
| 1270 | const _Digraph& digraph; |
---|
[1125] | 1271 | Constraints() {} |
---|
[57] | 1272 | }; |
---|
| 1273 | }; |
---|
| 1274 | |
---|
[626] | 1275 | /// \brief Skeleton class for alterable undirected graphs. |
---|
[209] | 1276 | /// |
---|
[626] | 1277 | /// This class describes the interface of alterable undirected |
---|
| 1278 | /// graphs. It extends \ref AlterableDigraphComponent with the alteration |
---|
| 1279 | /// notifier interface of undirected graphs. It implements |
---|
| 1280 | /// an observer-notifier pattern for the edges. More |
---|
[57] | 1281 | /// obsevers can be registered into the notifier and whenever an |
---|
[626] | 1282 | /// alteration occured in the graph all the observers will be |
---|
[57] | 1283 | /// notified about it. |
---|
[606] | 1284 | template <typename BAS = BaseGraphComponent> |
---|
| 1285 | class AlterableGraphComponent : public AlterableDigraphComponent<BAS> { |
---|
[57] | 1286 | public: |
---|
| 1287 | |
---|
[606] | 1288 | typedef BAS Base; |
---|
[1186] | 1289 | typedef AlterableDigraphComponent<Base> Parent; |
---|
[57] | 1290 | typedef typename Base::Edge Edge; |
---|
| 1291 | |
---|
| 1292 | |
---|
[626] | 1293 | /// Edge alteration notifier class. |
---|
[209] | 1294 | typedef AlterationNotifier<AlterableGraphComponent, Edge> |
---|
[57] | 1295 | EdgeNotifier; |
---|
[209] | 1296 | |
---|
[1186] | 1297 | mutable EdgeNotifier edge_notifier; |
---|
| 1298 | |
---|
| 1299 | using Parent::notifier; |
---|
| 1300 | |
---|
[626] | 1301 | /// \brief Return the edge alteration notifier. |
---|
[57] | 1302 | /// |
---|
[626] | 1303 | /// This function gives back the edge alteration notifier. |
---|
[57] | 1304 | EdgeNotifier& notifier(Edge) const { |
---|
[1186] | 1305 | return edge_notifier; |
---|
[57] | 1306 | } |
---|
| 1307 | |
---|
[209] | 1308 | template <typename _Graph> |
---|
[57] | 1309 | struct Constraints { |
---|
[209] | 1310 | void constraints() { |
---|
[626] | 1311 | checkConcept<AlterableDigraphComponent<Base>, _Graph>(); |
---|
[209] | 1312 | typename _Graph::EdgeNotifier& uen |
---|
[57] | 1313 | = graph.notifier(typename _Graph::Edge()); |
---|
| 1314 | ignore_unused_variable_warning(uen); |
---|
[209] | 1315 | } |
---|
| 1316 | |
---|
| 1317 | const _Graph& graph; |
---|
[1125] | 1318 | Constraints() {} |
---|
[57] | 1319 | }; |
---|
| 1320 | }; |
---|
| 1321 | |
---|
[1186] | 1322 | /// \brief Skeleton class for alterable undirected bipartite graphs. |
---|
| 1323 | /// |
---|
| 1324 | /// This class describes the interface of alterable undirected |
---|
| 1325 | /// bipartite graphs. It extends \ref AlterableGraphComponent with |
---|
| 1326 | /// the alteration notifier interface of bipartite graphs. It |
---|
| 1327 | /// implements an observer-notifier pattern for the red and blue |
---|
| 1328 | /// nodes. More obsevers can be registered into the notifier and |
---|
| 1329 | /// whenever an alteration occured in the graph all the observers |
---|
| 1330 | /// will be notified about it. |
---|
| 1331 | template <typename BAS = BaseBpGraphComponent> |
---|
| 1332 | class AlterableBpGraphComponent : public AlterableGraphComponent<BAS> { |
---|
| 1333 | public: |
---|
| 1334 | |
---|
| 1335 | typedef BAS Base; |
---|
| 1336 | typedef AlterableGraphComponent<Base> Parent; |
---|
| 1337 | typedef typename Base::RedNode RedNode; |
---|
| 1338 | typedef typename Base::BlueNode BlueNode; |
---|
| 1339 | |
---|
| 1340 | |
---|
| 1341 | /// Red node alteration notifier class. |
---|
| 1342 | typedef AlterationNotifier<AlterableBpGraphComponent, RedNode> |
---|
| 1343 | RedNodeNotifier; |
---|
| 1344 | |
---|
| 1345 | /// Blue node alteration notifier class. |
---|
| 1346 | typedef AlterationNotifier<AlterableBpGraphComponent, BlueNode> |
---|
| 1347 | BlueNodeNotifier; |
---|
| 1348 | |
---|
| 1349 | mutable RedNodeNotifier red_node_notifier; |
---|
| 1350 | mutable BlueNodeNotifier blue_node_notifier; |
---|
| 1351 | |
---|
| 1352 | using Parent::notifier; |
---|
| 1353 | |
---|
| 1354 | /// \brief Return the red node alteration notifier. |
---|
| 1355 | /// |
---|
| 1356 | /// This function gives back the red node alteration notifier. |
---|
| 1357 | RedNodeNotifier& notifier(RedNode) const { |
---|
| 1358 | return red_node_notifier; |
---|
| 1359 | } |
---|
| 1360 | |
---|
| 1361 | /// \brief Return the blue node alteration notifier. |
---|
| 1362 | /// |
---|
| 1363 | /// This function gives back the blue node alteration notifier. |
---|
| 1364 | BlueNodeNotifier& notifier(BlueNode) const { |
---|
| 1365 | return blue_node_notifier; |
---|
| 1366 | } |
---|
| 1367 | |
---|
| 1368 | template <typename _BpGraph> |
---|
| 1369 | struct Constraints { |
---|
| 1370 | void constraints() { |
---|
| 1371 | checkConcept<AlterableGraphComponent<Base>, _BpGraph>(); |
---|
| 1372 | typename _BpGraph::RedNodeNotifier& rnn |
---|
| 1373 | = bpgraph.notifier(typename _BpGraph::RedNode()); |
---|
| 1374 | typename _BpGraph::BlueNodeNotifier& bnn |
---|
| 1375 | = bpgraph.notifier(typename _BpGraph::BlueNode()); |
---|
| 1376 | ignore_unused_variable_warning(rnn); |
---|
| 1377 | ignore_unused_variable_warning(bnn); |
---|
| 1378 | } |
---|
| 1379 | |
---|
| 1380 | const _BpGraph& bpgraph; |
---|
| 1381 | }; |
---|
| 1382 | }; |
---|
| 1383 | |
---|
[626] | 1384 | /// \brief Concept class for standard graph maps. |
---|
[209] | 1385 | /// |
---|
[626] | 1386 | /// This class describes the concept of standard graph maps, i.e. |
---|
[956] | 1387 | /// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and |
---|
[626] | 1388 | /// graph types, which can be used for associating data to graph items. |
---|
[627] | 1389 | /// The standard graph maps must conform to the ReferenceMap concept. |
---|
[606] | 1390 | template <typename GR, typename K, typename V> |
---|
[627] | 1391 | class GraphMap : public ReferenceMap<K, V, V&, const V&> { |
---|
[664] | 1392 | typedef ReferenceMap<K, V, V&, const V&> Parent; |
---|
| 1393 | |
---|
[57] | 1394 | public: |
---|
| 1395 | |
---|
| 1396 | /// The key type of the map. |
---|
[606] | 1397 | typedef K Key; |
---|
[57] | 1398 | /// The value type of the map. |
---|
[606] | 1399 | typedef V Value; |
---|
[627] | 1400 | /// The reference type of the map. |
---|
| 1401 | typedef Value& Reference; |
---|
| 1402 | /// The const reference type of the map. |
---|
| 1403 | typedef const Value& ConstReference; |
---|
| 1404 | |
---|
| 1405 | // The reference map tag. |
---|
| 1406 | typedef True ReferenceMapTag; |
---|
[57] | 1407 | |
---|
| 1408 | /// \brief Construct a new map. |
---|
| 1409 | /// |
---|
| 1410 | /// Construct a new map for the graph. |
---|
[664] | 1411 | explicit GraphMap(const GR&) {} |
---|
[57] | 1412 | /// \brief Construct a new map with default value. |
---|
| 1413 | /// |
---|
[626] | 1414 | /// Construct a new map for the graph and initalize the values. |
---|
[664] | 1415 | GraphMap(const GR&, const Value&) {} |
---|
[263] | 1416 | |
---|
| 1417 | private: |
---|
[57] | 1418 | /// \brief Copy constructor. |
---|
| 1419 | /// |
---|
| 1420 | /// Copy Constructor. |
---|
| 1421 | GraphMap(const GraphMap&) : Parent() {} |
---|
[209] | 1422 | |
---|
[626] | 1423 | /// \brief Assignment operator. |
---|
[57] | 1424 | /// |
---|
[626] | 1425 | /// Assignment operator. It does not mofify the underlying graph, |
---|
[57] | 1426 | /// it just iterates on the current item set and set the map |
---|
[209] | 1427 | /// with the value returned by the assigned map. |
---|
[57] | 1428 | template <typename CMap> |
---|
[209] | 1429 | GraphMap& operator=(const CMap&) { |
---|
[57] | 1430 | checkConcept<ReadMap<Key, Value>, CMap>(); |
---|
| 1431 | return *this; |
---|
| 1432 | } |
---|
| 1433 | |
---|
[263] | 1434 | public: |
---|
[57] | 1435 | template<typename _Map> |
---|
| 1436 | struct Constraints { |
---|
[209] | 1437 | void constraints() { |
---|
[627] | 1438 | checkConcept |
---|
| 1439 | <ReferenceMap<Key, Value, Value&, const Value&>, _Map>(); |
---|
[626] | 1440 | _Map m1(g); |
---|
| 1441 | _Map m2(g,t); |
---|
[956] | 1442 | |
---|
[626] | 1443 | // Copy constructor |
---|
| 1444 | // _Map m3(m); |
---|
[209] | 1445 | |
---|
[626] | 1446 | // Assignment operator |
---|
[263] | 1447 | // ReadMap<Key, Value> cmap; |
---|
[626] | 1448 | // m3 = cmap; |
---|
[57] | 1449 | |
---|
[626] | 1450 | ignore_unused_variable_warning(m1); |
---|
| 1451 | ignore_unused_variable_warning(m2); |
---|
| 1452 | // ignore_unused_variable_warning(m3); |
---|
[209] | 1453 | } |
---|
[57] | 1454 | |
---|
[626] | 1455 | const _Map &m; |
---|
[664] | 1456 | const GR &g; |
---|
[209] | 1457 | const typename GraphMap::Value &t; |
---|
[1125] | 1458 | Constraints() {} |
---|
[57] | 1459 | }; |
---|
| 1460 | |
---|
| 1461 | }; |
---|
| 1462 | |
---|
[626] | 1463 | /// \brief Skeleton class for mappable directed graphs. |
---|
[57] | 1464 | /// |
---|
[626] | 1465 | /// This class describes the interface of mappable directed graphs. |
---|
[956] | 1466 | /// It extends \ref BaseDigraphComponent with the standard digraph |
---|
[626] | 1467 | /// map classes, namely \c NodeMap and \c ArcMap. |
---|
[57] | 1468 | /// This concept is part of the Digraph concept. |
---|
[606] | 1469 | template <typename BAS = BaseDigraphComponent> |
---|
| 1470 | class MappableDigraphComponent : public BAS { |
---|
[57] | 1471 | public: |
---|
| 1472 | |
---|
[606] | 1473 | typedef BAS Base; |
---|
[57] | 1474 | typedef typename Base::Node Node; |
---|
| 1475 | typedef typename Base::Arc Arc; |
---|
| 1476 | |
---|
| 1477 | typedef MappableDigraphComponent Digraph; |
---|
| 1478 | |
---|
[626] | 1479 | /// \brief Standard graph map for the nodes. |
---|
[57] | 1480 | /// |
---|
[626] | 1481 | /// Standard graph map for the nodes. |
---|
[627] | 1482 | /// It conforms to the ReferenceMap concept. |
---|
[606] | 1483 | template <typename V> |
---|
[626] | 1484 | class NodeMap : public GraphMap<MappableDigraphComponent, Node, V> { |
---|
[606] | 1485 | typedef GraphMap<MappableDigraphComponent, Node, V> Parent; |
---|
[57] | 1486 | |
---|
[664] | 1487 | public: |
---|
[209] | 1488 | /// \brief Construct a new map. |
---|
| 1489 | /// |
---|
| 1490 | /// Construct a new map for the digraph. |
---|
| 1491 | explicit NodeMap(const MappableDigraphComponent& digraph) |
---|
[57] | 1492 | : Parent(digraph) {} |
---|
| 1493 | |
---|
[209] | 1494 | /// \brief Construct a new map with default value. |
---|
| 1495 | /// |
---|
[626] | 1496 | /// Construct a new map for the digraph and initalize the values. |
---|
[606] | 1497 | NodeMap(const MappableDigraphComponent& digraph, const V& value) |
---|
[57] | 1498 | : Parent(digraph, value) {} |
---|
| 1499 | |
---|
[263] | 1500 | private: |
---|
[209] | 1501 | /// \brief Copy constructor. |
---|
| 1502 | /// |
---|
| 1503 | /// Copy Constructor. |
---|
| 1504 | NodeMap(const NodeMap& nm) : Parent(nm) {} |
---|
[57] | 1505 | |
---|
[626] | 1506 | /// \brief Assignment operator. |
---|
[209] | 1507 | /// |
---|
[626] | 1508 | /// Assignment operator. |
---|
[57] | 1509 | template <typename CMap> |
---|
[209] | 1510 | NodeMap& operator=(const CMap&) { |
---|
[606] | 1511 | checkConcept<ReadMap<Node, V>, CMap>(); |
---|
[57] | 1512 | return *this; |
---|
| 1513 | } |
---|
| 1514 | |
---|
| 1515 | }; |
---|
| 1516 | |
---|
[626] | 1517 | /// \brief Standard graph map for the arcs. |
---|
[57] | 1518 | /// |
---|
[626] | 1519 | /// Standard graph map for the arcs. |
---|
[627] | 1520 | /// It conforms to the ReferenceMap concept. |
---|
[606] | 1521 | template <typename V> |
---|
[626] | 1522 | class ArcMap : public GraphMap<MappableDigraphComponent, Arc, V> { |
---|
[606] | 1523 | typedef GraphMap<MappableDigraphComponent, Arc, V> Parent; |
---|
[57] | 1524 | |
---|
[664] | 1525 | public: |
---|
[209] | 1526 | /// \brief Construct a new map. |
---|
| 1527 | /// |
---|
| 1528 | /// Construct a new map for the digraph. |
---|
| 1529 | explicit ArcMap(const MappableDigraphComponent& digraph) |
---|
[57] | 1530 | : Parent(digraph) {} |
---|
| 1531 | |
---|
[209] | 1532 | /// \brief Construct a new map with default value. |
---|
| 1533 | /// |
---|
[626] | 1534 | /// Construct a new map for the digraph and initalize the values. |
---|
[606] | 1535 | ArcMap(const MappableDigraphComponent& digraph, const V& value) |
---|
[57] | 1536 | : Parent(digraph, value) {} |
---|
| 1537 | |
---|
[263] | 1538 | private: |
---|
[209] | 1539 | /// \brief Copy constructor. |
---|
| 1540 | /// |
---|
| 1541 | /// Copy Constructor. |
---|
| 1542 | ArcMap(const ArcMap& nm) : Parent(nm) {} |
---|
[57] | 1543 | |
---|
[626] | 1544 | /// \brief Assignment operator. |
---|
[209] | 1545 | /// |
---|
[626] | 1546 | /// Assignment operator. |
---|
[57] | 1547 | template <typename CMap> |
---|
[209] | 1548 | ArcMap& operator=(const CMap&) { |
---|
[606] | 1549 | checkConcept<ReadMap<Arc, V>, CMap>(); |
---|
[57] | 1550 | return *this; |
---|
| 1551 | } |
---|
| 1552 | |
---|
| 1553 | }; |
---|
| 1554 | |
---|
| 1555 | |
---|
| 1556 | template <typename _Digraph> |
---|
| 1557 | struct Constraints { |
---|
| 1558 | |
---|
[209] | 1559 | struct Dummy { |
---|
| 1560 | int value; |
---|
| 1561 | Dummy() : value(0) {} |
---|
| 1562 | Dummy(int _v) : value(_v) {} |
---|
| 1563 | }; |
---|
[57] | 1564 | |
---|
[209] | 1565 | void constraints() { |
---|
| 1566 | checkConcept<Base, _Digraph>(); |
---|
| 1567 | { // int map test |
---|
| 1568 | typedef typename _Digraph::template NodeMap<int> IntNodeMap; |
---|
| 1569 | checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>, |
---|
| 1570 | IntNodeMap >(); |
---|
| 1571 | } { // bool map test |
---|
| 1572 | typedef typename _Digraph::template NodeMap<bool> BoolNodeMap; |
---|
| 1573 | checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>, |
---|
| 1574 | BoolNodeMap >(); |
---|
| 1575 | } { // Dummy map test |
---|
| 1576 | typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap; |
---|
| 1577 | checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>, |
---|
| 1578 | DummyNodeMap >(); |
---|
| 1579 | } |
---|
[57] | 1580 | |
---|
[209] | 1581 | { // int map test |
---|
| 1582 | typedef typename _Digraph::template ArcMap<int> IntArcMap; |
---|
| 1583 | checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>, |
---|
| 1584 | IntArcMap >(); |
---|
| 1585 | } { // bool map test |
---|
| 1586 | typedef typename _Digraph::template ArcMap<bool> BoolArcMap; |
---|
| 1587 | checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>, |
---|
| 1588 | BoolArcMap >(); |
---|
| 1589 | } { // Dummy map test |
---|
| 1590 | typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap; |
---|
| 1591 | checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>, |
---|
| 1592 | DummyArcMap >(); |
---|
| 1593 | } |
---|
| 1594 | } |
---|
[57] | 1595 | |
---|
[626] | 1596 | const _Digraph& digraph; |
---|
[1125] | 1597 | Constraints() {} |
---|
[57] | 1598 | }; |
---|
| 1599 | }; |
---|
| 1600 | |
---|
[626] | 1601 | /// \brief Skeleton class for mappable undirected graphs. |
---|
[57] | 1602 | /// |
---|
[626] | 1603 | /// This class describes the interface of mappable undirected graphs. |
---|
[956] | 1604 | /// It extends \ref MappableDigraphComponent with the standard graph |
---|
[626] | 1605 | /// map class for edges (\c EdgeMap). |
---|
[57] | 1606 | /// This concept is part of the Graph concept. |
---|
[606] | 1607 | template <typename BAS = BaseGraphComponent> |
---|
| 1608 | class MappableGraphComponent : public MappableDigraphComponent<BAS> { |
---|
[57] | 1609 | public: |
---|
| 1610 | |
---|
[606] | 1611 | typedef BAS Base; |
---|
[57] | 1612 | typedef typename Base::Edge Edge; |
---|
| 1613 | |
---|
| 1614 | typedef MappableGraphComponent Graph; |
---|
| 1615 | |
---|
[626] | 1616 | /// \brief Standard graph map for the edges. |
---|
[57] | 1617 | /// |
---|
[626] | 1618 | /// Standard graph map for the edges. |
---|
[627] | 1619 | /// It conforms to the ReferenceMap concept. |
---|
[606] | 1620 | template <typename V> |
---|
[626] | 1621 | class EdgeMap : public GraphMap<MappableGraphComponent, Edge, V> { |
---|
[606] | 1622 | typedef GraphMap<MappableGraphComponent, Edge, V> Parent; |
---|
[57] | 1623 | |
---|
[664] | 1624 | public: |
---|
[209] | 1625 | /// \brief Construct a new map. |
---|
| 1626 | /// |
---|
| 1627 | /// Construct a new map for the graph. |
---|
| 1628 | explicit EdgeMap(const MappableGraphComponent& graph) |
---|
[57] | 1629 | : Parent(graph) {} |
---|
| 1630 | |
---|
[209] | 1631 | /// \brief Construct a new map with default value. |
---|
| 1632 | /// |
---|
[626] | 1633 | /// Construct a new map for the graph and initalize the values. |
---|
[606] | 1634 | EdgeMap(const MappableGraphComponent& graph, const V& value) |
---|
[57] | 1635 | : Parent(graph, value) {} |
---|
| 1636 | |
---|
[263] | 1637 | private: |
---|
[209] | 1638 | /// \brief Copy constructor. |
---|
| 1639 | /// |
---|
| 1640 | /// Copy Constructor. |
---|
| 1641 | EdgeMap(const EdgeMap& nm) : Parent(nm) {} |
---|
[57] | 1642 | |
---|
[626] | 1643 | /// \brief Assignment operator. |
---|
[209] | 1644 | /// |
---|
[626] | 1645 | /// Assignment operator. |
---|
[57] | 1646 | template <typename CMap> |
---|
[209] | 1647 | EdgeMap& operator=(const CMap&) { |
---|
[606] | 1648 | checkConcept<ReadMap<Edge, V>, CMap>(); |
---|
[57] | 1649 | return *this; |
---|
| 1650 | } |
---|
| 1651 | |
---|
| 1652 | }; |
---|
| 1653 | |
---|
| 1654 | |
---|
| 1655 | template <typename _Graph> |
---|
| 1656 | struct Constraints { |
---|
| 1657 | |
---|
[209] | 1658 | struct Dummy { |
---|
| 1659 | int value; |
---|
| 1660 | Dummy() : value(0) {} |
---|
| 1661 | Dummy(int _v) : value(_v) {} |
---|
| 1662 | }; |
---|
[57] | 1663 | |
---|
[209] | 1664 | void constraints() { |
---|
[626] | 1665 | checkConcept<MappableDigraphComponent<Base>, _Graph>(); |
---|
[57] | 1666 | |
---|
[209] | 1667 | { // int map test |
---|
| 1668 | typedef typename _Graph::template EdgeMap<int> IntEdgeMap; |
---|
| 1669 | checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>, |
---|
| 1670 | IntEdgeMap >(); |
---|
| 1671 | } { // bool map test |
---|
| 1672 | typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap; |
---|
| 1673 | checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>, |
---|
| 1674 | BoolEdgeMap >(); |
---|
| 1675 | } { // Dummy map test |
---|
| 1676 | typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap; |
---|
| 1677 | checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>, |
---|
| 1678 | DummyEdgeMap >(); |
---|
| 1679 | } |
---|
| 1680 | } |
---|
[57] | 1681 | |
---|
[626] | 1682 | const _Graph& graph; |
---|
[1125] | 1683 | Constraints() {} |
---|
[57] | 1684 | }; |
---|
| 1685 | }; |
---|
| 1686 | |
---|
[1186] | 1687 | /// \brief Skeleton class for mappable undirected bipartite graphs. |
---|
| 1688 | /// |
---|
| 1689 | /// This class describes the interface of mappable undirected |
---|
| 1690 | /// bipartite graphs. It extends \ref MappableGraphComponent with |
---|
| 1691 | /// the standard graph map class for red and blue nodes (\c |
---|
| 1692 | /// RedMap and BlueMap). This concept is part of the BpGraph concept. |
---|
| 1693 | template <typename BAS = BaseBpGraphComponent> |
---|
| 1694 | class MappableBpGraphComponent : public MappableGraphComponent<BAS> { |
---|
| 1695 | public: |
---|
| 1696 | |
---|
| 1697 | typedef BAS Base; |
---|
| 1698 | typedef typename Base::Node Node; |
---|
| 1699 | |
---|
| 1700 | typedef MappableBpGraphComponent BpGraph; |
---|
| 1701 | |
---|
| 1702 | /// \brief Standard graph map for the red nodes. |
---|
| 1703 | /// |
---|
| 1704 | /// Standard graph map for the red nodes. |
---|
| 1705 | /// It conforms to the ReferenceMap concept. |
---|
| 1706 | template <typename V> |
---|
| 1707 | class RedMap : public GraphMap<MappableBpGraphComponent, Node, V> { |
---|
| 1708 | typedef GraphMap<MappableBpGraphComponent, Node, V> Parent; |
---|
| 1709 | |
---|
| 1710 | public: |
---|
| 1711 | /// \brief Construct a new map. |
---|
| 1712 | /// |
---|
| 1713 | /// Construct a new map for the graph. |
---|
| 1714 | explicit RedMap(const MappableBpGraphComponent& graph) |
---|
| 1715 | : Parent(graph) {} |
---|
| 1716 | |
---|
| 1717 | /// \brief Construct a new map with default value. |
---|
| 1718 | /// |
---|
| 1719 | /// Construct a new map for the graph and initalize the values. |
---|
| 1720 | RedMap(const MappableBpGraphComponent& graph, const V& value) |
---|
| 1721 | : Parent(graph, value) {} |
---|
| 1722 | |
---|
| 1723 | private: |
---|
| 1724 | /// \brief Copy constructor. |
---|
| 1725 | /// |
---|
| 1726 | /// Copy Constructor. |
---|
| 1727 | RedMap(const RedMap& nm) : Parent(nm) {} |
---|
| 1728 | |
---|
| 1729 | /// \brief Assignment operator. |
---|
| 1730 | /// |
---|
| 1731 | /// Assignment operator. |
---|
| 1732 | template <typename CMap> |
---|
| 1733 | RedMap& operator=(const CMap&) { |
---|
| 1734 | checkConcept<ReadMap<Node, V>, CMap>(); |
---|
| 1735 | return *this; |
---|
| 1736 | } |
---|
| 1737 | |
---|
| 1738 | }; |
---|
| 1739 | |
---|
| 1740 | /// \brief Standard graph map for the blue nodes. |
---|
| 1741 | /// |
---|
| 1742 | /// Standard graph map for the blue nodes. |
---|
| 1743 | /// It conforms to the ReferenceMap concept. |
---|
| 1744 | template <typename V> |
---|
| 1745 | class BlueMap : public GraphMap<MappableBpGraphComponent, Node, V> { |
---|
| 1746 | typedef GraphMap<MappableBpGraphComponent, Node, V> Parent; |
---|
| 1747 | |
---|
| 1748 | public: |
---|
| 1749 | /// \brief Construct a new map. |
---|
| 1750 | /// |
---|
| 1751 | /// Construct a new map for the graph. |
---|
| 1752 | explicit BlueMap(const MappableBpGraphComponent& graph) |
---|
| 1753 | : Parent(graph) {} |
---|
| 1754 | |
---|
| 1755 | /// \brief Construct a new map with default value. |
---|
| 1756 | /// |
---|
| 1757 | /// Construct a new map for the graph and initalize the values. |
---|
| 1758 | BlueMap(const MappableBpGraphComponent& graph, const V& value) |
---|
| 1759 | : Parent(graph, value) {} |
---|
| 1760 | |
---|
| 1761 | private: |
---|
| 1762 | /// \brief Copy constructor. |
---|
| 1763 | /// |
---|
| 1764 | /// Copy Constructor. |
---|
| 1765 | BlueMap(const BlueMap& nm) : Parent(nm) {} |
---|
| 1766 | |
---|
| 1767 | /// \brief Assignment operator. |
---|
| 1768 | /// |
---|
| 1769 | /// Assignment operator. |
---|
| 1770 | template <typename CMap> |
---|
| 1771 | BlueMap& operator=(const CMap&) { |
---|
| 1772 | checkConcept<ReadMap<Node, V>, CMap>(); |
---|
| 1773 | return *this; |
---|
| 1774 | } |
---|
| 1775 | |
---|
| 1776 | }; |
---|
| 1777 | |
---|
| 1778 | |
---|
| 1779 | template <typename _BpGraph> |
---|
| 1780 | struct Constraints { |
---|
| 1781 | |
---|
| 1782 | struct Dummy { |
---|
| 1783 | int value; |
---|
| 1784 | Dummy() : value(0) {} |
---|
| 1785 | Dummy(int _v) : value(_v) {} |
---|
| 1786 | }; |
---|
| 1787 | |
---|
| 1788 | void constraints() { |
---|
| 1789 | checkConcept<MappableGraphComponent<Base>, _BpGraph>(); |
---|
| 1790 | |
---|
| 1791 | { // int map test |
---|
| 1792 | typedef typename _BpGraph::template RedMap<int> IntRedMap; |
---|
| 1793 | checkConcept<GraphMap<_BpGraph, typename _BpGraph::Node, int>, |
---|
| 1794 | IntRedMap >(); |
---|
| 1795 | } { // bool map test |
---|
| 1796 | typedef typename _BpGraph::template RedMap<bool> BoolRedMap; |
---|
| 1797 | checkConcept<GraphMap<_BpGraph, typename _BpGraph::Node, bool>, |
---|
| 1798 | BoolRedMap >(); |
---|
| 1799 | } { // Dummy map test |
---|
| 1800 | typedef typename _BpGraph::template RedMap<Dummy> DummyRedMap; |
---|
| 1801 | checkConcept<GraphMap<_BpGraph, typename _BpGraph::Node, Dummy>, |
---|
| 1802 | DummyRedMap >(); |
---|
| 1803 | } |
---|
| 1804 | |
---|
| 1805 | { // int map test |
---|
| 1806 | typedef typename _BpGraph::template BlueMap<int> IntBlueMap; |
---|
| 1807 | checkConcept<GraphMap<_BpGraph, typename _BpGraph::Node, int>, |
---|
| 1808 | IntBlueMap >(); |
---|
| 1809 | } { // bool map test |
---|
| 1810 | typedef typename _BpGraph::template BlueMap<bool> BoolBlueMap; |
---|
| 1811 | checkConcept<GraphMap<_BpGraph, typename _BpGraph::Node, bool>, |
---|
| 1812 | BoolBlueMap >(); |
---|
| 1813 | } { // Dummy map test |
---|
| 1814 | typedef typename _BpGraph::template BlueMap<Dummy> DummyBlueMap; |
---|
| 1815 | checkConcept<GraphMap<_BpGraph, typename _BpGraph::Node, Dummy>, |
---|
| 1816 | DummyBlueMap >(); |
---|
| 1817 | } |
---|
| 1818 | } |
---|
| 1819 | |
---|
| 1820 | const _BpGraph& bpgraph; |
---|
| 1821 | }; |
---|
| 1822 | }; |
---|
| 1823 | |
---|
[626] | 1824 | /// \brief Skeleton class for extendable directed graphs. |
---|
[57] | 1825 | /// |
---|
[626] | 1826 | /// This class describes the interface of extendable directed graphs. |
---|
[956] | 1827 | /// It extends \ref BaseDigraphComponent with functions for adding |
---|
[626] | 1828 | /// nodes and arcs to the digraph. |
---|
| 1829 | /// This concept requires \ref AlterableDigraphComponent. |
---|
[606] | 1830 | template <typename BAS = BaseDigraphComponent> |
---|
| 1831 | class ExtendableDigraphComponent : public BAS { |
---|
[57] | 1832 | public: |
---|
[606] | 1833 | typedef BAS Base; |
---|
[57] | 1834 | |
---|
[606] | 1835 | typedef typename Base::Node Node; |
---|
| 1836 | typedef typename Base::Arc Arc; |
---|
[57] | 1837 | |
---|
[626] | 1838 | /// \brief Add a new node to the digraph. |
---|
[57] | 1839 | /// |
---|
[626] | 1840 | /// This function adds a new node to the digraph. |
---|
[57] | 1841 | Node addNode() { |
---|
[209] | 1842 | return INVALID; |
---|
[57] | 1843 | } |
---|
[209] | 1844 | |
---|
[626] | 1845 | /// \brief Add a new arc connecting the given two nodes. |
---|
[57] | 1846 | /// |
---|
[626] | 1847 | /// This function adds a new arc connecting the given two nodes |
---|
| 1848 | /// of the digraph. |
---|
[57] | 1849 | Arc addArc(const Node&, const Node&) { |
---|
[209] | 1850 | return INVALID; |
---|
[57] | 1851 | } |
---|
| 1852 | |
---|
| 1853 | template <typename _Digraph> |
---|
| 1854 | struct Constraints { |
---|
[209] | 1855 | void constraints() { |
---|
[57] | 1856 | checkConcept<Base, _Digraph>(); |
---|
[209] | 1857 | typename _Digraph::Node node_a, node_b; |
---|
| 1858 | node_a = digraph.addNode(); |
---|
| 1859 | node_b = digraph.addNode(); |
---|
| 1860 | typename _Digraph::Arc arc; |
---|
| 1861 | arc = digraph.addArc(node_a, node_b); |
---|
| 1862 | } |
---|
[57] | 1863 | |
---|
[209] | 1864 | _Digraph& digraph; |
---|
[1125] | 1865 | Constraints() {} |
---|
[57] | 1866 | }; |
---|
| 1867 | }; |
---|
| 1868 | |
---|
[626] | 1869 | /// \brief Skeleton class for extendable undirected graphs. |
---|
[57] | 1870 | /// |
---|
[626] | 1871 | /// This class describes the interface of extendable undirected graphs. |
---|
[956] | 1872 | /// It extends \ref BaseGraphComponent with functions for adding |
---|
[626] | 1873 | /// nodes and edges to the graph. |
---|
| 1874 | /// This concept requires \ref AlterableGraphComponent. |
---|
[606] | 1875 | template <typename BAS = BaseGraphComponent> |
---|
| 1876 | class ExtendableGraphComponent : public BAS { |
---|
[57] | 1877 | public: |
---|
| 1878 | |
---|
[606] | 1879 | typedef BAS Base; |
---|
| 1880 | typedef typename Base::Node Node; |
---|
| 1881 | typedef typename Base::Edge Edge; |
---|
[57] | 1882 | |
---|
[626] | 1883 | /// \brief Add a new node to the digraph. |
---|
[57] | 1884 | /// |
---|
[626] | 1885 | /// This function adds a new node to the digraph. |
---|
[57] | 1886 | Node addNode() { |
---|
[209] | 1887 | return INVALID; |
---|
[57] | 1888 | } |
---|
[209] | 1889 | |
---|
[626] | 1890 | /// \brief Add a new edge connecting the given two nodes. |
---|
[57] | 1891 | /// |
---|
[626] | 1892 | /// This function adds a new edge connecting the given two nodes |
---|
| 1893 | /// of the graph. |
---|
| 1894 | Edge addEdge(const Node&, const Node&) { |
---|
[209] | 1895 | return INVALID; |
---|
[57] | 1896 | } |
---|
| 1897 | |
---|
| 1898 | template <typename _Graph> |
---|
| 1899 | struct Constraints { |
---|
[209] | 1900 | void constraints() { |
---|
| 1901 | checkConcept<Base, _Graph>(); |
---|
| 1902 | typename _Graph::Node node_a, node_b; |
---|
| 1903 | node_a = graph.addNode(); |
---|
| 1904 | node_b = graph.addNode(); |
---|
| 1905 | typename _Graph::Edge edge; |
---|
| 1906 | edge = graph.addEdge(node_a, node_b); |
---|
| 1907 | } |
---|
[57] | 1908 | |
---|
[209] | 1909 | _Graph& graph; |
---|
[1125] | 1910 | Constraints() {} |
---|
[57] | 1911 | }; |
---|
| 1912 | }; |
---|
| 1913 | |
---|
[1186] | 1914 | /// \brief Skeleton class for extendable undirected bipartite graphs. |
---|
| 1915 | /// |
---|
| 1916 | /// This class describes the interface of extendable undirected |
---|
| 1917 | /// bipartite graphs. It extends \ref BaseGraphComponent with |
---|
| 1918 | /// functions for adding nodes and edges to the graph. This |
---|
| 1919 | /// concept requires \ref AlterableBpGraphComponent. |
---|
| 1920 | template <typename BAS = BaseBpGraphComponent> |
---|
| 1921 | class ExtendableBpGraphComponent : public BAS { |
---|
| 1922 | public: |
---|
| 1923 | |
---|
| 1924 | typedef BAS Base; |
---|
| 1925 | typedef typename Base::Node Node; |
---|
| 1926 | typedef typename Base::Edge Edge; |
---|
| 1927 | |
---|
| 1928 | /// \brief Add a new red node to the digraph. |
---|
| 1929 | /// |
---|
| 1930 | /// This function adds a red new node to the digraph. |
---|
| 1931 | Node addRedNode() { |
---|
| 1932 | return INVALID; |
---|
| 1933 | } |
---|
| 1934 | |
---|
| 1935 | /// \brief Add a new blue node to the digraph. |
---|
| 1936 | /// |
---|
| 1937 | /// This function adds a blue new node to the digraph. |
---|
| 1938 | Node addBlueNode() { |
---|
| 1939 | return INVALID; |
---|
| 1940 | } |
---|
| 1941 | |
---|
| 1942 | /// \brief Add a new edge connecting the given two nodes. |
---|
| 1943 | /// |
---|
| 1944 | /// This function adds a new edge connecting the given two nodes |
---|
| 1945 | /// of the graph. The first node has to be a red node, and the |
---|
| 1946 | /// second one a blue node. |
---|
| 1947 | Edge addEdge(const Node&, const Node&) { |
---|
| 1948 | return INVALID; |
---|
| 1949 | } |
---|
| 1950 | |
---|
| 1951 | template <typename _BpGraph> |
---|
| 1952 | struct Constraints { |
---|
| 1953 | void constraints() { |
---|
| 1954 | checkConcept<Base, _BpGraph>(); |
---|
| 1955 | typename _BpGraph::Node red_node, blue_node; |
---|
| 1956 | red_node = bpgraph.addRedNode(); |
---|
| 1957 | blue_node = bpgraph.addBlueNode(); |
---|
| 1958 | typename _BpGraph::Edge edge; |
---|
| 1959 | edge = bpgraph.addEdge(red_node, blue_node); |
---|
| 1960 | } |
---|
| 1961 | |
---|
| 1962 | _BpGraph& bpgraph; |
---|
| 1963 | }; |
---|
| 1964 | }; |
---|
| 1965 | |
---|
[626] | 1966 | /// \brief Skeleton class for erasable directed graphs. |
---|
[209] | 1967 | /// |
---|
[626] | 1968 | /// This class describes the interface of erasable directed graphs. |
---|
[956] | 1969 | /// It extends \ref BaseDigraphComponent with functions for removing |
---|
[626] | 1970 | /// nodes and arcs from the digraph. |
---|
| 1971 | /// This concept requires \ref AlterableDigraphComponent. |
---|
[606] | 1972 | template <typename BAS = BaseDigraphComponent> |
---|
| 1973 | class ErasableDigraphComponent : public BAS { |
---|
[57] | 1974 | public: |
---|
| 1975 | |
---|
[606] | 1976 | typedef BAS Base; |
---|
[57] | 1977 | typedef typename Base::Node Node; |
---|
| 1978 | typedef typename Base::Arc Arc; |
---|
| 1979 | |
---|
| 1980 | /// \brief Erase a node from the digraph. |
---|
| 1981 | /// |
---|
[956] | 1982 | /// This function erases the given node from the digraph and all arcs |
---|
[626] | 1983 | /// connected to the node. |
---|
[209] | 1984 | void erase(const Node&) {} |
---|
[57] | 1985 | |
---|
| 1986 | /// \brief Erase an arc from the digraph. |
---|
| 1987 | /// |
---|
[626] | 1988 | /// This function erases the given arc from the digraph. |
---|
[57] | 1989 | void erase(const Arc&) {} |
---|
| 1990 | |
---|
| 1991 | template <typename _Digraph> |
---|
| 1992 | struct Constraints { |
---|
[209] | 1993 | void constraints() { |
---|
[57] | 1994 | checkConcept<Base, _Digraph>(); |
---|
[626] | 1995 | const typename _Digraph::Node node(INVALID); |
---|
[209] | 1996 | digraph.erase(node); |
---|
[626] | 1997 | const typename _Digraph::Arc arc(INVALID); |
---|
[209] | 1998 | digraph.erase(arc); |
---|
| 1999 | } |
---|
[57] | 2000 | |
---|
[209] | 2001 | _Digraph& digraph; |
---|
[1125] | 2002 | Constraints() {} |
---|
[57] | 2003 | }; |
---|
| 2004 | }; |
---|
| 2005 | |
---|
[626] | 2006 | /// \brief Skeleton class for erasable undirected graphs. |
---|
[209] | 2007 | /// |
---|
[626] | 2008 | /// This class describes the interface of erasable undirected graphs. |
---|
[956] | 2009 | /// It extends \ref BaseGraphComponent with functions for removing |
---|
[626] | 2010 | /// nodes and edges from the graph. |
---|
| 2011 | /// This concept requires \ref AlterableGraphComponent. |
---|
[606] | 2012 | template <typename BAS = BaseGraphComponent> |
---|
| 2013 | class ErasableGraphComponent : public BAS { |
---|
[57] | 2014 | public: |
---|
| 2015 | |
---|
[606] | 2016 | typedef BAS Base; |
---|
[57] | 2017 | typedef typename Base::Node Node; |
---|
| 2018 | typedef typename Base::Edge Edge; |
---|
| 2019 | |
---|
| 2020 | /// \brief Erase a node from the graph. |
---|
| 2021 | /// |
---|
[626] | 2022 | /// This function erases the given node from the graph and all edges |
---|
| 2023 | /// connected to the node. |
---|
[209] | 2024 | void erase(const Node&) {} |
---|
[57] | 2025 | |
---|
[626] | 2026 | /// \brief Erase an edge from the digraph. |
---|
[57] | 2027 | /// |
---|
[626] | 2028 | /// This function erases the given edge from the digraph. |
---|
[57] | 2029 | void erase(const Edge&) {} |
---|
| 2030 | |
---|
| 2031 | template <typename _Graph> |
---|
| 2032 | struct Constraints { |
---|
[209] | 2033 | void constraints() { |
---|
[57] | 2034 | checkConcept<Base, _Graph>(); |
---|
[626] | 2035 | const typename _Graph::Node node(INVALID); |
---|
[209] | 2036 | graph.erase(node); |
---|
[626] | 2037 | const typename _Graph::Edge edge(INVALID); |
---|
[209] | 2038 | graph.erase(edge); |
---|
| 2039 | } |
---|
[57] | 2040 | |
---|
[209] | 2041 | _Graph& graph; |
---|
[1125] | 2042 | Constraints() {} |
---|
[57] | 2043 | }; |
---|
| 2044 | }; |
---|
| 2045 | |
---|
[1186] | 2046 | /// \brief Skeleton class for erasable undirected graphs. |
---|
| 2047 | /// |
---|
| 2048 | /// This class describes the interface of erasable undirected |
---|
| 2049 | /// bipartite graphs. It extends \ref BaseBpGraphComponent with |
---|
| 2050 | /// functions for removing nodes and edges from the graph. This |
---|
| 2051 | /// concept requires \ref AlterableBpGraphComponent. |
---|
| 2052 | template <typename BAS = BaseBpGraphComponent> |
---|
| 2053 | class ErasableBpGraphComponent : public ErasableGraphComponent<BAS> {}; |
---|
| 2054 | |
---|
[626] | 2055 | /// \brief Skeleton class for clearable directed graphs. |
---|
[57] | 2056 | /// |
---|
[626] | 2057 | /// This class describes the interface of clearable directed graphs. |
---|
| 2058 | /// It extends \ref BaseDigraphComponent with a function for clearing |
---|
| 2059 | /// the digraph. |
---|
| 2060 | /// This concept requires \ref AlterableDigraphComponent. |
---|
[606] | 2061 | template <typename BAS = BaseDigraphComponent> |
---|
| 2062 | class ClearableDigraphComponent : public BAS { |
---|
[57] | 2063 | public: |
---|
| 2064 | |
---|
[606] | 2065 | typedef BAS Base; |
---|
[57] | 2066 | |
---|
| 2067 | /// \brief Erase all nodes and arcs from the digraph. |
---|
| 2068 | /// |
---|
[626] | 2069 | /// This function erases all nodes and arcs from the digraph. |
---|
[209] | 2070 | void clear() {} |
---|
[57] | 2071 | |
---|
| 2072 | template <typename _Digraph> |
---|
| 2073 | struct Constraints { |
---|
[209] | 2074 | void constraints() { |
---|
[57] | 2075 | checkConcept<Base, _Digraph>(); |
---|
[209] | 2076 | digraph.clear(); |
---|
| 2077 | } |
---|
[57] | 2078 | |
---|
[626] | 2079 | _Digraph& digraph; |
---|
[1125] | 2080 | Constraints() {} |
---|
[57] | 2081 | }; |
---|
| 2082 | }; |
---|
| 2083 | |
---|
[626] | 2084 | /// \brief Skeleton class for clearable undirected graphs. |
---|
[57] | 2085 | /// |
---|
[626] | 2086 | /// This class describes the interface of clearable undirected graphs. |
---|
| 2087 | /// It extends \ref BaseGraphComponent with a function for clearing |
---|
| 2088 | /// the graph. |
---|
| 2089 | /// This concept requires \ref AlterableGraphComponent. |
---|
[606] | 2090 | template <typename BAS = BaseGraphComponent> |
---|
[1186] | 2091 | class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {}; |
---|
[57] | 2092 | |
---|
[1186] | 2093 | /// \brief Skeleton class for clearable undirected biparite graphs. |
---|
| 2094 | /// |
---|
| 2095 | /// This class describes the interface of clearable undirected |
---|
| 2096 | /// bipartite graphs. It extends \ref BaseBpGraphComponent with a |
---|
| 2097 | /// function for clearing the graph. This concept requires \ref |
---|
| 2098 | /// AlterableBpGraphComponent. |
---|
| 2099 | template <typename BAS = BaseBpGraphComponent> |
---|
| 2100 | class ClearableBpGraphComponent : public ClearableGraphComponent<BAS> {}; |
---|
[57] | 2101 | |
---|
| 2102 | } |
---|
| 2103 | |
---|
| 2104 | } |
---|
| 2105 | |
---|
| 2106 | #endif |
---|