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