List from a Graph

Viewed 51

I have experienced with LightGraphs package in Julia and I have builded a random graph using erdos_renyi(n,p). I would like to know how can I generate a list of edges from this graph. For example:

If I do:

p=erdos_renyi(3,3)

I would like to have a function, which lists me the edges of this graph. That is to say:

List(p)=[1,2],[2,3],[1,3]]

Thank you so much for your collaboration.

1 Answers

Normally you should do just:

edges(p)

it will not create you a list of edges, but a lazy edge iterator. The reason why it is preferred is that the number of edges can be very large and it could use a lot of RAM.

If you need to have a vector of edges you can collect this iterator with:

collect(edges(p))
Related