Experimental autopackage specfile.
3 * src/lemon/concept/undir_graph_component.h - Part of LEMON, a generic
4 * C++ optimization library
6 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi
7 * Kutatocsoport (Egervary Combinatorial Optimization Research Group,
10 * Permission to use, modify and distribute this software is granted
11 * provided that this copyright notice appears in all copies. For
12 * precise terms see the accompanying LICENSE file.
14 * This software is provided "AS IS" with no warranty of any kind,
15 * express or implied, and with no claim as to its suitability for any
20 ///\ingroup graph_concepts
22 ///\brief Undirected graphs and components of.
25 #ifndef LEMON_CONCEPT_UNDIR_GRAPH_H
26 #define LEMON_CONCEPT_UNDIR_GRAPH_H
28 #include <lemon/concept/graph_component.h>
33 /// \addtogroup graph_concepts
37 /// Skeleton class which describes an edge with direction in \ref
38 /// UndirGraph "undirected graph".
39 template <typename UndirGraph>
40 class UndirGraphEdge : public UndirGraph::UndirEdge {
41 typedef typename UndirGraph::UndirEdge UndirEdge;
42 typedef typename UndirGraph::Node Node;
49 UndirGraphEdge(const UndirGraphEdge&) {}
52 UndirGraphEdge(Invalid) {}
54 /// \brief Directed edge from undirected edge and a source node.
56 /// Constructs a directed edge from undirected edge and a source node.
58 /// \note You have to specify the graph for this constructor.
59 UndirGraphEdge(const UndirGraph &g,
60 UndirEdge undir_edge, Node n) {
61 ignore_unused_variable_warning(undir_edge);
62 ignore_unused_variable_warning(g);
63 ignore_unused_variable_warning(n);
67 UndirGraphEdge& operator=(UndirGraphEdge) { return *this; }
70 bool operator==(UndirGraphEdge) const { return true; }
72 bool operator!=(UndirGraphEdge) const { return false; }
75 bool operator<(UndirGraphEdge) const { return false; }
77 template <typename Edge>
82 void const_constraints() const {
83 /// \bug This should be is_base_and_derived ...
87 Edge e_with_source(graph,ue,n);
88 ignore_unused_variable_warning(e_with_source);
98 struct BaseIterableUndirGraphConcept {
100 template <typename Graph>
103 typedef typename Graph::UndirEdge UndirEdge;
104 typedef typename Graph::Edge Edge;
105 typedef typename Graph::Node Node;
108 checkConcept<BaseIterableGraphComponent, Graph>();
109 checkConcept<GraphItem<>, UndirEdge>();
110 checkConcept<UndirGraphEdge<Graph>, Edge>();
117 void const_constraints() {
119 n = graph.target(ue);
120 n = graph.source(ue);
121 n = graph.oppositeNode(n0, ue);
124 b = graph.forward(e);
125 ignore_unused_variable_warning(b);
137 struct IterableUndirGraphConcept {
139 template <typename Graph>
142 /// \todo we don't need the iterable component to be base iterable
143 /// Don't we really???
144 //checkConcept< BaseIterableUndirGraphConcept, Graph > ();
146 checkConcept<IterableGraphComponent, Graph> ();
148 typedef typename Graph::UndirEdge UndirEdge;
149 typedef typename Graph::UndirEdgeIt UndirEdgeIt;
150 typedef typename Graph::IncEdgeIt IncEdgeIt;
152 checkConcept<GraphIterator<Graph, UndirEdge>, UndirEdgeIt>();
153 checkConcept<GraphIncIterator<Graph, UndirEdge>, IncEdgeIt>();
159 struct MappableUndirGraphConcept {
161 template <typename Graph>
166 Dummy() : value(0) {}
167 Dummy(int _v) : value(_v) {}
171 checkConcept<MappableGraphComponent, Graph>();
173 typedef typename Graph::template UndirEdgeMap<int> IntMap;
174 checkConcept<GraphMap<Graph, typename Graph::UndirEdge, int>,
177 typedef typename Graph::template UndirEdgeMap<bool> BoolMap;
178 checkConcept<GraphMap<Graph, typename Graph::UndirEdge, bool>,
181 typedef typename Graph::template UndirEdgeMap<Dummy> DummyMap;
182 checkConcept<GraphMap<Graph, typename Graph::UndirEdge, Dummy>,
189 struct ExtendableUndirGraphConcept {
191 template <typename Graph>
194 node_a = graph.addNode();
195 uedge = graph.addEdge(node_a, node_b);
197 typename Graph::Node node_a, node_b;
198 typename Graph::UndirEdge uedge;
204 struct ErasableUndirGraphConcept {
206 template <typename Graph>
213 typename Graph::Node n;
214 typename Graph::UndirEdge e;
219 /// Class describing the concept of Undirected Graphs.
221 /// This class describes the common interface of all Undirected
224 /// As all concept describing classes it provides only interface
225 /// without any sensible implementation. So any algorithm for
226 /// undirected graph should compile with this class, but it will not
227 /// run properly, of couse.
229 /// In LEMON undirected graphs also fulfill the concept of directed
230 /// graphs (\ref lemon::concept::Graph "Graph Concept"). For
231 /// explanation of this and more see also the page \ref undir_graphs,
232 /// a tutorial about undirected graphs.
237 /// Type describing a node in the graph
238 typedef GraphNode Node;
240 /// Type describing an undirected edge
241 typedef GraphItem<'u'> UndirEdge;
243 /// Type describing an UndirEdge with direction
245 typedef UndirGraphEdge<UndirGraph> Edge;
247 typedef UndirGraphEdge Edge;
250 /// Iterator type which iterates over all nodes
252 typedef GraphIterator<UndirGraph, Node> NodeIt;
254 typedef GraphIterator NodeIt;
257 /// Iterator type which iterates over all undirected edges
259 typedef GraphIterator<UndirGraph, UndirEdge> UndirEdgeIt;
261 typedef GraphIterator UndirEdgeIt;
264 /// Iterator type which iterates over all directed edges.
266 /// Iterator type which iterates over all edges (each undirected
267 /// edge occurs twice with both directions.
269 typedef GraphIterator<UndirGraph, Edge> EdgeIt;
271 typedef GraphIterator EdgeIt;
275 /// Iterator of undirected edges incident to a node
277 typedef GraphIncIterator<UndirGraph, UndirEdge, 'u'> IncEdgeIt;
279 typedef GraphIncIterator IncEdgeIt;
282 /// Iterator of edges incoming to a node
284 typedef GraphIncIterator<UndirGraph, Edge, 'i'> InEdgeIt;
286 typedef GraphIncIterator InEdgeIt;
289 /// Iterator of edges outgoing from a node
291 typedef GraphIncIterator<UndirGraph, Edge, 'o'> OutEdgeIt;
293 typedef GraphIncIterator OutEdgeIt;
298 typedef GraphMap NodeMap<T>;
301 /// UndirEdgeMap template
303 typedef GraphMap UndirEdgeMap<T>;
308 typedef GraphMap EdgeMap<T>;
311 template <typename T>
312 class NodeMap : public GraphMap<UndirGraph, Node, T> {
313 typedef GraphMap<UndirGraph, Node, T> Parent;
316 explicit NodeMap(const UndirGraph &g) : Parent(g) {}
317 NodeMap(const UndirGraph &g, T t) : Parent(g, t) {}
320 template <typename T>
321 class UndirEdgeMap : public GraphMap<UndirGraph, UndirEdge, T> {
322 typedef GraphMap<UndirGraph, UndirEdge, T> Parent;
325 explicit UndirEdgeMap(const UndirGraph &g) : Parent(g) {}
326 UndirEdgeMap(const UndirGraph &g, T t) : Parent(g, t) {}
329 template <typename T>
330 class EdgeMap : public GraphMap<UndirGraph, Edge, T> {
331 typedef GraphMap<UndirGraph, Edge, T> Parent;
334 explicit EdgeMap(const UndirGraph &g) : Parent(g) {}
335 EdgeMap(const UndirGraph &g, T t) : Parent(g, t) {}
338 /// Is the Edge oriented "forward"?
340 /// Returns whether the given directed edge is same orientation as
341 /// the corresponding undirected edge.
343 /// \todo "What does the direction of an undirected edge mean?"
344 bool forward(Edge) const { return true; }
346 /// Opposite node on an edge
348 /// \return the opposite of the given Node on the given Edge
350 /// \todo What should we do if given Node and Edge are not incident?
351 Node oppositeNode(Node, UndirEdge) const { return INVALID; }
353 /// First node of the undirected edge.
355 /// \return the first node of the given UndirEdge.
357 /// Naturally undirectected edges don't have direction and thus
358 /// don't have source and target node. But we use these two methods
359 /// to query the two endnodes of the edge. The direction of the edge
360 /// which arises this way is called the inherent direction of the
361 /// undirected edge, and is used to define the "forward" direction
362 /// of the directed versions of the edges.
364 Node source(UndirEdge) const { return INVALID; }
366 /// Second node of the undirected edge.
367 Node target(UndirEdge) const { return INVALID; }
369 /// Source node of the directed edge.
370 Node source(Edge) const { return INVALID; }
372 /// Target node of the directed edge.
373 Node target(Edge) const { return INVALID; }
375 /// First node of the graph
377 /// \note This method is part of so called \ref
378 /// developpers_interface "Developpers' interface", so it shouldn't
379 /// be used in an end-user program.
380 void first(Node&) const {}
381 /// Next node of the graph
383 /// \note This method is part of so called \ref
384 /// developpers_interface "Developpers' interface", so it shouldn't
385 /// be used in an end-user program.
386 void next(Node&) const {}
388 /// First undirected edge of the graph
390 /// \note This method is part of so called \ref
391 /// developpers_interface "Developpers' interface", so it shouldn't
392 /// be used in an end-user program.
393 void first(UndirEdge&) const {}
394 /// Next undirected edge of the graph
396 /// \note This method is part of so called \ref
397 /// developpers_interface "Developpers' interface", so it shouldn't
398 /// be used in an end-user program.
399 void next(UndirEdge&) const {}
401 /// First directed edge of the graph
403 /// \note This method is part of so called \ref
404 /// developpers_interface "Developpers' interface", so it shouldn't
405 /// be used in an end-user program.
406 void first(Edge&) const {}
407 /// Next directed edge of the graph
409 /// \note This method is part of so called \ref
410 /// developpers_interface "Developpers' interface", so it shouldn't
411 /// be used in an end-user program.
412 void next(Edge&) const {}
414 /// First outgoing edge from a given node
416 /// \note This method is part of so called \ref
417 /// developpers_interface "Developpers' interface", so it shouldn't
418 /// be used in an end-user program.
419 void firstOut(Edge&, Node) const {}
420 /// Next outgoing edge to a node
422 /// \note This method is part of so called \ref
423 /// developpers_interface "Developpers' interface", so it shouldn't
424 /// be used in an end-user program.
425 void nextOut(Edge&) const {}
427 /// First incoming edge to a given node
429 /// \note This method is part of so called \ref
430 /// developpers_interface "Developpers' interface", so it shouldn't
431 /// be used in an end-user program.
432 void firstIn(Edge&, Node) const {}
433 /// Next incoming edge to a node
435 /// \note This method is part of so called \ref
436 /// developpers_interface "Developpers' interface", so it shouldn't
437 /// be used in an end-user program.
438 void nextIn(Edge&) const {}
441 /// Base node of the iterator
443 /// Returns the base node (the source in this case) of the iterator
444 Node baseNode(OutEdgeIt e) const {
447 /// Running node of the iterator
449 /// Returns the running node (the target in this case) of the
451 Node runningNode(OutEdgeIt e) const {
455 /// Base node of the iterator
457 /// Returns the base node (the target in this case) of the iterator
458 Node baseNode(InEdgeIt e) const {
461 /// Running node of the iterator
463 /// Returns the running node (the source in this case) of the
465 Node runningNode(InEdgeIt e) const {
469 /// Base node of the iterator
471 /// Returns the base node of the iterator
472 Node baseNode(IncEdgeIt e) const {
475 /// Running node of the iterator
477 /// Returns the running node of the iterator
478 Node runningNode(IncEdgeIt e) const {
483 template <typename Graph>
486 checkConcept<BaseIterableUndirGraphConcept, Graph>();
487 checkConcept<IterableUndirGraphConcept, Graph>();
488 checkConcept<MappableUndirGraphConcept, Graph>();
494 class ExtendableUndirGraph : public UndirGraph {
497 template <typename Graph>
500 checkConcept<BaseIterableUndirGraphConcept, Graph>();
501 checkConcept<IterableUndirGraphConcept, Graph>();
502 checkConcept<MappableUndirGraphConcept, Graph>();
504 checkConcept<UndirGraph, Graph>();
505 checkConcept<ExtendableUndirGraphConcept, Graph>();
506 checkConcept<ClearableGraphComponent, Graph>();
512 class ErasableUndirGraph : public ExtendableUndirGraph {
515 template <typename Graph>
518 checkConcept<ExtendableUndirGraph, Graph>();
519 checkConcept<ErasableUndirGraphConcept, Graph>();