[Lemon-user] Inheriting from Lemon classes

Kovács Péter kpeter at inf.elte.hu
Wed May 25 17:15:18 CEST 2016


Hi All,

I suggest to keep using LEMON, because it provides more features and 
better performance than Boost Graph library.

Related to your question, Balázs Dezső already wrote the appropriate 
answer, but let me add a simple example for that.

You can declare your own map type like this:

     class MyMap : public MapBase<ListDigraph::Arc, double>
     {
       const Digraph &g;
       // TODO: add other required fields for cost computation

     public:
       Value operator[](Key e) const {
         return 3.14; // TODO: compute cost here
       }

       MyMap(const Digraph &_g) : g(_g) {};
     };

Once you have such a custom map type, you can use it with Dijkstra like 
this (without any modification to the algorithm itself!):

     MyMap myMap(g);
     Dijkstra<Digraph, MyMap> dijkstra(g, myMap);
     dijkstra.run(s);

This way the arc costs will be calculated dynamically on demand (at most 
once for each arc).

As Balázs suggested, you can also use the so-called map adaptor tools of 
LEMON to modify or combine existing arc maps dynamically:
http://lemon.cs.elte.hu/pub/doc/1.3.1/a00602.html

Regards,
Péter


> You could use Boost Graph, which was designed for exactly this sort of
> adaptation.
>
> THK
>
> http://www.keittlab.org/
>
> On Wed, May 25, 2016 at 8:30 AM, Marco Blanco <blanco at zib.de
> <mailto:blanco at zib.de>> wrote:
>
>     Hello,
>
>     I am implementing a shortest path algorithm where the arc costs are
>     unknown a priori and need to be computed on the fly. For that
>     reason, I decided to try to define a class MyDijkstra, which
>     inherits from lemon::Dijkstra<ListDigraph>. My plan was to override
>     the member function processNextNode(), but then I realized that the
>     Dijkstra class has some private members that I would need and don't
>     have access to, such as the underlying digraph object. I temporarily
>     solved the issue by replacing all "private" labels with "protected"
>     in "dijkstra.h", but I don't like messing with the Lemon source code.
>
>     Is inheriting from Lemon classes discouraged in general? Can you
>     think of an alternative way in which I could make use of the
>     existing structure without having to copy-paste the entire class
>     definition only to change two lines?
>
>     Thank you,
>     Marco
>
>     _______________________________________________
>     Lemon-user mailing list
>     Lemon-user at lemon.cs.elte.hu <mailto:Lemon-user at lemon.cs.elte.hu>
>     http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
>
>
>
>
> _______________________________________________
> Lemon-user mailing list
> Lemon-user at lemon.cs.elte.hu
> http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
>



More information about the Lemon-user mailing list