[Lemon-user] Copy constructors
D Haley
mycae at yahoo.com
Tue Feb 23 18:19:52 CET 2010
Péter:
Ah Thanks, I was doing (a), which I felt was messy but had not thought about (b) -- I think (b) is a lot cleaner.
Alpár:
The vector<> statement is not entirely valid. I utilise ::reserve() to advise the vector in advance of the size that I will require, as for my application all this information is known a-priori. The vector<> length never actually changes after the initial push_back().
In my current application I have many small graphs with 8-15 nodes and ~20-30 edges, so the copying overhead should be minimal.
Thanks for the help, again.
Cheers.
--- On Wed, 2/24/10, Kovács Péter <kpeter at inf.elte.hu> wrote:
> From: Kovács Péter <kpeter at inf.elte.hu>
> Subject: Re: [Lemon-user] Copy constructors
> To: "D Haley" <mycae at yahoo.com>
> Cc: "lemon-user at lemon.cs.elte.hu" <lemon-user at lemon.cs.elte.hu>
> Date: Wednesday, February 24, 2010, 5:08 AM
> 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