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

Error in FloydWarshwall algorithm #101

Closed
MNadal-Yseop opened this issue Nov 24, 2014 · 2 comments
Closed

Error in FloydWarshwall algorithm #101

MNadal-Yseop opened this issue Nov 24, 2014 · 2 comments

Comments

@MNadal-Yseop
Copy link

Hi,

It seems that the FloydWarshallShortestPaths algorithm could give a wrong result for PseudoGraph. Actually, it assumes there is only one edge between two node.

During path length computation process, the d matrix is initialized with the following lines :
Set edges = graph.edgeSet();
for (E edge : edges) {
V v1 = graph.getEdgeSource(edge);
V v2 = graph.getEdgeTarget(edge);

        int v_1 = vertices.indexOf(v1);
        int v_2 = vertices.indexOf(v2);

        d[v_1][v_2] = graph.getEdgeWeight(edge);
        if (!(graph instanceof DirectedGraph<?, ?>)) {
            d[v_2][v_1] = graph.getEdgeWeight(edge);
        }
    }

And no test are done to check if d[v_1][v_2] already have a value. It should be an if to check that :
Set edges = graph.edgeSet();
for (E edge : edges) {
V v1 = graph.getEdgeSource(edge);
V v2 = graph.getEdgeTarget(edge);

        int v_1 = vertices.indexOf(v1);
        int v_2 = vertices.indexOf(v2);
        if (d[v_1][v_2] > graph.getEdgeWeight(edge) {
            d[v_1][v_2] = graph.getEdgeWeight(edge);
            if (!(graph instanceof DirectedGraph<?, ?>)) {
                d[v_2][v_1] = graph.getEdgeWeight(edge);
            }
        }
    }

Sorry to don't make a real proper patch, it is my first comment on github so I'm not used to available tools ;).

Thanks for your work on JGraphT :)
M. Nadal

@jkinable
Copy link
Collaborator

This issue is currently being addressed in pull request #317

@jkinable
Copy link
Collaborator

jkinable commented Jan 9, 2017

This issue has been resolved in pull req #317. Thanks for reporting! Let us know if you encounter any other issues.

@jkinable jkinable closed this as completed Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants