-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_sumo.py
More file actions
executable file
·121 lines (103 loc) · 3.27 KB
/
start_sumo.py
File metadata and controls
executable file
·121 lines (103 loc) · 3.27 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python3
# Copyright (c) 2025 Green Wave Team
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
"""
Quick SUMO Launcher
Start SUMO-GUI with TraCI for dashboard integration
"""
import os
import sys
import subprocess
from pathlib import Path
# Scenarios
SCENARIOS = {
'1': {
'name': 'Nga4ThuDuc',
'config': 'Nga4ThuDuc/Nga4ThuDuc.sumocfg',
'desc': 'Ngã Tư Thủ Đức (4-way intersection)'
},
'2': {
'name': 'NguyenThaiSon',
'config': 'NguyenThaiSon/Nga6NguyenThaiSon.sumocfg',
'desc': 'Ngã 6 Nguyễn Thái Sơn (6-way intersection)'
},
'3': {
'name': 'QuangTrung',
'config': 'QuangTrung/quangtrungcar.sumocfg',
'desc': 'Quang Trung (Complex intersection)'
}
}
def main():
print("🚦 SUMO Quick Launcher")
print("=" * 50)
# Check SUMO_HOME
sumo_home = os.environ.get('SUMO_HOME', '/usr/share/sumo')
print(f"SUMO_HOME: {sumo_home}")
# Get sumo-gui path
sumo_gui = 'sumo-gui'
if not os.path.exists("{sumo_home}/bin/sumo-gui"):
# Try to find in PATH
try:
result = subprocess.run(['which', 'sumo-gui'], capture_output=True, text=True)
if result.returncode == 0:
sumo_gui = result.stdout.strip()
else:
print("❌ sumo-gui not found!")
print(" Install SUMO or set SUMO_HOME")
sys.exit(1)
except Exception:
print("❌ sumo-gui not found!")
sys.exit(1)
else:
sumo_gui = f"{sumo_home}/bin/sumo-gui"
print("SUMO Binary: {sumo_gui}")
print()
# Select scenario
print("Select scenario:")
for key, scenario in SCENARIOS.items():
print(" {key}) {scenario['name']} - {scenario['desc']}")
choice = input("\nChoice (1-3) [1]: ").strip() or '1'
if choice not in SCENARIOS:
print("❌ Invalid choice: {choice}")
sys.exit(1)
scenario = SCENARIOS[choice]
# Get config path
script_dir = Path(__file__).parent
sumo_files = script_dir / 'src' / 'backend' / 'app' / 'sumo_rl' / 'sumo_files'
config_path = sumo_files / scenario['config']
if not config_path.exists():
print("❌ Config not found: {config_path}")
sys.exit(1)
# TraCI port
port = input("\nTraCI Port [8813]: ").strip() or '8813'
print()
print("✅ Starting SUMO-GUI...")
print(" Scenario: {scenario['name']}")
print(" Config: {config_path}")
print(" TraCI Port: {port}")
print()
print("📡 After SUMO opens, connect from dashboard:")
print(" POST http://localhost:8000/sumo/connect")
print(" {{'scenario': '{scenario['name']}', 'port': {port}}}")
print()
print("Press Ctrl+C to stop SUMO")
print("-" * 50)
# Start SUMO
try:
cmd = [
sumo_gui,
'-c', str(config_path),
'--remote-port', port,
'--start',
'--quit-on-end'
]
subprocess.run(cmd)
except KeyboardInterrupt:
print("\n\n✅ SUMO stopped")
except Exception as e:
print("\n❌ Error: ", e)
sys.exit(1)
if __name__ == '__main__':
main()