C project to solve a linear variant of the minimum path problem.
Consider an highway containing several stations; each station stands at a given distance and can have an arbitrary number of cars with a fixed quantity of fuel, which allows the car to travel a certain distance. Given a start station and an end station, the goal is to find the minimum number of stops (and the sequence of stations) that allows to travel from the starting station to the ending one.
Formally, given:
- A set of stations
$S=$ {$s_1, s_2, ..., s_n$ }; - A function
$d : S \rightarrow \mathbb{N}$ , that associates at every station his distance; - A function
$c : S \rightarrow \mathbb{N}$ , that associates at every station the car with the max fuel;
Find
-
$k \in N$ , the minimum number of stops that allows to reach$s_n$ from$s_1$ , -
$M=$ {$s_1, s_{i_1}, s_{i_2}, ..., s_{i_k}, s_n$ }, the optimal sequence of stations.
Five commands avaibles:
-
aggiungi-stazione distance cars-number car-1 ... car-n
- Add a station to the highway, identified by
distance
and havingcars-number
vehicles. The fuels of each vehicle are listed after the number of vehicles. If a station at a given distance already exists, no insertion is performed. -
Expected output:
aggiunta
/non aggiunta
- Add a station to the highway, identified by
-
demolisci-stazione distance
- Remove the station at the indicated
distance
, if exists. -
Expected output:
demolita
/non demolita
- Remove the station at the indicated
-
aggiungi-auto station-distance car-fuel
- Add a car with the specified
car-fuel
to the station at the givenstation-distance
, provided that the station exists. It is possible to have more than one car with the same fuel. -
Expected output:
aggiunta / non aggiunta
- Add a car with the specified
-
rottama-auto station-distance car-fuel
- Removes a car with the indicated
car-fuel
from the station atstation-distance
, if exists. -
Expected output:
rottamata / non rottamata
- Removes a car with the indicated
-
pianifica-percorso start-station end-station
- Plan the route with the fewest stops between
start-station
andend-station
, assuming one exists. Stations are identified by their distance. It is possible to travel the highway backward just insertingstart-station
$>$ end-station
. -
Expected output:
- If the route exists: ordered sequence of stations distances, including
start-station
andend-station
. - If the route does not exist:
nessun-percorso
- If the route exists: ordered sequence of stations distances, including
- Plan the route with the fewest stops between
- Compile with the
make
tool - Receive commands from
stdin
- Outputs results on
stdout
- Example using BASH:
cat _commands_path_ | ./main
It is possible to generate HTML
documentation for the class through the doxygen tool. To do so, just install doxygen
, open the terminal in the project folder, and run the doxygen
command. It will automatically search for the Doxyfile which is in the folder and create a new folder containing the newly generated documentation. To read it, just go into the folder and open index.html
with your preferred browser.
Several tests with relative expected outputs are avaible in the directory test
as zip files; they can be run individually (using the Linux diff
tool for checking outputs, for example) or all together; for this last option:
- Compile the file
run_tests.c
withgcc run_tests.c -o run_tests
; - Extract all the tests from compressed archive into the directory
test
; - Run the executable run_tests (
./run_tests
).
For severals instances can be avaible multiple optimal solutions; as default is selected the solution which minimizes the distances from the start of the highway (both for forward or backward route), according to tests. This can be modified at compile time to upgrade perfomances (see module solver
in the documentation for more details).