Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

Fix Tarjan implementation #34

Merged
merged 1 commit into from
Feb 26, 2015
Merged

Fix Tarjan implementation #34

merged 1 commit into from
Feb 26, 2015

Conversation

kortschak
Copy link
Member

The previous code was giving incorrect results for a 2SAT solver I have
built on it (cannot release). This fixes that.

Tests to come.

// tarjan implements Tarjan's strongly connected component finding
// algorithm. The implementation is from the pseudocode at
//
// http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to add a date accessed as part of the reference here. Wikipedia changes.

Edit: or even a link to a specific revision, like http://en.wikipedia.org/w/index.php?title=Tarjan%27s_strongly_connected_components_algorithm&oldid=647184742

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed, thank you.

@soniakeys
Copy link
Contributor

Ugh. The current WP pseudocode doesn't even look correct. The commit comment makes the assumption that it's expensive to check if a node is on the stack and introduces the isRemoved flag. But without initialization, it's unclear that !isRemoved is a valid way to check if a node is on the stack. Instead of isRemoved, I would add a an "onStack" flag.

Update: Hmm. It does seem to work. I'll stick to my claim that it isn't clear that it should work. The comment says "Successor w is in stack S" and yet the flag doesn't correspond to that condition for all nodes. Maybe it does for the node being tested at that point in the algorithm, but gosh, that's obscure.

@kortschak
Copy link
Member Author

I have made that change. PTAL

Would you edit the WP article, or would you like me to add a comment that it is with changes? I'll update the comment when I know which.

UserAB1236872 referenced this pull request Feb 23, 2015
Mainly names.
@kortschak
Copy link
Member Author

ping

@soniakeys
Copy link
Contributor

Sorry I was distracted with other things for a bit. LGTM. For the comment, I would reference the previous version at WP with "http://en.wikipedia.org/w/index.php?title=Tarjan%27s_strongly_connected_components_algorithm&oldid=642744644." Pseudocode in that version simply reads if (w is in S) without attempting to direct implementation too much. I think it's fine to indicate our code is based on that.

I had a WP account once. You're right I should try to recover it and suggest changes there.

kortschak added a commit to gonum/plot that referenced this pull request Feb 26, 2015
This was raised in code review for gonum/graph#34. The code was changed,
but the comment was left. Now the comment points to the correct WP
revision.
The previous code was giving incorrect results for a 2SAT solver I have
built on it (cannot release). This fixes that.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants