-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Methods inOut*
broken for directed graphs
#406
Comments
This is still an issue. Below test should pass, but fails: TEST(Foo, bar) {
// Construct a simple directed graph (1) --> (2) --> (3).
CXXGraph::Graph<int> g;
CXXGraph::Node<int> n1("1", 1);
CXXGraph::Node<int> n2("2", 2);
CXXGraph::Node<int> n3("3", 3);
for (auto &&n : {n1, n2, n3}) {
g.addNode(&n);
}
CXXGraph::DirectedEdge<int> e1(1, {&n1, &n2});
CXXGraph::DirectedEdge<int> e2(2, {&n2, &n3});
for (auto &&e : {e1, e2}) {
g.addEdge(&e);
}
ASSERT_EQ(g.outNeighbors(&n1).size(), 1);
ASSERT_EQ(g.outNeighbors(&n2).size(), 1);
ASSERT_EQ(g.outNeighbors(&n3).size(), 0);
ASSERT_EQ(g.inOutNeighbors(&n1).size(), 1);
ASSERT_EQ(g.inOutNeighbors(&n2).size(), 2); // Fails, value is 1.
ASSERT_EQ(g.inOutNeighbors(&n3).size(), 1); // Fails, value is 0.
} |
Yes @bbannier this issue is still open, if you want to contribute to this, i can assign it to you! |
I might be able to fix this one issue, but would be afraid of missing APIs (e.g., what about directed weighted graphs?). My main motivation was less to rush anyone, but to provide a reproducer. Thanks for bumping the priority! |
maybe we need to correct the adjacency matrix use for the directed graph to return the correct result without broke the APIs. |
It looks to me that most of the methods
inOutEdges
orinOutNeighbors
are implemented incorrectly for directed graphs. All these methods use the adjacency matrix to access edges, e.g.,CXXGraph/include/CXXGraph/Graph/Graph_impl.hpp
Lines 715 to 725 in ae9bc56
This works well-enough for undirected graphs where the adjacency matrix is kept symmetric,
CXXGraph/include/CXXGraph/Graph/Graph_impl.hpp
Lines 94 to 121 in ae9bc56
For directed graphs the adjacency matrix is not symmetric which means that it cannot be used as-is to obtain incoming edges for a node,
CXXGraph/include/CXXGraph/Graph/Graph_impl.hpp
Lines 76 to 93 in ae9bc56
Originally posted by @bbannier in #405 (comment)
The text was updated successfully, but these errors were encountered: