Skip to content

Instantly share code, notes, and snippets.

@datawookie
Last active February 19, 2018 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save datawookie/d2863c14354a894a56dc22d4b7fd2f1f to your computer and use it in GitHub Desktop.
Save datawookie/d2863c14354a894a56dc22d4b7fd2f1f to your computer and use it in GitHub Desktop.
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