1.1 --- a/src/lemon/concept/graph.h Sat May 21 21:04:57 2005 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,578 +0,0 @@
1.4 -/* -*- C++ -*-
1.5 - * src/lemon/concept/graph.h - Part of LEMON, a generic C++ optimization library
1.6 - *
1.7 - * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.8 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.9 - *
1.10 - * Permission to use, modify and distribute this software is granted
1.11 - * provided that this copyright notice appears in all copies. For
1.12 - * precise terms see the accompanying LICENSE file.
1.13 - *
1.14 - * This software is provided "AS IS" with no warranty of any kind,
1.15 - * express or implied, and with no claim as to its suitability for any
1.16 - * purpose.
1.17 - *
1.18 - */
1.19 -
1.20 -#ifndef LEMON_CONCEPT_GRAPH_H
1.21 -#define LEMON_CONCEPT_GRAPH_H
1.22 -
1.23 -///\ingroup graph_concepts
1.24 -///\file
1.25 -///\brief Declaration of Graph.
1.26 -
1.27 -#include <lemon/invalid.h>
1.28 -#include <lemon/concept/maps.h>
1.29 -#include <lemon/concept_check.h>
1.30 -#include <lemon/concept/graph_component.h>
1.31 -
1.32 -namespace lemon {
1.33 - namespace concept {
1.34 -
1.35 -
1.36 - /// \addtogroup graph_concepts
1.37 - /// @{
1.38 -
1.39 - /**************** The full-featured graph concepts ****************/
1.40 -
1.41 -
1.42 - /// \brief Modular static graph class.
1.43 - ///
1.44 - /// It should be the same as the \c StaticGraph class.
1.45 - class _StaticGraph
1.46 - : virtual public BaseGraphComponent,
1.47 - public IterableGraphComponent, public MappableGraphComponent {
1.48 - public:
1.49 - typedef BaseGraphComponent::Node Node;
1.50 - typedef BaseGraphComponent::Edge Edge;
1.51 -
1.52 - template <typename _Graph>
1.53 - struct Constraints {
1.54 - void constraints() {
1.55 - checkConcept<IterableGraphComponent, _Graph>();
1.56 - checkConcept<MappableGraphComponent, _Graph>();
1.57 - }
1.58 - };
1.59 - };
1.60 -
1.61 - /// \brief Modular extendable graph class.
1.62 - ///
1.63 - /// It should be the same as the \c ExtendableGraph class.
1.64 - class _ExtendableGraph
1.65 - : virtual public BaseGraphComponent, public _StaticGraph,
1.66 - public ExtendableGraphComponent, public ClearableGraphComponent {
1.67 - public:
1.68 - typedef BaseGraphComponent::Node Node;
1.69 - typedef BaseGraphComponent::Edge Edge;
1.70 -
1.71 - template <typename _Graph>
1.72 - struct Constraints {
1.73 - void constraints() {
1.74 - checkConcept<_StaticGraph, _Graph >();
1.75 - checkConcept<ExtendableGraphComponent, _Graph >();
1.76 - checkConcept<ClearableGraphComponent, _Graph >();
1.77 - }
1.78 - };
1.79 - };
1.80 -
1.81 - /// \brief Modular erasable graph class.
1.82 - ///
1.83 - /// It should be the same as the \c ErasableGraph class.
1.84 - class _ErasableGraph
1.85 - : virtual public BaseGraphComponent, public _ExtendableGraph,
1.86 - public ErasableGraphComponent {
1.87 - public:
1.88 - typedef BaseGraphComponent::Node Node;
1.89 - typedef BaseGraphComponent::Edge Edge;
1.90 -
1.91 - template <typename _Graph>
1.92 - struct Constraints {
1.93 - void constraints() {
1.94 - checkConcept<_ExtendableGraph, _Graph >();
1.95 - checkConcept<ErasableGraphComponent, _Graph >();
1.96 - }
1.97 - };
1.98 - };
1.99 -
1.100 - /// An empty static graph class.
1.101 -
1.102 - /// This class provides all the common features of a graph structure,
1.103 - /// however completely without implementations and real data structures
1.104 - /// behind the interface.
1.105 - /// All graph algorithms should compile with this class, but it will not
1.106 - /// run properly, of course.
1.107 - ///
1.108 - /// It can be used for checking the interface compatibility,
1.109 - /// or it can serve as a skeleton of a new graph structure.
1.110 - ///
1.111 - /// Also, you will find here the full documentation of a certain graph
1.112 - /// feature, the documentation of a real graph imlementation
1.113 - /// like @ref ListGraph or
1.114 - /// @ref SmartGraph will just refer to this structure.
1.115 - ///
1.116 - /// \todo A pages describing the concept of concept description would
1.117 - /// be nice.
1.118 - class StaticGraph
1.119 - {
1.120 - public:
1.121 - /// Defalult constructor.
1.122 -
1.123 - /// Defalult constructor.
1.124 - ///
1.125 - StaticGraph() { }
1.126 - ///Copy consructor.
1.127 -
1.128 -// ///\todo It is not clear, what we expect from a copy constructor.
1.129 -// ///E.g. How to assign the nodes/edges to each other? What about maps?
1.130 -// StaticGraph(const StaticGraph& g) { }
1.131 -
1.132 - /// The base type of node iterators,
1.133 - /// or in other words, the trivial node iterator.
1.134 -
1.135 - /// This is the base type of each node iterator,
1.136 - /// thus each kind of node iterator converts to this.
1.137 - /// More precisely each kind of node iterator should be inherited
1.138 - /// from the trivial node iterator.
1.139 - class Node {
1.140 - public:
1.141 - /// Default constructor
1.142 -
1.143 - /// @warning The default constructor sets the iterator
1.144 - /// to an undefined value.
1.145 - Node() { }
1.146 - /// Copy constructor.
1.147 -
1.148 - /// Copy constructor.
1.149 - ///
1.150 - Node(const Node&) { }
1.151 -
1.152 - /// Invalid constructor \& conversion.
1.153 -
1.154 - /// This constructor initializes the iterator to be invalid.
1.155 - /// \sa Invalid for more details.
1.156 - Node(Invalid) { }
1.157 - /// Equality operator
1.158 -
1.159 - /// Two iterators are equal if and only if they point to the
1.160 - /// same object or both are invalid.
1.161 - bool operator==(Node) const { return true; }
1.162 -
1.163 - /// Inequality operator
1.164 -
1.165 - /// \sa operator==(Node n)
1.166 - ///
1.167 - bool operator!=(Node) const { return true; }
1.168 -
1.169 - };
1.170 -
1.171 - /// This iterator goes through each node.
1.172 -
1.173 - /// This iterator goes through each node.
1.174 - /// Its usage is quite simple, for example you can count the number
1.175 - /// of nodes in graph \c g of type \c Graph like this:
1.176 - /// \code
1.177 - /// int count=0;
1.178 - /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
1.179 - /// \endcode
1.180 - class NodeIt : public Node {
1.181 - public:
1.182 - /// Default constructor
1.183 -
1.184 - /// @warning The default constructor sets the iterator
1.185 - /// to an undefined value.
1.186 - NodeIt() { }
1.187 - /// Copy constructor.
1.188 -
1.189 - /// Copy constructor.
1.190 - ///
1.191 - NodeIt(const NodeIt& n) : Node(n) { }
1.192 - /// Invalid constructor \& conversion.
1.193 -
1.194 - /// Initialize the iterator to be invalid.
1.195 - /// \sa Invalid for more details.
1.196 - NodeIt(Invalid) { }
1.197 - /// Sets the iterator to the first node.
1.198 -
1.199 - /// Sets the iterator to the first node of \c g.
1.200 - ///
1.201 - NodeIt(const StaticGraph&) { }
1.202 - /// Node -> NodeIt conversion.
1.203 -
1.204 - /// Sets the iterator to the node of \c g pointed by the trivial
1.205 - /// iterator n.
1.206 - /// This feature necessitates that each time we
1.207 - /// iterate the edge-set, the iteration order is the same.
1.208 - NodeIt(const StaticGraph& g, const Node& n) { }
1.209 - /// Next node.
1.210 -
1.211 - /// Assign the iterator to the next node.
1.212 - ///
1.213 - NodeIt& operator++() { return *this; }
1.214 - };
1.215 -
1.216 -
1.217 - /// The base type of the edge iterators.
1.218 -
1.219 - /// The base type of the edge iterators.
1.220 - ///
1.221 - class Edge {
1.222 - public:
1.223 - /// Default constructor
1.224 -
1.225 - /// @warning The default constructor sets the iterator
1.226 - /// to an undefined value.
1.227 - Edge() { }
1.228 - /// Copy constructor.
1.229 -
1.230 - /// Copy constructor.
1.231 - ///
1.232 - Edge(const Edge&) { }
1.233 - /// Initialize the iterator to be invalid.
1.234 -
1.235 - /// Initialize the iterator to be invalid.
1.236 - ///
1.237 - Edge(Invalid) { }
1.238 - /// Equality operator
1.239 -
1.240 - /// Two iterators are equal if and only if they point to the
1.241 - /// same object or both are invalid.
1.242 - bool operator==(Edge) const { return true; }
1.243 - /// Inequality operator
1.244 -
1.245 - /// \sa operator==(Node n)
1.246 - ///
1.247 - bool operator!=(Edge) const { return true; }
1.248 - };
1.249 -
1.250 - /// This iterator goes trough the outgoing edges of a node.
1.251 -
1.252 - /// This iterator goes trough the \e outgoing edges of a certain node
1.253 - /// of a graph.
1.254 - /// Its usage is quite simple, for example you can count the number
1.255 - /// of outgoing edges of a node \c n
1.256 - /// in graph \c g of type \c Graph as follows.
1.257 - /// \code
1.258 - /// int count=0;
1.259 - /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
1.260 - /// \endcode
1.261 -
1.262 - class OutEdgeIt : public Edge {
1.263 - public:
1.264 - /// Default constructor
1.265 -
1.266 - /// @warning The default constructor sets the iterator
1.267 - /// to an undefined value.
1.268 - OutEdgeIt() { }
1.269 - /// Copy constructor.
1.270 -
1.271 - /// Copy constructor.
1.272 - ///
1.273 - OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
1.274 - /// Initialize the iterator to be invalid.
1.275 -
1.276 - /// Initialize the iterator to be invalid.
1.277 - ///
1.278 - OutEdgeIt(Invalid) { }
1.279 - /// This constructor sets the iterator to the first outgoing edge.
1.280 -
1.281 - /// This constructor sets the iterator to the first outgoing edge of
1.282 - /// the node.
1.283 - ///@param n the node
1.284 - ///@param g the graph
1.285 - OutEdgeIt(const StaticGraph&, const Node&) { }
1.286 - /// Edge -> OutEdgeIt conversion
1.287 -
1.288 - /// Sets the iterator to the value of the trivial iterator \c e.
1.289 - /// This feature necessitates that each time we
1.290 - /// iterate the edge-set, the iteration order is the same.
1.291 - OutEdgeIt(const StaticGraph& g, const Edge& e) { }
1.292 - ///Next outgoing edge
1.293 -
1.294 - /// Assign the iterator to the next
1.295 - /// outgoing edge of the corresponding node.
1.296 - OutEdgeIt& operator++() { return *this; }
1.297 - };
1.298 -
1.299 - /// This iterator goes trough the incoming edges of a node.
1.300 -
1.301 - /// This iterator goes trough the \e incoming edges of a certain node
1.302 - /// of a graph.
1.303 - /// Its usage is quite simple, for example you can count the number
1.304 - /// of outgoing edges of a node \c n
1.305 - /// in graph \c g of type \c Graph as follows.
1.306 - /// \code
1.307 - /// int count=0;
1.308 - /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
1.309 - /// \endcode
1.310 -
1.311 - class InEdgeIt : public Edge {
1.312 - public:
1.313 - /// Default constructor
1.314 -
1.315 - /// @warning The default constructor sets the iterator
1.316 - /// to an undefined value.
1.317 - InEdgeIt() { }
1.318 - /// Copy constructor.
1.319 -
1.320 - /// Copy constructor.
1.321 - ///
1.322 - InEdgeIt(const InEdgeIt& e) : Edge(e) { }
1.323 - /// Initialize the iterator to be invalid.
1.324 -
1.325 - /// Initialize the iterator to be invalid.
1.326 - ///
1.327 - InEdgeIt(Invalid) { }
1.328 - /// This constructor sets the iterator to first incoming edge.
1.329 -
1.330 - /// This constructor set the iterator to the first incoming edge of
1.331 - /// the node.
1.332 - ///@param n the node
1.333 - ///@param g the graph
1.334 - InEdgeIt(const StaticGraph&, const Node&) { }
1.335 - /// Edge -> InEdgeIt conversion
1.336 -
1.337 - /// Sets the iterator to the value of the trivial iterator \c e.
1.338 - /// This feature necessitates that each time we
1.339 - /// iterate the edge-set, the iteration order is the same.
1.340 - InEdgeIt(const StaticGraph&, const Edge&) { }
1.341 - /// Next incoming edge
1.342 -
1.343 - /// Assign the iterator to the next inedge of the corresponding node.
1.344 - ///
1.345 - InEdgeIt& operator++() { return *this; }
1.346 - };
1.347 - /// This iterator goes through each edge.
1.348 -
1.349 - /// This iterator goes through each edge of a graph.
1.350 - /// Its usage is quite simple, for example you can count the number
1.351 - /// of edges in a graph \c g of type \c Graph as follows:
1.352 - /// \code
1.353 - /// int count=0;
1.354 - /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
1.355 - /// \endcode
1.356 - class EdgeIt : public Edge {
1.357 - public:
1.358 - /// Default constructor
1.359 -
1.360 - /// @warning The default constructor sets the iterator
1.361 - /// to an undefined value.
1.362 - EdgeIt() { }
1.363 - /// Copy constructor.
1.364 -
1.365 - /// Copy constructor.
1.366 - ///
1.367 - EdgeIt(const EdgeIt& e) : Edge(e) { }
1.368 - /// Initialize the iterator to be invalid.
1.369 -
1.370 - /// Initialize the iterator to be invalid.
1.371 - ///
1.372 - EdgeIt(Invalid) { }
1.373 - /// This constructor sets the iterator to the first edge.
1.374 -
1.375 - /// This constructor sets the iterator to the first edge of \c g.
1.376 - ///@param g the graph
1.377 - EdgeIt(const StaticGraph&) { }
1.378 - /// Edge -> EdgeIt conversion
1.379 -
1.380 - /// Sets the iterator to the value of the trivial iterator \c e.
1.381 - /// This feature necessitates that each time we
1.382 - /// iterate the edge-set, the iteration order is the same.
1.383 - EdgeIt(const StaticGraph&, const Edge&) { }
1.384 - ///Next edge
1.385 -
1.386 - /// Assign the iterator to the next edge.
1.387 - EdgeIt& operator++() { return *this; }
1.388 - };
1.389 - ///Gives back the target node of an edge.
1.390 -
1.391 - ///Gives back the target node of an edge.
1.392 - ///
1.393 - Node target(Edge) const { return INVALID; }
1.394 - ///Gives back the source node of an edge.
1.395 -
1.396 - ///Gives back the source node of an edge.
1.397 - ///
1.398 - Node source(Edge) const { return INVALID; }
1.399 - /// Read write map of the nodes to type \c T.
1.400 -
1.401 - /// \ingroup concept
1.402 - /// ReadWrite map of the nodes to type \c T.
1.403 - /// \sa Reference
1.404 - /// \warning Making maps that can handle bool type (NodeMap<bool>)
1.405 - /// needs some extra attention!
1.406 - template<class T>
1.407 - class NodeMap : public ReadWriteMap< Node, T >
1.408 - {
1.409 - public:
1.410 -
1.411 - ///\e
1.412 - NodeMap(const StaticGraph&) { }
1.413 - ///\e
1.414 - NodeMap(const StaticGraph&, T) { }
1.415 -
1.416 - ///Copy constructor
1.417 - NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
1.418 - ///Assignment operator
1.419 - NodeMap& operator=(const NodeMap&) { return *this; }
1.420 - // \todo fix this concept
1.421 - };
1.422 -
1.423 - /// Read write map of the edges to type \c T.
1.424 -
1.425 - /// \ingroup concept
1.426 - ///Reference map of the edges to type \c T.
1.427 - /// \sa Reference
1.428 - /// \warning Making maps that can handle bool type (EdgeMap<bool>)
1.429 - /// needs some extra attention!
1.430 - template<class T>
1.431 - class EdgeMap : public ReadWriteMap<Edge,T>
1.432 - {
1.433 - public:
1.434 -
1.435 - ///\e
1.436 - EdgeMap(const StaticGraph&) { }
1.437 - ///\e
1.438 - EdgeMap(const StaticGraph&, T) { }
1.439 - ///Copy constructor
1.440 - EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
1.441 - ///Assignment operator
1.442 - EdgeMap& operator=(const EdgeMap&) { return *this; }
1.443 - // \todo fix this concept
1.444 - };
1.445 -
1.446 - template <typename _Graph>
1.447 - struct Constraints : public _StaticGraph::Constraints<_Graph> {};
1.448 -
1.449 - };
1.450 -
1.451 - /// An empty non-static graph class.
1.452 -
1.453 - /// This class provides everything that \ref StaticGraph does.
1.454 - /// Additionally it enables building graphs from scratch.
1.455 - class ExtendableGraph : public StaticGraph
1.456 - {
1.457 - public:
1.458 - /// Defalult constructor.
1.459 -
1.460 - /// Defalult constructor.
1.461 - ///
1.462 - ExtendableGraph() { }
1.463 - ///Add a new node to the graph.
1.464 -
1.465 - /// \return the new node.
1.466 - ///
1.467 - Node addNode() { return INVALID; }
1.468 - ///Add a new edge to the graph.
1.469 -
1.470 - ///Add a new edge to the graph with source node \c s
1.471 - ///and target node \c t.
1.472 - ///\return the new edge.
1.473 - Edge addEdge(Node, Node) { return INVALID; }
1.474 -
1.475 - /// Resets the graph.
1.476 -
1.477 - /// This function deletes all edges and nodes of the graph.
1.478 - /// It also frees the memory allocated to store them.
1.479 - /// \todo It might belong to \ref ErasableGraph.
1.480 - void clear() { }
1.481 -
1.482 - template <typename _Graph>
1.483 - struct Constraints : public _ExtendableGraph::Constraints<_Graph> {};
1.484 -
1.485 - };
1.486 -
1.487 - /// An empty erasable graph class.
1.488 -
1.489 - /// This class is an extension of \ref ExtendableGraph. It makes it
1.490 - /// possible to erase edges or nodes.
1.491 - class ErasableGraph : public ExtendableGraph
1.492 - {
1.493 - public:
1.494 - /// Defalult constructor.
1.495 -
1.496 - /// Defalult constructor.
1.497 - ///
1.498 - ErasableGraph() { }
1.499 - /// Deletes a node.
1.500 -
1.501 - /// Deletes node \c n node.
1.502 - ///
1.503 - void erase(Node) { }
1.504 - /// Deletes an edge.
1.505 -
1.506 - /// Deletes edge \c e edge.
1.507 - ///
1.508 - void erase(Edge) { }
1.509 -
1.510 - template <typename _Graph>
1.511 - struct Constraints : public _ErasableGraph::Constraints<_Graph> {};
1.512 -
1.513 - };
1.514 -
1.515 -
1.516 - /************* New GraphBase stuff **************/
1.517 -
1.518 -
1.519 -// /// A minimal GraphBase concept
1.520 -
1.521 -// /// This class describes a minimal concept which can be extended to a
1.522 -// /// full-featured graph with \ref GraphFactory.
1.523 -// class GraphBase {
1.524 -// public:
1.525 -
1.526 -// GraphBase() {}
1.527 -
1.528 -// /// \bug Should we demand that Node and Edge be subclasses of the
1.529 -// /// Graph class???
1.530 -
1.531 -// typedef GraphItem<'n'> Node;
1.532 -// typedef GraphItem<'e'> Edge;
1.533 -
1.534 -// // class Node : public BaseGraphItem<'n'> {};
1.535 -// // class Edge : public BaseGraphItem<'e'> {};
1.536 -
1.537 -// // Graph operation
1.538 -// void firstNode(Node &n) const { }
1.539 -// void firstEdge(Edge &e) const { }
1.540 -
1.541 -// void firstOutEdge(Edge &e, Node) const { }
1.542 -// void firstInEdge(Edge &e, Node) const { }
1.543 -
1.544 -// void nextNode(Node &n) const { }
1.545 -// void nextEdge(Edge &e) const { }
1.546 -
1.547 -
1.548 -// // Question: isn't it reasonable if this methods have a Node
1.549 -// // parameter? Like this:
1.550 -// // Edge& nextOut(Edge &e, Node) const { return e; }
1.551 -// void nextOutEdge(Edge &e) const { }
1.552 -// void nextInEdge(Edge &e) const { }
1.553 -
1.554 -// Node target(Edge) const { return Node(); }
1.555 -// Node source(Edge) const { return Node(); }
1.556 -
1.557 -
1.558 -// // Do we need id, nodeNum, edgeNum and co. in this basic graphbase
1.559 -// // concept?
1.560 -
1.561 -
1.562 -// // Maps.
1.563 -// //
1.564 -// // We need a special slimer concept which does not provide maps (it
1.565 -// // wouldn't be strictly slimer, cause for map-factory id() & friends
1.566 -// // a required...)
1.567 -
1.568 -// template<typename T>
1.569 -// class NodeMap : public GraphMap<GraphBase, Node, T> {};
1.570 -
1.571 -// template<typename T>
1.572 -// class EdgeMap : public GraphMap<GraphBase, Node, T> {};
1.573 -// };
1.574 -
1.575 - // @}
1.576 - } //namespace concept
1.577 -} //namespace lemon
1.578 -
1.579 -
1.580 -
1.581 -#endif // LEMON_CONCEPT_GRAPH_H