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 instancesData 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.jsonfile instatistic/instances)EXIST_OPTIMAL_TOUR:trueif the optimal tour for the problem has been found and put inoptimalResultsfolder, elsefalseGIVEN_COORDINATES:trueif the problem provides coordinates, elsefalse
- The problems whose dimensions are greater than or equal to 10000 are not considered.
- The two problems
lin318.tspandlinhp318.tsphave the same name and data.
Therefore, thelinhp318.tspproblem is not considered. - The problem
dsj1000.tsphasCEIL_2Das itsEDGE_WEIGHT_TYPE. Meanwhile, theTSPLIB_BestKnownSolution.jsoncontains two records of thedsj1000.tspproblems:dsj1000EUC_2Danddsj1000CEIL_2DwithEUC_2DandCEIL_2DasEDGE_WEIGHT_TYPErespectively.
Therefore, the recorddsj1000EUC_2Dis removed and the recorddsj1000CEIL_2Dis 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.gitor 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" /MNote:
- 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/TSPNote: 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~1200is 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 settingdataas 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 settingdistanceMatricesas 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 settingoptimalResultsas default. -
OUTPUT_FOLDER: path to the output folder.
Highly recommend settingoutputas 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 (yesorno). -
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.txtThe 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.txtThe 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.txtThe 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.txtThe 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.txtThe 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.txtThe 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.txtThe result will then be printed to the output.# TSP