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

Possible bug in Prim's algorithm #85

Open
gordicaleksa opened this issue Nov 30, 2017 · 4 comments
Open

Possible bug in Prim's algorithm #85

gordicaleksa opened this issue Nov 30, 2017 · 4 comments

Comments

@gordicaleksa
Copy link

It seems that by always taking the lowest cost edge like this:
final Graph.Edge<Integer> e = edgesAvailable.remove();
, without checking if it is still connecting us to the unvisited vertex we will end up with cycles.
When I added these lines of code in my project:
while (!unvisited.contains(e.getToVertex())) { e = edgesAvailable.remove(); }
It performs well. I've implemented my own Graph, Edge and Vertex class which should behave the same as these used in this project, maybe I'm missing something. Worth checking it out.

@gokberksahin
Copy link

gokberksahin commented May 5, 2018

Yeah i encountered same issue, added these lines for possibility of a cycle.

for (int i = 0; i < edgesAvailable.size(); i++) { if (!unvisited.contains(edgesAvailable.get(i).getDestinition())) edgesAvailable.remove(edgesAvailable.get(i)); }

@phishman3579
Copy link
Owner

I'll gladly fix this in master branch if you can provide a unit test which shows the bug.

@phishman3579
Copy link
Owner

Has anyone come up with a good unit test for this bug?

@KannanSnair
Copy link

Let me work on it

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

4 participants