JuliaGraphs / SimpleWeightedGraphs.jl

Edge-weighted graphs compatible with Graphs.jl
http://juliagraphs.org/SimpleWeightedGraphs.jl/
Other
36 stars 5 forks source link

Possiblity of having a graph weighted in two ways? #26

Closed ghost closed 1 year ago

ghost commented 2 years ago

Hi there!

To create a weighted graph we should issue this command: g = SimpleWeightedGraph(sources, destinations, weights). In addition to distance between edges, I want to asign their time also. That is, having a graph that its weight are both distance and time. I only want to do so, because at some point I need to query the time of some edges, and if I on;y construct the graph based on the distances, I cannot find out the time of a specific edge.

So, three questions: 1- Is is possible to have two ways of assigning weights to a graph? 2- Is there any better way? 3- How to iterate ove edges? I did for (i,j) in edges(g) and it did not work, which kind of make sense to me, but I don't know how to iterate.

Thanks!

gdalle commented 2 years ago

If you want graphs with two types of weights, I think you will be better off with packages that support arbitrary metadata, such as MetaGraphsNext.jl.

As for edge iteration, the edges(g) iterator yields a sequence of edge objectse, whose endpoints you can query with src(e) and dst(e)

ghost commented 2 years ago

Thanks @gdalle So, it is not possible to have a for loop like for (i,j) in edges(g), right? If so, is there any possiblity to query the weight of a certain edge??

gdalle commented 2 years ago

The way to do this would be:

for e in edges(g)
    i, j, w = src(e), dst(e), weight(e)
end

I'm not sure the weight(e) function is sufficiently discoverable, do you want to do a small PR that adds it to the code examples in the README?

ghost commented 2 years ago

Thanks so much @gdalle

gdalle commented 1 year ago

The documentation was improved a lot by #38, closing this