src/work/peter/edgepathgraph.h
changeset 1365 c280de819a73
parent 1364 ee5959aa4410
child 1366 d00b85f8be45
     1.1 --- a/src/work/peter/edgepathgraph.h	Sun Apr 17 18:57:22 2005 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,407 +0,0 @@
     1.4 -// -*- c++ -*-
     1.5 -#ifndef LEMON_NET_GRAPH_H
     1.6 -#define LEMON_NET_GRAPH_H
     1.7 -
     1.8 -///\file
     1.9 -///\brief Declaration of EdgePathGraph.
    1.10 -
    1.11 -#include <lemon/invalid.h>
    1.12 -#include <lemon/maps.h>
    1.13 -
    1.14 -/// The namespace of LEMON
    1.15 -namespace lemon {
    1.16 -
    1.17 -  // @defgroup empty_graph The EdgePathGraph class
    1.18 -  // @{
    1.19 -
    1.20 -  /// A graph class in that a simple edge can represent a path.
    1.21 -  
    1.22 -  /// This class provides all the common features of a graph structure
    1.23 -  /// that represents a network. You can handle with it layers. This
    1.24 -  /// means that an edge in one layer can be a complete path in a nother
    1.25 -  /// layer.
    1.26 -
    1.27 -  template <typename P, class Gact, class Gsub>
    1.28 -  class EdgePathGraph
    1.29 -  {
    1.30 -
    1.31 -  public:
    1.32 -
    1.33 -    /// The actual layer
    1.34 -    Gact actuallayer;
    1.35 -
    1.36 -
    1.37 -    /// The layer on which the edges in this layer can represent paths.
    1.38 -    Gsub * sublayer;
    1.39 -
    1.40 -
    1.41 -    /// Map of nodes that represent the nodes of this layer in the sublayer
    1.42 -    typename Gact::template NodeMap<typename Gsub::Node *> projection;
    1.43 -
    1.44 -
    1.45 -    /// Map of routes that are represented by some edges in this layer
    1.46 -    typename Gact::template EdgeMap<P *> edgepath;
    1.47 -
    1.48 -
    1.49 -    /// Defalult constructor.
    1.50 -    /// We don't need any extra lines, because the actuallayer
    1.51 -    /// variable has run its constructor, when we have created this class
    1.52 -    /// So only the two maps has to be initialised here.
    1.53 -    EdgePathGraph() : projection(actuallayer), edgepath(actuallayer)
    1.54 -    {
    1.55 -    }
    1.56 -
    1.57 -
    1.58 -    ///Copy consructor.
    1.59 -    EdgePathGraph(const EdgePathGraph<P, Gact, Gsub> & EPG ) : actuallayer(EPG.actuallayer) , edgepath(actuallayer), projection(actuallayer)
    1.60 -    {
    1.61 -    }
    1.62 -
    1.63 -
    1.64 -    /// Map adder
    1.65 -
    1.66 -    /// This function gets two edgemaps. One belongs to the actual layer and the
    1.67 -    /// other belongs to the sublayer.
    1.68 -    /// The function iterates through all of the edges in the edgemap belonging to the actual layer.
    1.69 -    /// It gets the value that belongs to the actual edge, and adds it to the value of each edge in the
    1.70 -    /// path represented by itself in the edgemap that belongs to the sublayer.
    1.71 -    
    1.72 -    template <typename T1, typename T2> void addMap (typename Gact::EdgeMap<T1> & actmap, typename Gsub::EdgeMap<T2> & submap)
    1.73 -    {
    1.74 -      for(EdgeIt e(actuallayer);actuallayer.valid(e);actuallayer.next(e))
    1.75 -      {
    1.76 -	typedef typename P::EdgeIt PEdgeIt;
    1.77 -	PEdgeIt f;
    1.78 -
    1.79 -	//dep//cout << "Edge " << id(source(e)) << " - " << id(target(e)) << " in actual layer is";
    1.80 -	T1 incr=actmap[e];
    1.81 -	//cout << incr << endl;
    1.82 -
    1.83 -        if(edgepath[e])
    1.84 -	{
    1.85 -	  //dep//cout << endl << "Path";
    1.86 -	  for(edgepath[e]->first(f); edgepath[e]->valid(f); edgepath[e]->next(f))
    1.87 -	  {
    1.88 -	    //dep//cout << " " << sublayer->id(sublayer->source(f)) << "-" << sublayer->id(sublayer->target(f));
    1.89 -	    submap[f]+=incr;
    1.90 -	  }
    1.91 -	  //dep////cout << EPGr2.id(EPGr2.target(f)) << endl;
    1.92 -	  //dep//cout << endl;
    1.93 -	}
    1.94 -	else
    1.95 -	{
    1.96 -	  //dep//cout << " itself." <<endl;
    1.97 -	}
    1.98 -      }  
    1.99 -
   1.100 -    };
   1.101 -
   1.102 -
   1.103 -    /// Describe
   1.104 -    /// This function walks thorugh the edges of the actual layer
   1.105 -    /// and displays the path represented by the actual edge.
   1.106 -    void describe ()
   1.107 -    {
   1.108 -      for(EdgeIt e(actuallayer);actuallayer.valid(e);actuallayer.next(e))
   1.109 -      {
   1.110 -	typedef typename P::EdgeIt PEdgeIt;
   1.111 -	PEdgeIt f;
   1.112 -
   1.113 -	cout << "Edge " << id(source(e)) << " - " << id(target(e)) << " in actual layer is";
   1.114 -        if(edgepath[e])
   1.115 -	{
   1.116 -	  cout << endl << "Path";
   1.117 -	  for(edgepath[e]->first(f); edgepath[e]->valid(f); edgepath[e]->next(f))
   1.118 -	  {
   1.119 -	    cout << " " << sublayer->id(sublayer->source(f)) << "-" << sublayer->id(sublayer->target(f));
   1.120 -	  }
   1.121 -	  //cout << EPGr2.id(EPGr2.target(f)) << endl;
   1.122 -	  cout << endl;
   1.123 -	}
   1.124 -	else
   1.125 -	{
   1.126 -	  cout << " itself." <<endl;
   1.127 -	}
   1.128 -      }  
   1.129 -
   1.130 -    };
   1.131 -
   1.132 -
   1.133 -
   1.134 -
   1.135 -    /// The base type of the node iterators.
   1.136 -
   1.137 -    /// This is the base type of each node iterators,
   1.138 -    /// thus each kind of node iterator will convert to this.
   1.139 -    /// The Node type of the EdgePathGraph is the Node type of the actual layer.
   1.140 -    typedef typename Gact::Node Node;
   1.141 -
   1.142 -    
   1.143 -    /// This iterator goes through each node.
   1.144 -
   1.145 -    /// Its usage is quite simple, for example you can count the number
   1.146 -    /// of nodes in graph \c G of type \c Graph like this:
   1.147 -    /// \code
   1.148 -    ///int count=0;
   1.149 -    ///for(Graph::NodeIt n(G);G.valid(n);G.next(n)) count++;
   1.150 -    /// \endcode
   1.151 -    /// The NodeIt type of the EdgePathGraph is the NodeIt type of the actual layer.
   1.152 -    typedef typename Gact::NodeIt NodeIt;
   1.153 -    
   1.154 -    
   1.155 -    /// The base type of the edge iterators.
   1.156 -    /// The Edge type of the EdgePathGraph is the Edge type of the actual layer.
   1.157 -    typedef typename  Gact::Edge Edge;
   1.158 -
   1.159 -    
   1.160 -    /// This iterator goes trough the outgoing edges of a node.
   1.161 -
   1.162 -    /// This iterator goes trough the \e outgoing edges of a certain node
   1.163 -    /// of a graph.
   1.164 -    /// Its usage is quite simple, for example you can count the number
   1.165 -    /// of outgoing edges of a node \c n
   1.166 -    /// in graph \c G of type \c Graph as follows.
   1.167 -    /// \code
   1.168 -    ///int count=0;
   1.169 -    ///for(Graph::OutEdgeIt e(G,n);G.valid(e);G.next(e)) count++;
   1.170 -    /// \endcode
   1.171 -    /// The OutEdgeIt type of the EdgePathGraph is the OutEdgeIt type of the actual layer.
   1.172 -    typedef typename Gact::OutEdgeIt OutEdgeIt;
   1.173 -
   1.174 -
   1.175 -    /// This iterator goes trough the incoming edges of a node.
   1.176 -
   1.177 -    /// This iterator goes trough the \e incoming edges of a certain node
   1.178 -    /// of a graph.
   1.179 -    /// Its usage is quite simple, for example you can count the number
   1.180 -    /// of outgoing edges of a node \c n
   1.181 -    /// in graph \c G of type \c Graph as follows.
   1.182 -    /// \code
   1.183 -    ///int count=0;
   1.184 -    ///for(Graph::InEdgeIt e(G,n);G.valid(e);G.next(e)) count++;
   1.185 -    /// \endcode
   1.186 -    /// The InEdgeIt type of the EdgePathGraph is the InEdgeIt type of the actual layer.
   1.187 -    typedef typename Gact::InEdgeIt InEdgeIt;
   1.188 -
   1.189 -
   1.190 -    /// This iterator goes through each edge.
   1.191 -
   1.192 -    /// This iterator goes through each edge of a graph.
   1.193 -    /// Its usage is quite simple, for example you can count the number
   1.194 -    /// of edges in a graph \c G of type \c Graph as follows:
   1.195 -    /// \code
   1.196 -    ///int count=0;
   1.197 -    ///for(Graph::EdgeIt e(G);G.valid(e);G.next(e)) count++;
   1.198 -    /// \endcode
   1.199 -    /// The EdgeIt type of the EdgePathGraph is the EdgeIt type of the actual layer.
   1.200 -    typedef typename Gact::EdgeIt EdgeIt;
   1.201 -
   1.202 -
   1.203 -    /// First node of the graph.
   1.204 -
   1.205 -    /// \retval i the first node.
   1.206 -    /// \return the first node.
   1.207 -    typename Gact::NodeIt &first(typename Gact::NodeIt &i) const { return actuallayer.first(i);}
   1.208 -
   1.209 -
   1.210 -    /// The first incoming edge.
   1.211 -    typename Gact::InEdgeIt &first(typename Gact::InEdgeIt &i, typename Gact::Node) const { return actuallayer.first(i);}
   1.212 -
   1.213 -
   1.214 -    /// The first outgoing edge.
   1.215 -    typename Gact::OutEdgeIt &first(typename Gact::OutEdgeIt &i, typename Gact::Node) const { return actuallayer.first(i);}
   1.216 -
   1.217 -
   1.218 -    //  SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}
   1.219 -    /// The first edge of the Graph.
   1.220 -    typename Gact::EdgeIt &first(typename Gact::EdgeIt &i) const { return actuallayer.first(i);}
   1.221 -
   1.222 -
   1.223 -//     Node getNext(Node) const {}
   1.224 -//     InEdgeIt getNext(InEdgeIt) const {}
   1.225 -//     OutEdgeIt getNext(OutEdgeIt) const {}
   1.226 -//     //SymEdgeIt getNext(SymEdgeIt) const {}
   1.227 -//     EdgeIt getNext(EdgeIt) const {}
   1.228 -
   1.229 -
   1.230 -    /// Go to the next node.
   1.231 -    typename Gact::NodeIt &next(typename Gact::NodeIt &i) const { return actuallayer.next(i);}
   1.232 -    /// Go to the next incoming edge.
   1.233 -    typename Gact::InEdgeIt &next(typename Gact::InEdgeIt &i) const { return actuallayer.next(i);}
   1.234 -    /// Go to the next outgoing edge.
   1.235 -    typename Gact::OutEdgeIt &next(typename Gact::OutEdgeIt &i) const { return actuallayer.next(i);}
   1.236 -    //SymEdgeIt &next(SymEdgeIt &) const {}
   1.237 -    /// Go to the next edge.
   1.238 -    typename Gact::EdgeIt &next(typename Gact::EdgeIt &i) const { return actuallayer.next(i);}
   1.239 -
   1.240 -    ///Gives back the target node of an edge.
   1.241 -    typename Gact::Node target(typename Gact::Edge edge) const { return actuallayer.target(edge); }
   1.242 -    ///Gives back the source node of an edge.
   1.243 -    typename Gact::Node source(typename Gact::Edge edge) const { return actuallayer.source(edge); }
   1.244 -  
   1.245 -    //   Node aNode(InEdgeIt) const {}
   1.246 -    //   Node aNode(OutEdgeIt) const {}
   1.247 -    //   Node aNode(SymEdgeIt) const {}
   1.248 -
   1.249 -    //   Node bNode(InEdgeIt) const {}
   1.250 -    //   Node bNode(OutEdgeIt) const {}
   1.251 -    //   Node bNode(SymEdgeIt) const {}
   1.252 -
   1.253 -    /// Checks if a node iterator is valid
   1.254 -
   1.255 -    ///\todo Maybe, it would be better if iterator converted to
   1.256 -    ///bool directly, as Jacint prefers.
   1.257 -    bool valid(const typename Gact::Node& node) const { return actuallayer.valid(node);}
   1.258 -    /// Checks if an edge iterator is valid
   1.259 -
   1.260 -    ///\todo Maybe, it would be better if iterator converted to
   1.261 -    ///bool directly, as Jacint prefers.
   1.262 -    bool valid(const typename Gact::Edge& edge) const { return actuallayer.valid(edge);}
   1.263 -
   1.264 -    ///Gives back the \e id of a node.
   1.265 -
   1.266 -    ///\warning Not all graph structures provide this feature.
   1.267 -    ///
   1.268 -    int id(const typename Gact::Node & node) const { return actuallayer.id(node);}
   1.269 -    ///Gives back the \e id of an edge.
   1.270 -
   1.271 -    ///\warning Not all graph structures provide this feature.
   1.272 -    ///
   1.273 -    int id(const typename Gact::Edge & edge) const { return actuallayer.id(edge);}
   1.274 -
   1.275 -    //void setInvalid(Node &) const {};
   1.276 -    //void setInvalid(Edge &) const {};
   1.277 -  
   1.278 -    ///Add a new node to the graph.
   1.279 -
   1.280 -    /// \return the new node.
   1.281 -    ///
   1.282 -    typename Gact::Node addNode() { return actuallayer.addNode();}
   1.283 -    ///Add a new edge to the graph.
   1.284 -
   1.285 -    ///Add a new edge to the graph with source node \c source
   1.286 -    ///and target node \c target.
   1.287 -    ///\return the new edge.
   1.288 -    typename Gact::Edge addEdge(typename Gact::Node node1, typename Gact::Node node2) { return actuallayer.addEdge(node1, node2);}
   1.289 -    
   1.290 -    /// Resets the graph.
   1.291 -
   1.292 -    /// This function deletes all edges and nodes of the graph.
   1.293 -    /// It also frees the memory allocated to store them.
   1.294 -    void clear() {actuallayer.clear();}
   1.295 -
   1.296 -    int nodeNum() const { return actuallayer.nodeNum();}
   1.297 -    int edgeNum() const { return actuallayer.edgeNum();}
   1.298 -
   1.299 -    ///Read/write/reference map of the nodes to type \c T.
   1.300 -
   1.301 -    ///Read/write/reference map of the nodes to type \c T.
   1.302 -    /// \sa MemoryMap
   1.303 -    /// \todo We may need copy constructor
   1.304 -    /// \todo We may need conversion from other nodetype
   1.305 -    /// \todo We may need operator=
   1.306 -    /// \warning Making maps that can handle bool type (NodeMap<bool>)
   1.307 -    /// needs extra attention!
   1.308 -
   1.309 -    template<class T> class NodeMap
   1.310 -    {
   1.311 -    public:
   1.312 -      typedef T Value;
   1.313 -      typedef Node Key;
   1.314 -
   1.315 -      NodeMap(const EdgePathGraph &) {}
   1.316 -      NodeMap(const EdgePathGraph &, T) {}
   1.317 -
   1.318 -      template<typename TT> NodeMap(const NodeMap<TT> &) {}
   1.319 -
   1.320 -      /// Sets the value of a node.
   1.321 -
   1.322 -      /// Sets the value associated with node \c i to the value \c t.
   1.323 -      ///
   1.324 -      void set(Node, T) {}
   1.325 -      // Gets the value of a node.
   1.326 -      //T get(Node i) const {return *(T*)0;}  //FIXME: Is it necessary?
   1.327 -      T &operator[](Node) {return *(T*)0;}
   1.328 -      const T &operator[](Node) const {return *(T*)0;}
   1.329 -
   1.330 -      /// Updates the map if the graph has been changed
   1.331 -
   1.332 -      /// \todo Do we need this?
   1.333 -      ///
   1.334 -      void update() {}
   1.335 -      void update(T a) {}   //FIXME: Is it necessary
   1.336 -    };
   1.337 -
   1.338 -    ///Read/write/reference map of the edges to type \c T.
   1.339 -
   1.340 -    ///Read/write/reference map of the edges to type \c T.
   1.341 -    ///It behaves exactly in the same way as \ref NodeMap.
   1.342 -    /// \sa NodeMap
   1.343 -    /// \sa MemoryMap
   1.344 -    /// \todo We may need copy constructor
   1.345 -    /// \todo We may need conversion from other edgetype
   1.346 -    /// \todo We may need operator=
   1.347 -    template<class T> class EdgeMap
   1.348 -    {
   1.349 -    public:
   1.350 -      typedef T Value;
   1.351 -      typedef Edge Key;
   1.352 -
   1.353 -      EdgeMap(const EdgePathGraph &) {}
   1.354 -      EdgeMap(const EdgePathGraph &, T ) {}
   1.355 -    
   1.356 -      ///\todo It can copy between different types.
   1.357 -      ///
   1.358 -      template<typename TT> EdgeMap(const EdgeMap<TT> &) {}
   1.359 -
   1.360 -      void set(Edge, T) {}
   1.361 -      //T get(Edge) const {return *(T*)0;}
   1.362 -      T &operator[](Edge) {return *(T*)0;}
   1.363 -      const T &operator[](Edge) const {return *(T*)0;}
   1.364 -    
   1.365 -      void update() {}
   1.366 -      void update(T a) {}   //FIXME: Is it necessary
   1.367 -    };
   1.368 -  };
   1.369 -
   1.370 -  /// An empty erasable graph class.
   1.371 -  
   1.372 -  /// This class provides all the common features of an \e erasable graph
   1.373 -  /// structure,
   1.374 -  /// however completely without implementations and real data structures
   1.375 -  /// behind the interface.
   1.376 -  /// All graph algorithms should compile with this class, but it will not
   1.377 -  /// run properly, of course.
   1.378 -  ///
   1.379 -  /// \todo This blabla could be replaced by a sepatate description about
   1.380 -  /// s.
   1.381 -  ///
   1.382 -  /// It can be used for checking the interface compatibility,
   1.383 -  /// or it can serve as a skeleton of a new graph structure.
   1.384 -  /// 
   1.385 -  /// Also, you will find here the full documentation of a certain graph
   1.386 -  /// feature, the documentation of a real graph imlementation
   1.387 -  /// like @ref ListGraph or
   1.388 -  /// @ref SmartGraph will just refer to this structure.
   1.389 -  template <typename P, typename Gact, typename Gsub>
   1.390 -  class ErasableEdgePathGraph : public EdgePathGraph<P, Gact, Gsub>
   1.391 -  {
   1.392 -  public:
   1.393 -    /// Deletes a node.
   1.394 -    void erase(typename Gact::Node n) {actuallayer.erase(n);}
   1.395 -    /// Deletes an edge.
   1.396 -    void erase(typename Gact::Edge e) {actuallayer.erase(e);}
   1.397 -
   1.398 -    /// Defalult constructor.
   1.399 -    ErasableEdgePathGraph() {}
   1.400 -    ///Copy consructor.
   1.401 -    ErasableEdgePathGraph(const EdgePathGraph<P, Gact, Gsub> &EPG) {}
   1.402 -  };
   1.403 -
   1.404 -  
   1.405 -  // @}
   1.406 -
   1.407 -} //namespace lemon
   1.408 -
   1.409 -
   1.410 -#endif // LEMON_SKELETON_GRAPH_H