CIT590- assignment 4

# Your final solution is unlikely to be the optimal

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern