Skip to content
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

[WIP] Add FloydWarshall Algorithm (All pairs shortest path) #71

Closed
wants to merge 5 commits into from

Conversation

juansrx
Copy link

@juansrx juansrx commented Aug 30, 2013

First attemps to create a FloydWarshall class for creating an Edge list for each index of an associative matrix representing the shortest path between two connected vertices.

@clue
Copy link
Member

clue commented Aug 30, 2013

Thanks a bunch for providing a new algorithm! Looks really good and I'd love to see it included 👍

Given the fact it's an all pairs shortest paths algorithm, it differs significantly from the other current single-source shortest paths implementations (Dijkstra, Moore-Bellman-Ford, Breadth-First). As such, I think it warrants a more thorough feedback and some adjustments to our current code structure.

Afaikt what needs to be done to our current code base before the algorithm fits our current design:

  • Rename Algorithm\ShortestPath\Base to Algorithm\ShortestPath\BaseSingleSource
  • Add new abstract Algorithm\ShortestPath\BaseAllPairs, among with a bunch of documentation (making this the future base class for your implementation)
  • Adjust logic in unit tests

Other than that, I think your implementation looks really promising! I'll add a few remarks to the code layout for some things that come to mind. Most of the remarks probably stem for the fact that this is the first all pairs shortest paths algorithm, so please don't take those personally as it's a natural thing we have to work out some of the differences. Most of this will probably also be needed in order to provide some documentation on which use-case each algorithm covers and how it handles some edge cases (such as null graphs, edgeless graphs, negative weights, parallel edges, multiple components, etc.)

Any thoughts besides this? @clemens-tolboom, care to take look?

* An implementation of the Floyd Warshall algorithm to find the shortest path from each vertex to each vertex.
* @link http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm
*
* @package Fhaculty\Graph\Algorithm\ShortestPath
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Description should be wrapped at 80 chars (see e.g. Dijkstra's description)
  • First line should be more descriptive
  • No need to define package :) (redundant with namespace)
  • Extend description to describe some edge cases (related to what was done in Improve Algorithm\ShortestPath #62)
    • Distance between isolated Vertices?
    • Are parallel (multiple) edges supported?
    • Expected results for negative edge weights?
    • Expected results for negative cycles?
    • Expected results for null Graph (no vertices), edgeless Graph?
    • Distance between Vertex A and Vertex A? What about Loops? What about negative Loops?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the answer!, I'm working on some changes to the algorithm according to your comments, as soon as possible you will see them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to hear! 👍 Just keep me updated once you want me to review your results.

…hrow an Exception in case of negative cycles (or loops), the Tests were also rewritten to be more specific.
@juansrx
Copy link
Author

juansrx commented Oct 3, 2013

This commit implemented a Result interface for handling the Result of the FloydWarshall Algorithm better.

@clue
Copy link
Member

clue commented Oct 3, 2013

Thanks for the update, these changes look really good! 👍 In particular the amount and quality of documentation and unit tests is very much appreciated!

I'm quite busy for the next few days, so I'm a afraid a more thorough review may take some time, but I'll come back to this ticket ASAP.

What's your status on this ticket? What do you think still has to be done before this should be merged?

$vertex[0] = self::$graphs[1]->createVertex('A');
$vertex[1] = self::$graphs[1]->createVertex('B');
$vertex[0]->createEdgeTo($vertex[1]);
$edges = $vertex[0]->getEdgesTo($vertex[1]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'd don't quite like the style, but the failing test can be fixed with:

$edges = $vertex[0]->getEdgesTo($vertex[1])->getVector()

@clue
Copy link
Member

clue commented Nov 9, 2013

So, I've finally had the time to take a more thorough look at your PR. And I really like the high quality of it and would love to merge it once the remaining remarks have been resolved.

Sorry for bugging you with those (sometimes subtle) remarks :)

I'd love to hear back from you!

@juansrx
Copy link
Author

juansrx commented Nov 14, 2013

Hello

Thank you for your attention. I am a bit busy right now, but I will make the changes as soon as possible.

I hope to have a new pull request soon.

@clue
Copy link
Member

clue commented Nov 14, 2013

No worries, glad to hear we'll eventually manage to sort out the remaining remarks :)

I hope to have a new pull request soon.

Sure, keep them coming 👍

juansrx and others added 2 commits November 18, 2013 16:27
…ithm classes moved to new namespace, and Result class had the createGraph and getVertices methods rewritten.
@juansrx
Copy link
Author

juansrx commented Nov 18, 2013

Hello.

I made a new pull request, I hope the new changes will resolve the remarks you stated.

Thank you.

@clue
Copy link
Member

clue commented Dec 30, 2013

The changes look good to me. Unfortunately, there's still a failing unit test.

Is there anything you'd like to address yourself or would you want me to dig a little deeper? :)

Thanks!

@juansrx
Copy link
Author

juansrx commented Jan 28, 2014

Hello.

Sorry for the late answer, I've been very busy these months.

I will re-check the code, if you could give information about the test that
failed it would help me.

If everything goes ok, you should be receiving a new pull request soon.

Thank you.

On Sun, Dec 29, 2013 at 9:13 PM, Christian Lück notifications@git.luolix.topwrote:

The changes look good to me. Unfortunately, there's still a failing unit
test.

Is there anything you'd like to address yourself or would you want me to
dig a little deeper? :)

Thanks!

Reply to this email directly or view it on GitHubhttps://github.com//pull/71#issuecomment-31331016
.

"porque el fracaso es como el exito...pero al reves"

@clue
Copy link
Member

clue commented Jan 30, 2014

Sorry for the late answer, I've been very busy these months.

No worries, we all face that same issue :)

if you could give information about the test that failed

You can either run phpunit locally or take a look at travis output:
https://travis-ci.org/clue/graph/builds/14163097.

Otherwise, we also usually hang around on #graphp on irc.freenode.net, so feel free to stop by.

The master branch has advanced quite a bit, most notably this code has to be changed:

// old:
$array = $vertex->getEdges();
// new:
$array = $vertex->getEdges()->getVector();

If everything goes ok, you should be receiving a new pull request soon.

As always, thanks for your work, it's very much appreciated!

@clue
Copy link
Member

clue commented Feb 25, 2015

Thanks for your interest!

All algorithms will be split off to a separate package graphp/algorithms (see also #119 for some background). As such, this PR can no longer be merged into this repo.

That being said, I'd still love this see this in! 👍 I've filed a new ticket as a reminder to keep track of this PR until it has been migrated over.

@clue clue closed this Feb 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants