Skip to content

A multi-threaded gas station simulation for Linux, featuring dynamic vehicle queues, fuel tracking, priority management, and JSON-based configuration. πŸš—β›½πŸš›

Notifications You must be signed in to change notification settings

liubomyr123/gas-station-simulation

Repository files navigation

Gas Station Simulation

Project description is outdated, documentation in progress. More details in description.txt files.

Overview

This project simulates a gas station where different types of vehicles arrive to refuel. The simulation includes queue management, fuel consumption tracking, and various optimization strategies for prioritizing vehicles. The project is designed to run on Linux-based systems.

Features

  • Supports multiple vehicle types with different fuel consumption rates:
    • πŸš— Auto: 10L/100km
    • πŸš™ Van: 15L/100km
    • πŸš› Truck: 30L/100km
  • User-defined number of vehicles per type.
  • Dynamic queue system where vehicles wait for available fuel points.
  • Separate fuel points exclusively for trucks.
  • Vehicles leave the station if fuel is insufficient.
  • Logging system that tracks refueling events and waiting times.
  • Results are saved to a file.

Requirements

  • Linux OS (a warning is displayed if a different OS is detected).
  • A multi-threaded environment (number of threads is auto-detected).
  • JSON file support for structured input.

Setup & Compilation

To compile the project, use:

make

To build and run the simulation in one step:

make start

To run the simulation after building:

make run

For debugging purposes:

make start_debug

Input Configuration

The user can either enter the number of cars manually or use a JSON file to specify details. Example JSON format:

{
  "total_fuel": 999999999,
  "vehicles": [
    {
      "type": "auto",
      "fuel_by_car": 10,
      "waiting_time_sec": 2,
      "count": 5
    },
    {
      "type": "van",
      "fuel_by_car": 15,
      "waiting_list": [
        { "waiting_time_sec": 2, "count": 3 },
        { "waiting_time_sec": 5, "count": 7 }
      ]
    },
    {
      "type": "truck",
      "fuel_by_car": 30,
      "waiting_list": [
        { "waiting_time_sec": 15, "count": 10 },
        { "waiting_time_sec": 9, "count": 2 }
      ]
    }
  ]
}

Simulation Logic

  1. Step 1: Ask the user for the number of cars and the total available fuel.
  2. Step 2: Introduce different car types and allow the user to specify how many of each type to include.
  3. Step 3: Store all results into a file.
  4. Step 4: Implement a queue where each vehicle has a waiting time. If a car exceeds this waiting time, it leaves the station.

Output Example

[00:00:00] πŸš— Auto #1 is refueling...
[00:00:02] πŸš™ Van #2 arrived at the station. Waiting...
[00:00:05] πŸš› Truck #3 left due to long waiting (timeout).
[00:00:07] πŸš— Auto #1 left the station. Fuel used: 10L
[00:00:10] 🚚 Tanker #1 arrived at the station to deliver fuel.

Future Improvements

  • Implement more advanced priority handling.
  • Add support for real-time monitoring via a graphical interface.
  • Optimize queue management using different scheduling algorithms.

License

This project is open-source and available under the MIT License.

About

A multi-threaded gas station simulation for Linux, featuring dynamic vehicle queues, fuel tracking, priority management, and JSON-based configuration. πŸš—β›½πŸš›

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published