Solve, time, and profile programs solving the traveling salesperson problem in various languages. Solution relies on use of graph object.

avg_calcs.sh 453B

123456789101112131415161718
  1. #!/bin/sh
  2. #
  3. # Extract the total calculation time from the output file.
  4. # Perform an averaging procedure on all numbers.
  5. # Report the result back.
  6. for f in `/bin/ls -1 avgtimeout_tsp*`
  7. do
  8. touch tmpfile
  9. cat /dev/null > tmpfile
  10. export N=$(echo $f | sed 's/^.*_\([0-9]\{1,\}\).out/\1/')
  11. export AVG=$(cat $f | grep "Elapsed" | cut -d" " -f3 | awk '{a+=$1} END{print a/NR}')
  12. echo "Average time : ${N}-node TSP problem : ${AVG} s"
  13. rm tmpfile
  14. done