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