iflow-mcp_xrds76354_sumo-mcp 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- iflow_mcp_xrds76354_sumo_mcp-0.1.0.dist-info/METADATA +402 -0
- iflow_mcp_xrds76354_sumo_mcp-0.1.0.dist-info/RECORD +27 -0
- iflow_mcp_xrds76354_sumo_mcp-0.1.0.dist-info/WHEEL +4 -0
- iflow_mcp_xrds76354_sumo_mcp-0.1.0.dist-info/entry_points.txt +2 -0
- iflow_mcp_xrds76354_sumo_mcp-0.1.0.dist-info/licenses/LICENSE +21 -0
- mcp_tools/__init__.py +0 -0
- mcp_tools/analysis.py +33 -0
- mcp_tools/network.py +94 -0
- mcp_tools/py.typed +0 -0
- mcp_tools/rl.py +425 -0
- mcp_tools/route.py +91 -0
- mcp_tools/signal.py +96 -0
- mcp_tools/simulation.py +79 -0
- mcp_tools/vehicle.py +52 -0
- resources/__init__.py +0 -0
- server.py +493 -0
- utils/__init__.py +0 -0
- utils/connection.py +145 -0
- utils/output.py +26 -0
- utils/sumo.py +185 -0
- utils/timeout.py +364 -0
- utils/traci.py +82 -0
- workflows/__init__.py +0 -0
- workflows/py.typed +0 -0
- workflows/rl_train.py +34 -0
- workflows/signal_opt.py +210 -0
- workflows/sim_gen.py +70 -0
workflows/sim_gen.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from mcp_tools.network import netgenerate
|
|
3
|
+
from mcp_tools.route import random_trips, duarouter
|
|
4
|
+
from mcp_tools.simulation import run_simple_simulation
|
|
5
|
+
from mcp_tools.analysis import analyze_fcd
|
|
6
|
+
|
|
7
|
+
def sim_gen_workflow(output_dir: str, grid_number: int = 3, steps: int = 100) -> str:
|
|
8
|
+
"""
|
|
9
|
+
Executes the Simulation Generation & Evaluation workflow:
|
|
10
|
+
1. Generate Grid Network
|
|
11
|
+
2. Generate Random Trips
|
|
12
|
+
3. Compute Routes
|
|
13
|
+
4. Create Config
|
|
14
|
+
5. Run Simulation
|
|
15
|
+
6. Analyze Results
|
|
16
|
+
"""
|
|
17
|
+
if not os.path.exists(output_dir):
|
|
18
|
+
os.makedirs(output_dir)
|
|
19
|
+
|
|
20
|
+
net_file = os.path.join(output_dir, "grid.net.xml")
|
|
21
|
+
trips_file = os.path.join(output_dir, "trips.xml")
|
|
22
|
+
route_file = os.path.join(output_dir, "routes.xml")
|
|
23
|
+
sumocfg_file = os.path.join(output_dir, "sim.sumocfg")
|
|
24
|
+
fcd_file = os.path.join(output_dir, "fcd.xml")
|
|
25
|
+
|
|
26
|
+
# 1. Generate Net
|
|
27
|
+
res = netgenerate(net_file, grid=True, grid_number=grid_number)
|
|
28
|
+
if "failed" in res.lower(): return f"Step 1 Failed: {res}"
|
|
29
|
+
|
|
30
|
+
# 2. Generate Trips
|
|
31
|
+
res = random_trips(net_file, trips_file, end_time=steps)
|
|
32
|
+
if "failed" in res.lower(): return f"Step 2 Failed: {res}"
|
|
33
|
+
|
|
34
|
+
# 3. Generate Routes
|
|
35
|
+
res = duarouter(net_file, trips_file, route_file)
|
|
36
|
+
if "failed" in res.lower(): return f"Step 3 Failed: {res}"
|
|
37
|
+
|
|
38
|
+
# 4. Create Config
|
|
39
|
+
# We use absolute paths for safety or relative if SUMO expects it.
|
|
40
|
+
# Usually relative to config file is best.
|
|
41
|
+
try:
|
|
42
|
+
with open(sumocfg_file, "w") as f:
|
|
43
|
+
f.write(f"""<configuration>
|
|
44
|
+
<input>
|
|
45
|
+
<net-file value="{os.path.basename(net_file)}"/>
|
|
46
|
+
<route-files value="{os.path.basename(route_file)}"/>
|
|
47
|
+
</input>
|
|
48
|
+
<time>
|
|
49
|
+
<begin value="0"/>
|
|
50
|
+
<end value="{steps}"/>
|
|
51
|
+
</time>
|
|
52
|
+
<output>
|
|
53
|
+
<fcd-output value="{os.path.basename(fcd_file)}"/>
|
|
54
|
+
</output>
|
|
55
|
+
</configuration>""")
|
|
56
|
+
except Exception as e:
|
|
57
|
+
return f"Step 4 Failed: Could not write config file. {e}"
|
|
58
|
+
|
|
59
|
+
# 5. Run Sim
|
|
60
|
+
res = run_simple_simulation(sumocfg_file, steps)
|
|
61
|
+
if "error" in res.lower(): return f"Step 5 Failed: {res}"
|
|
62
|
+
|
|
63
|
+
# 6. Analyze
|
|
64
|
+
# FCD file should exist after sim
|
|
65
|
+
if not os.path.exists(fcd_file):
|
|
66
|
+
return "Step 6 Failed: FCD file not generated."
|
|
67
|
+
|
|
68
|
+
res_analysis = analyze_fcd(fcd_file)
|
|
69
|
+
|
|
70
|
+
return f"Workflow Completed Successfully.\n\nSimulation Output:\n{res}\n\nAnalysis Result:\n{res_analysis}"
|