/* -*- C++ -*- * * This file is a part of LEMON, a generic C++ optimization library * * Copyright (C) 2003-2007 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Research Group on Combinatorial Optimization, EGRES). * * Permission to use, modify and distribute this software is granted * provided that this copyright notice appears in all copies. For * precise terms see the accompanying LICENSE file. * * This software is provided "AS IS" with no warranty of any kind, * express or implied, and with no claim as to its suitability for any * purpose. * */ /** \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[](const Key &e) const { return M_PI;} }; \endcode An alternative way to define maps is to use MapBase \code struct MyMap : public MapBase { Value operator[](const 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 */