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