[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 | * |
---|
[440] | 5 | * Copyright (C) 2003-2009 |
---|
[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 |
---|
| 21 | ///\brief The concept of graph components. |
---|
| 22 | |
---|
[529] | 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 | |
---|
| 34 | /// \brief Skeleton class for graph Node and Arc types |
---|
| 35 | /// |
---|
| 36 | /// This class describes the interface of Node and Arc (and Edge |
---|
| 37 | /// in undirected graphs) subtypes of graph types. |
---|
| 38 | /// |
---|
| 39 | /// \note This class is a template class so that we can use it to |
---|
| 40 | /// create graph skeleton classes. The reason for this is than Node |
---|
| 41 | /// and Arc types should \em not derive from the same base class. |
---|
| 42 | /// For Node you should instantiate it with character 'n' and for Arc |
---|
| 43 | /// with 'a'. |
---|
| 44 | |
---|
| 45 | #ifndef DOXYGEN |
---|
[559] | 46 | template <char sel = '0'> |
---|
[57] | 47 | #endif |
---|
| 48 | class GraphItem { |
---|
| 49 | public: |
---|
| 50 | /// \brief Default constructor. |
---|
[209] | 51 | /// |
---|
[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() {} |
---|
| 56 | /// \brief Copy constructor. |
---|
| 57 | /// |
---|
| 58 | /// Copy constructor. |
---|
| 59 | /// |
---|
| 60 | GraphItem(const GraphItem &) {} |
---|
| 61 | /// \brief Invalid constructor \& conversion. |
---|
| 62 | /// |
---|
| 63 | /// This constructor initializes the item to be invalid. |
---|
| 64 | /// \sa Invalid for more details. |
---|
| 65 | GraphItem(Invalid) {} |
---|
| 66 | /// \brief Assign operator for nodes. |
---|
| 67 | /// |
---|
[209] | 68 | /// The nodes are assignable. |
---|
[57] | 69 | /// |
---|
| 70 | GraphItem& operator=(GraphItem const&) { return *this; } |
---|
| 71 | /// \brief Equality operator. |
---|
| 72 | /// |
---|
| 73 | /// Two iterators are equal if and only if they represents the |
---|
| 74 | /// same node in the graph or both are invalid. |
---|
| 75 | bool operator==(GraphItem) const { return false; } |
---|
| 76 | /// \brief Inequality operator. |
---|
| 77 | /// |
---|
| 78 | /// \sa operator==(const Node& n) |
---|
| 79 | /// |
---|
| 80 | bool operator!=(GraphItem) const { return false; } |
---|
| 81 | |
---|
| 82 | /// \brief Artificial ordering operator. |
---|
| 83 | /// |
---|
| 84 | /// To allow the use of graph descriptors as key type in std::map or |
---|
| 85 | /// similar associative container we require this. |
---|
| 86 | /// |
---|
| 87 | /// \note This operator only have to define some strict ordering of |
---|
| 88 | /// the items; this order has nothing to do with the iteration |
---|
| 89 | /// ordering of the items. |
---|
| 90 | bool operator<(GraphItem) const { return false; } |
---|
| 91 | |
---|
| 92 | template<typename _GraphItem> |
---|
| 93 | struct Constraints { |
---|
[209] | 94 | void constraints() { |
---|
| 95 | _GraphItem i1; |
---|
| 96 | _GraphItem i2 = i1; |
---|
| 97 | _GraphItem i3 = INVALID; |
---|
[57] | 98 | |
---|
[209] | 99 | i1 = i2 = i3; |
---|
| 100 | |
---|
| 101 | bool b; |
---|
| 102 | // b = (ia == ib) && (ia != ib) && (ia < ib); |
---|
| 103 | b = (ia == ib) && (ia != ib); |
---|
| 104 | b = (ia == INVALID) && (ib != INVALID); |
---|
[57] | 105 | b = (ia < ib); |
---|
[209] | 106 | } |
---|
[57] | 107 | |
---|
[209] | 108 | const _GraphItem &ia; |
---|
| 109 | const _GraphItem &ib; |
---|
[57] | 110 | }; |
---|
| 111 | }; |
---|
| 112 | |
---|
| 113 | /// \brief An empty base directed graph class. |
---|
[209] | 114 | /// |
---|
[57] | 115 | /// This class provides the minimal set of features needed for a |
---|
[503] | 116 | /// directed graph structure. All digraph concepts have to |
---|
[57] | 117 | /// conform to this base directed graph. It just provides types |
---|
| 118 | /// for nodes and arcs and functions to get the source and the |
---|
| 119 | /// target of the arcs. |
---|
| 120 | class BaseDigraphComponent { |
---|
| 121 | public: |
---|
| 122 | |
---|
| 123 | typedef BaseDigraphComponent Digraph; |
---|
[209] | 124 | |
---|
[57] | 125 | /// \brief Node class of the digraph. |
---|
| 126 | /// |
---|
[209] | 127 | /// This class represents the Nodes of the digraph. |
---|
[57] | 128 | /// |
---|
| 129 | typedef GraphItem<'n'> Node; |
---|
| 130 | |
---|
| 131 | /// \brief Arc class of the digraph. |
---|
| 132 | /// |
---|
[209] | 133 | /// This class represents the Arcs of the digraph. |
---|
[57] | 134 | /// |
---|
| 135 | typedef GraphItem<'e'> Arc; |
---|
| 136 | |
---|
| 137 | /// \brief Gives back the target node of an arc. |
---|
| 138 | /// |
---|
| 139 | /// Gives back the target node of an arc. |
---|
| 140 | /// |
---|
| 141 | Node target(const Arc&) const { return INVALID;} |
---|
| 142 | |
---|
| 143 | /// \brief Gives back the source node of an arc. |
---|
| 144 | /// |
---|
| 145 | /// Gives back the source node of an arc. |
---|
| 146 | /// |
---|
| 147 | Node source(const Arc&) const { return INVALID;} |
---|
| 148 | |
---|
| 149 | /// \brief Gives back the opposite node on the given arc. |
---|
| 150 | /// |
---|
| 151 | /// Gives back the opposite node on the given arc. |
---|
| 152 | Node oppositeNode(const Node&, const Arc&) const { |
---|
| 153 | return INVALID; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | template <typename _Digraph> |
---|
| 157 | struct Constraints { |
---|
[209] | 158 | typedef typename _Digraph::Node Node; |
---|
| 159 | typedef typename _Digraph::Arc Arc; |
---|
| 160 | |
---|
| 161 | void constraints() { |
---|
| 162 | checkConcept<GraphItem<'n'>, Node>(); |
---|
| 163 | checkConcept<GraphItem<'a'>, Arc>(); |
---|
| 164 | { |
---|
| 165 | Node n; |
---|
| 166 | Arc e(INVALID); |
---|
| 167 | n = digraph.source(e); |
---|
| 168 | n = digraph.target(e); |
---|
[57] | 169 | n = digraph.oppositeNode(n, e); |
---|
[209] | 170 | } |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | const _Digraph& digraph; |
---|
[57] | 174 | }; |
---|
| 175 | }; |
---|
| 176 | |
---|
| 177 | /// \brief An empty base undirected graph class. |
---|
[209] | 178 | /// |
---|
[57] | 179 | /// This class provides the minimal set of features needed for an |
---|
| 180 | /// undirected graph structure. All undirected graph concepts have |
---|
[503] | 181 | /// to conform to this base graph. It just provides types for |
---|
[57] | 182 | /// nodes, arcs and edges and functions to get the |
---|
| 183 | /// source and the target of the arcs and edges, |
---|
| 184 | /// conversion from arcs to edges and function to get |
---|
| 185 | /// both direction of the edges. |
---|
| 186 | class BaseGraphComponent : public BaseDigraphComponent { |
---|
| 187 | public: |
---|
| 188 | typedef BaseDigraphComponent::Node Node; |
---|
| 189 | typedef BaseDigraphComponent::Arc Arc; |
---|
| 190 | /// \brief Undirected arc class of the graph. |
---|
| 191 | /// |
---|
| 192 | /// This class represents the edges of the graph. |
---|
| 193 | /// The undirected graphs can be used as a directed graph which |
---|
| 194 | /// for each arc contains the opposite arc too so the graph is |
---|
| 195 | /// bidirected. The edge represents two opposite |
---|
| 196 | /// directed arcs. |
---|
| 197 | class Edge : public GraphItem<'u'> { |
---|
| 198 | public: |
---|
| 199 | typedef GraphItem<'u'> Parent; |
---|
| 200 | /// \brief Default constructor. |
---|
[209] | 201 | /// |
---|
[57] | 202 | /// \warning The default constructor is not required to set |
---|
| 203 | /// the item to some well-defined value. So you should consider it |
---|
| 204 | /// as uninitialized. |
---|
| 205 | Edge() {} |
---|
| 206 | /// \brief Copy constructor. |
---|
| 207 | /// |
---|
| 208 | /// Copy constructor. |
---|
| 209 | /// |
---|
| 210 | Edge(const Edge &) : Parent() {} |
---|
| 211 | /// \brief Invalid constructor \& conversion. |
---|
| 212 | /// |
---|
| 213 | /// This constructor initializes the item to be invalid. |
---|
| 214 | /// \sa Invalid for more details. |
---|
| 215 | Edge(Invalid) {} |
---|
| 216 | /// \brief Converter from arc to edge. |
---|
| 217 | /// |
---|
| 218 | /// Besides the core graph item functionality each arc should |
---|
[209] | 219 | /// be convertible to the represented edge. |
---|
[57] | 220 | Edge(const Arc&) {} |
---|
| 221 | /// \brief Assign arc to edge. |
---|
| 222 | /// |
---|
| 223 | /// Besides the core graph item functionality each arc should |
---|
[209] | 224 | /// be convertible to the represented edge. |
---|
[57] | 225 | Edge& operator=(const Arc&) { return *this; } |
---|
| 226 | }; |
---|
| 227 | |
---|
| 228 | /// \brief Returns the direction of the arc. |
---|
| 229 | /// |
---|
| 230 | /// Returns the direction of the arc. Each arc represents an |
---|
| 231 | /// edge with a direction. It gives back the |
---|
| 232 | /// direction. |
---|
| 233 | bool direction(const Arc&) const { return true; } |
---|
| 234 | |
---|
| 235 | /// \brief Returns the directed arc. |
---|
| 236 | /// |
---|
| 237 | /// Returns the directed arc from its direction and the |
---|
| 238 | /// represented edge. |
---|
[209] | 239 | Arc direct(const Edge&, bool) const { return INVALID;} |
---|
[57] | 240 | |
---|
| 241 | /// \brief Returns the directed arc. |
---|
| 242 | /// |
---|
| 243 | /// Returns the directed arc from its source and the |
---|
| 244 | /// represented edge. |
---|
[209] | 245 | Arc direct(const Edge&, const Node&) const { return INVALID;} |
---|
[57] | 246 | |
---|
| 247 | /// \brief Returns the opposite arc. |
---|
| 248 | /// |
---|
| 249 | /// Returns the opposite arc. It is the arc representing the |
---|
| 250 | /// same edge and has opposite direction. |
---|
| 251 | Arc oppositeArc(const Arc&) const { return INVALID;} |
---|
| 252 | |
---|
| 253 | /// \brief Gives back one ending of an edge. |
---|
| 254 | /// |
---|
| 255 | /// Gives back one ending of an edge. |
---|
| 256 | Node u(const Edge&) const { return INVALID;} |
---|
| 257 | |
---|
| 258 | /// \brief Gives back the other ending of an edge. |
---|
| 259 | /// |
---|
| 260 | /// Gives back the other ending of an edge. |
---|
| 261 | Node v(const Edge&) const { return INVALID;} |
---|
[209] | 262 | |
---|
[57] | 263 | template <typename _Graph> |
---|
| 264 | struct Constraints { |
---|
[209] | 265 | typedef typename _Graph::Node Node; |
---|
| 266 | typedef typename _Graph::Arc Arc; |
---|
| 267 | typedef typename _Graph::Edge Edge; |
---|
| 268 | |
---|
| 269 | void constraints() { |
---|
[57] | 270 | checkConcept<BaseDigraphComponent, _Graph>(); |
---|
[209] | 271 | checkConcept<GraphItem<'u'>, Edge>(); |
---|
| 272 | { |
---|
| 273 | Node n; |
---|
| 274 | Edge ue(INVALID); |
---|
[57] | 275 | Arc e; |
---|
[209] | 276 | n = graph.u(ue); |
---|
| 277 | n = graph.v(ue); |
---|
[57] | 278 | e = graph.direct(ue, true); |
---|
| 279 | e = graph.direct(ue, n); |
---|
| 280 | e = graph.oppositeArc(e); |
---|
| 281 | ue = e; |
---|
| 282 | bool d = graph.direction(e); |
---|
| 283 | ignore_unused_variable_warning(d); |
---|
[209] | 284 | } |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | const _Graph& graph; |
---|
[57] | 288 | }; |
---|
| 289 | |
---|
| 290 | }; |
---|
| 291 | |
---|
| 292 | /// \brief An empty idable base digraph class. |
---|
[209] | 293 | /// |
---|
[57] | 294 | /// This class provides beside the core digraph features |
---|
| 295 | /// core id functions for the digraph structure. |
---|
[503] | 296 | /// The most of the base digraphs should conform to this concept. |
---|
[57] | 297 | /// The id's are unique and immutable. |
---|
[559] | 298 | template <typename BAS = BaseDigraphComponent> |
---|
| 299 | class IDableDigraphComponent : public BAS { |
---|
[57] | 300 | public: |
---|
| 301 | |
---|
[559] | 302 | typedef BAS Base; |
---|
[57] | 303 | typedef typename Base::Node Node; |
---|
| 304 | typedef typename Base::Arc Arc; |
---|
| 305 | |
---|
[209] | 306 | /// \brief Gives back an unique integer id for the Node. |
---|
[57] | 307 | /// |
---|
[209] | 308 | /// Gives back an unique integer id for the Node. |
---|
[57] | 309 | /// |
---|
| 310 | int id(const Node&) const { return -1;} |
---|
| 311 | |
---|
| 312 | /// \brief Gives back the node by the unique id. |
---|
| 313 | /// |
---|
| 314 | /// Gives back the node by the unique id. |
---|
| 315 | /// If the digraph does not contain node with the given id |
---|
[209] | 316 | /// then the result of the function is undetermined. |
---|
[57] | 317 | Node nodeFromId(int) const { return INVALID;} |
---|
| 318 | |
---|
[209] | 319 | /// \brief Gives back an unique integer id for the Arc. |
---|
[57] | 320 | /// |
---|
[209] | 321 | /// Gives back an unique integer id for the Arc. |
---|
[57] | 322 | /// |
---|
| 323 | int id(const Arc&) const { return -1;} |
---|
| 324 | |
---|
| 325 | /// \brief Gives back the arc by the unique id. |
---|
| 326 | /// |
---|
| 327 | /// Gives back the arc by the unique id. |
---|
| 328 | /// If the digraph does not contain arc with the given id |
---|
[209] | 329 | /// then the result of the function is undetermined. |
---|
[57] | 330 | Arc arcFromId(int) const { return INVALID;} |
---|
| 331 | |
---|
| 332 | /// \brief Gives back an integer greater or equal to the maximum |
---|
| 333 | /// Node id. |
---|
| 334 | /// |
---|
| 335 | /// Gives back an integer greater or equal to the maximum Node |
---|
| 336 | /// id. |
---|
| 337 | int maxNodeId() const { return -1;} |
---|
| 338 | |
---|
| 339 | /// \brief Gives back an integer greater or equal to the maximum |
---|
| 340 | /// Arc id. |
---|
| 341 | /// |
---|
| 342 | /// Gives back an integer greater or equal to the maximum Arc |
---|
| 343 | /// id. |
---|
| 344 | int maxArcId() const { return -1;} |
---|
| 345 | |
---|
| 346 | template <typename _Digraph> |
---|
| 347 | struct Constraints { |
---|
| 348 | |
---|
[209] | 349 | void constraints() { |
---|
| 350 | checkConcept<Base, _Digraph >(); |
---|
| 351 | typename _Digraph::Node node; |
---|
| 352 | int nid = digraph.id(node); |
---|
| 353 | nid = digraph.id(node); |
---|
| 354 | node = digraph.nodeFromId(nid); |
---|
| 355 | typename _Digraph::Arc arc; |
---|
| 356 | int eid = digraph.id(arc); |
---|
| 357 | eid = digraph.id(arc); |
---|
| 358 | arc = digraph.arcFromId(eid); |
---|
[57] | 359 | |
---|
[209] | 360 | nid = digraph.maxNodeId(); |
---|
| 361 | ignore_unused_variable_warning(nid); |
---|
| 362 | eid = digraph.maxArcId(); |
---|
| 363 | ignore_unused_variable_warning(eid); |
---|
| 364 | } |
---|
[57] | 365 | |
---|
[209] | 366 | const _Digraph& digraph; |
---|
[57] | 367 | }; |
---|
| 368 | }; |
---|
| 369 | |
---|
| 370 | /// \brief An empty idable base undirected graph class. |
---|
[209] | 371 | /// |
---|
[57] | 372 | /// This class provides beside the core undirected graph features |
---|
| 373 | /// core id functions for the undirected graph structure. The |
---|
[503] | 374 | /// most of the base undirected graphs should conform to this |
---|
[57] | 375 | /// concept. The id's are unique and immutable. |
---|
[559] | 376 | template <typename BAS = BaseGraphComponent> |
---|
| 377 | class IDableGraphComponent : public IDableDigraphComponent<BAS> { |
---|
[57] | 378 | public: |
---|
| 379 | |
---|
[559] | 380 | typedef BAS Base; |
---|
[57] | 381 | typedef typename Base::Edge Edge; |
---|
| 382 | |
---|
[559] | 383 | using IDableDigraphComponent<Base>::id; |
---|
[57] | 384 | |
---|
[209] | 385 | /// \brief Gives back an unique integer id for the Edge. |
---|
[57] | 386 | /// |
---|
[209] | 387 | /// Gives back an unique integer id for the Edge. |
---|
[57] | 388 | /// |
---|
| 389 | int id(const Edge&) const { return -1;} |
---|
| 390 | |
---|
| 391 | /// \brief Gives back the edge by the unique id. |
---|
| 392 | /// |
---|
| 393 | /// Gives back the edge by the unique id. If the |
---|
| 394 | /// graph does not contain arc with the given id then the |
---|
| 395 | /// result of the function is undetermined. |
---|
| 396 | Edge edgeFromId(int) const { return INVALID;} |
---|
| 397 | |
---|
| 398 | /// \brief Gives back an integer greater or equal to the maximum |
---|
| 399 | /// Edge id. |
---|
| 400 | /// |
---|
| 401 | /// Gives back an integer greater or equal to the maximum Edge |
---|
| 402 | /// id. |
---|
| 403 | int maxEdgeId() const { return -1;} |
---|
| 404 | |
---|
| 405 | template <typename _Graph> |
---|
| 406 | struct Constraints { |
---|
| 407 | |
---|
[209] | 408 | void constraints() { |
---|
| 409 | checkConcept<Base, _Graph >(); |
---|
| 410 | checkConcept<IDableDigraphComponent<Base>, _Graph >(); |
---|
| 411 | typename _Graph::Edge edge; |
---|
| 412 | int ueid = graph.id(edge); |
---|
| 413 | ueid = graph.id(edge); |
---|
| 414 | edge = graph.edgeFromId(ueid); |
---|
| 415 | ueid = graph.maxEdgeId(); |
---|
| 416 | ignore_unused_variable_warning(ueid); |
---|
| 417 | } |
---|
[57] | 418 | |
---|
[209] | 419 | const _Graph& graph; |
---|
[57] | 420 | }; |
---|
| 421 | }; |
---|
| 422 | |
---|
| 423 | /// \brief Skeleton class for graph NodeIt and ArcIt |
---|
| 424 | /// |
---|
| 425 | /// Skeleton class for graph NodeIt and ArcIt. |
---|
| 426 | /// |
---|
[559] | 427 | template <typename GR, typename Item> |
---|
| 428 | class GraphItemIt : public Item { |
---|
[57] | 429 | public: |
---|
| 430 | /// \brief Default constructor. |
---|
| 431 | /// |
---|
| 432 | /// @warning The default constructor sets the iterator |
---|
| 433 | /// to an undefined value. |
---|
| 434 | GraphItemIt() {} |
---|
| 435 | /// \brief Copy constructor. |
---|
| 436 | /// |
---|
| 437 | /// Copy constructor. |
---|
| 438 | /// |
---|
| 439 | GraphItemIt(const GraphItemIt& ) {} |
---|
| 440 | /// \brief Sets the iterator to the first item. |
---|
| 441 | /// |
---|
| 442 | /// Sets the iterator to the first item of \c the graph. |
---|
| 443 | /// |
---|
[559] | 444 | explicit GraphItemIt(const GR&) {} |
---|
[57] | 445 | /// \brief Invalid constructor \& conversion. |
---|
| 446 | /// |
---|
| 447 | /// This constructor initializes the item to be invalid. |
---|
| 448 | /// \sa Invalid for more details. |
---|
| 449 | GraphItemIt(Invalid) {} |
---|
| 450 | /// \brief Assign operator for items. |
---|
| 451 | /// |
---|
[209] | 452 | /// The items are assignable. |
---|
[57] | 453 | /// |
---|
[209] | 454 | GraphItemIt& operator=(const GraphItemIt&) { return *this; } |
---|
[57] | 455 | /// \brief Next item. |
---|
[209] | 456 | /// |
---|
[57] | 457 | /// Assign the iterator to the next item. |
---|
| 458 | /// |
---|
| 459 | GraphItemIt& operator++() { return *this; } |
---|
| 460 | /// \brief Equality operator |
---|
[209] | 461 | /// |
---|
[57] | 462 | /// Two iterators are equal if and only if they point to the |
---|
| 463 | /// same object or both are invalid. |
---|
| 464 | bool operator==(const GraphItemIt&) const { return true;} |
---|
| 465 | /// \brief Inequality operator |
---|
[209] | 466 | /// |
---|
[57] | 467 | /// \sa operator==(Node n) |
---|
| 468 | /// |
---|
| 469 | bool operator!=(const GraphItemIt&) const { return true;} |
---|
[209] | 470 | |
---|
[57] | 471 | template<typename _GraphItemIt> |
---|
| 472 | struct Constraints { |
---|
[209] | 473 | void constraints() { |
---|
| 474 | _GraphItemIt it1(g); |
---|
| 475 | _GraphItemIt it2; |
---|
[57] | 476 | |
---|
[209] | 477 | it2 = ++it1; |
---|
| 478 | ++it2 = it1; |
---|
| 479 | ++(++it1); |
---|
[57] | 480 | |
---|
[559] | 481 | Item bi = it1; |
---|
[209] | 482 | bi = it2; |
---|
| 483 | } |
---|
[559] | 484 | GR& g; |
---|
[57] | 485 | }; |
---|
| 486 | }; |
---|
| 487 | |
---|
| 488 | /// \brief Skeleton class for graph InArcIt and OutArcIt |
---|
| 489 | /// |
---|
| 490 | /// \note Because InArcIt and OutArcIt may not inherit from the same |
---|
[559] | 491 | /// base class, the \c sel is a additional template parameter (selector). |
---|
| 492 | /// For InArcIt you should instantiate it with character 'i' and for |
---|
[57] | 493 | /// OutArcIt with 'o'. |
---|
[559] | 494 | template <typename GR, |
---|
| 495 | typename Item = typename GR::Arc, |
---|
| 496 | typename Base = typename GR::Node, |
---|
| 497 | char sel = '0'> |
---|
| 498 | class GraphIncIt : public Item { |
---|
[57] | 499 | public: |
---|
| 500 | /// \brief Default constructor. |
---|
| 501 | /// |
---|
| 502 | /// @warning The default constructor sets the iterator |
---|
| 503 | /// to an undefined value. |
---|
| 504 | GraphIncIt() {} |
---|
| 505 | /// \brief Copy constructor. |
---|
| 506 | /// |
---|
| 507 | /// Copy constructor. |
---|
| 508 | /// |
---|
[559] | 509 | GraphIncIt(GraphIncIt const& gi) : Item(gi) {} |
---|
[209] | 510 | /// \brief Sets the iterator to the first arc incoming into or outgoing |
---|
[57] | 511 | /// from the node. |
---|
| 512 | /// |
---|
[209] | 513 | /// Sets the iterator to the first arc incoming into or outgoing |
---|
[57] | 514 | /// from the node. |
---|
| 515 | /// |
---|
[559] | 516 | explicit GraphIncIt(const GR&, const Base&) {} |
---|
[57] | 517 | /// \brief Invalid constructor \& conversion. |
---|
| 518 | /// |
---|
| 519 | /// This constructor initializes the item to be invalid. |
---|
| 520 | /// \sa Invalid for more details. |
---|
| 521 | GraphIncIt(Invalid) {} |
---|
| 522 | /// \brief Assign operator for iterators. |
---|
| 523 | /// |
---|
[209] | 524 | /// The iterators are assignable. |
---|
[57] | 525 | /// |
---|
[209] | 526 | GraphIncIt& operator=(GraphIncIt const&) { return *this; } |
---|
[57] | 527 | /// \brief Next item. |
---|
| 528 | /// |
---|
| 529 | /// Assign the iterator to the next item. |
---|
| 530 | /// |
---|
| 531 | GraphIncIt& operator++() { return *this; } |
---|
| 532 | |
---|
| 533 | /// \brief Equality operator |
---|
| 534 | /// |
---|
| 535 | /// Two iterators are equal if and only if they point to the |
---|
| 536 | /// same object or both are invalid. |
---|
| 537 | bool operator==(const GraphIncIt&) const { return true;} |
---|
| 538 | |
---|
| 539 | /// \brief Inequality operator |
---|
| 540 | /// |
---|
| 541 | /// \sa operator==(Node n) |
---|
| 542 | /// |
---|
| 543 | bool operator!=(const GraphIncIt&) const { return true;} |
---|
| 544 | |
---|
| 545 | template <typename _GraphIncIt> |
---|
| 546 | struct Constraints { |
---|
[209] | 547 | void constraints() { |
---|
[559] | 548 | checkConcept<GraphItem<sel>, _GraphIncIt>(); |
---|
[209] | 549 | _GraphIncIt it1(graph, node); |
---|
| 550 | _GraphIncIt it2; |
---|
[57] | 551 | |
---|
[209] | 552 | it2 = ++it1; |
---|
| 553 | ++it2 = it1; |
---|
| 554 | ++(++it1); |
---|
[559] | 555 | Item e = it1; |
---|
[209] | 556 | e = it2; |
---|
[57] | 557 | |
---|
[209] | 558 | } |
---|
[57] | 559 | |
---|
[559] | 560 | Item arc; |
---|
| 561 | Base node; |
---|
| 562 | GR graph; |
---|
[209] | 563 | _GraphIncIt it; |
---|
[57] | 564 | }; |
---|
| 565 | }; |
---|
| 566 | |
---|
| 567 | |
---|
| 568 | /// \brief An empty iterable digraph class. |
---|
| 569 | /// |
---|
| 570 | /// This class provides beside the core digraph features |
---|
| 571 | /// iterator based iterable interface for the digraph structure. |
---|
| 572 | /// This concept is part of the Digraph concept. |
---|
[559] | 573 | template <typename BAS = BaseDigraphComponent> |
---|
| 574 | class IterableDigraphComponent : public BAS { |
---|
[57] | 575 | |
---|
| 576 | public: |
---|
[209] | 577 | |
---|
[559] | 578 | typedef BAS Base; |
---|
[57] | 579 | typedef typename Base::Node Node; |
---|
| 580 | typedef typename Base::Arc Arc; |
---|
| 581 | |
---|
| 582 | typedef IterableDigraphComponent Digraph; |
---|
| 583 | |
---|
| 584 | /// \name Base iteration |
---|
[209] | 585 | /// |
---|
[57] | 586 | /// This interface provides functions for iteration on digraph items |
---|
| 587 | /// |
---|
[209] | 588 | /// @{ |
---|
[57] | 589 | |
---|
| 590 | /// \brief Gives back the first node in the iterating order. |
---|
[209] | 591 | /// |
---|
[57] | 592 | /// Gives back the first node in the iterating order. |
---|
[209] | 593 | /// |
---|
[57] | 594 | void first(Node&) const {} |
---|
| 595 | |
---|
| 596 | /// \brief Gives back the next node in the iterating order. |
---|
| 597 | /// |
---|
| 598 | /// Gives back the next node in the iterating order. |
---|
[209] | 599 | /// |
---|
[57] | 600 | void next(Node&) const {} |
---|
| 601 | |
---|
| 602 | /// \brief Gives back the first arc in the iterating order. |
---|
| 603 | /// |
---|
| 604 | /// Gives back the first arc in the iterating order. |
---|
[209] | 605 | /// |
---|
[57] | 606 | void first(Arc&) const {} |
---|
| 607 | |
---|
| 608 | /// \brief Gives back the next arc in the iterating order. |
---|
| 609 | /// |
---|
| 610 | /// Gives back the next arc in the iterating order. |
---|
[209] | 611 | /// |
---|
[57] | 612 | void next(Arc&) const {} |
---|
| 613 | |
---|
| 614 | |
---|
| 615 | /// \brief Gives back the first of the arcs point to the given |
---|
| 616 | /// node. |
---|
| 617 | /// |
---|
| 618 | /// Gives back the first of the arcs point to the given node. |
---|
[209] | 619 | /// |
---|
[57] | 620 | void firstIn(Arc&, const Node&) const {} |
---|
| 621 | |
---|
| 622 | /// \brief Gives back the next of the arcs points to the given |
---|
| 623 | /// node. |
---|
| 624 | /// |
---|
| 625 | /// Gives back the next of the arcs points to the given node. |
---|
| 626 | /// |
---|
| 627 | void nextIn(Arc&) const {} |
---|
| 628 | |
---|
| 629 | /// \brief Gives back the first of the arcs start from the |
---|
| 630 | /// given node. |
---|
[209] | 631 | /// |
---|
[57] | 632 | /// Gives back the first of the arcs start from the given node. |
---|
[209] | 633 | /// |
---|
[57] | 634 | void firstOut(Arc&, const Node&) const {} |
---|
| 635 | |
---|
| 636 | /// \brief Gives back the next of the arcs start from the given |
---|
| 637 | /// node. |
---|
| 638 | /// |
---|
| 639 | /// Gives back the next of the arcs start from the given node. |
---|
[209] | 640 | /// |
---|
[57] | 641 | void nextOut(Arc&) const {} |
---|
| 642 | |
---|
| 643 | /// @} |
---|
| 644 | |
---|
| 645 | /// \name Class based iteration |
---|
[209] | 646 | /// |
---|
[57] | 647 | /// This interface provides functions for iteration on digraph items |
---|
| 648 | /// |
---|
| 649 | /// @{ |
---|
| 650 | |
---|
| 651 | /// \brief This iterator goes through each node. |
---|
| 652 | /// |
---|
| 653 | /// This iterator goes through each node. |
---|
| 654 | /// |
---|
| 655 | typedef GraphItemIt<Digraph, Node> NodeIt; |
---|
| 656 | |
---|
| 657 | /// \brief This iterator goes through each node. |
---|
| 658 | /// |
---|
| 659 | /// This iterator goes through each node. |
---|
| 660 | /// |
---|
| 661 | typedef GraphItemIt<Digraph, Arc> ArcIt; |
---|
| 662 | |
---|
| 663 | /// \brief This iterator goes trough the incoming arcs of a node. |
---|
| 664 | /// |
---|
| 665 | /// This iterator goes trough the \e inccoming arcs of a certain node |
---|
| 666 | /// of a digraph. |
---|
| 667 | typedef GraphIncIt<Digraph, Arc, Node, 'i'> InArcIt; |
---|
| 668 | |
---|
| 669 | /// \brief This iterator goes trough the outgoing arcs of a node. |
---|
| 670 | /// |
---|
| 671 | /// This iterator goes trough the \e outgoing arcs of a certain node |
---|
| 672 | /// of a digraph. |
---|
| 673 | typedef GraphIncIt<Digraph, Arc, Node, 'o'> OutArcIt; |
---|
| 674 | |
---|
| 675 | /// \brief The base node of the iterator. |
---|
| 676 | /// |
---|
| 677 | /// Gives back the base node of the iterator. |
---|
| 678 | /// It is always the target of the pointed arc. |
---|
| 679 | Node baseNode(const InArcIt&) const { return INVALID; } |
---|
| 680 | |
---|
| 681 | /// \brief The running node of the iterator. |
---|
| 682 | /// |
---|
| 683 | /// Gives back the running node of the iterator. |
---|
| 684 | /// It is always the source of the pointed arc. |
---|
| 685 | Node runningNode(const InArcIt&) const { return INVALID; } |
---|
| 686 | |
---|
| 687 | /// \brief The base node of the iterator. |
---|
| 688 | /// |
---|
| 689 | /// Gives back the base node of the iterator. |
---|
| 690 | /// It is always the source of the pointed arc. |
---|
| 691 | Node baseNode(const OutArcIt&) const { return INVALID; } |
---|
| 692 | |
---|
| 693 | /// \brief The running node of the iterator. |
---|
| 694 | /// |
---|
| 695 | /// Gives back the running node of the iterator. |
---|
| 696 | /// It is always the target of the pointed arc. |
---|
| 697 | Node runningNode(const OutArcIt&) const { return INVALID; } |
---|
| 698 | |
---|
| 699 | /// @} |
---|
| 700 | |
---|
[209] | 701 | template <typename _Digraph> |
---|
[57] | 702 | struct Constraints { |
---|
[209] | 703 | void constraints() { |
---|
| 704 | checkConcept<Base, _Digraph>(); |
---|
[57] | 705 | |
---|
| 706 | { |
---|
[209] | 707 | typename _Digraph::Node node(INVALID); |
---|
[57] | 708 | typename _Digraph::Arc arc(INVALID); |
---|
| 709 | { |
---|
| 710 | digraph.first(node); |
---|
| 711 | digraph.next(node); |
---|
| 712 | } |
---|
| 713 | { |
---|
| 714 | digraph.first(arc); |
---|
| 715 | digraph.next(arc); |
---|
| 716 | } |
---|
| 717 | { |
---|
| 718 | digraph.firstIn(arc, node); |
---|
| 719 | digraph.nextIn(arc); |
---|
| 720 | } |
---|
| 721 | { |
---|
| 722 | digraph.firstOut(arc, node); |
---|
| 723 | digraph.nextOut(arc); |
---|
| 724 | } |
---|
[209] | 725 | } |
---|
[57] | 726 | |
---|
| 727 | { |
---|
| 728 | checkConcept<GraphItemIt<_Digraph, typename _Digraph::Arc>, |
---|
| 729 | typename _Digraph::ArcIt >(); |
---|
| 730 | checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>, |
---|
| 731 | typename _Digraph::NodeIt >(); |
---|
[209] | 732 | checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, |
---|
[57] | 733 | typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>(); |
---|
[209] | 734 | checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, |
---|
[57] | 735 | typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>(); |
---|
| 736 | |
---|
| 737 | typename _Digraph::Node n; |
---|
| 738 | typename _Digraph::InArcIt ieit(INVALID); |
---|
| 739 | typename _Digraph::OutArcIt oeit(INVALID); |
---|
| 740 | n = digraph.baseNode(ieit); |
---|
| 741 | n = digraph.runningNode(ieit); |
---|
| 742 | n = digraph.baseNode(oeit); |
---|
| 743 | n = digraph.runningNode(oeit); |
---|
| 744 | ignore_unused_variable_warning(n); |
---|
| 745 | } |
---|
| 746 | } |
---|
[209] | 747 | |
---|
| 748 | const _Digraph& digraph; |
---|
| 749 | |
---|
[57] | 750 | }; |
---|
| 751 | }; |
---|
| 752 | |
---|
| 753 | /// \brief An empty iterable undirected graph class. |
---|
| 754 | /// |
---|
| 755 | /// This class provides beside the core graph features iterator |
---|
| 756 | /// based iterable interface for the undirected graph structure. |
---|
| 757 | /// This concept is part of the Graph concept. |
---|
[559] | 758 | template <typename BAS = BaseGraphComponent> |
---|
| 759 | class IterableGraphComponent : public IterableDigraphComponent<BAS> { |
---|
[57] | 760 | public: |
---|
| 761 | |
---|
[559] | 762 | typedef BAS Base; |
---|
[57] | 763 | typedef typename Base::Node Node; |
---|
| 764 | typedef typename Base::Arc Arc; |
---|
| 765 | typedef typename Base::Edge Edge; |
---|
| 766 | |
---|
[209] | 767 | |
---|
[57] | 768 | typedef IterableGraphComponent Graph; |
---|
| 769 | |
---|
| 770 | /// \name Base iteration |
---|
[209] | 771 | /// |
---|
[57] | 772 | /// This interface provides functions for iteration on graph items |
---|
[209] | 773 | /// @{ |
---|
[57] | 774 | |
---|
[559] | 775 | using IterableDigraphComponent<Base>::first; |
---|
| 776 | using IterableDigraphComponent<Base>::next; |
---|
[57] | 777 | |
---|
| 778 | /// \brief Gives back the first edge in the iterating |
---|
| 779 | /// order. |
---|
| 780 | /// |
---|
| 781 | /// Gives back the first edge in the iterating order. |
---|
[209] | 782 | /// |
---|
[57] | 783 | void first(Edge&) const {} |
---|
| 784 | |
---|
| 785 | /// \brief Gives back the next edge in the iterating |
---|
| 786 | /// order. |
---|
| 787 | /// |
---|
| 788 | /// Gives back the next edge in the iterating order. |
---|
[209] | 789 | /// |
---|
[57] | 790 | void next(Edge&) const {} |
---|
| 791 | |
---|
| 792 | |
---|
| 793 | /// \brief Gives back the first of the edges from the |
---|
| 794 | /// given node. |
---|
| 795 | /// |
---|
| 796 | /// Gives back the first of the edges from the given |
---|
| 797 | /// node. The bool parameter gives back that direction which |
---|
| 798 | /// gives a good direction of the edge so the source of the |
---|
| 799 | /// directed arc is the given node. |
---|
| 800 | void firstInc(Edge&, bool&, const Node&) const {} |
---|
| 801 | |
---|
| 802 | /// \brief Gives back the next of the edges from the |
---|
| 803 | /// given node. |
---|
| 804 | /// |
---|
| 805 | /// Gives back the next of the edges from the given |
---|
| 806 | /// node. The bool parameter should be used as the \c firstInc() |
---|
| 807 | /// use it. |
---|
| 808 | void nextInc(Edge&, bool&) const {} |
---|
| 809 | |
---|
[559] | 810 | using IterableDigraphComponent<Base>::baseNode; |
---|
| 811 | using IterableDigraphComponent<Base>::runningNode; |
---|
[57] | 812 | |
---|
| 813 | /// @} |
---|
| 814 | |
---|
| 815 | /// \name Class based iteration |
---|
[209] | 816 | /// |
---|
[57] | 817 | /// This interface provides functions for iteration on graph items |
---|
| 818 | /// |
---|
| 819 | /// @{ |
---|
| 820 | |
---|
| 821 | /// \brief This iterator goes through each node. |
---|
| 822 | /// |
---|
| 823 | /// This iterator goes through each node. |
---|
| 824 | typedef GraphItemIt<Graph, Edge> EdgeIt; |
---|
| 825 | /// \brief This iterator goes trough the incident arcs of a |
---|
| 826 | /// node. |
---|
| 827 | /// |
---|
| 828 | /// This iterator goes trough the incident arcs of a certain |
---|
| 829 | /// node of a graph. |
---|
[78] | 830 | typedef GraphIncIt<Graph, Edge, Node, 'u'> IncEdgeIt; |
---|
[57] | 831 | /// \brief The base node of the iterator. |
---|
| 832 | /// |
---|
| 833 | /// Gives back the base node of the iterator. |
---|
[78] | 834 | Node baseNode(const IncEdgeIt&) const { return INVALID; } |
---|
[57] | 835 | |
---|
| 836 | /// \brief The running node of the iterator. |
---|
| 837 | /// |
---|
| 838 | /// Gives back the running node of the iterator. |
---|
[78] | 839 | Node runningNode(const IncEdgeIt&) const { return INVALID; } |
---|
[57] | 840 | |
---|
| 841 | /// @} |
---|
| 842 | |
---|
[209] | 843 | template <typename _Graph> |
---|
[57] | 844 | struct Constraints { |
---|
[209] | 845 | void constraints() { |
---|
| 846 | checkConcept<IterableDigraphComponent<Base>, _Graph>(); |
---|
[57] | 847 | |
---|
| 848 | { |
---|
| 849 | typename _Graph::Node node(INVALID); |
---|
| 850 | typename _Graph::Edge edge(INVALID); |
---|
| 851 | bool dir; |
---|
| 852 | { |
---|
| 853 | graph.first(edge); |
---|
| 854 | graph.next(edge); |
---|
| 855 | } |
---|
| 856 | { |
---|
| 857 | graph.firstInc(edge, dir, node); |
---|
| 858 | graph.nextInc(edge, dir); |
---|
| 859 | } |
---|
[209] | 860 | |
---|
| 861 | } |
---|
| 862 | |
---|
[57] | 863 | { |
---|
| 864 | checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>, |
---|
| 865 | typename _Graph::EdgeIt >(); |
---|
[209] | 866 | checkConcept<GraphIncIt<_Graph, typename _Graph::Edge, |
---|
[78] | 867 | typename _Graph::Node, 'u'>, typename _Graph::IncEdgeIt>(); |
---|
[209] | 868 | |
---|
[57] | 869 | typename _Graph::Node n; |
---|
[78] | 870 | typename _Graph::IncEdgeIt ueit(INVALID); |
---|
[57] | 871 | n = graph.baseNode(ueit); |
---|
| 872 | n = graph.runningNode(ueit); |
---|
| 873 | } |
---|
| 874 | } |
---|
[209] | 875 | |
---|
| 876 | const _Graph& graph; |
---|
[57] | 877 | }; |
---|
| 878 | }; |
---|
| 879 | |
---|
| 880 | /// \brief An empty alteration notifier digraph class. |
---|
[209] | 881 | /// |
---|
[57] | 882 | /// This class provides beside the core digraph features alteration |
---|
| 883 | /// notifier interface for the digraph structure. This implements |
---|
| 884 | /// an observer-notifier pattern for each digraph item. More |
---|
| 885 | /// obsevers can be registered into the notifier and whenever an |
---|
| 886 | /// alteration occured in the digraph all the observers will |
---|
| 887 | /// notified about it. |
---|
[559] | 888 | template <typename BAS = BaseDigraphComponent> |
---|
| 889 | class AlterableDigraphComponent : public BAS { |
---|
[57] | 890 | public: |
---|
| 891 | |
---|
[559] | 892 | typedef BAS Base; |
---|
[57] | 893 | typedef typename Base::Node Node; |
---|
| 894 | typedef typename Base::Arc Arc; |
---|
| 895 | |
---|
| 896 | |
---|
| 897 | /// The node observer registry. |
---|
[209] | 898 | typedef AlterationNotifier<AlterableDigraphComponent, Node> |
---|
[57] | 899 | NodeNotifier; |
---|
| 900 | /// The arc observer registry. |
---|
[209] | 901 | typedef AlterationNotifier<AlterableDigraphComponent, Arc> |
---|
[57] | 902 | ArcNotifier; |
---|
[209] | 903 | |
---|
[57] | 904 | /// \brief Gives back the node alteration notifier. |
---|
| 905 | /// |
---|
| 906 | /// Gives back the node alteration notifier. |
---|
| 907 | NodeNotifier& notifier(Node) const { |
---|
[209] | 908 | return NodeNotifier(); |
---|
[57] | 909 | } |
---|
[209] | 910 | |
---|
[57] | 911 | /// \brief Gives back the arc alteration notifier. |
---|
| 912 | /// |
---|
| 913 | /// Gives back the arc alteration notifier. |
---|
| 914 | ArcNotifier& notifier(Arc) const { |
---|
[209] | 915 | return ArcNotifier(); |
---|
[57] | 916 | } |
---|
| 917 | |
---|
[209] | 918 | template <typename _Digraph> |
---|
[57] | 919 | struct Constraints { |
---|
[209] | 920 | void constraints() { |
---|
| 921 | checkConcept<Base, _Digraph>(); |
---|
| 922 | typename _Digraph::NodeNotifier& nn |
---|
[57] | 923 | = digraph.notifier(typename _Digraph::Node()); |
---|
| 924 | |
---|
[209] | 925 | typename _Digraph::ArcNotifier& en |
---|
[57] | 926 | = digraph.notifier(typename _Digraph::Arc()); |
---|
[209] | 927 | |
---|
[57] | 928 | ignore_unused_variable_warning(nn); |
---|
| 929 | ignore_unused_variable_warning(en); |
---|
[209] | 930 | } |
---|
| 931 | |
---|
| 932 | const _Digraph& digraph; |
---|
| 933 | |
---|
[57] | 934 | }; |
---|
[209] | 935 | |
---|
[57] | 936 | }; |
---|
| 937 | |
---|
| 938 | /// \brief An empty alteration notifier undirected graph class. |
---|
[209] | 939 | /// |
---|
[57] | 940 | /// This class provides beside the core graph features alteration |
---|
| 941 | /// notifier interface for the graph structure. This implements |
---|
| 942 | /// an observer-notifier pattern for each graph item. More |
---|
| 943 | /// obsevers can be registered into the notifier and whenever an |
---|
| 944 | /// alteration occured in the graph all the observers will |
---|
| 945 | /// notified about it. |
---|
[559] | 946 | template <typename BAS = BaseGraphComponent> |
---|
| 947 | class AlterableGraphComponent : public AlterableDigraphComponent<BAS> { |
---|
[57] | 948 | public: |
---|
| 949 | |
---|
[559] | 950 | typedef BAS Base; |
---|
[57] | 951 | typedef typename Base::Edge Edge; |
---|
| 952 | |
---|
| 953 | |
---|
| 954 | /// The arc observer registry. |
---|
[209] | 955 | typedef AlterationNotifier<AlterableGraphComponent, Edge> |
---|
[57] | 956 | EdgeNotifier; |
---|
[209] | 957 | |
---|
[57] | 958 | /// \brief Gives back the arc alteration notifier. |
---|
| 959 | /// |
---|
| 960 | /// Gives back the arc alteration notifier. |
---|
| 961 | EdgeNotifier& notifier(Edge) const { |
---|
[209] | 962 | return EdgeNotifier(); |
---|
[57] | 963 | } |
---|
| 964 | |
---|
[209] | 965 | template <typename _Graph> |
---|
[57] | 966 | struct Constraints { |
---|
[209] | 967 | void constraints() { |
---|
| 968 | checkConcept<AlterableGraphComponent<Base>, _Graph>(); |
---|
| 969 | typename _Graph::EdgeNotifier& uen |
---|
[57] | 970 | = graph.notifier(typename _Graph::Edge()); |
---|
| 971 | ignore_unused_variable_warning(uen); |
---|
[209] | 972 | } |
---|
| 973 | |
---|
| 974 | const _Graph& graph; |
---|
[57] | 975 | }; |
---|
| 976 | }; |
---|
| 977 | |
---|
| 978 | /// \brief Class describing the concept of graph maps |
---|
[209] | 979 | /// |
---|
[57] | 980 | /// This class describes the common interface of the graph maps |
---|
[313] | 981 | /// (NodeMap, ArcMap), that is maps that can be used to |
---|
[57] | 982 | /// associate data to graph descriptors (nodes or arcs). |
---|
[559] | 983 | template <typename GR, typename K, typename V> |
---|
| 984 | class GraphMap : public ReadWriteMap<K, V> { |
---|
[57] | 985 | public: |
---|
| 986 | |
---|
[559] | 987 | typedef ReadWriteMap<K, V> Parent; |
---|
[57] | 988 | |
---|
| 989 | /// The graph type of the map. |
---|
[559] | 990 | typedef GR Graph; |
---|
[57] | 991 | /// The key type of the map. |
---|
[559] | 992 | typedef K Key; |
---|
[57] | 993 | /// The value type of the map. |
---|
[559] | 994 | typedef V Value; |
---|
[57] | 995 | |
---|
| 996 | /// \brief Construct a new map. |
---|
| 997 | /// |
---|
| 998 | /// Construct a new map for the graph. |
---|
| 999 | explicit GraphMap(const Graph&) {} |
---|
| 1000 | /// \brief Construct a new map with default value. |
---|
| 1001 | /// |
---|
| 1002 | /// Construct a new map for the graph and initalise the values. |
---|
| 1003 | GraphMap(const Graph&, const Value&) {} |
---|
[263] | 1004 | |
---|
| 1005 | private: |
---|
[57] | 1006 | /// \brief Copy constructor. |
---|
| 1007 | /// |
---|
| 1008 | /// Copy Constructor. |
---|
| 1009 | GraphMap(const GraphMap&) : Parent() {} |
---|
[209] | 1010 | |
---|
[57] | 1011 | /// \brief Assign operator. |
---|
| 1012 | /// |
---|
| 1013 | /// Assign operator. It does not mofify the underlying graph, |
---|
| 1014 | /// it just iterates on the current item set and set the map |
---|
[209] | 1015 | /// with the value returned by the assigned map. |
---|
[57] | 1016 | template <typename CMap> |
---|
[209] | 1017 | GraphMap& operator=(const CMap&) { |
---|
[57] | 1018 | checkConcept<ReadMap<Key, Value>, CMap>(); |
---|
| 1019 | return *this; |
---|
| 1020 | } |
---|
| 1021 | |
---|
[263] | 1022 | public: |
---|
[57] | 1023 | template<typename _Map> |
---|
| 1024 | struct Constraints { |
---|
[209] | 1025 | void constraints() { |
---|
| 1026 | checkConcept<ReadWriteMap<Key, Value>, _Map >(); |
---|
| 1027 | // Construction with a graph parameter |
---|
| 1028 | _Map a(g); |
---|
| 1029 | // Constructor with a graph and a default value parameter |
---|
| 1030 | _Map a2(g,t); |
---|
| 1031 | // Copy constructor. |
---|
[263] | 1032 | // _Map b(c); |
---|
[209] | 1033 | |
---|
[263] | 1034 | // ReadMap<Key, Value> cmap; |
---|
| 1035 | // b = cmap; |
---|
[57] | 1036 | |
---|
[263] | 1037 | ignore_unused_variable_warning(a); |
---|
[209] | 1038 | ignore_unused_variable_warning(a2); |
---|
[263] | 1039 | // ignore_unused_variable_warning(b); |
---|
[209] | 1040 | } |
---|
[57] | 1041 | |
---|
[209] | 1042 | const _Map &c; |
---|
| 1043 | const Graph &g; |
---|
| 1044 | const typename GraphMap::Value &t; |
---|
[57] | 1045 | }; |
---|
| 1046 | |
---|
| 1047 | }; |
---|
| 1048 | |
---|
| 1049 | /// \brief An empty mappable digraph class. |
---|
| 1050 | /// |
---|
| 1051 | /// This class provides beside the core digraph features |
---|
| 1052 | /// map interface for the digraph structure. |
---|
| 1053 | /// This concept is part of the Digraph concept. |
---|
[559] | 1054 | template <typename BAS = BaseDigraphComponent> |
---|
| 1055 | class MappableDigraphComponent : public BAS { |
---|
[57] | 1056 | public: |
---|
| 1057 | |
---|
[559] | 1058 | typedef BAS Base; |
---|
[57] | 1059 | typedef typename Base::Node Node; |
---|
| 1060 | typedef typename Base::Arc Arc; |
---|
| 1061 | |
---|
| 1062 | typedef MappableDigraphComponent Digraph; |
---|
| 1063 | |
---|
| 1064 | /// \brief ReadWrite map of the nodes. |
---|
| 1065 | /// |
---|
| 1066 | /// ReadWrite map of the nodes. |
---|
| 1067 | /// |
---|
[559] | 1068 | template <typename V> |
---|
| 1069 | class NodeMap : public GraphMap<Digraph, Node, V> { |
---|
[57] | 1070 | public: |
---|
[559] | 1071 | typedef GraphMap<MappableDigraphComponent, Node, V> Parent; |
---|
[57] | 1072 | |
---|
[209] | 1073 | /// \brief Construct a new map. |
---|
| 1074 | /// |
---|
| 1075 | /// Construct a new map for the digraph. |
---|
| 1076 | explicit NodeMap(const MappableDigraphComponent& digraph) |
---|
[57] | 1077 | : Parent(digraph) {} |
---|
| 1078 | |
---|
[209] | 1079 | /// \brief Construct a new map with default value. |
---|
| 1080 | /// |
---|
| 1081 | /// Construct a new map for the digraph and initalise the values. |
---|
[559] | 1082 | NodeMap(const MappableDigraphComponent& digraph, const V& value) |
---|
[57] | 1083 | : Parent(digraph, value) {} |
---|
| 1084 | |
---|
[263] | 1085 | private: |
---|
[209] | 1086 | /// \brief Copy constructor. |
---|
| 1087 | /// |
---|
| 1088 | /// Copy Constructor. |
---|
| 1089 | NodeMap(const NodeMap& nm) : Parent(nm) {} |
---|
[57] | 1090 | |
---|
[209] | 1091 | /// \brief Assign operator. |
---|
| 1092 | /// |
---|
| 1093 | /// Assign operator. |
---|
[57] | 1094 | template <typename CMap> |
---|
[209] | 1095 | NodeMap& operator=(const CMap&) { |
---|
[559] | 1096 | checkConcept<ReadMap<Node, V>, CMap>(); |
---|
[57] | 1097 | return *this; |
---|
| 1098 | } |
---|
| 1099 | |
---|
| 1100 | }; |
---|
| 1101 | |
---|
| 1102 | /// \brief ReadWrite map of the arcs. |
---|
| 1103 | /// |
---|
| 1104 | /// ReadWrite map of the arcs. |
---|
| 1105 | /// |
---|
[559] | 1106 | template <typename V> |
---|
| 1107 | class ArcMap : public GraphMap<Digraph, Arc, V> { |
---|
[57] | 1108 | public: |
---|
[559] | 1109 | typedef GraphMap<MappableDigraphComponent, Arc, V> Parent; |
---|
[57] | 1110 | |
---|
[209] | 1111 | /// \brief Construct a new map. |
---|
| 1112 | /// |
---|
| 1113 | /// Construct a new map for the digraph. |
---|
| 1114 | explicit ArcMap(const MappableDigraphComponent& digraph) |
---|
[57] | 1115 | : Parent(digraph) {} |
---|
| 1116 | |
---|
[209] | 1117 | /// \brief Construct a new map with default value. |
---|
| 1118 | /// |
---|
| 1119 | /// Construct a new map for the digraph and initalise the values. |
---|
[559] | 1120 | ArcMap(const MappableDigraphComponent& digraph, const V& value) |
---|
[57] | 1121 | : Parent(digraph, value) {} |
---|
| 1122 | |
---|
[263] | 1123 | private: |
---|
[209] | 1124 | /// \brief Copy constructor. |
---|
| 1125 | /// |
---|
| 1126 | /// Copy Constructor. |
---|
| 1127 | ArcMap(const ArcMap& nm) : Parent(nm) {} |
---|
[57] | 1128 | |
---|
[209] | 1129 | /// \brief Assign operator. |
---|
| 1130 | /// |
---|
| 1131 | /// Assign operator. |
---|
[57] | 1132 | template <typename CMap> |
---|
[209] | 1133 | ArcMap& operator=(const CMap&) { |
---|
[559] | 1134 | checkConcept<ReadMap<Arc, V>, CMap>(); |
---|
[57] | 1135 | return *this; |
---|
| 1136 | } |
---|
| 1137 | |
---|
| 1138 | }; |
---|
| 1139 | |
---|
| 1140 | |
---|
| 1141 | template <typename _Digraph> |
---|
| 1142 | struct Constraints { |
---|
| 1143 | |
---|
[209] | 1144 | struct Dummy { |
---|
| 1145 | int value; |
---|
| 1146 | Dummy() : value(0) {} |
---|
| 1147 | Dummy(int _v) : value(_v) {} |
---|
| 1148 | }; |
---|
[57] | 1149 | |
---|
[209] | 1150 | void constraints() { |
---|
| 1151 | checkConcept<Base, _Digraph>(); |
---|
| 1152 | { // int map test |
---|
| 1153 | typedef typename _Digraph::template NodeMap<int> IntNodeMap; |
---|
| 1154 | checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>, |
---|
| 1155 | IntNodeMap >(); |
---|
| 1156 | } { // bool map test |
---|
| 1157 | typedef typename _Digraph::template NodeMap<bool> BoolNodeMap; |
---|
| 1158 | checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>, |
---|
| 1159 | BoolNodeMap >(); |
---|
| 1160 | } { // Dummy map test |
---|
| 1161 | typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap; |
---|
| 1162 | checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>, |
---|
| 1163 | DummyNodeMap >(); |
---|
| 1164 | } |
---|
[57] | 1165 | |
---|
[209] | 1166 | { // int map test |
---|
| 1167 | typedef typename _Digraph::template ArcMap<int> IntArcMap; |
---|
| 1168 | checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>, |
---|
| 1169 | IntArcMap >(); |
---|
| 1170 | } { // bool map test |
---|
| 1171 | typedef typename _Digraph::template ArcMap<bool> BoolArcMap; |
---|
| 1172 | checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>, |
---|
| 1173 | BoolArcMap >(); |
---|
| 1174 | } { // Dummy map test |
---|
| 1175 | typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap; |
---|
| 1176 | checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>, |
---|
| 1177 | DummyArcMap >(); |
---|
| 1178 | } |
---|
| 1179 | } |
---|
[57] | 1180 | |
---|
[209] | 1181 | _Digraph& digraph; |
---|
[57] | 1182 | }; |
---|
| 1183 | }; |
---|
| 1184 | |
---|
| 1185 | /// \brief An empty mappable base bipartite graph class. |
---|
| 1186 | /// |
---|
| 1187 | /// This class provides beside the core graph features |
---|
| 1188 | /// map interface for the graph structure. |
---|
| 1189 | /// This concept is part of the Graph concept. |
---|
[559] | 1190 | template <typename BAS = BaseGraphComponent> |
---|
| 1191 | class MappableGraphComponent : public MappableDigraphComponent<BAS> { |
---|
[57] | 1192 | public: |
---|
| 1193 | |
---|
[559] | 1194 | typedef BAS Base; |
---|
[57] | 1195 | typedef typename Base::Edge Edge; |
---|
| 1196 | |
---|
| 1197 | typedef MappableGraphComponent Graph; |
---|
| 1198 | |
---|
| 1199 | /// \brief ReadWrite map of the edges. |
---|
| 1200 | /// |
---|
| 1201 | /// ReadWrite map of the edges. |
---|
| 1202 | /// |
---|
[559] | 1203 | template <typename V> |
---|
| 1204 | class EdgeMap : public GraphMap<Graph, Edge, V> { |
---|
[57] | 1205 | public: |
---|
[559] | 1206 | typedef GraphMap<MappableGraphComponent, Edge, V> Parent; |
---|
[57] | 1207 | |
---|
[209] | 1208 | /// \brief Construct a new map. |
---|
| 1209 | /// |
---|
| 1210 | /// Construct a new map for the graph. |
---|
| 1211 | explicit EdgeMap(const MappableGraphComponent& graph) |
---|
[57] | 1212 | : Parent(graph) {} |
---|
| 1213 | |
---|
[209] | 1214 | /// \brief Construct a new map with default value. |
---|
| 1215 | /// |
---|
| 1216 | /// Construct a new map for the graph and initalise the values. |
---|
[559] | 1217 | EdgeMap(const MappableGraphComponent& graph, const V& value) |
---|
[57] | 1218 | : Parent(graph, value) {} |
---|
| 1219 | |
---|
[263] | 1220 | private: |
---|
[209] | 1221 | /// \brief Copy constructor. |
---|
| 1222 | /// |
---|
| 1223 | /// Copy Constructor. |
---|
| 1224 | EdgeMap(const EdgeMap& nm) : Parent(nm) {} |
---|
[57] | 1225 | |
---|
[209] | 1226 | /// \brief Assign operator. |
---|
| 1227 | /// |
---|
| 1228 | /// Assign operator. |
---|
[57] | 1229 | template <typename CMap> |
---|
[209] | 1230 | EdgeMap& operator=(const CMap&) { |
---|
[559] | 1231 | checkConcept<ReadMap<Edge, V>, CMap>(); |
---|
[57] | 1232 | return *this; |
---|
| 1233 | } |
---|
| 1234 | |
---|
| 1235 | }; |
---|
| 1236 | |
---|
| 1237 | |
---|
| 1238 | template <typename _Graph> |
---|
| 1239 | struct Constraints { |
---|
| 1240 | |
---|
[209] | 1241 | struct Dummy { |
---|
| 1242 | int value; |
---|
| 1243 | Dummy() : value(0) {} |
---|
| 1244 | Dummy(int _v) : value(_v) {} |
---|
| 1245 | }; |
---|
[57] | 1246 | |
---|
[209] | 1247 | void constraints() { |
---|
| 1248 | checkConcept<MappableGraphComponent<Base>, _Graph>(); |
---|
[57] | 1249 | |
---|
[209] | 1250 | { // int map test |
---|
| 1251 | typedef typename _Graph::template EdgeMap<int> IntEdgeMap; |
---|
| 1252 | checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>, |
---|
| 1253 | IntEdgeMap >(); |
---|
| 1254 | } { // bool map test |
---|
| 1255 | typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap; |
---|
| 1256 | checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>, |
---|
| 1257 | BoolEdgeMap >(); |
---|
| 1258 | } { // Dummy map test |
---|
| 1259 | typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap; |
---|
| 1260 | checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>, |
---|
| 1261 | DummyEdgeMap >(); |
---|
| 1262 | } |
---|
| 1263 | } |
---|
[57] | 1264 | |
---|
[209] | 1265 | _Graph& graph; |
---|
[57] | 1266 | }; |
---|
| 1267 | }; |
---|
| 1268 | |
---|
| 1269 | /// \brief An empty extendable digraph class. |
---|
| 1270 | /// |
---|
| 1271 | /// This class provides beside the core digraph features digraph |
---|
| 1272 | /// extendable interface for the digraph structure. The main |
---|
| 1273 | /// difference between the base and this interface is that the |
---|
| 1274 | /// digraph alterations should handled already on this level. |
---|
[559] | 1275 | template <typename BAS = BaseDigraphComponent> |
---|
| 1276 | class ExtendableDigraphComponent : public BAS { |
---|
[57] | 1277 | public: |
---|
[559] | 1278 | typedef BAS Base; |
---|
[57] | 1279 | |
---|
[559] | 1280 | typedef typename Base::Node Node; |
---|
| 1281 | typedef typename Base::Arc Arc; |
---|
[57] | 1282 | |
---|
| 1283 | /// \brief Adds a new node to the digraph. |
---|
| 1284 | /// |
---|
| 1285 | /// Adds a new node to the digraph. |
---|
| 1286 | /// |
---|
| 1287 | Node addNode() { |
---|
[209] | 1288 | return INVALID; |
---|
[57] | 1289 | } |
---|
[209] | 1290 | |
---|
[57] | 1291 | /// \brief Adds a new arc connects the given two nodes. |
---|
| 1292 | /// |
---|
| 1293 | /// Adds a new arc connects the the given two nodes. |
---|
| 1294 | Arc addArc(const Node&, const Node&) { |
---|
[209] | 1295 | return INVALID; |
---|
[57] | 1296 | } |
---|
| 1297 | |
---|
| 1298 | template <typename _Digraph> |
---|
| 1299 | struct Constraints { |
---|
[209] | 1300 | void constraints() { |
---|
[57] | 1301 | checkConcept<Base, _Digraph>(); |
---|
[209] | 1302 | typename _Digraph::Node node_a, node_b; |
---|
| 1303 | node_a = digraph.addNode(); |
---|
| 1304 | node_b = digraph.addNode(); |
---|
| 1305 | typename _Digraph::Arc arc; |
---|
| 1306 | arc = digraph.addArc(node_a, node_b); |
---|
| 1307 | } |
---|
[57] | 1308 | |
---|
[209] | 1309 | _Digraph& digraph; |
---|
[57] | 1310 | }; |
---|
| 1311 | }; |
---|
| 1312 | |
---|
| 1313 | /// \brief An empty extendable base undirected graph class. |
---|
| 1314 | /// |
---|
| 1315 | /// This class provides beside the core undirected graph features |
---|
| 1316 | /// core undircted graph extend interface for the graph structure. |
---|
| 1317 | /// The main difference between the base and this interface is |
---|
| 1318 | /// that the graph alterations should handled already on this |
---|
| 1319 | /// level. |
---|
[559] | 1320 | template <typename BAS = BaseGraphComponent> |
---|
| 1321 | class ExtendableGraphComponent : public BAS { |
---|
[57] | 1322 | public: |
---|
| 1323 | |
---|
[559] | 1324 | typedef BAS Base; |
---|
| 1325 | typedef typename Base::Node Node; |
---|
| 1326 | typedef typename Base::Edge Edge; |
---|
[57] | 1327 | |
---|
| 1328 | /// \brief Adds a new node to the graph. |
---|
| 1329 | /// |
---|
| 1330 | /// Adds a new node to the graph. |
---|
| 1331 | /// |
---|
| 1332 | Node addNode() { |
---|
[209] | 1333 | return INVALID; |
---|
[57] | 1334 | } |
---|
[209] | 1335 | |
---|
[57] | 1336 | /// \brief Adds a new arc connects the given two nodes. |
---|
| 1337 | /// |
---|
| 1338 | /// Adds a new arc connects the the given two nodes. |
---|
| 1339 | Edge addArc(const Node&, const Node&) { |
---|
[209] | 1340 | return INVALID; |
---|
[57] | 1341 | } |
---|
| 1342 | |
---|
| 1343 | template <typename _Graph> |
---|
| 1344 | struct Constraints { |
---|
[209] | 1345 | void constraints() { |
---|
| 1346 | checkConcept<Base, _Graph>(); |
---|
| 1347 | typename _Graph::Node node_a, node_b; |
---|
| 1348 | node_a = graph.addNode(); |
---|
| 1349 | node_b = graph.addNode(); |
---|
| 1350 | typename _Graph::Edge edge; |
---|
| 1351 | edge = graph.addEdge(node_a, node_b); |
---|
| 1352 | } |
---|
[57] | 1353 | |
---|
[209] | 1354 | _Graph& graph; |
---|
[57] | 1355 | }; |
---|
| 1356 | }; |
---|
| 1357 | |
---|
| 1358 | /// \brief An empty erasable digraph class. |
---|
[209] | 1359 | /// |
---|
[57] | 1360 | /// This class provides beside the core digraph features core erase |
---|
| 1361 | /// functions for the digraph structure. The main difference between |
---|
| 1362 | /// the base and this interface is that the digraph alterations |
---|
| 1363 | /// should handled already on this level. |
---|
[559] | 1364 | template <typename BAS = BaseDigraphComponent> |
---|
| 1365 | class ErasableDigraphComponent : public BAS { |
---|
[57] | 1366 | public: |
---|
| 1367 | |
---|
[559] | 1368 | typedef BAS Base; |
---|
[57] | 1369 | typedef typename Base::Node Node; |
---|
| 1370 | typedef typename Base::Arc Arc; |
---|
| 1371 | |
---|
| 1372 | /// \brief Erase a node from the digraph. |
---|
| 1373 | /// |
---|
[209] | 1374 | /// Erase a node from the digraph. This function should |
---|
[57] | 1375 | /// erase all arcs connecting to the node. |
---|
[209] | 1376 | void erase(const Node&) {} |
---|
[57] | 1377 | |
---|
| 1378 | /// \brief Erase an arc from the digraph. |
---|
| 1379 | /// |
---|
| 1380 | /// Erase an arc from the digraph. |
---|
| 1381 | /// |
---|
| 1382 | void erase(const Arc&) {} |
---|
| 1383 | |
---|
| 1384 | template <typename _Digraph> |
---|
| 1385 | struct Constraints { |
---|
[209] | 1386 | void constraints() { |
---|
[57] | 1387 | checkConcept<Base, _Digraph>(); |
---|
[209] | 1388 | typename _Digraph::Node node; |
---|
| 1389 | digraph.erase(node); |
---|
| 1390 | typename _Digraph::Arc arc; |
---|
| 1391 | digraph.erase(arc); |
---|
| 1392 | } |
---|
[57] | 1393 | |
---|
[209] | 1394 | _Digraph& digraph; |
---|
[57] | 1395 | }; |
---|
| 1396 | }; |
---|
| 1397 | |
---|
| 1398 | /// \brief An empty erasable base undirected graph class. |
---|
[209] | 1399 | /// |
---|
[57] | 1400 | /// This class provides beside the core undirected graph features |
---|
| 1401 | /// core erase functions for the undirceted graph structure. The |
---|
| 1402 | /// main difference between the base and this interface is that |
---|
| 1403 | /// the graph alterations should handled already on this level. |
---|
[559] | 1404 | template <typename BAS = BaseGraphComponent> |
---|
| 1405 | class ErasableGraphComponent : public BAS { |
---|
[57] | 1406 | public: |
---|
| 1407 | |
---|
[559] | 1408 | typedef BAS Base; |
---|
[57] | 1409 | typedef typename Base::Node Node; |
---|
| 1410 | typedef typename Base::Edge Edge; |
---|
| 1411 | |
---|
| 1412 | /// \brief Erase a node from the graph. |
---|
| 1413 | /// |
---|
| 1414 | /// Erase a node from the graph. This function should erase |
---|
| 1415 | /// arcs connecting to the node. |
---|
[209] | 1416 | void erase(const Node&) {} |
---|
[57] | 1417 | |
---|
| 1418 | /// \brief Erase an arc from the graph. |
---|
| 1419 | /// |
---|
| 1420 | /// Erase an arc from the graph. |
---|
| 1421 | /// |
---|
| 1422 | void erase(const Edge&) {} |
---|
| 1423 | |
---|
| 1424 | template <typename _Graph> |
---|
| 1425 | struct Constraints { |
---|
[209] | 1426 | void constraints() { |
---|
[57] | 1427 | checkConcept<Base, _Graph>(); |
---|
[209] | 1428 | typename _Graph::Node node; |
---|
| 1429 | graph.erase(node); |
---|
| 1430 | typename _Graph::Edge edge; |
---|
| 1431 | graph.erase(edge); |
---|
| 1432 | } |
---|
[57] | 1433 | |
---|
[209] | 1434 | _Graph& graph; |
---|
[57] | 1435 | }; |
---|
| 1436 | }; |
---|
| 1437 | |
---|
| 1438 | /// \brief An empty clearable base digraph class. |
---|
| 1439 | /// |
---|
| 1440 | /// This class provides beside the core digraph features core clear |
---|
| 1441 | /// functions for the digraph structure. The main difference between |
---|
| 1442 | /// the base and this interface is that the digraph alterations |
---|
| 1443 | /// should handled already on this level. |
---|
[559] | 1444 | template <typename BAS = BaseDigraphComponent> |
---|
| 1445 | class ClearableDigraphComponent : public BAS { |
---|
[57] | 1446 | public: |
---|
| 1447 | |
---|
[559] | 1448 | typedef BAS Base; |
---|
[57] | 1449 | |
---|
| 1450 | /// \brief Erase all nodes and arcs from the digraph. |
---|
| 1451 | /// |
---|
| 1452 | /// Erase all nodes and arcs from the digraph. |
---|
| 1453 | /// |
---|
[209] | 1454 | void clear() {} |
---|
[57] | 1455 | |
---|
| 1456 | template <typename _Digraph> |
---|
| 1457 | struct Constraints { |
---|
[209] | 1458 | void constraints() { |
---|
[57] | 1459 | checkConcept<Base, _Digraph>(); |
---|
[209] | 1460 | digraph.clear(); |
---|
| 1461 | } |
---|
[57] | 1462 | |
---|
[209] | 1463 | _Digraph digraph; |
---|
[57] | 1464 | }; |
---|
| 1465 | }; |
---|
| 1466 | |
---|
| 1467 | /// \brief An empty clearable base undirected graph class. |
---|
| 1468 | /// |
---|
| 1469 | /// This class provides beside the core undirected graph features |
---|
| 1470 | /// core clear functions for the undirected graph structure. The |
---|
| 1471 | /// main difference between the base and this interface is that |
---|
| 1472 | /// the graph alterations should handled already on this level. |
---|
[559] | 1473 | template <typename BAS = BaseGraphComponent> |
---|
| 1474 | class ClearableGraphComponent : public ClearableDigraphComponent<BAS> { |
---|
[57] | 1475 | public: |
---|
| 1476 | |
---|
[559] | 1477 | typedef BAS Base; |
---|
[57] | 1478 | |
---|
| 1479 | template <typename _Graph> |
---|
| 1480 | struct Constraints { |
---|
[209] | 1481 | void constraints() { |
---|
[57] | 1482 | checkConcept<ClearableGraphComponent<Base>, _Graph>(); |
---|
[209] | 1483 | } |
---|
[57] | 1484 | |
---|
[209] | 1485 | _Graph graph; |
---|
[57] | 1486 | }; |
---|
| 1487 | }; |
---|
| 1488 | |
---|
| 1489 | } |
---|
| 1490 | |
---|
| 1491 | } |
---|
| 1492 | |
---|
| 1493 | #endif |
---|