[Lemon-user] Copy constructors

Kovács Péter kpeter at inf.elte.hu
Tue Feb 23 17:08:00 CET 2010


Hi All,

In LEMON, the maps don't have default constructors nor copy 
constructors. The first one is clear: the graph has to be given for the 
map. The second one is because there is a long-standing discussion 
between the developers whether the maps should be copied by value or by 
a reference-counted solution. For more details, see these tickets:
http://lemon.cs.elte.hu/trac/lemon/ticket/137
http://lemon.cs.elte.hu/trac/lemon/ticket/146

So the copy constructors are decided to set to 'private'. In LEMON 1.1, 
the maps can only be copied by hand. However, a mapCopy() function is 
intorduced in the development verison, which will be present in the 
upcomming release 1.2.

Therefore I suggest to
     (a) create the maps dynimcally or
     (b) couple each graph and its map(s) into a class/struct.

See the details below. If I were you, I would use (b).

Regards,
Peter


(a):
     using namespace lemon;

     vector<ListGraph> g;
     vector<ListGraph::EdgeMap<float>*> edgeCostVec;

     makeSomeGraphs(g); //pass-by-ref (non-const)

     edgeCostVec[ui].resize(g.size());
     for(unsigned int ui=0;ui<g.size(); ui++)
         edgeCostVec[ui] = new ListGraph::EdgeMap<float>(g[ui]);

     // use g[i] with (*edgeCostMap[i])

     for(unsigned int ui=0;ui<g.size(); ui++)
         delete edgeCostVec[ui];


(b):
     using namespace lemon;

     struct GraphWithCostMap {
       ListGraph g;
       ListGraph::EdgeMap<float> cost;
       GraphWithCostMap() : g(), cost(g) {}
     };

     vector<GraphWithCostMap> graphs;

     makeSomeGraphs(graphs); //pass-by-ref (non-const)

     // use graphs.g[i] with graphs.cost[i]





> Hello again,
>
> I am having more troubles with edgemaps (thanks for the prev. help,
worked a treat). Due to the library interface, the copy constructors are
private for edgemaps, which seem to prevent me assigning or dupliating
them in any way. Is there a way I can do something like the following?
I'm currently dropping to pointer semantics, but it feels like a kludge.
>
>          vector<lemon::ListGraph>  g;
>          vector<lemon::ListGraph::EdgeMap<float>  >  edgeCostVec;
>
>          makeSomeGraphs(g); //pass-by-ref (non-const)
>
>          edgeCostVec[ui].resize(g.size());
>          for(unsigned int ui=0;ui<g.size(); ui++)
>                  edgeCostVec[ui] = (lemon::ListGraph::EdgeMap<float>(g[ui]));
>
> _______________________________________________
> 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