diff -r f47faf6913ab -r 09af6d2b683b doc/maps2.dox --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/maps2.dox Mon Sep 04 20:07:37 2006 +0000 @@ -0,0 +1,72 @@ +/** +\page maps2 Maps II. + +Here we discuss some advanced map techniques. Like writing your own maps or how to +extend/modify a maps functionality with adaptors. + +\section custom_maps Writing Custom ReadMap +\subsection custom_read_maps Readable Maps + +Readable maps are very frequently used as the input of an +algorithm. For this purpose the most straightforward way is the use of the +default maps provided by LEMON's graph structures. +Very often however, it is more +convenient and/or more efficient to write your own readable map. + +You can find some examples below. In these examples \c Graph is the +type of the particular graph structure you use. + + +This simple map assigns \f$\pi\f$ to each edge. + +\code +struct MyMap +{ + typedef double Value; + typedef Graph::Edge Key; + double operator[](Key e) const { return M_PI;} +}; +\endcode + +An alternative way to define maps is to use MapBase + +\code +struct MyMap : public MapBase +{ + Value operator[](Key e) const { return M_PI;} +}; +\endcode + +Here is a bit more complex example. +It provides a length function obtained +from a base length function shifted by a potential difference. + +\code +class ReducedLengthMap : public MapBase +{ + const Graph &g; + const Graph::EdgeMap &orig_len; + const Graph::NodeMap &pot; + +public: + Value operator[](Key e) const { + return orig_len[e]-(pot[g.target(e)]-pot[g.source(e)]); + } + + ReducedLengthMap(const Graph &_g, + const Graph::EdgeMap &_o, + const Graph::NodeMap &_p) + : g(_g), orig_len(_o), pot(_p) {}; +}; +\endcode + +Then, you can call e.g. Dijkstra algoritm on this map like this: +\code + ... + ReducedLengthMap rm(g,len,pot); + Dijkstra dij(g,rm); + dij.run(s); + ... +\endcode + +*/