iFoxz17 / Highway_minimum_path

C project to solve a linear variant of the minimum path problem.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Highway_minimum_path

C project to solve a linear variant of the minimum path problem.

Description

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.

Commands

Five commands avaibles:

  • aggiungi-stazione distance cars-number car-1 ... car-n

    • Add a station to the highway, identified by distance and having cars-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
  • demolisci-stazione distance

    • Remove the station at the indicated distance, if exists.
    • Expected output: demolita / non demolita
  • aggiungi-auto station-distance car-fuel

    • Add a car with the specified car-fuel to the station at the given station-distance, provided that the station exists. It is possible to have more than one car with the same fuel.
    • Expected output: aggiunta / non aggiunta
  • rottama-auto station-distance car-fuel

    • Removes a car with the indicated car-fuel from the station at station-distance, if exists.
    • Expected output: rottamata / non rottamata
  • pianifica-percorso start-station end-station

    • Plan the route with the fewest stops between start-station and end-station, assuming one exists. Stations are identified by their distance. It is possible to travel the highway backward just inserting start-station $>$ end-station.
    • Expected output:
      • If the route exists: ordered sequence of stations distances, including start-station and end-station.
      • If the route does not exist: nessun-percorso

Usage

  • Compile with the make tool
  • Receive commands from stdin
  • Outputs results on stdout
  • Example using BASH: cat _commands_path_ | ./main

Documentation

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.

Tests

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 with gcc run_tests.c -o run_tests;
  • Extract all the tests from compressed archive into the directory test;
  • Run the executable run_tests (./run_tests).

Notes

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).

About

C project to solve a linear variant of the minimum path problem.


Languages

Language:C 99.3%Language:Makefile 0.7%