In this version of the travelling saleseman problem we assume that the
graph is fully connected and the goal is to find the shortest path.
You are given a statement of the problem which is the list
of all the cities and their coordinates in the following form:
( (City1 X1 Y1) (City2 X2 Y2) (City3 X3 Y3) .... ).
The statement of the problem is stored in file cities.dat
.
You are also given the file skel1.lisp
which has the skeleton of the
code. It has functions for reading the input file, generates all the
permutations
and prints them. You are asked to modify the code in the following
way:
1.(3) Remove the city coordinates to make the output more readable
(modify the function print in permute)
2.(3) Modify file skel1.lisp such that all the tours start in City1.
3.(9) Modify the code to compute the tour lengths and solve the TSP
by
printing the shortest tour length and the corresponding
tours.
Tour length is Euclidean distance between the cities i
and j given by:
(sqrt (+ (* x x) (* y y))) where x = xj-xi and y
= yj-yi
i and j
File cities.dat uses different sizes of the problem. Use the smaller
sizes
to debug your code first. The individual problem involve making
incrementaly mode difficult changes to some of the functions which
were
given as a start. For each case you should write the following functions
and
name the appropriately, such that at the upper level all one needs
to call and get the appropriate behavior by running appropriate
function.
1. Function called permute1 which prints the output without city coordinates.
2. Function permute2 which generates all permutations starting with
the first city
3. Function called permute3 and solve_tsp3 returns the shortest tours
and their
lenghts.
Hints: There are two marcos which we did not use yet. Here is their
description
to help you understand the code:
Function format for printing things out in a formatted way (such as
printf).
The most common arguments are ~A which stands for variable and ~% which
stands
for newline.
> (setq h '(1 2 3))
> (format t "~A " h)
(1 2 3)
NIL
Function :
(dolist (variable list)
body )
takes a list and executes the body by instantiating variable to different
elements of the list. There can be a third optional argument
which
the function returns at the end. For example:
> (dolist (x '(a b c d) 'done)
(format t "~A" x))
A B C D
done
The subsequent versions of your functions should include the features
developed in the previous versions (e.g. not printing the coordinates).
If
you will write some auxiliary functions which your implementation of
permute or solve_tsp use, define them in the same file. Comment your
code.
Instructions for submission:
----------------------------
(1) Using script or dribble, you are to capture the output of a Lisp
session
in which you successfully load and execute your
code, showing sufficient
testing of your function(s). On osf1 type script
and your session
will be saved in a file typescript, whose hardcopy
you will hand in.
To exit script simply type 'exit'.
(2) a. In class hand in a hardcopy report consisting of:
- a cover sheet containing:
Your name
CS580 Spring 2001,
J. Kosecka
Homework #3
(A short summary stating
whether you were successful, describing
any problems,
etc.)
- a print out of the Lisp code.
- a printout of a captured Lisp
session involving the execution of
the HW3 Lisp code.
b. Send a SINGLE email to clevcovi@cs.gmu.edu formatted
in the
following way:
- the subject field of the email should read: CS580 HW#3 Kosecka
- the content of the email should
be a commented version of the
Lisp code for HW3.
Comments at the top should include:
Your name
CS580 Spring 2001,
J. Kosecka
Homework #3
As a safety precaution,
always CC yourself when you submit homework
this way and keep
it around until it has been graded and returned.