This homework is to be prepared in teams of two students. Find your partner on http://moodle.uni-graz.at/. Download hw_6.tar.gz and extract it. Then add your homework solutions to the directory. Rename the directory according to the rules in the syllabus before submitting it as compressed archive. Don't forget to add the correct subject to the email when submitting.
Properly document the files you hand in to receive full credit. Each module (file), class and function needs a docstring. The purpose of each function needs to be summarized as a single sentence and then, if required, your intent and the behavior of the function can be described in more detail.
Furthermore - provide doctests for all functions and classes.
Each of the modules
needs to include a main()
function which calls the other functions and prints
appropriate output to stdout
.
main()
itself must be called by the ifmain pattern at the end of the file.
Algorithm
that
defines an API for a
travelling salesman problem (TSP) algorithm.time
, ov
, and
solution
, where time
and
ov
are floating-point numbers and
solution
is a list of integers each denoting a vertex.solve(self, instance)
. solve(.)
must call the
method algorithm(self, instance)
which is not implemented
and measure its execution time.
Both methods take the parameter instance
which is an object
of the class Instance2D
in the file
instance2D.py. The API should be used
in the following way:
from instance2D import Instance2D
instance = Instance2D("filename.tsp")
algorithm = Algorithm()
algorithm.solve(instance)
print(algorithm.time)
print(algorithm.ov)
print(algorithm.solution)
"""
T
and NN
, which
implement the method algorithm(self, instance)
and solve the TSP by two different algorithms:
T
just orders the vertices one
after another, i.e. if the test instance has 5 vertices,
the solution will be [0, 1, 2, 3, 4, 0]
.NN
implements the
nearest neighbour heuristic startetd from the vertex
0
.solve_moore(filename)
)
has to be a Python list containing project ids (the sequence in which the
projects should be processed). Only the projects that can be completed in
time should be part of that list. The remaining jobs should be discarded.
project | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
duration | 5 | 3 | 7 | 2 | 9 | 6 | 5 |
due time | 6 | 16 | 27 | 19 | 14 | 17 | 21 |
project | duration | due time |
1 | 5 | 6 |
2 | 3 | 16 |
3 | 7 | 27 |
... |
solve_moore(filename)
and checks if the results are correct.