completed · optimization / algorithms · 2026

Package Router


problem solved

This package routing system is a rebuild of a previous academic project.

The original academic solution only accounted for a set number of packages and trucks. Additionally, package loading per truck was hard-coded. This resulted in a "solution" that had zero randomness tolerance and was not scalable.

This solution uses one genetic algorithm to solve both package loading and routing. First, configurable constraint distributions simulator random package generation, and truck counts scale automatically according to demand. The GA then tackles the bulk of the work, testing through thousands of generations which loading + route combination results in the best score (lowest fleet milage & fewest constraints violations).



algorithm pipeline

bundle_packages() group by address, validate constraint compatibility
↓
create_population() capacity-aware chromosome seeding
↓ GA loop
fitness()

multi-objective scoring

tournament_selection()

k=3 pressure selection

ordered_crossover()

sentinel-aware recombination

mutate()

four-strategy adaptive mutation

↓
load_chromosome() assign packages to truck objects
↓
run_simulation() delivery execution at 18 mph

chromosome encoding

A complete multi-truck routing solution is represented as a single flat array. Negative integers act as sentinels — boundaries between truck routes. Positive integers are bundle IDs. Order within each segment is the delivery sequence for that truck.

2 5 3 -1 7 1 -2 4 6 truck 1 truck 2 truck 3

This encoding lets a single crossover or mutation operator affect both assignment (which truck gets a bundle) and sequencing (what order it delivers) in one operation.


♜ stack ♖

languages

python

algorithm

genetic algorithm vrp-tw

core concepts

chromosome encoding tournament selection ordered crossover adaptive mutation

cli

argparse colorama

testing & tooling

pytest uv