Skip to content

Repository files navigation

Vehicle Routing Problem Solver

A modular C implementation of the Vehicle Routing Problem (VRP). The project compares constructive heuristics, local search, iterated local search, and an exact solver for small instances. Every generated route is checked by an independent validation layer before it is reported.

Algorithms

  • Naive sequential baseline
  • Nearest Neighbor with 2-opt improvement
  • Time-limited Iterated Local Search (ILS) with 2-opt
  • Exact backtracking for small, single-vehicle inputs

Validation

The validator checks that:

  • every route begins and ends at the depot;
  • every client is visited exactly once;
  • vehicle capacity limits are respected;
  • the stored distance matches an independent recalculation.

Build

Requires a C11-compatible compiler.

gcc -Wall -Wextra -std=c11 \
  main.c input.c distance.c validation.c heuristic.c exact.c \
  -o task3 -lm

Run

Plain mode prints the total distance followed by the vehicle routes:

./task3 --plain < input/in.txt

Detailed mode compares the algorithms, execution times, validation results, and known reference gaps:

./task3 < input/in.txt

Input Format

clientCount vehicleCount maxClientsPerVehicle
client1_x client1_y
client2_x client2_y
...
clientN_x clientN_y
depot_x depot_y

The depot is represented as 0; clients are represented as 1..clientCount.

Project Structure

  • main.c: program flow and output modes
  • input.*: input parsing
  • distance.*: distance matrix and route calculations
  • validation.*: independent solution checks
  • heuristic.*: baseline, Nearest Neighbor, 2-opt, and ILS
  • exact.*: exact backtracking for small instances
  • input/: sample and test inputs
  • output/: example plain and detailed outputs
  • docs/: implementation notes and reference results

Reference Values

The reference values in docs/optimal_solutions.pdf are used only to report the percentage gap; they do not influence route construction.

About

Modular C solution for the Vehicle Routing Problem using heuristics, 2-opt, ILS, exact search, and validation.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages