Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test script for Fleet Resource Optimization Simulator | |
| """ | |
| from fleet_optimizer import FleetOptimizer | |
| import time | |
| import json | |
| def test_fleet_optimizer(): | |
| """Test the fleet optimizer functionality""" | |
| print("π Testing Fleet Resource Optimization Simulator") | |
| print("=" * 50) | |
| # 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") | |
| # Test initial state | |
| initial_stats = optimizer.get_simulation_stats() | |
| print(f"\nπ Initial Statistics:") | |
| print(f" Available vehicles: {initial_stats['available_vehicles']}") | |
| print(f" Total demands: {initial_stats['total_demands']}") | |
| print(f" Total earnings: ${initial_stats['total_earnings']:.2f}") | |
| # Run simulation for a few steps | |
| print(f"\nπ Running simulation for 10 steps...") | |
| for i in range(10): | |
| optimizer.run_simulation_step() | |
| time.sleep(0.1) # Small delay to see progress | |
| if i % 2 == 0: # Print stats every 2 steps | |
| stats = optimizer.get_simulation_stats() | |
| print(f" Step {i+1}: {stats['available_vehicles']} available, " | |
| f"{stats['pending_demands']} pending demands, " | |
| f"${stats['total_earnings']:.2f} earnings") | |
| # Final statistics | |
| final_stats = optimizer.get_simulation_stats() | |
| print(f"\nπ Final Statistics:") | |
| print(json.dumps(final_stats, indent=2)) | |
| # Test dashboard creation | |
| print(f"\nπΊοΈ Creating dashboard...") | |
| try: | |
| fig = optimizer.create_dashboard() | |
| print("β Dashboard created successfully") | |
| except Exception as e: | |
| print(f"β Dashboard creation failed: {e}") | |
| print(f"\nπ Fleet optimization test completed successfully!") | |
| print(f" - Total vehicles: {len(optimizer.vehicles)}") | |
| print(f" - Total demands generated: {len(optimizer.demands)}") | |
| print(f" - Total earnings: ${final_stats['total_earnings']:.2f}") | |
| print(f" - Total distance: {final_stats['total_distance']:.1f} km") | |
| if __name__ == "__main__": | |
| test_fleet_optimizer() | |