[Lemon-user] Question about copying graphs and maps

Alpár Jüttner alpar at cs.elte.hu
Sun Jul 29 07:29:23 CEST 2012


Hi,

> I am very new to Lemon and I am a bit confused about graph copying.

First of all, are you sure you really want to copy it? If you need it
because you want the work with slightly modified versions of a base
graph, then you might also consider using SubDigraph adaptor and/or
custom map adaptors.

> I have to copy a graph and some related maps in a constructor of my
> class:
> 
> class network_map
>     {
>     public:
>         ListDigraph g;
>         ListDigraph::NodeMap<node_block>  nodes;
>         ListDigraph::ArcMap<arc_block>    arches;
> 
>         network_map  (const ListDigraph & _g, 
>                               const ListDigraph::NodeMap<node_block>
> & _nm,
>                               const ListDigraph::ArcMap<arc_block> &
> _am) 
>                             : g(), nodes(_g), arches(_g)

It looks like a bug. I think 'nodes' and 'arches' should be attached to
g, not to _g:

: g(), nodes(g), arches(g)

>         {       
>             DigraphCopy<ListDigraph,ListDigraph> dg_copy(_g,g);
>             
>             // create nodes and arches references: is it necessary?
>             ListDigraph::NodeMap<node_block> nmap(g);
>             ListDigraph::ArcMap<arc_block> amap(g);
>             dg_copy.nodeRef(nmap);
>             dg_copy.arcRef(amap);
> 
>             // copy maps:
>             dg_copy.nodeMap(_nm,nodes);
>             dg_copy.arcMap(_am, arches);
>             
>             dg_copy.run();
>         };
>    };
> 
> The maps of nodes and arches "nm" and "am" refers to the graph _g that
> I want to copy. My class maps are created to refer to the class graph
> g that will be a copy of the input graph _g, and they will be in turn
> a copy on n, and am.
>  I want to be sure that my new graph g contains all references to _g,
> as I want to use it in my class as it were _g.

The (cross)references are used to map the original and the copied
node/arcs to each other.

In your example if _n is a node of _g, then the corresponding node in g
is nmap[n].

> My questions are:
> - Is it necessary to copy node references from a convenience map
> (nmap) of the original graph if I am copying a map that already refers
> to the original graph nodes?

Not sure if I understand your question correctly, but you don't have to
use .nodeRef()/.arcRef() explicitely if you don't need values.

Note however that DigraphCopy will create temporary ones internally
anyway.

> - What does .nodeRef(map) exactly do?

See above.

Note that you can also use digraphCopy(), which might be simpler.

        digraphCopy(g,_g).nodeMap(_nm,nodes).arcMap(_am,arcs).run();

Regards,
Alpar

> I hope this is clear to you!
> Thank you in advance,
> 
> -- 
> Dalia De Santis
> 
> MEng, Ph.D. Student
> Istituto Italiano di Tecnologia
> Robotics, Brain and Cognitive Sciences Dept.
> Via Morego, 30, 16163 Genova
> dalia.desantis at iit.it
> 
> 
> _______________________________________________
> 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