[Lemon-user] graphCopy() does not overwrite target
Kovács Péter
kpeter at inf.elte.hu
Tue Jun 22 15:30:47 CEST 2010
Dear Allan,
> Hello,
>
> I've been using graphCopy() to backup and restore a graph's state and
> noticed that rather than overwriting the contents of the target graph it
> seems to append the source graph's contents to it somehow.
Yes, it seems to be true.
> This does not
> seem to be the intended behavior and is not mentioned in the
> documentation.
I think, graph copying must clear the target graph before adding nodes
and edges to it. However, it is not performed currently.
I made a bug report ticket about it:
http://lemon.cs.elte.hu/trac/lemon/ticket/371
> There also does not seem to be a built-in way to clear
> the contents of a graph.
All the graph structures that can be used as a target graph provide a
clear() function to remove all nodes and edes.
> As a work around I had to use something like
> the following code segment:
>
> while(countNodes(graph) != 0) {
> ListGraph::NodeIt n(graph);
> graph.erase(n);
> }
> graphCopy(backupGraph, graph).nodemap(backupNodemap, nodemap).run()
Consider to use:
graph.clear();
graphCopy(backupGraph, graph).nodemap(backupNodemap, nodemap).run();
(It seems to be a bug that clear() is necessary, but you can use this
work around until the bug is fixed.)
> I am also aware of the Snapshot class for saving the state of a graph
> but because I contract nodes in my graph it would invalidate the snapshot.
The Snapshot feature cannot handle this case, use graphCopy().
Regards,
Peter
More information about the Lemon-user
mailing list