adityajamdar/freight-pricing-simulator
Truckload Contract Pricing Simulator
Overview
This project is a proof-of-concept (POC) demonstrating an end-to-end workflow for a data-driven truckload pricing engine. It showcases how machine learning and optimization can be combined to make intelligent pricing decisions in the freight industry.
The core idea is to move beyond simple cost-plus pricing and instead use a model that understands price elasticity—how the probability of winning a bid changes as the price changes. This win-rate model then feeds into an optimization engine that selects the price maximizing expected profit.
Methodology
The project follows a three-step methodology:
- Synthetic Data Generation: A realistic dataset is created to simulate historical bidding data. It includes a rich set of features that typically influence bid outcomes, such as distance, customer tier, incumbency, and lane characteristics.
- ML Elasticity Modeling: Two machine learning models are trained to predict the probability of winning a bid:
- Logistic Regression: A standard, interpretable model for binary classification.
- LightGBM (LGBM): A powerful gradient boosting framework that can capture complex, non-linear relationships. These models learn the relationship between the bid price (and other features) and the win/loss outcome.
- Expected-Profit Optimization: The win probabilities from the ML models are used to calculate the expected profit for a range of potential prices. A Mixed-Integer Linear Program (MILP) is then used to formally select the single price that maximizes this expected profit. The formula is:
Expected Profit = (Price - Cost) * P(Win | Price)
Project Structure
The project is organized into a modular structure to ensure clarity and maintainability:
├── app.py <- The main Gradio application.
├── data
│ └── synthetic_bids.csv <- The generated dataset.
├── notebooks
│ └── truckload_pricing_demo.ipynb <- The main demo notebook.
├── src
│ ├── data_generation.py <- Logic for creating the dataset.
│ ├── modeling.py <- ML model training and prediction.
│ ├── optimization.py <- MILP logic for price optimization.
│ └── plotting.py <- Helper functions for visualizations.
├── README.md <- This file.
└── requirements.txt <- Project dependencies.How to Run the Project
There are two ways to engage with this project:
1. The Interactive Gradio Demo (Recommended)
This is the fastest way to see the pricing engine in action.
- Ensure all dependencies are installed:
pip install -r requirements.txt- Run the app:
python app.py This will launch a web server. Open the local URL (e.g., http://127.0.0.1:7860) in your browser to use the simulator.
2. The Jupyter Notebook
This allows you to step through the data generation, model training, and optimization process in detail.
- Clone the repository and install dependencies (if you haven't already).
- Launch Jupyter Lab:
jupyter lab- Run the notebook: Open the
notebooks/truckload_pricing_demo.ipynbfile in Jupyter Lab and run the cells from top to bottom. The notebook will: - Generate the synthetic dataset.
- Train both the Logistic Regression and LightGBM models.
- Save the trained model pipelines (
.joblibfiles) to thenotebooks/directory so they can be used by the Gradio app. - Run a sample optimization.
How to Extend the Project
This POC is a strong foundation that can be extended in several ways:
- Incorporate Real Data: Replace the synthetic data generator with a real-world dataset of historical bids.
- Add More Features: Enhance the dataset with more complex features, such as market-level data (e.g., tender rejection rates like OTRI) or macroeconomic indicators.
- Portfolio Optimization: Expand the optimization model to price a portfolio of multiple lanes simultaneously, subject to overall capacity or revenue constraints.
- Deploy as an Interactive App: The project already includes a Gradio web application. This can be easily deployed to services like Hugging Face Spaces for public access.
