doc/maps.dox
changeset 1025 3b1ad8bc21da
parent 986 e997802b855c
child 1043 52a2201a88e9
equal deleted inserted replaced
12:d5c6a1c3edfe 13:d6fa8f38a14b
     7 Maps play central role in LEMON. As their name suggests, they map a
     7 Maps play central role in LEMON. As their name suggests, they map a
     8 certain range of \e keys to certain \e values. Each map has two
     8 certain range of \e keys to certain \e values. Each map has two
     9 <tt>typedef</tt>'s to determine the types of keys and values, like this:
     9 <tt>typedef</tt>'s to determine the types of keys and values, like this:
    10 
    10 
    11 \code
    11 \code
    12   typedef Edge KeyType;
    12   typedef Edge Key;
    13   typedef double ValueType;
    13   typedef double Value;
    14 \endcode
    14 \endcode
    15 
    15 
    16 A map can \e readable (ReadMap, for short), \e writable (WriteMap) or both
    16 A map can \e readable (ReadMap, for short), \e writable (WriteMap) or both
    17 (ReadWrite Map). There also exists a special type of
    17 (ReadWrite Map). There also exists a special type of
    18 ReadWrite map called <em>reference map</em>. In addition that you can
    18 ReadWrite map called <em>reference map</em>. In addition that you can
    50 value, thus you can use this.
    50 value, thus you can use this.
    51 \code
    51 \code
    52   length[e]=3.5;
    52   length[e]=3.5;
    53 \endcode
    53 \endcode
    54 - <em>Writable maps</em> have
    54 - <em>Writable maps</em> have
    55 a member function \c set(KeyType,const ValueType &)
    55 a member function \c set(Key,const Value &)
    56 for this purpose.
    56 for this purpose.
    57 \code
    57 \code
    58   length.set(e,3.5);
    58   length.set(e,3.5);
    59 \endcode
    59 \endcode
    60 
    60 
    80 This simple map assigns \f$\pi\f$ to each edge.
    80 This simple map assigns \f$\pi\f$ to each edge.
    81 
    81 
    82 \code
    82 \code
    83 struct MyMap 
    83 struct MyMap 
    84 {
    84 {
    85   typedef double ValueType;
    85   typedef double Value;
    86   typedef Graph::Edge KeyType;
    86   typedef Graph::Edge Key;
    87   double operator[](KeyType e) const { return M_PI;}
    87   double operator[](Key e) const { return M_PI;}
    88 };
    88 };
    89 \endcode
    89 \endcode
    90 
    90 
    91 An alternative way to define maps is to use \c MapBase
    91 An alternative way to define maps is to use \c MapBase
    92 
    92 
    93 \todo For this, \c MapBase seems to be a better name then \c NullMap.
    93 \todo For this, \c MapBase seems to be a better name then \c NullMap.
    94 
    94 
    95 \code
    95 \code
    96 struct MyMap : public MapBase<Graph::Edge,double>
    96 struct MyMap : public MapBase<Graph::Edge,double>
    97 {
    97 {
    98   ValueType operator[](KeyType e) const { return M_PI;}
    98   Value operator[](Key e) const { return M_PI;}
    99 };
    99 };
   100 \endcode
   100 \endcode
   101 
   101 
   102 Here is a bit more complex example.
   102 Here is a bit more complex example.
   103 It provides a length function which is obtained
   103 It provides a length function which is obtained
   109   const Graph &G;
   109   const Graph &G;
   110   const Graph::EdgeMap<double> &orig_len;
   110   const Graph::EdgeMap<double> &orig_len;
   111   const Graph::NodeMap<double> &pot;
   111   const Graph::NodeMap<double> &pot;
   112   
   112   
   113 public:
   113 public:
   114   ValueType operator[](KeyType e) const {
   114   Value operator[](Key e) const {
   115     return orig_len.get(e)-pot.get(G.target(e))-pot.get(G.source(e));
   115     return orig_len.get(e)-pot.get(G.target(e))-pot.get(G.source(e));
   116   }
   116   }
   117   
   117   
   118   MyLengthMap(const Graph &g, const Graph::EdgeMap &o,const Graph::NodeMap &p)
   118   MyLengthMap(const Graph &g, const Graph::EdgeMap &o,const Graph::NodeMap &p)
   119     : G(g), orig_len(o), pot(p) {};
   119     : G(g), orig_len(o), pot(p) {};