libgraph
libgraph copied to clipboard
Graph.edges/2 does not work with bidirectional edges between vertices
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}
]
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
I think the issue @ctbucha describes is about multi graphs, which are not supported. See the feature request #18
@AndrewDryga is describing a bug this lib haves with undirected graphs. I will look at it and submit a pr.
any news about this? i have the same problem @AndrewDryga described