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