AI-powered supply-chain optimization and what-if scenario analysis for coffee distribution across India.
OptiGuide is a full-stack logistics optimization system that combines Gurobi's industrial-grade LP/MIP solver with OpenAI-powered natural-language what-if analysis to help supply chain managers find the least-cost distribution strategy β and instantly see how it changes under various disruption scenarios.
| Feature | Description |
|---|---|
| πΊοΈ Interactive Route Map | Real-time visualization of optimized supply routes on a dark-themed Leaflet map centered on India |
| π Cost Breakdown Charts | Doughnut chart segmentation of shipping, roasting, and management costs |
| π§ͺ What-If Scenarios | AI-driven scenario simulation β ask natural language questions like "What if Supplier 1 capacity increases by 50%?" |
| π Point-to-Point Routing | Calculate logistics cost for specific originβdestination lanes |
| βοΈ Parameter Tuning | Sliders for supplier capacity, cafe demand, and cost multipliers |
| π Quick Presets | One-click scenario presets (Baseline, High Demand, Cost Shock, Cap Cut) |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FRONTEND (Static) β
β ββββββββββββ ββββββββββββ βββββββββββββ βββββββββββββ β
β β Leaflet β β Chart.js β β Lucide β β Vanilla β β
β β Map β β Doughnut β β Icons β β CSS/JS β β
β ββββββββββββ ββββββββββββ βββββββββββββ βββββββββββββ β
β index.html Β· app.js Β· style.css β
βββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββ
β HTTP (JSON) β port 8000
βββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββ
β BACKEND (FastAPI) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β main.py β REST API β β
β β βββ POST /optimize β run optimization query β β
β β βββ GET /health β backend status β β
β β βββ GET /api-check β OpenAI key validation β β
β β βββ GET /services β available service list β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β optiguide_service.py β Core Logic β β
β β βββ Gurobi LP Model (coffee distribution) β β
β β βββ OptiGuide Agent (AutoGen + OpenAI) β β
β β βββ Mock Mode (offline testing) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The system models a 3-tier coffee supply chain across Indian cities:
| Tier | Nodes | Cities |
|---|---|---|
| Suppliers | 3 | Delhi, Mumbai, Kolkata |
| Roasteries | 2 | Bengaluru, Hyderabad |
| Cafes | 3 | Chennai, Pune, Ahmedabad |
The optimizer finds the minimum-cost flow from suppliers β roasteries β cafes while respecting capacity constraints and demand requirements for both light and dark coffee variants.
- Python 3.10+
- Gurobi Optimizer (with a valid license β free academic licenses available at gurobi.com)
- OpenAI API Key (for AI-powered what-if analysis; optional if using Mock Mode)
git clone https://github.com/<your-username>/logistic-optimization-system.git
cd logistic-optimization-systemcd backend
# Create and activate virtual environment
python -m venv venv
# Windows
venv\Scripts\activate
# Linux/macOS
source venv/bin/activate
# Install dependencies
pip install fastapi uvicorn python-dotenv openai pydantic gurobipy pyautogenCreate a .env file in the backend/ directory:
OPENAI_API_KEY=sk-your-openai-api-key-here
MOCK_MODE=falseTip
Set MOCK_MODE=true to run the system without an OpenAI API key or Gurobi license. The backend will return realistic pre-computed scenarios for testing and demonstration.
cd backend
uvicorn main:app --reload --host 0.0.0.0 --port 8000Navigate to http://localhost:8000 in your browser. The frontend is served as static files by the FastAPI backend β no separate build step required.
logistic-optimization-system/
β
βββ backend/
β βββ main.py # FastAPI application & API routes
β βββ .env # Environment variables (API keys, mode)
β βββ test_optimize.py # Quick API test script
β βββ services/
β β βββ optiguide_service.py # Core optimization logic & mock engine
β βββ optiguide/ # OptiGuide library (AutoGen agent)
β β βββ what-if/ # What-if scenario analysis module
β βββ venv/ # Python virtual environment
β
βββ frontend/
β βββ index.html # Main dashboard UI
β βββ style.css # Full design system (glassmorphism, dark theme)
β βββ app.js # Application logic (map, charts, API calls)
β βββ components.js # Reusable UI component templates
β
βββ README.md # This file
Run an optimization query with optional parameter overrides.
Request Body:
{
"question": "What if Supplier 1 capacity increases by 50%?",
"params": {
"capacity": { "supplier1": 225, "supplier2": 50, "supplier3": 100 },
"demand": {
"cafe1": { "light": 20, "dark": 20 },
"cafe2": { "light": 30, "dark": 20 },
"cafe3": { "light": 40, "dark": 100 }
},
"multipliers": { "shipping": 1.0, "roasting": 1.0 }
}
}Response:
{
"cost": 685.2,
"breakdown": { "shipping": 342.6, "roasting": 205.6, "management": 137.0 },
"routes": [
{ "from": "supplier1", "to": "roastery1", "volume": 90, "cost": 450 },
{ "from": "roastery2", "to": "cafe3", "volume": 110, "cost": 220 }
],
"explanation": "Expanding Supplier 1 capacity enables higher Bengaluru throughput...",
"mode": "mock"
}Returns backend status and engine info.
{ "status": "ok", "mode": "mock", "engine": "OptiGuide + Gurobi", "version": "2.0.0" }Validates the configured OpenAI API key.
{ "valid": true, "mode": "production", "model_count": 42 }Lists all available optimization services.
{
"mode": "mock",
"services": [
{ "id": "route_opt", "name": "Route Optimization", "description": "Find least-cost shipping paths", "available": true },
{ "id": "what_if", "name": "What-If Analysis", "description": "AI-powered scenario simulation", "available": true }
]
}cd backend
# Quick endpoint test
python test_optimize.pyEnsure the server is running on localhost:8000 before executing the test script.
| Mode | MOCK_MODE |
Requirements | Description |
|---|---|---|---|
| Production | false |
OpenAI API key + Gurobi license | Full AI-powered optimization with real Gurobi solver |
| Mock | true |
None | Pre-computed scenario responses for demo/testing |
| Layer | Technology | Purpose |
|---|---|---|
| Backend Framework | FastAPI | High-performance REST API |
| Optimization Solver | Gurobi (gurobipy) | Linear/Mixed-Integer Programming |
| AI Agent | AutoGen + OpenAI GPT | Natural-language what-if queries |
| Map Visualization | Leaflet.js | Interactive route map |
| Charts | Chart.js | Cost breakdown doughnut chart |
| Icons | Lucide | Consistent, lightweight SVG icons |
| Typography | Inter + Outfit | Modern, clean UI fonts |
| Styling | Vanilla CSS | Glassmorphism dark theme with custom animations |
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is built on top of the OptiGuide framework by Microsoft Research, licensed under the MIT License.
Built with β€οΈ using FastAPI, Gurobi, and OpenAI