Skip to content

BUG: fixed the if condition in asadpour_atsp - #7753

Merged
mjschwenne merged 3 commits into
networkx:mainfrom
Schefflera-Arboricola:tsp_fix
Dec 5, 2024
Merged

mjschwenne merged 3 commits into
networkx:mainfrom
Schefflera-Arboricola:tsp_fix

Conversation

@Schefflera-Arboricola

Copy link
Copy Markdown
Member

fixes #7752

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems pretty straightforward :) - let's add the regression test as well. Thanks @Schefflera-Arboricola !

@mjschwenne mjschwenne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good to me as well, a simple off by one error.

I agree with Ross about the regression test though.

@dschult

dschult commented Dec 4, 2024

Copy link
Copy Markdown
Member

Adding a regression test shows that the current code doesn't work for 2 nodes (tries to take the min of an empty list at line 630). So I added some code to handle the 2 node case.

@mjschwenne can you check that this 2-node code is correct?

@mjschwenne

Copy link
Copy Markdown
Contributor

Nice catch! In this case we can simply brute force the TSP since there is only one possible path. Our only choice is which one of the two nodes should be returned first, and I think your new check handles that quite well. Everything here makes sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

asadpour_atsp unexpeted behaviour for digraph with just two nodes.

5 participants