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