[Lemon-user] Selecting a random Node or Edge
Kovács Péter
kpeter at inf.elte.hu
Tue Sep 6 14:38:22 CEST 2011
Hi Tom,
In LEMON, nodes and edges have unique and immutable integer IDs, but
these IDs are not necessarily form a continuous range.
Possible solutions for your problem:
1. Store all Node objects in a vector/array and use a random index to
obtain a node. Similarily for edges.
2. Create an IdMap for the nodes/edges and use its operator()() function
or its inverse map for retrieving an item by its ID.
http://lemon.cs.elte.hu/pub/doc/1.2.2/a00174.html
Peter
On 2011.08.20. 19:06, Thomas Gorochowski wrote:
> Hi there,
>
> I am attempting to randomly select a Node and Edge in a graph, but
> cannot find any function to do this. The only work around I have found
> it is pick a random integer in the range 0 <= x < number of Nodes/Edges
> and then iterate through until I reach it. I have noticed there is an
> id() function, but am unsure if these will maintain sequential numbering
> as I do a lot of inserts and deletes.
>
> Many thanks for the help,
>
> Tom.
>
> --
> Thomas E. Gorochowski
> University of Bristol, Centre for Complexity Sciences (BCCS)
> http://www.chofski.co.uk, tgorochowski at me.com <mailto:tgorochowski at me.com>
>
More information about the Lemon-user
mailing list