1 | /* -*- C++ -*- |
---|
2 | * lemon/concept/graph_component.h - Part of LEMON, a generic C++ optimization library |
---|
3 | * |
---|
4 | * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
5 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
6 | * |
---|
7 | * Permission to use, modify and distribute this software is granted |
---|
8 | * provided that this copyright notice appears in all copies. For |
---|
9 | * precise terms see the accompanying LICENSE file. |
---|
10 | * |
---|
11 | * This software is provided "AS IS" with no warranty of any kind, |
---|
12 | * express or implied, and with no claim as to its suitability for any |
---|
13 | * purpose. |
---|
14 | * |
---|
15 | */ |
---|
16 | |
---|
17 | ///\ingroup graph_concepts |
---|
18 | ///\file |
---|
19 | ///\brief The graph components. |
---|
20 | |
---|
21 | |
---|
22 | #ifndef LEMON_CONCEPT_GRAPH_COMPONENT_H |
---|
23 | #define LEMON_CONCEPT_GRAPH_COMPONENT_H |
---|
24 | |
---|
25 | #include <lemon/invalid.h> |
---|
26 | #include <lemon/concept/maps.h> |
---|
27 | |
---|
28 | #include <lemon/bits/alteration_notifier.h> |
---|
29 | |
---|
30 | namespace lemon { |
---|
31 | namespace concept { |
---|
32 | |
---|
33 | /**************** Graph iterator concepts ****************/ |
---|
34 | |
---|
35 | /// Skeleton class for graph Node and Edge types |
---|
36 | |
---|
37 | /// This class describes the interface of Node and Edge (and UndirEdge |
---|
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 Edge types should \em not derive from the same base class. |
---|
43 | /// For Node you should instantiate it with character 'n' and for Edge |
---|
44 | /// with 'e'. |
---|
45 | |
---|
46 | #ifndef DOXYGEN |
---|
47 | template <char _selector = '0'> |
---|
48 | #endif |
---|
49 | class GraphItem { |
---|
50 | public: |
---|
51 | /// 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 | /// Copy constructor. |
---|
58 | |
---|
59 | /// Copy constructor. |
---|
60 | /// |
---|
61 | GraphItem(GraphItem const&) {} |
---|
62 | /// Invalid constructor \& conversion. |
---|
63 | |
---|
64 | /// This constructor initializes the item to be invalid. |
---|
65 | /// \sa Invalid for more details. |
---|
66 | GraphItem(Invalid) {} |
---|
67 | /// Assign operator for nodes. |
---|
68 | |
---|
69 | /// The nodes are assignable. |
---|
70 | /// |
---|
71 | GraphItem& operator=(GraphItem const&) { return *this; } |
---|
72 | /// 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 | /// Inequality operator. |
---|
78 | |
---|
79 | /// \sa operator==(const Node& n) |
---|
80 | /// |
---|
81 | bool operator!=(GraphItem) const { return false; } |
---|
82 | |
---|
83 | /// 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 | /// |
---|
92 | /// \bug This is a technical requirement. Do we really need this? |
---|
93 | bool operator<(GraphItem) const { return false; } |
---|
94 | |
---|
95 | template<typename _GraphItem> |
---|
96 | struct Constraints { |
---|
97 | void constraints() { |
---|
98 | _GraphItem i1; |
---|
99 | _GraphItem i2 = i1; |
---|
100 | _GraphItem i3 = INVALID; |
---|
101 | |
---|
102 | i1 = i2 = i3; |
---|
103 | |
---|
104 | bool b; |
---|
105 | // b = (ia == ib) && (ia != ib) && (ia < ib); |
---|
106 | b = (ia == ib) && (ia != ib); |
---|
107 | b = (ia == INVALID) && (ib != INVALID); |
---|
108 | // b = (ia < ib); |
---|
109 | } |
---|
110 | |
---|
111 | const _GraphItem &ia; |
---|
112 | const _GraphItem &ib; |
---|
113 | }; |
---|
114 | }; |
---|
115 | |
---|
116 | /// A type describing the concept of graph node |
---|
117 | |
---|
118 | /// This is an instantiation of \ref GraphItem which can be used as a |
---|
119 | /// Node subtype in graph skeleton definitions |
---|
120 | typedef GraphItem<'n'> GraphNode; |
---|
121 | |
---|
122 | /// A type describing the concept of graph edge |
---|
123 | |
---|
124 | /// This is an instantiation of \ref GraphItem which can be used as a |
---|
125 | /// Edge subtype in graph skeleton definitions |
---|
126 | typedef GraphItem<'e'> GraphEdge; |
---|
127 | |
---|
128 | |
---|
129 | /**************** Basic features of graphs ****************/ |
---|
130 | |
---|
131 | /// An empty base graph class. |
---|
132 | |
---|
133 | /// This class provides the minimal set of features needed for a graph |
---|
134 | /// structure. All graph concepts have to be conform to this base |
---|
135 | /// graph. |
---|
136 | /// |
---|
137 | /// \bug This is not true. The minimal graph concept is the |
---|
138 | /// BaseIterableGraphComponent. |
---|
139 | |
---|
140 | class BaseGraphComponent { |
---|
141 | public: |
---|
142 | |
---|
143 | typedef BaseGraphComponent Graph; |
---|
144 | |
---|
145 | /// Node class of the graph. |
---|
146 | |
---|
147 | /// This class represents the Nodes of the graph. |
---|
148 | /// |
---|
149 | typedef GraphItem<'n'> Node; |
---|
150 | |
---|
151 | /// Edge class of the graph. |
---|
152 | |
---|
153 | /// This class represents the Edges of the graph. |
---|
154 | /// |
---|
155 | typedef GraphItem<'e'> Edge; |
---|
156 | |
---|
157 | ///Gives back the target node of an edge. |
---|
158 | |
---|
159 | ///Gives back the target node of an edge. |
---|
160 | /// |
---|
161 | Node target(const Edge&) const { return INVALID;} |
---|
162 | |
---|
163 | ///Gives back the source node of an edge. |
---|
164 | |
---|
165 | ///Gives back the source node of an edge. |
---|
166 | /// |
---|
167 | Node source(const Edge&) const { return INVALID;} |
---|
168 | |
---|
169 | |
---|
170 | template <typename _Graph> |
---|
171 | struct Constraints { |
---|
172 | typedef typename _Graph::Node Node; |
---|
173 | typedef typename _Graph::Edge Edge; |
---|
174 | |
---|
175 | void constraints() { |
---|
176 | checkConcept<GraphItem<'n'>, Node>(); |
---|
177 | checkConcept<GraphItem<'e'>, Edge>(); |
---|
178 | { |
---|
179 | Node n; |
---|
180 | Edge e; |
---|
181 | n = graph.source(e); |
---|
182 | n = graph.target(e); |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | const _Graph& graph; |
---|
187 | }; |
---|
188 | }; |
---|
189 | |
---|
190 | /// An empty iterable base graph class. |
---|
191 | |
---|
192 | /// This class provides beside the core graph features |
---|
193 | /// core iterable interface for the graph structure. |
---|
194 | /// Most of the base graphs should be conform to this concept. |
---|
195 | |
---|
196 | class BaseIterableGraphComponent : virtual public BaseGraphComponent { |
---|
197 | public: |
---|
198 | |
---|
199 | typedef BaseGraphComponent::Node Node; |
---|
200 | typedef BaseGraphComponent::Edge Edge; |
---|
201 | |
---|
202 | /// Gives back the first Node in the iterating order. |
---|
203 | |
---|
204 | /// Gives back the first Node in the iterating order. |
---|
205 | /// |
---|
206 | void first(Node&) const {} |
---|
207 | |
---|
208 | /// Gives back the next Node in the iterating order. |
---|
209 | |
---|
210 | /// Gives back the next Node in the iterating order. |
---|
211 | /// |
---|
212 | void next(Node&) const {} |
---|
213 | |
---|
214 | /// Gives back the first Edge in the iterating order. |
---|
215 | |
---|
216 | /// Gives back the first Edge in the iterating order. |
---|
217 | /// |
---|
218 | void first(Edge&) const {} |
---|
219 | /// Gives back the next Edge in the iterating order. |
---|
220 | |
---|
221 | /// Gives back the next Edge in the iterating order. |
---|
222 | /// |
---|
223 | void next(Edge&) const {} |
---|
224 | |
---|
225 | |
---|
226 | /// Gives back the first of the Edges point to the given Node. |
---|
227 | |
---|
228 | /// Gives back the first of the Edges point to the given Node. |
---|
229 | /// |
---|
230 | void firstIn(Edge&, const Node&) const {} |
---|
231 | |
---|
232 | /// Gives back the next of the Edges points to the given Node. |
---|
233 | |
---|
234 | |
---|
235 | /// Gives back the next of the Edges points to the given Node. |
---|
236 | /// |
---|
237 | void nextIn(Edge&) const {} |
---|
238 | |
---|
239 | /// Gives back the first of the Edges start from the given Node. |
---|
240 | |
---|
241 | /// Gives back the first of the Edges start from the given Node. |
---|
242 | /// |
---|
243 | void firstOut(Edge&, const Node&) const {} |
---|
244 | |
---|
245 | /// Gives back the next of the Edges start from the given Node. |
---|
246 | |
---|
247 | /// Gives back the next of the Edges start from the given Node. |
---|
248 | /// |
---|
249 | void nextOut(Edge&) const {} |
---|
250 | |
---|
251 | |
---|
252 | template <typename _Graph> |
---|
253 | struct Constraints { |
---|
254 | |
---|
255 | void constraints() { |
---|
256 | checkConcept< BaseGraphComponent, _Graph >(); |
---|
257 | typename _Graph::Node node; |
---|
258 | typename _Graph::Edge edge; |
---|
259 | { |
---|
260 | graph.first(node); |
---|
261 | graph.next(node); |
---|
262 | } |
---|
263 | { |
---|
264 | graph.first(edge); |
---|
265 | graph.next(edge); |
---|
266 | } |
---|
267 | { |
---|
268 | graph.firstIn(edge, node); |
---|
269 | graph.nextIn(edge); |
---|
270 | } |
---|
271 | { |
---|
272 | graph.firstOut(edge, node); |
---|
273 | graph.nextOut(edge); |
---|
274 | } |
---|
275 | } |
---|
276 | |
---|
277 | const _Graph& graph; |
---|
278 | }; |
---|
279 | }; |
---|
280 | |
---|
281 | /// An empty idable base graph class. |
---|
282 | |
---|
283 | /// This class provides beside the core graph features |
---|
284 | /// core id functions for the graph structure. |
---|
285 | /// The most of the base graphs should be conform to this concept. |
---|
286 | /// The id's are unique and immutable. |
---|
287 | class IDableGraphComponent : virtual public BaseGraphComponent { |
---|
288 | public: |
---|
289 | |
---|
290 | typedef BaseGraphComponent::Node Node; |
---|
291 | typedef BaseGraphComponent::Edge Edge; |
---|
292 | |
---|
293 | /// Gives back an unique integer id for the Node. |
---|
294 | |
---|
295 | /// Gives back an unique integer id for the Node. |
---|
296 | /// |
---|
297 | int id(const Node&) const { return -1;} |
---|
298 | |
---|
299 | /// \brief Gives back the node by the unique id. |
---|
300 | /// |
---|
301 | /// Gives back the node by the unique id. |
---|
302 | /// If the graph does not contain node with the given id |
---|
303 | /// then the result of the function is undetermined. |
---|
304 | Node fromId(int , Node) const { return INVALID;} |
---|
305 | |
---|
306 | /// \brief Gives back an unique integer id for the Edge. |
---|
307 | /// |
---|
308 | /// Gives back an unique integer id for the Edge. |
---|
309 | /// |
---|
310 | int id(const Edge&) const { return -1;} |
---|
311 | |
---|
312 | /// \brief Gives back the edge by the unique id. |
---|
313 | /// |
---|
314 | /// Gives back the edge by the unique id. |
---|
315 | /// If the graph does not contain edge with the given id |
---|
316 | /// then the result of the function is undetermined. |
---|
317 | Edge fromId(int, Edge) const { return INVALID;} |
---|
318 | |
---|
319 | template <typename _Graph> |
---|
320 | struct Constraints { |
---|
321 | |
---|
322 | void constraints() { |
---|
323 | checkConcept< BaseGraphComponent, _Graph >(); |
---|
324 | typename _Graph::Node node; |
---|
325 | int nid = graph.id(node); |
---|
326 | nid = graph.id(node); |
---|
327 | node = graph.fromId(nid, Node()); |
---|
328 | typename _Graph::Edge edge; |
---|
329 | int eid = graph.id(edge); |
---|
330 | eid = graph.id(edge); |
---|
331 | edge = graph.fromId(eid, Edge()); |
---|
332 | } |
---|
333 | |
---|
334 | const _Graph& graph; |
---|
335 | }; |
---|
336 | }; |
---|
337 | |
---|
338 | |
---|
339 | /// An empty max-idable base graph class. |
---|
340 | |
---|
341 | /// This class provides beside the core graph features |
---|
342 | /// core max id functions for the graph structure. |
---|
343 | /// The most of the base graphs should be conform to this concept. |
---|
344 | /// The id's are unique and immutable. |
---|
345 | class MaxIDableGraphComponent : virtual public BaseGraphComponent { |
---|
346 | public: |
---|
347 | |
---|
348 | /// Gives back an integer greater or equal to the maximum Node id. |
---|
349 | |
---|
350 | /// Gives back an integer greater or equal to the maximum Node id. |
---|
351 | /// |
---|
352 | int maxId(Node = INVALID) const { return -1;} |
---|
353 | |
---|
354 | /// Gives back an integer greater or equal to the maximum Edge id. |
---|
355 | |
---|
356 | /// Gives back an integer greater or equal to the maximum Edge id. |
---|
357 | /// |
---|
358 | int maxId(Edge = INVALID) const { return -1;} |
---|
359 | |
---|
360 | template <typename _Graph> |
---|
361 | struct Constraints { |
---|
362 | |
---|
363 | void constraints() { |
---|
364 | checkConcept<BaseGraphComponent, _Graph>(); |
---|
365 | int nid = graph.maxId(typename _Graph::Node()); |
---|
366 | ignore_unused_variable_warning(nid); |
---|
367 | int eid = graph.maxId(typename _Graph::Edge()); |
---|
368 | ignore_unused_variable_warning(eid); |
---|
369 | } |
---|
370 | |
---|
371 | const _Graph& graph; |
---|
372 | }; |
---|
373 | }; |
---|
374 | |
---|
375 | /// An empty extendable base graph class. |
---|
376 | |
---|
377 | /// This class provides beside the core graph features |
---|
378 | /// core graph extend interface for the graph structure. |
---|
379 | /// The most of the base graphs should be conform to this concept. |
---|
380 | class BaseExtendableGraphComponent : virtual public BaseGraphComponent { |
---|
381 | public: |
---|
382 | |
---|
383 | typedef BaseGraphComponent::Node Node; |
---|
384 | typedef BaseGraphComponent::Edge Edge; |
---|
385 | |
---|
386 | /// Adds a new Node to the graph. |
---|
387 | |
---|
388 | /// Adds a new Node to the graph. |
---|
389 | /// |
---|
390 | Node addNode() { |
---|
391 | return INVALID; |
---|
392 | } |
---|
393 | |
---|
394 | /// Adds a new Edge connects the two Nodes to the graph. |
---|
395 | |
---|
396 | /// Adds a new Edge connects the two Nodes to the graph. |
---|
397 | /// |
---|
398 | Edge addEdge(const Node&, const Node&) { |
---|
399 | return INVALID; |
---|
400 | } |
---|
401 | |
---|
402 | template <typename _Graph> |
---|
403 | struct Constraints { |
---|
404 | void constraints() { |
---|
405 | checkConcept<BaseGraphComponent, _Graph >(); |
---|
406 | typename _Graph::Node node_a, node_b; |
---|
407 | node_a = graph.addNode(); |
---|
408 | node_b = graph.addNode(); |
---|
409 | typename _Graph::Edge edge; |
---|
410 | edge = graph.addEdge(node_a, node_b); |
---|
411 | } |
---|
412 | |
---|
413 | _Graph& graph; |
---|
414 | }; |
---|
415 | }; |
---|
416 | |
---|
417 | /// An empty erasable base graph class. |
---|
418 | |
---|
419 | /// This class provides beside the core graph features |
---|
420 | /// core erase functions for the graph structure. |
---|
421 | /// The most of the base graphs should be conform to this concept. |
---|
422 | class BaseErasableGraphComponent : virtual public BaseGraphComponent { |
---|
423 | public: |
---|
424 | |
---|
425 | typedef BaseGraphComponent::Node Node; |
---|
426 | typedef BaseGraphComponent::Edge Edge; |
---|
427 | |
---|
428 | /// Erase a Node from the graph. |
---|
429 | |
---|
430 | /// Erase a Node from the graph. This function should not |
---|
431 | /// erase edges connecting to the Node. |
---|
432 | void erase(const Node&) {} |
---|
433 | |
---|
434 | /// Erase an Edge from the graph. |
---|
435 | |
---|
436 | /// Erase an Edge from the graph. |
---|
437 | /// |
---|
438 | void erase(const Edge&) {} |
---|
439 | |
---|
440 | template <typename _Graph> |
---|
441 | struct Constraints { |
---|
442 | void constraints() { |
---|
443 | checkConcept<BaseGraphComponent, _Graph>(); |
---|
444 | typename _Graph::Node node; |
---|
445 | graph.erase(node); |
---|
446 | typename _Graph::Edge edge; |
---|
447 | graph.erase(edge); |
---|
448 | } |
---|
449 | |
---|
450 | _Graph& graph; |
---|
451 | }; |
---|
452 | }; |
---|
453 | |
---|
454 | /// An empty clearable base graph class. |
---|
455 | |
---|
456 | /// This class provides beside the core graph features |
---|
457 | /// core clear functions for the graph structure. |
---|
458 | /// The most of the base graphs should be conform to this concept. |
---|
459 | class ClearableGraphComponent : virtual public BaseGraphComponent { |
---|
460 | public: |
---|
461 | |
---|
462 | /// Erase all the Nodes and Edges from the graph. |
---|
463 | |
---|
464 | /// Erase all the Nodes and Edges from the graph. |
---|
465 | /// |
---|
466 | void clear() {} |
---|
467 | |
---|
468 | template <typename _Graph> |
---|
469 | struct Constraints { |
---|
470 | void constraints() { |
---|
471 | checkConcept<BaseGraphComponent, _Graph>(); |
---|
472 | graph.clear(); |
---|
473 | } |
---|
474 | |
---|
475 | _Graph graph; |
---|
476 | }; |
---|
477 | }; |
---|
478 | |
---|
479 | |
---|
480 | /// Skeleton class for graph NodeIt and EdgeIt |
---|
481 | |
---|
482 | /// Skeleton class for graph NodeIt and EdgeIt. |
---|
483 | /// |
---|
484 | template <typename _Graph, typename _Item> |
---|
485 | class GraphIterator : public _Item { |
---|
486 | public: |
---|
487 | /// \todo Don't we need the Item type as typedef? |
---|
488 | |
---|
489 | /// Default constructor. |
---|
490 | |
---|
491 | /// @warning The default constructor sets the iterator |
---|
492 | /// to an undefined value. |
---|
493 | GraphIterator() {} |
---|
494 | /// Copy constructor. |
---|
495 | |
---|
496 | /// Copy constructor. |
---|
497 | /// |
---|
498 | GraphIterator(GraphIterator const&) {} |
---|
499 | /// Sets the iterator to the first item. |
---|
500 | |
---|
501 | /// Sets the iterator to the first item of \c the graph. |
---|
502 | /// |
---|
503 | explicit GraphIterator(const _Graph&) {} |
---|
504 | /// Invalid constructor \& conversion. |
---|
505 | |
---|
506 | /// This constructor initializes the item to be invalid. |
---|
507 | /// \sa Invalid for more details. |
---|
508 | GraphIterator(Invalid) {} |
---|
509 | /// Assign operator for items. |
---|
510 | |
---|
511 | /// The items are assignable. |
---|
512 | /// |
---|
513 | GraphIterator& operator=(GraphIterator const&) { return *this; } |
---|
514 | /// Next item. |
---|
515 | |
---|
516 | /// Assign the iterator to the next item. |
---|
517 | /// |
---|
518 | GraphIterator& operator++() { return *this; } |
---|
519 | // Node operator*() const { return INVALID; } |
---|
520 | /// Equality operator |
---|
521 | |
---|
522 | /// Two iterators are equal if and only if they point to the |
---|
523 | /// same object or both are invalid. |
---|
524 | bool operator==(const GraphIterator&) const { return true;} |
---|
525 | /// Inequality operator |
---|
526 | |
---|
527 | /// \sa operator==(Node n) |
---|
528 | /// |
---|
529 | bool operator!=(const GraphIterator&) const { return true;} |
---|
530 | |
---|
531 | template<typename _GraphIterator> |
---|
532 | struct Constraints { |
---|
533 | void constraints() { |
---|
534 | // checkConcept< Item, _GraphIterator >(); |
---|
535 | _GraphIterator it1(g); |
---|
536 | |
---|
537 | /// \todo Do we need NodeIt(Node) kind of constructor? |
---|
538 | // _GraphIterator it2(bj); |
---|
539 | _GraphIterator it2; |
---|
540 | |
---|
541 | it2 = ++it1; |
---|
542 | ++it2 = it1; |
---|
543 | ++(++it1); |
---|
544 | /// \bug This should be: is_base_and_derived<BaseItem, _GraphIterator> |
---|
545 | _Item bi = it1; |
---|
546 | bi = it2; |
---|
547 | } |
---|
548 | _Graph& g; |
---|
549 | }; |
---|
550 | }; |
---|
551 | |
---|
552 | /// Skeleton class for graph InEdgeIt and OutEdgeIt |
---|
553 | |
---|
554 | /// \note Because InEdgeIt and OutEdgeIt may not inherit from the same |
---|
555 | /// base class, the _selector is a additional template parameter. For |
---|
556 | /// InEdgeIt you should instantiate it with character 'i' and for |
---|
557 | /// OutEdgeIt with 'o'. |
---|
558 | /// \todo Is this a good name for this concept? |
---|
559 | template <typename Graph, |
---|
560 | typename Edge = typename Graph::Edge, |
---|
561 | char _selector = '0'> |
---|
562 | class GraphIncIterator : public Edge { |
---|
563 | public: |
---|
564 | /// Default constructor. |
---|
565 | |
---|
566 | /// @warning The default constructor sets the iterator |
---|
567 | /// to an undefined value. |
---|
568 | GraphIncIterator() {} |
---|
569 | /// Copy constructor. |
---|
570 | |
---|
571 | /// Copy constructor. |
---|
572 | /// |
---|
573 | GraphIncIterator(GraphIncIterator const& gi) :Edge(gi) {} |
---|
574 | /// Sets the iterator to the first edge incoming into or outgoing |
---|
575 | /// from the node. |
---|
576 | |
---|
577 | /// Sets the iterator to the first edge incoming into or outgoing |
---|
578 | /// from the node. |
---|
579 | /// |
---|
580 | explicit GraphIncIterator(const Graph&, const typename Graph::Node&) {} |
---|
581 | /// Invalid constructor \& conversion. |
---|
582 | |
---|
583 | /// This constructor initializes the item to be invalid. |
---|
584 | /// \sa Invalid for more details. |
---|
585 | GraphIncIterator(Invalid) {} |
---|
586 | /// Assign operator for nodes. |
---|
587 | |
---|
588 | /// The nodes are assignable. |
---|
589 | /// |
---|
590 | GraphIncIterator& operator=(GraphIncIterator const&) { return *this; } |
---|
591 | /// Next edge. |
---|
592 | |
---|
593 | /// Assign the iterator to the next node. |
---|
594 | /// |
---|
595 | GraphIncIterator& operator++() { return *this; } |
---|
596 | |
---|
597 | // Node operator*() const { return INVALID; } |
---|
598 | |
---|
599 | /// Equality operator |
---|
600 | |
---|
601 | /// Two iterators are equal if and only if they point to the |
---|
602 | /// same object or both are invalid. |
---|
603 | bool operator==(const GraphIncIterator&) const { return true;} |
---|
604 | |
---|
605 | /// Inequality operator |
---|
606 | |
---|
607 | /// \sa operator==(Node n) |
---|
608 | /// |
---|
609 | bool operator!=(const GraphIncIterator&) const { return true;} |
---|
610 | |
---|
611 | template <typename _GraphIncIterator> |
---|
612 | struct Constraints { |
---|
613 | typedef typename Graph::Node Node; |
---|
614 | void constraints() { |
---|
615 | checkConcept<GraphItem<'e'>, _GraphIncIterator>(); |
---|
616 | _GraphIncIterator it1(graph, node); |
---|
617 | /// \todo Do we need OutEdgeIt(Edge) kind of constructor? |
---|
618 | // _GraphIncIterator it2(edge); |
---|
619 | _GraphIncIterator it2; |
---|
620 | |
---|
621 | it2 = ++it1; |
---|
622 | ++it2 = it1; |
---|
623 | ++(++it1); |
---|
624 | Edge e = it1; |
---|
625 | e = it2; |
---|
626 | |
---|
627 | const_constraits(); |
---|
628 | } |
---|
629 | |
---|
630 | void const_constraits() { |
---|
631 | Node n = graph.baseNode(it); |
---|
632 | n = graph.runningNode(it); |
---|
633 | } |
---|
634 | |
---|
635 | Edge edge; |
---|
636 | Node node; |
---|
637 | Graph graph; |
---|
638 | _GraphIncIterator it; |
---|
639 | }; |
---|
640 | }; |
---|
641 | |
---|
642 | |
---|
643 | /// An empty iterable base graph class. |
---|
644 | |
---|
645 | /// This class provides beside the core graph features |
---|
646 | /// iterator based iterable interface for the graph structure. |
---|
647 | /// This concept is part of the StaticGraphConcept. |
---|
648 | class IterableGraphComponent : virtual public BaseGraphComponent { |
---|
649 | |
---|
650 | public: |
---|
651 | |
---|
652 | typedef IterableGraphComponent Graph; |
---|
653 | |
---|
654 | typedef BaseGraphComponent::Node Node; |
---|
655 | typedef BaseGraphComponent::Edge Edge; |
---|
656 | |
---|
657 | /// This iterator goes through each node. |
---|
658 | |
---|
659 | /// This iterator goes through each node. |
---|
660 | /// |
---|
661 | typedef GraphIterator<Graph, Node> NodeIt; |
---|
662 | /// This iterator goes through each node. |
---|
663 | |
---|
664 | /// This iterator goes through each node. |
---|
665 | /// |
---|
666 | typedef GraphIterator<Graph, Edge> EdgeIt; |
---|
667 | /// This iterator goes trough the incoming edges of a node. |
---|
668 | |
---|
669 | /// This iterator goes trough the \e inccoming edges of a certain node |
---|
670 | /// of a graph. |
---|
671 | typedef GraphIncIterator<Graph, Edge, 'i'> InEdgeIt; |
---|
672 | /// This iterator goes trough the outgoing edges of a node. |
---|
673 | |
---|
674 | /// This iterator goes trough the \e outgoing edges of a certain node |
---|
675 | /// of a graph. |
---|
676 | typedef GraphIncIterator<Graph, Edge, 'o'> OutEdgeIt; |
---|
677 | |
---|
678 | /// \brief The base node of the iterator. |
---|
679 | /// |
---|
680 | /// Gives back the base node of the iterator. |
---|
681 | Node baseNode(const InEdgeIt&) const { return INVALID; } |
---|
682 | |
---|
683 | /// \brief The running node of the iterator. |
---|
684 | /// |
---|
685 | /// Gives back the running node of the iterator. |
---|
686 | Node runningNode(const InEdgeIt&) const { return INVALID; } |
---|
687 | |
---|
688 | /// \brief The base node of the iterator. |
---|
689 | /// |
---|
690 | /// Gives back the base node of the iterator. |
---|
691 | Node baseNode(const OutEdgeIt&) const { return INVALID; } |
---|
692 | |
---|
693 | /// \brief The running node of the iterator. |
---|
694 | /// |
---|
695 | /// Gives back the running node of the iterator. |
---|
696 | Node runningNode(const OutEdgeIt&) const { return INVALID; } |
---|
697 | |
---|
698 | |
---|
699 | template <typename _Graph> |
---|
700 | struct Constraints { |
---|
701 | void constraints() { |
---|
702 | checkConcept< BaseGraphComponent, _Graph>(); |
---|
703 | |
---|
704 | checkConcept<GraphIterator<_Graph, typename _Graph::Edge>, |
---|
705 | typename _Graph::EdgeIt >(); |
---|
706 | checkConcept<GraphIterator<_Graph, typename _Graph::Node>, |
---|
707 | typename _Graph::NodeIt >(); |
---|
708 | checkConcept<GraphIncIterator<_Graph>, typename _Graph::InEdgeIt>(); |
---|
709 | checkConcept<GraphIncIterator<_Graph>, typename _Graph::OutEdgeIt>(); |
---|
710 | } |
---|
711 | }; |
---|
712 | }; |
---|
713 | |
---|
714 | /// An empty alteration notifier base graph class. |
---|
715 | |
---|
716 | /// This class provides beside the core graph features |
---|
717 | /// alteration notifier interface for the graph structure. |
---|
718 | /// This is an observer-notifier pattern. More Obsevers can |
---|
719 | /// be registered into the notifier and whenever an alteration |
---|
720 | /// occured in the graph all the observers will notified about it. |
---|
721 | class AlterableGraphComponent : virtual public BaseGraphComponent { |
---|
722 | public: |
---|
723 | |
---|
724 | /// The edge observer registry. |
---|
725 | typedef AlterationNotifier<Edge> EdgeNotifier; |
---|
726 | /// The node observer registry. |
---|
727 | typedef AlterationNotifier<Node> NodeNotifier; |
---|
728 | |
---|
729 | /// \brief Gives back the edge alteration notifier. |
---|
730 | /// |
---|
731 | /// Gives back the edge alteration notifier. |
---|
732 | EdgeNotifier getNotifier(Edge) const { |
---|
733 | return EdgeNotifier(); |
---|
734 | } |
---|
735 | |
---|
736 | /// \brief Gives back the node alteration notifier. |
---|
737 | /// |
---|
738 | /// Gives back the node alteration notifier. |
---|
739 | NodeNotifier getNotifier(Node) const { |
---|
740 | return NodeNotifier(); |
---|
741 | } |
---|
742 | |
---|
743 | }; |
---|
744 | |
---|
745 | |
---|
746 | /// Class describing the concept of graph maps |
---|
747 | |
---|
748 | /// This class describes the common interface of the graph maps |
---|
749 | /// (NodeMap, EdgeMap), that is \ref maps-pages "maps" which can be used to |
---|
750 | /// associate data to graph descriptors (nodes or edges). |
---|
751 | template <typename Graph, typename Item, typename _Value> |
---|
752 | class GraphMap : public ReadWriteMap<Item, _Value> { |
---|
753 | protected: |
---|
754 | GraphMap() {} |
---|
755 | public: |
---|
756 | /// \brief Construct a new map. |
---|
757 | /// |
---|
758 | /// Construct a new map for the graph. |
---|
759 | explicit GraphMap(const Graph&) {} |
---|
760 | /// \brief Construct a new map with default value. |
---|
761 | /// |
---|
762 | /// Construct a new map for the graph and initalise the values. |
---|
763 | GraphMap(const Graph&, const _Value&) {} |
---|
764 | /// \brief Copy constructor. |
---|
765 | /// |
---|
766 | /// Copy Constructor. |
---|
767 | GraphMap(const GraphMap& gm) :ReadWriteMap<Item, _Value>(gm) {} |
---|
768 | |
---|
769 | /// \brief Assign operator. |
---|
770 | /// |
---|
771 | /// Assign operator. |
---|
772 | GraphMap& operator=(const GraphMap&) { return *this;} |
---|
773 | |
---|
774 | template<typename _Map> |
---|
775 | struct Constraints { |
---|
776 | void constraints() { |
---|
777 | checkConcept<ReadWriteMap<Item, _Value>, _Map >(); |
---|
778 | // Construction with a graph parameter |
---|
779 | _Map a(g); |
---|
780 | // Constructor with a graph and a default value parameter |
---|
781 | _Map a2(g,t); |
---|
782 | // Copy constructor. Do we need it? |
---|
783 | _Map b=c; |
---|
784 | // Copy operator. Do we need it? |
---|
785 | a=b; |
---|
786 | |
---|
787 | ignore_unused_variable_warning(a2); |
---|
788 | } |
---|
789 | |
---|
790 | const _Map &c; |
---|
791 | const Graph &g; |
---|
792 | const typename GraphMap::Value &t; |
---|
793 | }; |
---|
794 | |
---|
795 | }; |
---|
796 | |
---|
797 | /// An empty mappable base graph class. |
---|
798 | |
---|
799 | /// This class provides beside the core graph features |
---|
800 | /// map interface for the graph structure. |
---|
801 | /// This concept is part of the StaticGraphConcept. |
---|
802 | class MappableGraphComponent : virtual public BaseGraphComponent { |
---|
803 | public: |
---|
804 | |
---|
805 | typedef MappableGraphComponent Graph; |
---|
806 | |
---|
807 | typedef BaseGraphComponent::Node Node; |
---|
808 | typedef BaseGraphComponent::Edge Edge; |
---|
809 | |
---|
810 | /// ReadWrite map of the nodes. |
---|
811 | |
---|
812 | /// ReadWrite map of the nodes. |
---|
813 | /// |
---|
814 | template <typename _Value> |
---|
815 | class NodeMap : public GraphMap<Graph, Node, _Value> { |
---|
816 | private: |
---|
817 | NodeMap(); |
---|
818 | public: |
---|
819 | /// \brief Construct a new map. |
---|
820 | /// |
---|
821 | /// Construct a new map for the graph. |
---|
822 | /// \todo call the right parent class constructor |
---|
823 | explicit NodeMap(const Graph&) {} |
---|
824 | /// \brief Construct a new map with default value. |
---|
825 | /// |
---|
826 | /// Construct a new map for the graph and initalise the values. |
---|
827 | NodeMap(const Graph&, const _Value&) {} |
---|
828 | /// \brief Copy constructor. |
---|
829 | /// |
---|
830 | /// Copy Constructor. |
---|
831 | NodeMap(const NodeMap& nm) : GraphMap<Graph, Node, _Value>(nm) {} |
---|
832 | |
---|
833 | /// \brief Assign operator. |
---|
834 | /// |
---|
835 | /// Assign operator. |
---|
836 | NodeMap& operator=(const NodeMap&) { return *this;} |
---|
837 | |
---|
838 | }; |
---|
839 | |
---|
840 | /// ReadWrite map of the edges. |
---|
841 | |
---|
842 | /// ReadWrite map of the edges. |
---|
843 | /// |
---|
844 | template <typename _Value> |
---|
845 | class EdgeMap : public GraphMap<Graph, Edge, _Value> { |
---|
846 | private: |
---|
847 | EdgeMap(); |
---|
848 | public: |
---|
849 | /// \brief Construct a new map. |
---|
850 | /// |
---|
851 | /// Construct a new map for the graph. |
---|
852 | /// \todo call the right parent class constructor |
---|
853 | explicit EdgeMap(const Graph&) {} |
---|
854 | /// \brief Construct a new map with default value. |
---|
855 | /// |
---|
856 | /// Construct a new map for the graph and initalise the values. |
---|
857 | EdgeMap(const Graph&, const _Value&) {} |
---|
858 | /// \brief Copy constructor. |
---|
859 | /// |
---|
860 | /// Copy Constructor. |
---|
861 | EdgeMap(const EdgeMap& em) :GraphMap<Graph, Edge, _Value>(em) {} |
---|
862 | |
---|
863 | /// \brief Assign operator. |
---|
864 | /// |
---|
865 | /// Assign operator. |
---|
866 | EdgeMap& operator=(const EdgeMap&) { return *this;} |
---|
867 | |
---|
868 | }; |
---|
869 | |
---|
870 | template <typename _Graph> |
---|
871 | struct Constraints { |
---|
872 | |
---|
873 | struct Type { |
---|
874 | int value; |
---|
875 | Type() : value(0) {} |
---|
876 | Type(int _v) : value(_v) {} |
---|
877 | }; |
---|
878 | |
---|
879 | void constraints() { |
---|
880 | checkConcept<BaseGraphComponent, _Graph>(); |
---|
881 | { // int map test |
---|
882 | typedef typename _Graph::template NodeMap<int> IntNodeMap; |
---|
883 | checkConcept<GraphMap<_Graph, typename _Graph::Node, int>, |
---|
884 | IntNodeMap >(); |
---|
885 | } { // bool map test |
---|
886 | typedef typename _Graph::template NodeMap<bool> BoolNodeMap; |
---|
887 | checkConcept<GraphMap<_Graph, typename _Graph::Node, bool>, |
---|
888 | BoolNodeMap >(); |
---|
889 | } { // Type map test |
---|
890 | typedef typename _Graph::template NodeMap<Type> TypeNodeMap; |
---|
891 | checkConcept<GraphMap<_Graph, typename _Graph::Node, Type>, |
---|
892 | TypeNodeMap >(); |
---|
893 | } |
---|
894 | |
---|
895 | { // int map test |
---|
896 | typedef typename _Graph::template EdgeMap<int> IntEdgeMap; |
---|
897 | checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>, |
---|
898 | IntEdgeMap >(); |
---|
899 | } { // bool map test |
---|
900 | typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap; |
---|
901 | checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>, |
---|
902 | BoolEdgeMap >(); |
---|
903 | } { // Type map test |
---|
904 | typedef typename _Graph::template EdgeMap<Type> TypeEdgeMap; |
---|
905 | checkConcept<GraphMap<_Graph, typename _Graph::Edge, Type>, |
---|
906 | TypeEdgeMap >(); |
---|
907 | } |
---|
908 | } |
---|
909 | |
---|
910 | _Graph& graph; |
---|
911 | }; |
---|
912 | }; |
---|
913 | |
---|
914 | /// \brief An empty extendable extended graph class. |
---|
915 | /// |
---|
916 | /// This class provides beside the core graph features |
---|
917 | /// item addition interface for the graph structure. |
---|
918 | /// The difference between this class and the |
---|
919 | /// \c BaseExtendableGraphComponent is that it should |
---|
920 | /// notify the item alteration observers. |
---|
921 | class ExtendableGraphComponent : virtual public BaseGraphComponent { |
---|
922 | public: |
---|
923 | |
---|
924 | typedef ExtendableGraphComponent Graph; |
---|
925 | |
---|
926 | typedef BaseGraphComponent::Node Node; |
---|
927 | typedef BaseGraphComponent::Edge Edge; |
---|
928 | |
---|
929 | /// \brief Add a node to the graph. |
---|
930 | /// |
---|
931 | /// Add a node to the graph and notify the observers. |
---|
932 | Node addNode() { |
---|
933 | return INVALID; |
---|
934 | } |
---|
935 | |
---|
936 | /// \brief Add an edge to the graph. |
---|
937 | /// |
---|
938 | /// Add an edge to the graph and notify the observers. |
---|
939 | Edge addEdge(const Node&, const Node&) { |
---|
940 | return INVALID; |
---|
941 | } |
---|
942 | |
---|
943 | template <typename _Graph> |
---|
944 | struct Constraints { |
---|
945 | void constraints() { |
---|
946 | checkConcept<BaseGraphComponent, _Graph >(); |
---|
947 | typename _Graph::Node node_a, node_b; |
---|
948 | node_a = graph.addNode(); |
---|
949 | node_b = graph.addNode(); |
---|
950 | typename _Graph::Edge edge; |
---|
951 | edge = graph.addEdge(node_a, node_b); |
---|
952 | } |
---|
953 | _Graph& graph; |
---|
954 | }; |
---|
955 | }; |
---|
956 | |
---|
957 | /// \brief An empty erasable extended graph class. |
---|
958 | /// |
---|
959 | /// This class provides beside the core graph features |
---|
960 | /// item erase interface for the graph structure. |
---|
961 | /// The difference between this class and the |
---|
962 | /// \c BaseErasableGraphComponent is that it should |
---|
963 | /// notify the item alteration observers. |
---|
964 | class ErasableGraphComponent : virtual public BaseGraphComponent { |
---|
965 | public: |
---|
966 | |
---|
967 | typedef ErasableGraphComponent Graph; |
---|
968 | |
---|
969 | typedef BaseGraphComponent::Node Node; |
---|
970 | typedef BaseGraphComponent::Edge Edge; |
---|
971 | |
---|
972 | /// \brief Erase the Node and notify the node alteration observers. |
---|
973 | /// |
---|
974 | /// Erase the Node and notify the node alteration observers. |
---|
975 | void erase(const Node&) {} |
---|
976 | |
---|
977 | /// \brief Erase the Edge and notify the edge alteration observers. |
---|
978 | /// |
---|
979 | /// Erase the Edge and notify the edge alteration observers. |
---|
980 | void erase(const Edge&) {} |
---|
981 | |
---|
982 | template <typename _Graph> |
---|
983 | struct Constraints { |
---|
984 | void constraints() { |
---|
985 | checkConcept<BaseGraphComponent, _Graph >(); |
---|
986 | typename _Graph::Node node; |
---|
987 | graph.erase(node); |
---|
988 | typename _Graph::Edge edge; |
---|
989 | graph.erase(edge); |
---|
990 | } |
---|
991 | |
---|
992 | _Graph& graph; |
---|
993 | }; |
---|
994 | }; |
---|
995 | |
---|
996 | } |
---|
997 | |
---|
998 | } |
---|
999 | |
---|
1000 | #endif |
---|