doc/maps.dox
changeset 2219 c263168e0964
parent 1183 8f623d1833a7
child 2260 4274224f8a7d
equal deleted inserted replaced
17:0865b7e8f291 18:44c92206a0a9
    25 where it is stored.
    25 where it is stored.
    26 
    26 
    27 Each graph structure in LEMON provides two standard map templates called
    27 Each graph structure in LEMON provides two standard map templates called
    28 \c EdgeMap and \c NodeMap. Both are reference maps and you can easily
    28 \c EdgeMap and \c NodeMap. Both are reference maps and you can easily
    29 assign data to the nodes and to the edges of the graph. For example if you
    29 assign data to the nodes and to the edges of the graph. For example if you
    30 have a graph \c G defined as
    30 have a graph \c g defined as
    31 \code
    31 \code
    32   ListGraph G;
    32   ListGraph g;
    33 \endcode
    33 \endcode
    34 and you want to assign a floating point value to each edge, you can do
    34 and you want to assign a floating point value to each edge, you can do
    35 it like this.
    35 it like this.
    36 \code
    36 \code
    37   ListGraph::EdgeMap<double> length(G);
    37   ListGraph::EdgeMap<double> length(g);
    38 \endcode
    38 \endcode
    39 Note that you must give the underlying graph to the constructor.
    39 Note that you must give the underlying graph to the constructor.
    40 
    40 
    41 The value of a readable map can be obtained by <tt>operator[]</tt>.
    41 The value of a readable map can be obtained by <tt>operator[]</tt>.
    42 \code
    42 \code
    92 };
    92 };
    93 \endcode
    93 \endcode
    94 
    94 
    95 An alternative way to define maps is to use \c MapBase
    95 An alternative way to define maps is to use \c MapBase
    96 
    96 
    97 \todo For this, \c MapBase seems to be a better name then \c NullMap.
       
    98 
       
    99 \code
    97 \code
   100 struct MyMap : public MapBase<Graph::Edge,double>
    98 struct MyMap : public MapBase<Graph::Edge,double>
   101 {
    99 {
   102   Value operator[](Key e) const { return M_PI;}
   100   Value operator[](Key e) const { return M_PI;}
   103 };
   101 };
   114   const Graph::EdgeMap<double> &orig_len;
   112   const Graph::EdgeMap<double> &orig_len;
   115   const Graph::NodeMap<double> &pot;
   113   const Graph::NodeMap<double> &pot;
   116   
   114   
   117 public:
   115 public:
   118   Value operator[](Key e) const {
   116   Value operator[](Key e) const {
   119     return orig_len.get(e)-(pot.get(G.target(e))-pot.get(G.source(e)));
   117     return orig_len[e]-(pot[g.target(e)]-pot[g.source(e)]);
   120   }
   118   }
   121   
   119   
   122   ReducedLengthMap(const Graph &_g,
   120   ReducedLengthMap(const Graph &_g,
   123                    const Graph::EdgeMap &o,
   121                    const Graph::EdgeMap &_o,
   124                    const Graph::NodeMap &p)
   122                    const Graph::NodeMap &_p)
   125     : G(g), orig_len(o), pot(p) {};
   123     : g(_g), orig_len(_o), pot(_p) {};
   126 };
   124 };
   127 \endcode
   125 \endcode
   128 
   126 
   129 Then, you can call e.g. Dijkstra algoritm on this map like this:
   127 Then, you can call e.g. Dijkstra algoritm on this map like this:
   130 \code
   128 \code