Optimizing Maritime Logistics and Trade Operations
An advanced AI-powered optimization platform for minimizing bulk cargo transportation costs in HPCL's coastal vessel operations.
| # | Section |
|---|---|
| 1 | Overview |
| 2 | Problem Statement |
| 3 | Key Features |
| 4 | Architecture |
| 5 | Technology Stack |
| 6 | Quick Start |
| 7 | Project Structure |
| 8 | API Documentation |
| 9 | Usage Examples |
| 10 | Challenge 7.1 Specification |
| 11 | Performance Metrics |
| 12 | Development |
| 13 | Deployment |
| 14 | Contributing |
| 15 | License |
RouteX is an enterprise-grade maritime logistics optimization platform designed specifically for Hindustan Petroleum Corporation Limited (HPCL) to solve the Challenge 7.1: Coastal Vessel Optimization problem. The system minimizes bulk cargo transportation costs while satisfying complex operational constraints using advanced Constraint Programming (CP-SAT) algorithms powered by Google's OR-Tools.
RouteX tackles the Set Partitioning Problem in maritime logistics:
- 9 coastal tankers with varying capacities (25,000-50,000 MT) and charter rates (₹0.38-0.65 Cr/day)
- 6 loading ports with unlimited supply capacity
- 11 unloading ports with specific monthly demand requirements (5,000-135,000 MT)
- Complex routing constraints: Single-port loading, maximum 2-port discharge per trip
- Cost optimization: Minimize total transportation cost = Charter Rate × Trip Duration
Traditional manual planning methods are:
- Time-consuming: Days to weeks for a single monthly plan
- Suboptimal: Often 40-50% higher costs than optimal solution
- Error-prone: Human calculation mistakes in complex routing
- Inflexible: Cannot quickly adapt to changing demands or vessel availability
RouteX delivers:
- Speed: Optimal solutions in seconds to minutes
- Cost savings: 40-50% reduction in transportation costs
- Accuracy: Mathematically proven optimal or near-optimal solutions
- Flexibility: Real-time re-optimization for changing scenarios
Optimizing coastal tanker allocation is critical for cost-effective bulk cargo movement in HPCL's international and coastal trade operations. The objective is to develop an optimal transportation model for coastal shipping of bulk cargo using:
- Fleet: 9 coastal tankers
- Loading Network: 6 ports with unlimited supply
- Unloading Network: 11 ports with specific monthly demands
- Objective: Minimize total transportation cost while satisfying all demands
- Single-Port Full Loading: Each tanker must load its full capacity from only ONE loading port (no multiport loading)
- Maximum Two-Port Discharge: A tanker may unload at a maximum of TWO unloading ports per trip
- Unlimited Supply: Loading ports have unlimited cargo availability
- Demand Satisfaction: ALL unloading port demands must be fully met
Trip Cost = Charter Rate (₹ Cr/day) × Trip Duration (days)
Trip Duration includes:
- Loading port → First discharge port (sailing time)
- First discharge → Second discharge port (if applicable, inter-port sailing time)
- Loading/unloading service times
- Optional: Return journey to loading port
- CP-SAT Solver: Google OR-Tools Constraint Programming solver
- Set Partitioning Model: Pre-generates ~726 feasible route patterns
- Multi-Objective Support: Cost, time, emissions, or balanced optimization
- Solver Profiles: Quick (15s), Balanced (60s), Thorough (300s) modes
- Parallel Processing: Multi-threaded route generation and solving
- Real-time Vessel Status: Track all 9 HPCL tankers
- Vessel Specifications: Capacity, speed, fuel consumption, charter rates
- Dynamic Assignment: Automatic optimal tanker-to-route allocation
- Utilization Analytics: Fleet efficiency and utilization metrics
- 17 Indian Coastal Ports: 6 loading + 11 unloading ports
- Realistic Sea Routes: Integration with searoute-py for actual maritime distances
- Trip Time Tables: Pre-calculated voyage durations from challenge data
- Inter-Port Navigation: Optimal sequencing for multi-port discharge
- Cost Breakdown: Charter, fuel, port charges, cargo handling
- Demand Satisfaction: Real-time tracking of fulfilled/unfulfilled demands
- Fleet Utilization: Vessel working hours and efficiency metrics
- Emissions Tracking: EEOI (Energy Efficiency Operational Indicator) calculations
- Comparative Analysis: Optimal vs. manual planning cost comparison
- Real-time Visualization: Live maritime map with route playback
- Gantt Chart: Fleet timeline and voyage scheduling
- Results Export: CSV, JSON, PDF report generation
- Guided Tour: Interactive onboarding for new users
- Run History: Track and compare multiple optimization runs
- RESTful API: FastAPI with automatic OpenAPI documentation
- Type Safety: Full TypeScript frontend, Pydantic backend validation
- Async Operations: Non-blocking optimization with Celery task queue
- Database Flexibility: MongoDB support with in-memory fallback
- Comprehensive Testing: Unit, integration, and end-to-end tests
┌─────────────────────────────────────────────────────────────┐
│ Frontend Layer (Next.js) │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Dashboard │ │ Optimization │ │ Results │ │
│ │ (React) │ │ Panel │ │ Visualizer │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ ↕ HTTP/REST │
└─────────────────────────────────────────────────────────────┘
↕
┌─────────────────────────────────────────────────────────────┐
│ API Layer (FastAPI) │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Challenge │ │ Fleet │ │ Port │ │
│ │ Routes │ │ Management │ │ Management │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
↕
┌─────────────────────────────────────────────────────────────┐
│ Business Logic Layer (Services) │
│ ┌────────────────────────────────────────────────────┐ │
│ │ CP-SAT Optimization Engine │ │
│ │ • Route Generation (Set Partitioning Columns) │ │
│ │ • Constraint Modeling (CP-SAT Variables) │ │
│ │ • Objective Function (Cost Minimization) │ │
│ │ • Solution Extraction & Validation │ │
│ └────────────────────────────────────────────────────┘ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Cost │ │ Distance │ │ EEOI │ │
│ │ Calculator │ │ Calculator │ │ Calculator │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
↕
┌─────────────────────────────────────────────────────────────┐
│ Data Layer (Database) │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ MongoDB │ │ In-Memory │ │ Redis │ │
│ │ (Primary) │ │ (Fallback) │ │ (Cache) │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
↕
┌─────────────────────────────────────────────────────────────┐
│ Async Task Queue (Celery + Redis) │
│ • Long-running optimizations │
│ • Background analytics processing │
│ • Monitoring and alerts │
└─────────────────────────────────────────────────────────────┘
- MVC Pattern: Separation of concerns (Models, Views, Controllers)
- Repository Pattern: Database abstraction with in-memory fallback
- Service Layer: Business logic encapsulation
- Factory Pattern: Dynamic solver profile creation
- Observer Pattern: Real-time status updates via WebSocket (planned)
| Technology | Version | Purpose |
|---|---|---|
| Python | 3.11+ | Core programming language |
| FastAPI | 0.117+ | High-performance async web framework |
| OR-Tools | 9.0+ | Google's optimization library (CP-SAT solver) |
| Pydantic | 2.11+ | Data validation and settings management |
| Motor | 3.7+ | Async MongoDB driver |
| Celery | 5.4+ | Distributed task queue |
| Redis | 5.2+ | Message broker and caching |
| searoute | 1.4.3 | Maritime routing and distance calculation |
| NumPy | 1.26+ | Numerical computations |
| Pandas | 2.0+ | Data manipulation and analysis |
| Technology | Version | Purpose |
|---|---|---|
| Next.js | 14+ | React framework with SSR/SSG |
| React | 18+ | UI component library |
| TypeScript | 5.0+ | Type-safe JavaScript |
| Tailwind CSS | 3.4+ | Utility-first CSS framework |
| Phosphor Icons | Latest | Modern icon library |
| Recharts | Latest | Charting library for analytics |
| Google Maps | Latest | Interactive maritime maps |
- Uvicorn: ASGI server for FastAPI
- Pytest: Testing framework
- ESLint: JavaScript/TypeScript linting
- Git: Version control
Ensure you have the following installed:
- Python 3.11 or higher
- Node.js 18.0 or higher
- npm or yarn package manager
- MongoDB 5.0+ (optional, has in-memory fallback)
- Redis 6.0+ (optional, for async tasks)
git clone https://github.com/your-username/RouteX.git
cd RouteX# Navigate to backend directory
cd backend
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt# Navigate to frontend directory (from root)
cd frontend
# Install dependencies
npm install
# or
yarn installCreate .env file in backend directory:
# Backend Configuration
MONGODB_URL=mongodb://localhost:27017
DATABASE_NAME=hpcl_coastal_optimizer
USE_MONGODB=true
REDIS_URL=redis://localhost:6379/0
# API Settings
API_PREFIX=/api/v1
CORS_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
# Security
SECRET_KEY=your-super-secret-key-change-in-productionCreate .env.local file in frontend directory:
NEXT_PUBLIC_API_URL=http://localhost:8000# From backend directory
cd backend
# Start FastAPI server
python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 --reloadBackend will be available at: http://localhost:8000
API Documentation: http://localhost:8000/docs
# From frontend directory (new terminal)
cd frontend
# Start Next.js development server
npm run dev
# or
yarn devFrontend will be available at: http://localhost:3000
# From backend directory (new terminal)
cd backend
# Start Celery worker
celery -A app.core.celery_app worker --loglevel=info- Open browser and navigate to http://localhost:3000
- The guided tour will automatically start on first visit
- Navigate to Challenge 7.1 tab
- Click "Run Optimization" to solve the challenge problem
- View results in the Results Display panel
RouteX/
├── backend/ # Python FastAPI Backend
│ ├── app/
│ │ ├── __init__.py
│ │ ├── main.py # FastAPI application entry point
│ │ ├── api/ # API route handlers
│ │ │ ├── routes.py # Main API routes
│ │ │ └── challenge_routes.py # Challenge 7.1 specific endpoints
│ │ ├── core/ # Core configuration
│ │ │ ├── config.py # Settings and environment variables
│ │ │ └── celery_app.py # Celery task queue configuration
│ │ ├── data/ # Data fixtures and samples
│ │ │ ├── challenge_data.py # Challenge 7.1 exact specifications
│ │ │ └── sample_data.py # Sample vessel and port data
│ │ ├── models/ # Data models and schemas
│ │ │ ├── database.py # MongoDB models with in-memory fallback
│ │ │ └── schemas.py # Pydantic validation schemas
│ │ ├── services/ # Business logic services
│ │ │ ├── cp_sat_optimizer.py # CP-SAT optimization engine
│ │ │ ├── route_generator.py # Feasible route generation
│ │ │ ├── cost_calculator.py # Cost calculation service
│ │ │ ├── distance_calculator.py # Maritime distance service
│ │ │ ├── eeoi_calculator.py # Emissions calculation
│ │ │ ├── grid_manager.py # Spatial grid management
│ │ │ └── infeasibility_analyzer.py # Infeasibility diagnostics
│ │ └── tasks/ # Async Celery tasks
│ │ ├── optimization_tasks.py # Background optimization
│ │ ├── analytics_tasks.py # Analytics processing
│ │ └── monitoring_tasks.py # System monitoring
│ ├── tests/ # Test suite
│ │ ├── test_cost_calc.py
│ │ ├── test_demand_satisfaction.py
│ │ ├── test_end_to_end.py
│ │ └── test_route_time.py
│ ├── requirements.txt # Python dependencies
│ ├── pyproject.toml # Python project configuration
│ └── README.md # Backend documentation
│
├── frontend/ # Next.js Frontend
│ ├── src/
│ │ ├── app/ # Next.js app directory
│ │ │ ├── layout.tsx # Root layout
│ │ │ ├── page.tsx # Home page
│ │ │ └── globals.css # Global styles
│ │ ├── components/ # React components
│ │ │ ├── HPCLDashboard.tsx # Main dashboard
│ │ │ ├── OptimizationPanel.tsx # Optimization controls
│ │ │ ├── ResultsDisplay.tsx # Results visualization
│ │ │ ├── ChallengeOutput.tsx # Challenge 7.1 output
│ │ │ ├── FleetOverview.tsx # Fleet status cards
│ │ │ ├── MaritimeMap.tsx # Interactive map
│ │ │ ├── FleetGanttChart.tsx # Timeline visualization
│ │ │ ├── RunHistory.tsx # Optimization history
│ │ │ ├── GuidedTour.tsx # User onboarding
│ │ │ └── ...
│ │ └── utils/ # Utility functions
│ │ ├── formatters.ts # Number/date formatting
│ │ ├── accessibility.ts # A11y utilities
│ │ └── jps-pathfinding.ts # Pathfinding algorithms
│ ├── public/ # Static assets
│ ├── package.json # Node dependencies
│ ├── tsconfig.json # TypeScript configuration
│ ├── next.config.js # Next.js configuration
│ └── tailwind.config.js # Tailwind CSS configuration
│
├── dump.rdb # Redis snapshot (dev)
├── run.sh # Quick start script
├── README.md # This file
└── TECHNICAL.md # In-depth technical documentation
http://localhost:8000/api/v1
Currently using API key authentication (development):
X-API-Key: hpcl-demo-keyGET /healthResponse:
{
"status": "healthy",
"database": "connected",
"timestamp": "2026-01-17T10:30:00Z"
}GET /api/v1/fleetResponse:
{
"vessels": [
{
"id": "T1",
"name": "Tanker T1",
"capacity_mt": 50000,
"daily_charter_rate": 6300000,
"status": "available"
}
],
"total_vessels": 9
}GET /api/v1/ports?type=loadingResponse:
{
"ports": [
{
"id": "L1",
"name": "Mumbai Port",
"type": "loading",
"latitude": 18.9388,
"longitude": 72.8354
}
],
"total_ports": 6
}POST /api/v1/challenge/optimize
Content-Type: application/json
{
"vessels": [], // Optional: custom vessel data
"demands": [], // Optional: custom demand data
"round_trip": false,
"optimization_objective": "cost"
}Response:
{
"request_id": "opt_abc123",
"status": "completed",
"total_cost_cr": "2.856",
"total_trips": 12,
"routes_generated": 726,
"solve_time_seconds": 45.2,
"selected_routes": [...]
}Visit http://localhost:8000/docs for Swagger UI documentation with interactive endpoint testing.
import requests
response = requests.post(
"http://localhost:8000/api/v1/challenge/optimize",
json={
"round_trip": False,
"optimization_objective": "cost"
}
)
result = response.json()
print(f"Total Cost: ₹{result['summary']['total_cost_cr']} Cr")
print(f"Trips: {result['summary']['total_trips']}")objectives = ["cost", "emissions", "time", "balanced"]
results = {}
for objective in objectives:
response = requests.post(
"http://localhost:8000/api/v1/challenge/optimize",
json={"optimization_objective": objective}
)
results[objective] = response.json()
# Compare results
for objective, result in results.items():
print(f"{objective}: ₹{result['summary']['total_cost_cr']} Cr")# Optimize for emissions instead of cost
response = requests.post(
"http://localhost:8000/api/v1/challenge/optimize",
json={
"optimization_objective": "emissions",
"solver_profile": "balanced"
}
)
result = response.json()
print(f"Total Emissions: {result['total_emissions_kg']} kg CO2")| Tanker | Capacity (MT) | Charter Rate (₹ Cr/day) |
|---|---|---|
| T1-T7 | 50,000 | 0.63, 0.49, 0.51, 0.51, 0.53, 0.57, 0.65 |
| T8-T9 | 25,000 | 0.39, 0.38 |
| Port | Demand | Port | Demand | Port | Demand |
|---|---|---|---|---|---|
| U1 | 40,000 | U5 | 20,000 | U9 | 20,000 |
| U2 | 135,000 | U6 | 20,000 | U10 | 20,000 |
| U3 | 5,000 | U7 | 110,000 | U11 | 20,000 |
| U4 | 20,000 | U8 | 30,000 |
Total Monthly Demand: 440,000 MT
Source Destination Tanker Volume (MT) Trip Cost (₹ Cr)
L1 U2 T2 50000 0.294
L1 U2,U3 T3 50000 0.357
...
- Total Cost: ≤ ₹3.0 Cr/month
- Demand Satisfaction: 100%
- Solve Time: < 5 minutes
- Route Feasibility: All constraints satisfied
| Metric | Value |
|---|---|
| Cost Reduction vs. Manual | 40-50% |
| Optimal Gap | < 1% |
| Demand Satisfaction | 100% |
| Fleet Utilization | 85-95% |
| Solver Profile | Time | Solution Quality |
|---|---|---|
| Quick | 15s | Good (5-10% gap) |
| Balanced | 60s | Very Good (1-3% gap) |
| Thorough | 300s | Optimal (< 1% gap) |
- Feasible Routes Generated: ~726 patterns
- Average Routes per Vessel: 80-85
- Route Generation Time: 2-5 seconds
- Memory Usage: < 500 MB
# Backend tests
cd backend
pytest tests/ -v
# Run specific test
pytest tests/test_end_to_end.py -v
# Frontend tests (if available)
cd frontend
npm test# Python linting
cd backend
flake8 app/
# TypeScript linting
cd frontend
npm run lint# Start MongoDB (if using)
mongod --dbpath /path/to/data
# Start Redis (if using)
redis-server# Coming soon: Docker Compose configurationThe application can be deployed on:
- Backend: AWS EC2, Google Cloud Run, Azure App Service
- Frontend: Vercel, Netlify, AWS Amplify
- Database: MongoDB Atlas, AWS DocumentDB
- Cache: Redis Cloud, AWS ElastiCache
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- HPCL (Hindustan Petroleum Corporation Limited) for the challenge problem
- Google OR-Tools team for the excellent CP-SAT solver
- FastAPI and Next.js communities for amazing frameworks
- searoute-py for maritime routing calculations