doc/maps.dox
author alpar
Thu, 29 Apr 2004 16:26:01 +0000
changeset 477 02b8ddcb207a
parent 289 98adf9276de0
child 685 c7e37b066033
permissions -rw-r--r--
doc
     1 /*!
     2 
     3 \page maps How to write your own maps
     4 
     5 \section read-maps Readable Maps
     6 
     7 The readable maps are very frequently used as the input of the
     8 algorithms.  For this purpose the most straightforward is to use the
     9 maps provided by Hugo's graph structres. Very often however, it is more
    10 convenient and/or more efficient to write your own readable map.
    11 
    12 You can find some example below.
    13 
    14 This simple map assigns \f$\pi\f$ to each edge.
    15 
    16 \code
    17 struct MyMap 
    18 {
    19   typedef double ValueType;
    20   double operator[](Graph::Edge e) const { return M_PI;}
    21 };
    22 \endcode
    23 
    24 An alternative way to define maps. For this, \c MapBase seems to
    25 be a better name then \c NullMap
    26 
    27 \code
    28 struct MyMap : public MapBase<Edge,double>
    29 {
    30   double operator[](Graph::Edge e) const { return M_PI;}
    31 };
    32 \endcode
    33 
    34 Or, if we had \c KeyType and \c ValueType
    35 
    36 \code
    37 struct MyMap : public MapBase<Edge,double>
    38 {
    39   ValueType operator[](KeyType e) const { return M_PI;}
    40 };
    41 \endcode
    42 
    43 
    44 Here is a more complex example. It provides a length function which is obtained
    45 from a base length function modified by a potential difference.
    46 
    47 \code
    48 class MyLengthMap 
    49 {
    50   const Graph::EdgeMap &ol;
    51   const Graph::NodeMap &pot;
    52   
    53 public:
    54   typedef double ValueType;
    55 
    56   double operator[](Graph::Edge e) const {
    57     return ol.get(e)-pot.get(v)-pot.get(u);
    58   }
    59   
    60   MyComplexMap(const Graph::EdgeMap &o,const Graph::NodeMap &p) :
    61     ol(o), pot(p);
    62 };
    63 \endcode
    64 
    65 \todo Please improve on the english. 
    66 \todo Don't we need \e to \e require a 'typedef xxx KeyType' tag, as well?
    67 */