-
Notifications
You must be signed in to change notification settings - Fork 59
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
feat: implement bidirectional adjacency graph #78
Conversation
Keeps private @reverse graph. Passes all unit tests for DirectedAdjacencyGraph. Once full functionality is verified we can think about a more efficient implementation.
Original bidirectional.rb module restored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with this implementation. Thank you! When we are through with my comments, I would prepare a new release with your changes.
test/bidirectional_graph_test.rb
Outdated
include RGL | ||
include RGL::Edge | ||
|
||
class TestBidirectionalAdjacencyGraph < TestDirectedGraph |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #76 (comment) I meant to define two separate test classes:
- Your new class
- The test class which inherits from TestDirectedGraph
I think, that this would increase readability. Perhaps providing a comment, that we simply reuse the tests from the super test class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been unable to make this work.
First of all, TestDirectedGraph
has dependencies on DirectedAdjacencyGraph
scattered throughout. It's not difficult to hoist them all up into #setup
, but that would have to be done.
I tried it, but simply subclassing the TestDirectedGraph
and overriding #setup
did not work as expected. I'll push what I have but it's not right yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me that worked. See changes in 8c98f8a.
It also contains a minor doc change:
# This implementation of {BidirectionalGraph} creates an internal
# {DirectedAdjacencyGraph} to store the in-edges and overrides methods
Does not work as expected. TestBirectionalAdjacencyGraphBasic is never run. I modifed setup() so all tests should fail but there are no failures.
It appears to work but when you run the tests there's no result for |
You are right. I do not understand it either. The POLS is violated here by the test library. I just ran the test in TestDirectedGraph using the new I propose to forget this experiment. I do not want to dig deeper... |
Agreed. |
Before you finalize anything, I think there's a bug in the constructor for |
Ok, which tests do we need? |
Bug in BidirectionalAdjacencyGraph constructor fixed.
I fixed the constructor and added tests in |
- New class BidirectionalAdjacencyGraph which implements the protocol defined in module BidirectionalGraph - add has_in_edge?, in_neighbors in BidirectionalGraph - add tests for DirectedAdjacencyGraph similar to those in TestBidirectionalAdjacencyGraph
Close and release in #83 |
I'm not very experienced at working across forks. Can you clarify what you want me to do? |
Something like this: git remote add monora https://github.com/monora/rgl.git # perhaps you have already this remote
git fetch monora
# last commit must be e70fdc
git log monora/78-bidirectional-graph
# Now in your local branch (bidirectional-1), which should have no changes:
git reset --hard monora/master # Bring branch to top of master
git reset --soft monora/78-bidirectional-graph # Apply changes from my branch Now your branch should have the desired changes e70fdc0 (check this). git add .
git commit -m'my comment...'
git push --force
|
I forgot: If you do not want to loose the commits in your branch git checkout -b bidirectional-1-original bidirectional-1
git push
git checkout bidirectional-1 |
After the
Unless it matters to you, I don't mind if the changes aren't attributed to me. It was a fun little project but sic transit gloria mundi. If it's easier to just make the release yourself, feel free. |
- New class BidirectionalAdjacencyGraph which implements the protocol defined in module BidirectionalGraph - add has_in_edge?, in_neighbors in BidirectionalGraph - add tests for DirectedAdjacencyGraph similar to those in TestBidirectionalAdjacencyGraph
git commit --amend --author "Steven Jenkins <j.s.jenkins@jpl.nasa.gov>" See new commit 1d6c1b4 |
- New class BidirectionalAdjacencyGraph which implements the protocol defined in module BidirectionalGraph - add has_in_edge?, in_neighbors in BidirectionalGraph - add tests for DirectedAdjacencyGraph similar to those in TestBidirectionalAdjacencyGraph
Closed after changing commit author of #78 to @StevenJenkinsJPL |
Closed after changing commit author of #78 to @StevenJenkinsJPL. |
If you're comfortable with a separate
vertices_dict
for in-edges, I think this approach is cleaner. ADirectedAdjacencyGraph
has hardly any state other than thevertices_dict
, so why not simply make a separate graph? This avoids having to copy any implementation from the base class; it is implemented using only methods exposed byDirectedAdjacencyGraph
.This was my original proposed approach.
The only downside that I can see is that it duplicates the vertex references used as keys in the two
vertices_dict
s and duplicates operations on them. As you noted a couple of days ago, however, it is impossible to eliminate that without pulling some implementation into the subclass.I restored the original module and made the changes to the test you suggested.