doc/maps.dox
changeset 289 98adf9276de0
parent 273 e9024dad7fc1
child 290 e37a05270e80
equal deleted inserted replaced
4:8d508c34268a 5:33e0d9a82e8b
     1 /*!
     1 /*!
     2 
     2 
     3 \page maps How to write maps
     3 \page maps How to write your own maps
     4 
     4 
     5 \section read-maps Readable Maps
     5 \section read-maps Readable Maps
     6 
     6 
     7 It is quite easy to write your own readmap for the edges or nodes of a graph.
     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.
     8 
    11 
     9 You can find some example below.
    12 You can find some example below.
    10 
    13 
    11 This simple map assigns \f$\pi\f$ to each edge.
    14 This simple map assigns \f$\pi\f$ to each edge.
    12 
    15 
    13 \code
    16 \code
    14 struct MyMap 
    17 struct MyMap 
    15 {
    18 {
    16   typedef double ValueType;
    19   typedef double ValueType;
    17   double operator[](Graph::EdgeIt e) const { return M_PI;}
    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;}
    18 };
    40 };
    19 \endcode
    41 \endcode
    20 
    42 
    21 
    43 
    22 Here is a more complex example. It provides a length function which is obtained
    44 Here is a more complex example. It provides a length function which is obtained
    23 from a base length function modified by a potential difference.
    45 from a base length function modified by a potential difference.
    24 \todo Please improve on the english. 
       
    25 
    46 
    26 \code
    47 \code
    27 class MyLengthMap 
    48 class MyLengthMap 
    28 {
    49 {
    29   const Graph::EdgeMap &ol;
    50   const Graph::EdgeMap &ol;
    30   const Graph::NodeMap &pot;
    51   const Graph::NodeMap &pot;
    31   
    52   
    32 public:
    53 public:
    33   typedef double ValueType;
    54   typedef double ValueType;
    34 
    55 
    35   double operator[](Graph::EdgeIt e) const {
    56   double operator[](Graph::Edge e) const {
    36     return ol.get(e)-pot.get(v)-pot.get(u);
    57     return ol.get(e)-pot.get(v)-pot.get(u);
    37   }
    58   }
    38   
    59   
    39   MyComplexMap(const Graph::EdgeMap &o,const Graph::NodeMap &p) :
    60   MyComplexMap(const Graph::EdgeMap &o,const Graph::NodeMap &p) :
    40     ol(o), pot(p);
    61     ol(o), pot(p);
    41 };
    62 };
    42 \endcode
    63 \endcode
    43 
    64 
       
    65 \todo Please improve on the english. 
    44 \todo Don't we need \e to \e require a 'typedef xxx KeyType' tag, as well?
    66 \todo Don't we need \e to \e require a 'typedef xxx KeyType' tag, as well?
    45 */
    67 */