-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
73 lines (59 loc) · 2.34 KB
/
demo.py
File metadata and controls
73 lines (59 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""
Demo script that showcases the traffic simulation features.
This script runs a short demonstration of all scheduling algorithms.
"""
import pygame
import time
import sys
from main import TrafficSimulation
def run_demo():
"""Run a demonstration of the traffic simulation."""
print("🎬 Traffic Simulation Demo")
print("=" * 40)
print("This demo will showcase all scheduling algorithms.")
print("Watch how different algorithms handle traffic flow!")
print()
try:
# Initialize simulation
simulation = TrafficSimulation()
# Demo parameters
demo_duration = 30 # seconds per algorithm
algorithms = ["FCFS", "Round Robin", "Priority", "Dynamic"]
print("Starting demo in 3 seconds...")
time.sleep(3)
# Run demo for each algorithm
for i, algorithm in enumerate(algorithms):
print(f"\n🔄 Demo {i+1}/4: {algorithm} Algorithm")
print("Watch how vehicles are processed...")
# Set algorithm
simulation.scheduler.set_algorithm(algorithm)
# Run for demo duration
start_time = time.time()
while time.time() - start_time < demo_duration:
dt = simulation.clock.tick(60)
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
return
elif event.key == pygame.K_SPACE:
simulation.paused = not simulation.paused
# Update and render
simulation.update(dt)
simulation.render()
print(f"✓ {algorithm} demo completed!")
print("\n🎉 Demo completed!")
print("You can now run 'python main.py' for the full simulation.")
except KeyboardInterrupt:
print("\n\n👋 Demo stopped by user")
except Exception as e:
print(f"\n❌ Demo error: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
run_demo()
pygame.quit()
sys.exit(0)