Backend system for optimizing fleet vehicle placement and route assignments with predictive swap recommendations.
# Start the FastAPI server
python src/main.py
# Or use the helper script
./run_server.shThen open upload_test.html in your browser to test file uploads!
- API Docs: http://localhost:8000/docs
- Test Interface: Open
upload_test.htmlin browser
# Run full optimization
python src/run_optimizer.py full
# Or quick test (uses config lookahead windows)
python src/run_optimizer.py test
# Using helper scripts
./run_full.sh # Full optimization (takes 15-60 minutes)
./run_test.sh # Quick testfleet-backend/
├── src/
│ ├── main.py # FastAPI server launcher ⭐
│ ├── run_optimizer.py # CLI optimization runner
│ ├── endpoints.py # API endpoints (upload/validate/process)
│ ├── endpoint_csv.py # CSV utilities
│ ├── models.py # Data models
│ ├── optimizer.py # Main optimization engine
│ ├── placement.py # Vehicle placement algorithm
│ ├── assignment.py # Route assignment algorithm
│ ├── constraints.py # Business constraints
│ ├── costs.py # Cost calculation
│ ├── pathfinding.py # Multi-hop routing
│ ├── data_loader.py # CSV data loading
│ └── output.py # Results generation
├── data/ # Input CSV files
├── output/ # Generated results
├── upload_test.html # Web UI for testing uploads ⭐
├── algorithm_config.json # Algorithm configuration
├── API_README.md # Detailed API documentation
├── QUICKSTART_API.md # API quick start guide
├── test_api.py # API automated tests
└── run_server.sh # Server launch script
The FastAPI server provides endpoints for uploading and processing fleet data files.
# Method 1: Direct
python src/main.py
# Method 2: Script
./run_server.sh
# Method 3: Custom port
API_PORT=8080 python src/main.pyPOST /upload/validate- Validate uploaded filesPOST /upload/process- Validate and process files
- Web Interface: Open
upload_test.htmlin browser - Python Script:
python test_api.py - Interactive Docs: http://localhost:8000/docs
- curl: See examples in
API_README.md
# Core dependencies (for algorithms)
pip install numpy
# Web dependencies (for API server)
pip install fastapi uvicorn pydantic python-multipart
# Or install all at once
pip install ".[web]"Place these CSV files in the data/ directory:
locations.csv- Location information (300 locations)locations_relations.csv- Distance/time between locationsroutes.csv- Route definitions (100k+ routes)segments.csv- Route segmentsvehicles.csv- Vehicle fleet information (180 vehicles)
Plus: algorithm_config.json in project root
Edit algorithm_config.json to configure:
- Placement strategy and parameters
- Assignment strategy and lookahead
- Cost parameters (relocation, overage, service)
- Swap policies
- Service policies
- Performance tuning
See ALGORITHM_SPEC_V2.md for detailed algorithm documentation.
import requests
files = {
'locations': open('data/locations.csv', 'rb'),
'locations_relations': open('data/locations_relations.csv', 'rb'),
'routes': open('data/routes.csv', 'rb'),
'segments': open('data/segments.csv', 'rb'),
'vehicles': open('data/vehicles.csv', 'rb'),
'config': open('algorithm_config.json', 'rb'),
}
response = requests.post('http://localhost:8000/upload/validate', files=files)
print(response.json())# Full optimization (all routes)
python src/run_optimizer.py full
# Quick test (using lookahead from config)
python src/run_optimizer.py test
# Results will be in output/ directoryThe system generates several output files:
vehicles_placed_{timestamp}.csv- Initial vehicle placementassignments_{timestamp}.csv- Route-to-vehicle assignmentsvehicle_states_{timestamp}.csv- Final vehicle statessummary_{timestamp}.json- Optimization summaryplacement_report_{timestamp}.json- Placement analysiscritical_alerts_{timestamp}.json- Issues and warningsfleet_prediction_summary_{timestamp}.json- Future predictions
python test_api.pypython test_placement.py
python test_assignment.py./run_test.sh- API_README.md - Detailed API documentation
- QUICKSTART_API.md - Quick API start guide
- ALGORITHM_SPEC_V2.md - Algorithm specification
- API Docs (Interactive) - http://localhost:8000/docs (when server running)
- Coverage-first strategy
- Hub utilization
- Demand analysis from historical routes
- Concentration limits to avoid clustering
- Greedy assignment with optional lookahead
- Swap policy enforcement (max 1 swap per 90 days)
- Service interval tracking
- Overage cost minimization
- Multi-hop pathfinding (optional)
- Relocation costs (base + km + time)
- Overage penalties
- Service costs
- Swap restrictions
- Annual mileage limits
- Lifetime contract limits
- Service intervals
- Swap windows
- Vehicle availability
- Max 1 relocation per vehicle per 90 days
- Service required at interval + tolerance
- Annual mileage limits enforced
- Relocation costs include base + distance + time
- Overage penalties applied at 0.92 PLN/km
# Run linter
ruff check src/
# Run tests
pytest
# Format code
ruff format src/- The API server (
src/main.py) is for uploading/validating files - The optimization CLI (
src/run_optimizer.py) runs the actual algorithms - Full optimization processes 100k+ routes and takes 15-60 minutes
- Test mode uses configurable lookahead windows for faster iteration
- All uploaded files are validated against strict schemas
- Console output shows first 10 rows of each CSV for verification
This is a hackathon project for LSP Group. The system implements:
- Vehicle Placement - Strategic initial positioning
- Route Assignment - Cost-optimized vehicle-to-route matching
- Predictive Swaps - Proactive relocation recommendations
Proprietary - LSP Group Hackathon Project
Quick Commands
# Start API server
python src/main.py
# Run optimization
python src/run_optimizer.py full
# Test API
python test_api.py
# View docs
open http://localhost:8000/docs