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
Add farthest-insertion algorithm for the TSP #1105
Conversation
Any interest in this? |
@jkinable any interest on this? |
Just FYI - the tests would not "run" after merging because JGraphT now uses JUnit 5 and your tests are written in JUnit 4. Edit: After taking a closer look, some tests require more than just editing the imports; specifically, the |
Thanks so much for the observation. I can update the PR for JUnit 5; nevertheless, before any effort, it would be great to know if the JGrapht team is interested in integrating this PR since it has not been merged for a long time, maybe because it is not of interest. UPDATE |
@jsichi would you mind taking a look? |
Previous implementation was based on the jgrapht implementation of Nearest Neighbor. Now it was changed and now is based on Nearest Insertion.
3ba835e
to
5a72934
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your incredible patience! I will merge this after the swap methods are made private.
* @param i the index of the first element | ||
* @param j the index of the second element | ||
*/ | ||
public static void swap(double[] arr, int i, int j) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about moving the swap methods to the org.jgrapht.util.ArrayUtil
class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's better!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for your feedback. Done.
* @param i the index of the first element | ||
* @param j the index of the second element | ||
*/ | ||
public static void swap(int[] arr, int i, int j) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just few documentation stuff that came up to me while reading the changes:
- I think that
@since
tags should be added to Javadoc for the new classes / methods (see suggestions) - I don't think the license headers for the two new files are accurate? It isn't 2021 now for sure...
Disclaimer: I am not associated with the maintainer(s) of the JGraphT repository, nor do I claim to be.
* @param <V> the graph vertex type | ||
* @param <E> the graph edge type | ||
* @author José Alejandro Cornejo Acosta | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param <V> the graph vertex type | |
* @param <E> the graph edge type | |
* @author José Alejandro Cornejo Acosta | |
*/ | |
* @param <V> the graph vertex type | |
* @param <E> the graph edge type | |
* @author José Alejandro Cornejo Acosta | |
* | |
* @since 1.5.3 | |
*/ |
/** | ||
* Unit tests for the {@link FarthestInsertionHeuristicTSP} | ||
* | ||
* @author Jose Alejandro Cornejo Acosta | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* Unit tests for the {@link FarthestInsertionHeuristicTSP} | |
* | |
* @author Jose Alejandro Cornejo Acosta | |
*/ | |
/** | |
* Unit tests for the {@link FarthestInsertionHeuristicTSP} | |
* | |
* @author Jose Alejandro Cornejo Acosta | |
* | |
* @since 1.5.3 | |
*/ |
Interesting. I agree with you about the dates. Let's
Interesting. I agree with you about the dates, but the instructions say not to change the header. @jsichi What do you think about it? |
As it says in: https://github.com/jgrapht/jgrapht/wiki/Dev-guide%3A-How-to-make-your-first-(code)-contribution The only modifications you are allowed to make to the header are the year, and your name on the first line. The first line of the header should read: Since these are new files, you should use your name (instead of copying the names from other files). For the year range, you can put 2021-2024 due to the long review period. Thanks @syoon2 for noticing that. |
I updated the headers. Thanks so much for the observation. |
Co-authored-by: Sung Ho Yoon <55358516+syoon2@users.noreply.github.com>
Thanks! |
Issue: #1104.
Add an implementation of the farthest-insertion heuristic for the Traveling Salesman Problem (TSP).
For the purpose of coding this algorithm with good quality, this implementation takes some performance ideas from other algorithm implementations such as NearhestInsertionTSP, NearhestNeighborTSP, and FloydWharsall.
This implementation has a similar structure to other algorithms implementations for the TSP already implemented in jGrapht.
According to some references and experimentation I performed, in several cases, this algorithm outperforms the others regarding running time and quality of found solutions.
Please see the linked issue #1104 to check additional details and a small comparison I performed.
Some references:
HISTORY.md
orCONTRIBUTORS.md