Unformatted text preview: derstand. Your final solution is unlikely to be the optimal (best possible) solution, but that's
okay, so long as it isn't obviously terrible. Specific requirem ents
Data r epr esentation
There will be from 1 to 26 cities, with names " " " " " " etc. Each city will have an x y locat ion,
a, b, c,
which is a 2 tuple of floating point numbers, such as ( 4 . 2 2 5 5 ) where each number is between
730, 1.3,
0 0and 1 0 . . When I use the term d r c o yin the function descriptions below, it will refer to a
.
000
ietr
dictionary whose ke ys are city names and whose value s are the corresponding x y locations.
To represent either a circuit or a spanning tree, use a dictionary whose ke ys are city names, and whose
value s are a s e t of the names of the directly connected cities. In the function descriptions below, I will call
this kind of dictionary a r a _ a . For a circuit, each set will contain exactly two city names; for a spanning
odmp
tree, each set will contain one or more city names.
While I will require these particular data representations as function parameters and function results, this does
not imply that you have to work with these representations as you solve the problems. Python makes it easy
to convert from one kind of sequence to another. Requir ed functions (file c t e . y
iisp)
dfcet_iishwmn)
e raecte(o_ay
Given a number between 1 and 26, inclusive, creates that many cities, and returns them as a
drcoy
ietr.
dfpitcte(ietr)
e rn_iisdrcoy
Prints a list of cities, along with their locations. Print only one or two digits after the decimal
point.
dfcet_yl(ietr)
e raeccedrcoy
Returns a r a _ a that describes an initial (probably not very good) cycle.
odmp
dfcet_pnigte(ietr)
e raesann_redrcoy
Returns a r a _ a that describes an initial (probably not very good) spanning tree.
odmp
dfcmuecs(odmp drcoy
e opt_otra_a, ietr)
Returns, as a floating point number, the sum of the distances of all the connections in the
ra_a.
odmp
dfipoeccera_a,drcoy
e mrv_yl(odmp ietr)
Tries to modify the r a _ a to be slightly better (have a lower cost) and returns T u if it
odmp
re
succeeds, F l eif...
View
Full
Document
This document was uploaded on 02/02/2014.
 Spring '09

Click to edit the document details