cs102 lab9
http://www.maths.nuigalway.ie/~gettrick/teach/cs102/labs/2021labs/l9.html
-
For this lab you must submit all source code (python .PY files, or
JUPYTER .IPYNB notebooks)
and, if applicable, the result(s) of running the program on (a few)
test cases. This should be sent in via BLACKBOARD (not directly by email).
The source code must
be well presented (indenting, spaces, reasonable variable/function names,
etc.) and must include comments (as a rough guideline - aim to have nearly as
many comments as lines of code). Any questions asked should be answered by
typing the answers into the relevant box on the BLACKBOARD upload form.
-
This material should be uploaded
before
the deadline of 5pm
Saturday May 8th., 2021. You will lose 20% for each day
(or part of day) the lab is late. If you have a genuine reason for
submitting a late lab, please contact Scott before the lab
due date/time.
-
Plagiarism (the unattributed copying of work from other sources
(internet, fellow students,....)) will not be tolerated.
You risk getting zero for your lab if it is found to be
plagiarized.
Once again we consider
the (20x20) array of numbers here.
Lets say this represents a matrix A of distances (in kilometers) between
cities. Note that A is symmetric A(i,j) = A(j,i) and all its diagonal
elements are zero.
In our lectures, we have covered a greedy strategy to solve
the so-called travelling salesperson problem (TSP).
In that problem, the salesperson starts at a particular city
i, and wants to visit all the other cities j (where j
is not equal to i), and "return to base" (i), minimizing their
total distance travelled.
Write PYTHON code to calculate the best route, where the user inputs
the starting city i (as a number from 1 to 20).
Your program should output both the route and the total distance on that
route.
Calculate the total distance travelled if the TSP starts at city
-
i=6
-
i=13
©
NUI, Galway