Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Files for Productivity Hacks talk.

Some files for talk about Productivity Hacks.

#!/bin/bash
for method in nearest_insertion farthest_insertion cheapest_insertion arbitrary_insertion nn repetitive_nn two_opt
do
sed "s/# \(.*${method}\)/\1/" travelling-salesman.R | R --slave &
done
wait
#!/bin/bash
for method in nearest_insertion farthest_insertion cheapest_insertion arbitrary_insertion nn repetitive_nn two_opt
do
sed "s/# \(.*${method}\)/\1/" travelling-salesman.R | R --slave
done
# CONFIGURATION -------------------------------------------------------------------------------------------------------
# METHOD = 'nearest_insertion'
# METHOD = 'farthest_insertion'
# METHOD = 'cheapest_insertion'
# METHOD = 'arbitrary_insertion'
# METHOD = 'nn'
# METHOD = 'repetitive_nn'
# METHOD = 'two_opt'
# Conversion factor. Set this to 1.60934 for length in km.
#
CONVERSION = 1.0
# ---------------------------------------------------------------------------------------------------------------------
library(TSP)
# Distances between 312 cities in the USA and Canada.
#
data(USCA312)
solution = solve_TSP(USCA312, method = METHOD)
cat(sprintf("%-19s -> tour length = %d\n", METHOD, tour_length(solution) * CONVERSION))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment