Skip to content

ashrithabollam/forgentics-truck-optimization

Repository files navigation

Forgentics Take-Home Optimization Challenge

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.


Approach

Step 1 – Import and Setup

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.

Step 2 – Read and Validate Orders

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).

Step 3 – Heuristic Packing (First Solution)

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.

Step 4 – Exact Optimization (CP-SAT)

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.

Step 5 – Output and Validation

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_numbers is 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.

Results

  • Minimum trucks used: 10 (proven optimal).
  • Output: loads.csv with the exact load assignments.

How to Run

  1. Open the notebook or script in Google Colab (or any Python 3 environment).
  2. Upload orders.csv or orders.xlsx.
  3. Run the cells step by step.
  4. The program prints the load summary and generates loads.csv in the working directory.

Notes

  • 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.

About

Solution for Forgentics Take-Home Optimization Challenge

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors