libgraph icon indicating copy to clipboard operation
libgraph copied to clipboard

Graph.edges/2 does not work with bidirectional edges between vertices

Open ctbucha opened this issue 6 years ago • 4 comments

Graph.edges/2 only returns a single direction of edges from one vertex :a to another vertex :b instead of both directions from the vertex :a to the other vertex :b.

iex(1)> g = Graph.new() |> Graph.add_edges([{:a, :b, label: "label1"}, {:a, :b, label: "label2"}, {:b, :a, label: "label3"}]) |> Graph.edges(:a)
[
  %Graph.Edge{label: "label1", v1: :a, v2: :b, weight: 1},
  %Graph.Edge{label: "label2", v1: :a, v2: :b, weight: 1}
]

Expected:

[
  %Graph.Edge{label: "label1", v1: :a, v2: :b, weight: 1},
  %Graph.Edge{label: "label2", v1: :a, v2: :b, weight: 1},
  %Graph.Edge{label: "label3", v1: :b, v2: :a, weight: 1}
]

ctbucha avatar Jan 31 '19 21:01 ctbucha

There are more places that do not support bidirectional graphs. Here is example:

g = (
Graph.new(type: :undirected) 
|> Graph.add_edge(1, 2, weight: 1) 
|> Graph.add_edge(2, 3, weight: 2) 
|> Graph.add_edge(1, 3, weight: 3)
)

Then when we trying to find path in this graph it works like it’s not undirected:

iex(52)> Graph.a_star(g, 1, 2, fn _v -> 0 end)
[1, 2]
iex(53)> Graph.a_star(g, 2, 1, fn _v -> 0 end)
nil

AndrewDryga avatar Feb 17 '19 22:02 AndrewDryga

I think the issue @ctbucha describes is about multi graphs, which are not supported. See the feature request #18

robindaumann avatar Mar 23 '19 18:03 robindaumann

@AndrewDryga is describing a bug this lib haves with undirected graphs. I will look at it and submit a pr.

robindaumann avatar Mar 23 '19 18:03 robindaumann

any news about this? i have the same problem @AndrewDryga described

sgessa avatar Sep 25 '19 12:09 sgessa