travels.icn: Program to animate the traveling salesman problem

September 17, 1997; Gregg M. Townsend
Requires: Version 9 graphics
This file is in the public domain.
Usage:  travels [window options] [-q] [npoints]

   -q        (quiet) suppresses commentary normally written to stdout

   npoints   seeds the field with that many initial cities
             and sets the count for the "reseed" button


   travels illustrates several heuristic algorithms for obtaining
approximate solutions to the traveling salesman problem.  Cities may
be seeded randomly or entered with the mouse.  Speed may be controlled
using a slider.  The CPU time, number of cities, and path length are
displayed on a status line and written to standard output after every
major action.
____________________________________________________________

   Several types of controls are provided.  New cities may be added
at any time, invalidating any current path.  At least two cities must
be seeded before a path can be constructed.  A path must be constructed
before any of the optimization algorithms can be applied.

   For a description on of the algorithms used, see:
      David S. Johnson
      Local Optimization and the Traveling Salesman Problem
      Proc. 17th Colloquium on Automata, Languages, & Programming
      Springer-Verlag (1990), pp. 446-461


Mouse Actions:

   Clicking the left mouse button adds a new point.


Keyboard Actions:

   The digit 0 clears all points.
   The digits 1 through 9 seed 1 to 81 (n ^ 2) new points.

   Each of the pushbuttons below also has a keyboard equivalent
   which is indicated on the pushbutton.


Pushbuttons:

  Removing and adding points:
     Clear      Remove all points
     Reseed     Add n random points (a command option, default 20)

  Path construction:
     Initial    Connect points in order of initialization
     Random     Random path
     Strip      Strip-wise construction
     NearNbr    Nearest-neighbor algorithm
     NearIns    Nearest-insertion algorithm
     FarIns     Farthest-insertion algorithm
     Greedy     Greedy algorithm

  Optimizations:
     2-Adj      Swap pairs of adjacent points
     Uncross    Swap pairs of intersecting segments
     2-Opt      Swap all segment pairs that shorten the path

  Control:
     List       List coordinates of points on standard output
     Refresh    Redraw the screen
     Quit       Exit the program


Delay Slider:

   The delay slider can be used to slow down the action.  It specifies a
number of milliseconds to pause before visiting a new point or drawing
a new path segment.  Its response is nonlinear in order to allow finer
control of short delays.  Delays are inexact due to system granularity
and other problems.

   Unfortunately, the delay slider can only be changed between actions,
not during construction or optimization.

Source code | Program Library Page | Icon Home Page