This repository contains algorithms to solve the CVRP (Capacitated Vehicle Routing Problem) in C++ and incorporating Machine Learning (ML) from python
- Genetic Algorithm (GA)
- Genetic Algorithm (GA) - Machine Learning (ML)
git clone https://github.com/sakshisingh1809/CVRP-with-GA.git
cd cvrp
mkdir build
cd build
cmake .. && make -j4
./cvrp
- The code contains
Problem
,Solution
andVehicle
classes. Each algorithm implementation has its own class and inherits theSolution
class. - The problem is setup using the
Problem
class which specifies the number of nodes (centres/dropoff points), maximum demand, number of vehicles, their capacity, the grid range and the type of distribution. The demand for each centre as well as its location is randomly generated. - A base class called
Solution
has been created to store the basic elements of the solution in a user friendly format. This includes avector
of instances of theVehicle
class. - The
Vehicle
class stores the vehicle id, the route it takes, the total capacity, the number of units still left in the vehicle, and the cost associated with the vehicle's route. The<<
operator is overloaded to show the status of the node and vehicle respectively.PrintVehicleRoute()
prints only the route of the vehicle. - The
Solution
class also contains a virtual method calledSolve()
. Each algorithm class overrides theSolve()
method. - The
Solution
class also contains a method calledPrintSolution(option)
with the an input option (option
) to print vehicles' statuses or routes in addition to the total cost and validity of the solution.
- The documentation for private functions (such as operators in the
GASolution
class) has been made available to aid understanding. - Custom hybrid algorithms, that involve feeding in the solution of 1 algorithm to another can easily be implemented, as the structure allows the extraction of solution from the algorithm classes. An example is shown at the end of
main.cpp
.