This project solves the Forgentics truck-loading problem. The goal is to assign metal plate orders to trucks so that:
- Every order ships today (no splits allowed).
- Each truck has a maximum capacity of 24.0 tons.
- All orders are delivered to the same customer (routing is ignored).
- The total number of trucks is minimized.
The input file is provided as orders.csv (or .xlsx) and the output is loads.csv.
The program is written in Python 3 and uses:
- pandas for reading/writing CSV/Excel.
- OR-Tools CP-SAT solver for the optimization.
- Built-in utilities (
Path,json, etc.) for clean file handling.
The code reads the orders file and normalizes the data.
It checks that:
- All sales order numbers are unique.
- Weights are positive and no order exceeds 24.0 tons.
To avoid floating-point errors, weights are multiplied by 10 and converted into integers (so 23.9 tons becomes 239 units).
Before optimization, the code builds a good initial packing:
- First-Fit Decreasing (FFD): orders are sorted from heaviest to lightest and placed in the first truck that fits.
- Best-Fit Decreasing (BFD): tries to minimize wasted space by filling the tightest remaining truck.
- The better of FFD and BFD is kept.
- A “squeeze pass” then attempts to eliminate the last truck by moving its items into earlier trucks.
This heuristic often reaches the minimum number of trucks immediately and also provides a warm start for the solver.
The packing is then proven optimal using CP-SAT:
- Decision variables assign each order to one truck.
- Constraints ensure:
- Each order is assigned exactly once.
- No truck exceeds 24.0 tons.
- Objective is to minimize the number of trucks.
The heuristic solution is provided as a hint to speed up solving. The solver confirmed that 10 trucks is both feasible and optimal for this dataset.
The final assignment is written to loads.csv with columns:
- load_id,so_numbers,total_weight_tons
- 1,"[SO-10001,SO-10012,...]",23.9
- ...
so_numbersis a bracketed list with no spaces after commas.- A console summary is also printed showing each load and weight.
- Automatic checks confirm:
- Every order is included exactly once.
- No truck exceeds 24.0 tons.
- Total weight matches the input.
- Minimum trucks used: 10 (proven optimal).
- Output:
loads.csvwith the exact load assignments.
- Open the notebook or script in Google Colab (or any Python 3 environment).
- Upload
orders.csvororders.xlsx. - Run the cells step by step.
- The program prints the load summary and generates
loads.csvin the working directory.
- The code is deterministic (same input -> same output).
- Integer scaling avoids rounding problems in capacity checks.
- The approach combines a practical heuristic for speed and an exact solver for proof of optimality.