EX_03/level-2/tsp/subject.txt
2025-09-23 08:41:21 +01:00

64 lines
1.8 KiB
Plaintext

Assignment name: tsp
Expected files: *.c *.h
Allowed functions: write, sqrtf, getline, fseek, fscanf, ferror, feof,
fabsf, memcpy, fprintf, fclose, malloc, calloc, realloc, free, fopen,
errno, stderr, stdin, stdout
-------------------------------------------------------
The first publication referring to this problem as the "traveling salesman
problem" is found in the 1949 RAND Corporation report by Julia Robinson,
"On the Hamiltonian game (a traveling salesman problem)."
Here is how she defines the problem:
"The purpose of this note is to give a method for solving a problem related
to the traveling salesman problem. It seems worthwhile to give a description
of the original problem. One formulation is to find the shortest route for a
salesman starting from Washington, visiting all the state capitals and then
returning to Washington.
More generally, to find the shortest CLOSED CURVE containing n given points
in the plane."
for example with the following set of cities:
0, 0
1, 0
2, 0
0, 1
1, 1
2, 1
1, 2
2, 2
which can be presented as follows:
+ + +
+ + +
+ +
the shortest path is:
_____
|__ |
|__|
so you should print the length of this path that is:
8.00
Write a program that will read a set of city coordinates in the form
'%f, %f\n' from the standard input and will print the length of the shortest
possible path containing all these cities under the form '%.2f'.
Your program will not be tested with more than 11 cities.
You will find in this directory a file tsp.c containing all the boring parts of
this exercise and example files to help you test your program.
hint: in order to use sqrtf, add -lm at the end of your compilation command.
For example this should work:
$> cat square.txt
1, 1
0, 1
1, 0
0, 0
$> ./tsp < square.txt | cat -e
4.00$
Hint : in order to use sqrtf , add -lm at the end of your compilation command