Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Comprehensive demo of Fleet Resource Optimization Simulator | |
| """ | |
| from fleet_optimizer import FleetOptimizer | |
| import time | |
| import json | |
| def demo_fleet_optimization(): | |
| """Demonstrate the fleet optimization system""" | |
| print("π Fleet Resource Optimization Demo") | |
| print("=" * 60) | |
| # Create optimizer | |
| optimizer = FleetOptimizer() | |
| print(f"β Initialized {optimizer.config.num_vehicles} vehicles") | |
| print(f"β Vehicle capacity: {optimizer.config.vehicle_capacity} passengers") | |
| print(f"β Base cost: ${optimizer.config.base_cost_per_km}/km") | |
| # Set simulation to peak hours for better demand | |
| optimizer.simulation_time = optimizer.simulation_time.replace(hour=8) # 8 AM | |
| print(f"\nπ Starting simulation at {optimizer.simulation_time.strftime('%H:%M')}") | |
| # Run simulation with detailed output | |
| for step in range(20): | |
| print(f"\n--- Step {step + 1} ---") | |
| print(f"Time: {optimizer.simulation_time.strftime('%H:%M')}") | |
| # Run simulation step | |
| optimizer.run_simulation_step() | |
| # Get current stats | |
| stats = optimizer.get_simulation_stats() | |
| print(f"π Stats: {stats['available_vehicles']} available, " | |
| f"{stats['busy_vehicles']} busy, " | |
| f"{stats['pending_demands']} pending, " | |
| f"${stats['total_earnings']:.2f} earnings") | |
| # Show demand details if any | |
| if optimizer.demands: | |
| recent_demands = [d for d in optimizer.demands if d.status == 'pending'][-3:] | |
| if recent_demands: | |
| print(f"π Recent demands:") | |
| for demand in recent_demands: | |
| print(f" - Demand {demand.id}: Priority {demand.priority}, " | |
| f"{demand.passengers} passengers") | |
| # Show vehicle activity | |
| busy_vehicles = [v for v in optimizer.vehicles if v.status == 'busy'] | |
| if busy_vehicles: | |
| print(f"π Active vehicles:") | |
| for vehicle in busy_vehicles[:3]: # Show first 3 | |
| print(f" - Vehicle {vehicle.id}: ${vehicle.earnings:.2f} earnings, " | |
| f"{vehicle.total_distance:.1f}km") | |
| time.sleep(0.5) # Small delay for readability | |
| # Final comprehensive report | |
| print(f"\n" + "="*60) | |
| print("π FINAL SIMULATION REPORT") | |
| print("="*60) | |
| final_stats = optimizer.get_simulation_stats() | |
| print(json.dumps(final_stats, indent=2)) | |
| # Vehicle performance | |
| print(f"\nπ Vehicle Performance:") | |
| total_vehicles = len(optimizer.vehicles) | |
| utilization_rate = (final_stats['busy_vehicles'] / total_vehicles) * 100 | |
| avg_earnings = final_stats['total_earnings'] / total_vehicles | |
| print(f" Utilization Rate: {utilization_rate:.1f}%") | |
| print(f" Average Earnings per Vehicle: ${avg_earnings:.2f}") | |
| print(f" Total Distance Traveled: {final_stats['total_distance']:.1f} km") | |
| # Demand analysis | |
| if optimizer.demands: | |
| total_demands = len(optimizer.demands) | |
| pending_demands = len([d for d in optimizer.demands if d.status == 'pending']) | |
| completed_demands = len([d for d in optimizer.demands if d.status == 'assigned']) | |
| print(f"\nπ Demand Analysis:") | |
| print(f" Total Demands Generated: {total_demands}") | |
| print(f" Pending Demands: {pending_demands}") | |
| print(f" Assigned Demands: {completed_demands}") | |
| print(f" Demand Satisfaction Rate: {(completed_demands/total_demands)*100:.1f}%") | |
| # Priority distribution | |
| priorities = [d.priority for d in optimizer.demands] | |
| print(f" Average Priority: {sum(priorities)/len(priorities):.1f}") | |
| # Top performing vehicles | |
| top_vehicles = sorted(optimizer.vehicles, key=lambda v: v.earnings, reverse=True)[:5] | |
| print(f"\nπ Top Performing Vehicles:") | |
| for i, vehicle in enumerate(top_vehicles, 1): | |
| print(f" {i}. Vehicle {vehicle.id}: ${vehicle.earnings:.2f}, " | |
| f"{vehicle.total_distance:.1f}km, {vehicle.status}") | |
| print(f"\nπ Demo completed successfully!") | |
| print(f" The fleet optimization system is working correctly!") | |
| print(f" - Zero human intervention required") | |
| print(f" - Real-time decision making") | |
| print(f" - Dynamic vehicle allocation") | |
| print(f" - Weather and traffic consideration") | |
| if __name__ == "__main__": | |
| demo_fleet_optimization() | |