TSP/
app/ contains algorithms and features
data/ contains data instances
distanceMatrices/ contains distance matrix files
documentation/ contains documentation for the algorithms
evaluation/ contains evaluation of algorithms
logs/ contains log files
optimalResults/ contains optimal results
output/ contains exported solution files
parameters/ contains parameter files
statistics/ contains statistical analysis of the data instances
Data http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/tsp/
Large data http://www.math.uwaterloo.ca/tsp/world/countries.html
Data description http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/tsp95.pdf
Data FAQ http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/TSPFAQ.html
One can download the datasets .tsp
, .opt.tsp
from here by:
- For Windows:
- Install winrar and set path:
set path="path\to\WinRAR\";%path%
- Run
getData-Win.bat
:> getData-Win.bat
- Install winrar and set path:
- For Linux/MacOS:
- Install
curl
:> sudo apt install curl
- Run getData-Unix.sh:
> bash getData-Unix.sh
- Install
The file dataInstances.json
contains general statistics on some basic information about the problems (or instances):
NAME
: name of the problemDIMENSION
: the number of cities in the problemBEST_KNOWN_SOLUTION
: the best value of a solution has been found from all sources (currentely based onTSPLIB_BestKnownSolution.json
file instatistic/instances
)EXIST_OPTIMAL_TOUR
:true
if the optimal tour for the problem has been found and put inoptimalResults
folder, elsefalse
GIVEN_COORDINATES
:true
if the problem provides coordinates, elsefalse
- The problems whose dimensions are greater than or equal to 10000 are not considered.
- The two problems
lin318.tsp
andlinhp318.tsp
have the same name and data.
Therefore, thelinhp318.tsp
problem is not considered. - The problem
dsj1000.tsp
hasCEIL_2D
as itsEDGE_WEIGHT_TYPE
. Meanwhile, theTSPLIB_BestKnownSolution.json
contains two records of thedsj1000.tsp
problems:dsj1000EUC_2D
anddsj1000CEIL_2D
withEUC_2D
andCEIL_2D
asEDGE_WEIGHT_TYPE
respectively.
Therefore, the recorddsj1000EUC_2D
is removed and the recorddsj1000CEIL_2D
is renamed todsj1000
.
Edmund K. Burke, Graham Kendall. "Search Methodologies", 2014, 2nd Edition, Springer
Note: The directory in Linux is different from that in Windows. Therefore, if errors with '/' and '\' encountered, the path need to be modified.
Example:
- On Linux:
https://github.com/godfeed27
- On Windows:
https:\\github.com\godfeed27
First of all, you need to download the repository. You can either run the script below on the command-line or terminal:
git clone https://github.com/godfeed27/TSP.git
or download zip file of repository and unzip.
If you have the problem related to personal access token, try following the steps below:
- Log in to your GitHub account
- Go to
Settings
, then chooseDeveloper Settings
- Choose
Personal access tokens
- Generate and copy your tokens
- Clone again and paste tokens to password space
Add TSP/
directory pathname to PYTHONPATH.
-
For Windows:
Run command line as administrator and execute the following command:
setx PYTHONPATH "%PYTHONPATH%;\path\to\TSP" /M
Note:
- After run this command, you need restart terminal to update PYTHONPATH.
- Windows can't set PYTHONPATH for the current terminal session, so this command sets PYTHONPATH permanently.
-
For Linux/MacOS:
export PYTHONPATH=$PYTHONPATH:/path/to/TSP
Note: This command only set PYTHONPATH for the current terminal session.
Change the path
that points to your TSP folder.
cd path/to/TSP
-
Create environment by following command:
python3 -m venv env
-
Activate environment:
env/Scripts/activate # For windows source env/bin/activate # For Linux or MaxOS
-
Install libraries in by:
pip install -r requirements.txt
-
Deactivate environment:
env/Scripts/deactivate # For windows source env/bin/deactivate # For Linux or MaxOS
In folder parameters/
, one has to create parameter files based on the corresponding sample parameter files:
-
TSP_Folder
: path to the TSP directory. -
PROBLEM_NAMES
: problem names seperated by commas. -
ALGORITHM_NAMES
: algorithm abbreviations seperated by commas. -
TIME_LIMIT_OPTIONS
: time limits that depend on the dimensions of the problems.
For example,TIME_LIMIT_OPTIONS:100~60|1000~600|10000~600|100000~1200
is equivalent to:
Number of Cities Time Limit 1 <= n <= 100 60 s 100 < n <= 1,000 600 s 1,000 < n <= 10,000 600 s 10,000 < n <= 100,000 1200 s Note: The last bound's dimension must be greater than the greatest dimension in the problems.
-
DATA_FOLDER
: path to the folder that contains data instances.
Highly recommend settingdata
as default. -
DATA_INSTANCES_FOLDER
: path to the folder that contains the statistics of the data instances.
Highly recommend settingstatistics/instances/
as default. -
DISTANCE_MATRICES_FOLDER
: path to the folder that contains the distance matrix files.
Highly recommend settingdistanceMatrices
as default. -
EVALUATE_IMAGE_FOLDER
: path to the folder that contains the evaluation images. -
LEADER_BOARD_FOLDER
: path to the folder that contains the algorithms leader board. -
OPTIMAL_RESULTS_FOLDER
: path to the folder that contains the optimal result files.
Highly recommend settingoptimalResults
as default. -
OUTPUT_FOLDER
: path to the output folder.
Highly recommend settingoutput
as default. -
LOGS_FOLDER
: path to the report folder that contains log files. -
STATISTICS_IMAGE_FOLDER
: path to the folder that contains the statistical images. -
EXPORT_SOLUTION
: decides whether the solution is exported or not (yes
orno
). -
DATE_RUN
: date when script was run (format:yyyymmdd
). -
VERBOSE
: decides how much detailed the output should be.
IfVERBOSE
= 0, prints nothing.
IfVERBOSE
= 1, prints header and final result only.
IfVERBOSE
= 2, prints the whole algorithm's process. -
Algorithm parameters: parameters' values for the algorithms.
Note: Default parameters' values are given in the sample parameters files in the parameters/
folder.
One can generate and save distance matrix files locally by running the following:
python3 app/feature/saveDistanceMatrix.py path/to/parameter.txt
The distance matrix files (e.g. a280.matrix.tsp
) will then be generated and saved in DISTANCE_MATRICES_FOLDER
(in the parameter file) folder.
One can get data instances' information summary in a json file dataInstances.json
by running the following:
python3 app/feature/getDataInstances.py path/to/parameter.txt
The dataInstances.json
will then be saved in dataInstances
(in the parameter file) folder.
One can get statistical analysis of the problems on dimensions, coordinates and optimal tours by running the following:
python3 app/feature/statisticsPlot.py path/to/parameter.txt
The statistical analysis will then be saved in STATISTICS_IMAGE_FOLDER
(in the parameter file) folder.
One can check if the optimal results are reasonable by running the following:
python3 app/feature/checkOptimalResults.py path/to/parameter.txt
The result will then be printed to the output.
One can solve the TSP problems using the algorithms above by running the following:
python3 app/feature/problemSolve.py path/to/parameters.txt
The results will then be saved in OUTPUT_FOLDER
(in the parameter file) folder.
Note:
- The distance matrix files should be generated locally beforehand (feature 1) for faster performance.
- Rerunning the same parameter file will not guarantee the same solution
One can evaluate the results after solving by running the following:
python3 app/feature/evaluateResults.py path/to/parameters.txt
The algorithms' results comparison and the leader board for the algorithms will then be saved in STATISTICS_IMAGE_FOLDER
and LEADER_BOARD_FOLDER
(in the parameter file) folders , respectively.
In the TSPLIB95 data description, there is a remark:
There may exist several shortest tours for a problem instance.
One can check if a solution tour with the optimal total distance is different from the optimal tour by running the following:
python3 app/feature/checkExistDistinceOptTours.py path/to/parameters.txt
The result will then be printed to the output.# TSP