Using Genetic Algorithms to solve Vehicle Route Optimization Problem | by Umang Udbhav | Jul, 2024


Genetic algorithms (GAs) are a class of optimization algorithms inspired by the principles of natural selection and genetics. They are particularly useful for solving complex optimization problems where traditional methods might struggle. GAs work by evolving a population of candidate solutions over several generations, using operators selection, crossover, and mutation to explore the solution space. Crossover is a process where we combine parts of two solutions to create a new solution, similar to how offspring inherit traits from both parents. Mutation randomly alters parts of a solution to introduce diversity and help find new and potentially better solutions.

The strength of GAs lies in their ability to find near-optimal solutions in large and complex search spaces, making them suitable for the Vehicle Route Optimization Problem.

A YouTube video to have a better understanding of how genetic algorithms work : https://youtu.be/-kpcAa-qKwY?si=QE96JpPgn-QcuKvB

The Vehicle Routing Problem (VRP) is a complex optimization challenge in which the objective is to determine the most efficient routes for a fleet of vehicles to deliver goods or services to a set of locations. Each vehicle starts and ends at a central depot, and each location must be visited exactly once. The primary goal is to minimize the total distance traveled and balance the distance travelled by each vehicle.

VRP is highly relevant in logistics and supply chain management because efficient vehicle routing can lead to significant cost savings and improved service levels. Key benefits include:

  • Reduced Operational Costs: By minimizing the total distance traveled and optimizing the use of vehicles, companies can lower fuel consumption, maintenance costs, and labor expenses.
  • Environmental Impact: Optimized routes contribute to lower emissions and a smaller carbon footprint, supporting sustainability goals.
2D visualization of depot(in red) and locations(in blue)

Objective: Define how solutions (individuals) are represented and how a population of these solutions is initialized.

  • Creator: Defines the fitness function (FitnessMin) which we want to minimize. Individual is a list of indices representing the route.
  • Toolbox:
  • indices: Generates a random permutation of location indices.
  • individual: Creates an individual by shuffling location indices.
  • population: Initializes a population of individuals.

Rationale: The permutation of indices represents the order of locations each vehicle will visit. This is a natural fit for permutation-based problems like VRP.

Objective: Evaluate how good a solution (individual) is based on total distance and balance of vehicle routes.

  • Distance Calculation: Computes the distance traveled by each vehicle using Euclidean distance.
  • Balance Penalty: Measures the standard deviation of distances across vehicles to ensure balanced routes.

Objective: Set up crossover, mutation, and selection methods to evolve solutions.

Crossover (cxPartialyMatched):

  • Method: Partially Matched Crossover (PMX) is suitable for permutation problems. It ensures offspring maintain valid permutations.

Mutation (mutShuffleIndexes):

  • Method: Shuffles indices with a small probability of 5% at each index, preserving permutation validity.

Selection (selTournament):

  • Method: Tournament selection randomly selects a subset of 3 individuals and picks the best among them. It maintains diversity and helps prevent premature convergence.

Seeding the Random Number Generator: Sets the seed for the random number generator to ensure reproducibility of results. Using a fixed seed allows for consistent results across multiple runs, which is crucial for debugging and comparing results.

Generating the Initial Population: Creates an initial population of 300 individuals (solutions). Each individual represents a possible route configuration for the VRP. The size of the population affects the diversity of solutions and the performance of the GA.

Setting Up the Hall of Fame: Initializes the Hall of Fame (HoF) to keep track of the best individual found during the run. Here, 1 indicates that only the single best individual is stored. The HoF helps in easily accessing the optimal solution found by the algorithm.

Setting Up Statistics Tracking: Configures statistics to track during the GA execution. Statistics is used to gather and report data about the population.

  • "avg": Registers the average fitness value of the population. This helps in understanding the overall progress of the GA.
  • "min": Registers the minimum fitness value. This shows the best fitness in the population at any point, indicating the best solution found so far.

Running the Genetic Algorithm: Executes the eaSimple algorithm using the DEAP library.

  • pop: The initial population of individuals.
  • toolbox: Contains the genetic algorithm operations (e.g., evaluation, crossover, mutation).
  • 0.7: Crossover probability. 70% of the population will undergo crossover operations.
  • 0.2: Mutation probability. 20% of the population will undergo mutation operations.
  • 500: Number of generations to evolve the population.
  • stats=stats: Passes the statistics object to collect and report statistics during the run.
  • halloffame=hof: Passes the Hall of Fame object to keep track of the best solutions found.
Optimal route for the vehicles

In my experience with optimizing the Vehicle Routing Problem (VRP) using genetic algorithms, the DEAP library and its eaSimple algorithm have proven to be incredibly powerful and flexible tools.

DEAP offers a full suite of genetic algorithm tools and eaSimple algorithm offers a straightforward way to implement genetic algorithms, making it easy to set up and customize. The algorithm efficiently explores and converges towards optimal solutions over multiple generations.

Ford Motor Company has applied genetic algorithms to streamline the design and production processes of its vehicles. In one notable application, Ford used genetic algorithms to optimize the design of car components. The use of genetic algorithms enabled Ford to simulate thousands of potential designs rapidly and identify the most optimal ones before creating physical prototypes, significantly speeding up the development process and reducing expenses.

Recent Articles

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here