[Lemon-user] is there a way to write a subgraph?
John Lagerquist
john at rallytronics.com
Sat Dec 31 06:47:56 CET 2016
No worries, thanks the for the explanation. I figured it was a copy
constructor issue. I ended using some smart pointers to deal with the
problem.
On Fri, Dec 30, 2016 at 2:46 PM, Kovács Péter <kpeter at inf.elte.hu> wrote:
> Hi John,
>
> The issue is most likely what Balázs wrote: "the FilterNodes is initiated
> with a local map, which is destroyed when the execution leaves the function
> scope."
>
> Note that FilterNodes is a light-weight wrapper class that only stores
> pointers to the underlying graph and to the node map. You should be aware
> of the lifetime of the original graph and node map even if you pass the
> FilterNodes as value. (Because it is a shallow copy.)
>
> Anyway, the main graph types of LEMON, such as ListDigraph, do not allow
> the assingment operator and the copy constructor (these functions are
> private). You should pass such graphs as references or pointers, or if you
> would really like to make a copy, you can use DigraphCopy. FilterNodes,
> however, allows these operations as it is a light-weight class.
>
> I hope this helps. And sorry for the confusion, I sent the first email in
> a haste.
>
> Péter
>
>
>
> My graphs are quite small, 10 nodes on average.
>>
>> On Fri, Dec 30, 2016 at 1:47 PM, Kovács Péter <kpeter at inf.elte.hu
>> <mailto:kpeter at inf.elte.hu>> wrote:
>>
>> Hi All,
>>
>> Thanks for the corrections. I'm terribly sorry for the stupid
>> mistake. So I suggest passing references, but of course, not for
>> local variables. :)
>>
>> Péter
>>
>>
>>
>> FilterNodes<ListDigraph>& get_subgraph(void)
>> {
>> FilterNodes<ListDigraph> subgraph;
>> ...
>> return g;
>> }
>>
>> This is a bad idea as it creates a reference to a temporary
>> variable. I
>> think the real problem is that the FilterNodes is initiated with
>> a local
>> map, which is destroyed when the execution leaves the function
>> scope.
>>
>> Balazs
>>
>> On Fri, Dec 30, 2016 at 9:17 PM, Kovács Péter
>> <kpeter at inf.elte.hu <mailto:kpeter at inf.elte.hu>
>> <mailto:kpeter at inf.elte.hu <mailto:kpeter at inf.elte.hu>>> wrote:
>>
>> Hi John,
>>
>> You should avoid passing graphs (and other large data
>> structures) as
>> values between functions. Use references or pointers
>> instead. For
>> example:
>>
>> FilterNodes<ListDigraph>& get_subgraph(void)
>> {
>> FilterNodes<ListDigraph> subgraph;
>> ...
>> return g;
>> }
>>
>> Note the '&' sign in the return type of the function. (If its
>> meaning is not clear, read some C++ tutorials about
>> references and
>> pointers.)
>>
>> Regards,
>> Péter
>>
>>
>>
>> Péter,
>>
>> It turns out that the issue I am having is related to
>> trying to
>> return
>> a FilterNodes<ListDigraph> issue from a function. If
>> the FilterNodes<ListDigraph> object is local I can iterate
>> through the
>> nodes as expected. If the object is returned from a
>> function i.e.
>>
>> FilterNodes<ListDigraph> get_subgraph(void)
>> {
>> }
>>
>> void another_function()
>> {
>> auto x = get_subgraph();
>>
>> for (FilterNodes<ListDigraph>::NodeIt n(x); n !=
>> INVALID; ++n)
>> ...
>> }
>>
>> I get an exception when trying to iterate through the
>> nodes.
>>
>> John
>>
>>
>>
>>
>> On Thu, Dec 29, 2016 at 5:28 PM, Kovács Péter
>> <kpeter at inf.elte.hu <mailto:kpeter at inf.elte.hu>
>> <mailto:kpeter at inf.elte.hu <mailto:kpeter at inf.elte.hu>>
>> <mailto:kpeter at inf.elte.hu <mailto:kpeter at inf.elte.hu>
>> <mailto:kpeter at inf.elte.hu <mailto:kpeter at inf.elte.hu>>>> wrote:
>>
>> Hi John,
>>
>> What kind of write method are you looking for? Could
>> you
>> send a code
>> snippet that works for the graph, but does not apply
>> to the
>> subgraph?
>>
>> Regards,
>> Péter
>>
>>
>> I have a subgraph as follows:
>>
>> FilterNodes<ListDigraph> sub(*graph, filter);
>>
>> There doesn't appear to be a write method for the
>> subgraph as
>> there is
>> for the graph.
>>
>> Suggestions?
>>
>>
>> --
>> John Lagerquist
>> Chief Engineer
>> RallyTronics LLC
>> 801-866-5981
>>
>>
>>
>>
>> _______________________________________________
>> Lemon-user mailing list
>> Lemon-user at lemon.cs.elte.hu
>> <mailto:Lemon-user at lemon.cs.elte.hu>
>> <mailto:Lemon-user at lemon.cs.elte.hu
>> <mailto:Lemon-user at lemon.cs.elte.hu>>
>> <mailto:Lemon-user at lemon.cs.elte.hu
>> <mailto:Lemon-user at lemon.cs.elte.hu>
>> <mailto:Lemon-user at lemon.cs.elte.hu
>> <mailto:Lemon-user at lemon.cs.elte.hu>>>
>>
>> http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
>> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user>
>> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
>> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user>>
>>
>> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
>> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user>
>> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
>> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user>>>
>>
>>
>>
>>
>>
>> --
>> John Lagerquist
>> Chief Engineer
>> RallyTronics LLC
>> 801-866-5981
>>
>>
>>
>> _______________________________________________
>> Lemon-user mailing list
>> Lemon-user at lemon.cs.elte.hu
>> <mailto:Lemon-user at lemon.cs.elte.hu>
>> <mailto:Lemon-user at lemon.cs.elte.hu
>> <mailto:Lemon-user at lemon.cs.elte.hu>>
>> http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
>> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user>
>> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
>> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user>>
>>
>>
>>
>>
>>
>>
>> --
>> John Lagerquist
>> Chief Engineer
>> RallyTronics LLC
>> 801-866-5981
>>
>>
>>
>
--
John Lagerquist
Chief Engineer
RallyTronics LLC
801-866-5981
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lemon.cs.elte.hu/pipermail/lemon-user/attachments/20161230/e00b3a54/attachment-0001.html>
More information about the Lemon-user
mailing list