Hi,
On 05/02/2018 04:44 PM, Arman Mohseni Kabir wrote:
> I want to randomly choose a node from the graph
You can use graph.chooseNode(); but it is not suited for every
use-case (because it needs linear time).
> and restore all the
> hidden edges of that node form the HiddenEdgeSet. I would be
> grateful if you could help me.
I am not sure if there is builtin functionality for that.
However, you can maintain a
NodeArray<List<edge>> hiddenIncidentEdges{graph};
that contains a list of incident hidden edges for each node.
So always when you hide an edge e, you also have to do add it to the
lists:
hiddenIncidentEdges[e->source()].pushBack(e);
hiddenIncidentEdges[e->target()].pushBack(e);
Then when you want to restore all incident edges of v, simply do
for (edge e : hiddenIncidentEdges[v]) {
hiddenEdges.restore(e);
hiddenIncidentEdges[e->source()].removeFirst(e);
hiddenIncidentEdges[e->target()].removeFirst(e);
}
Note again that List::removeFirst() needs linear time.
> Also, how can I randomly choose an edge from the HiddenEdgeSet and
> restore it in the original graph?
Again I am not sure if there is builtin functionality for that
but you can manually maintain a list of all hidden edges and choose
a random member.
Note that the original purpose of the hidden edges is to temporarily
hide edges and let an auxiliary algorithm run on the graph without
these edges. Afterwards all hidden edges are restored.
Your need to restore edges selectively sounds to me like
HiddenEdgeSet is not the right tool. Instead, you probably want to
use a GraphCopy of a graph that you createEmpty() and then
selectively add edges from the original graph. I hope the reference
documentation for GraphCopy will help you.
Best
Stephan