Compare commits

...

2 Commits

Author SHA1 Message Date
Zihan Ye 70de65d973 限速策略热力图绘制更新 2026-04-17 07:30:24 +08:00
Zihan Ye 4edf0e5310 隧道限速修正 2026-04-17 07:29:56 +08:00
4 changed files with 38 additions and 35 deletions

View File

@ -935,12 +935,12 @@ def plot_model_heatmaps(edge_df: pd.DataFrame, detector_df: pd.DataFrame, output
occ_grid = detector_model_df.pivot(index="cell_id", columns="step", values="occupancy").reindex(ordered_cell_ids).values
edge_order = (
edge_model_df[edge_model_df["action_applied"].astype(bool)][["edge_index", "edge_id"]]
edge_model_df[["edge_index", "edge_id"]]
.drop_duplicates()
.sort_values("edge_index")
)
ordered_edge_ids = edge_order["edge_id"].tolist()
action_plot_df = edge_model_df[edge_model_df["action_applied"].astype(bool)].copy()
action_plot_df = edge_model_df.copy()
action_grid = (
action_plot_df.pivot(index="edge_id", columns="step", values="action_speed_kmh")
.reindex(ordered_edge_ids)
@ -960,7 +960,8 @@ def plot_model_heatmaps(edge_df: pd.DataFrame, detector_df: pd.DataFrame, output
build_action_panel(
action_grid,
ordered_edge_ids,
f"{MODEL_LABELS[model_name]} Applied VSL (km/h)",
f"{MODEL_LABELS[model_name]} Segment Speed Limit (km/h)",
ylabel="Corridor Segment",
)
)
panels.append(

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated on 2026-04-14T05:58:52.443980+08:00 by Eclipse SUMO netedit 1.26.0
<!-- generated on 2026-04-17T07:29:31.408392+08:00 by Eclipse SUMO netedit 1.26.0
<neteditConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/neteditConfiguration.xsd">
<input>
@ -43,9 +43,9 @@
<type id="highway.primary" priority="12" numLanes="2" speed="27.78" disallow="tram rail_urban rail rail_electric rail_fast ship container cable_car subway aircraft wheelchair scooter drone" oneway="0"/>
<edge id=":-25378_0" function="internal">
<lane id=":-25378_0_0" index="0" allow="emergency" speed="26.39" length="29.99" width="3.75" shape="8239.75,6274.28 8233.75,6266.77 8230.16,6260.27 8227.33,6254.34 8223.59,6248.58"/>
<lane id=":-25378_0_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="26.39" length="29.99" width="3.75" shape="8242.20,6271.95 8235.83,6264.83 8231.40,6259.12 8227.71,6253.99 8223.59,6248.58"/>
<lane id=":-25378_0_2" index="2" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="26.39" length="29.99" width="3.75" shape="8244.91,6269.36 8238.62,6262.32 8234.25,6256.69 8230.61,6251.60 8226.51,6246.22"/>
<lane id=":-25378_0_0" index="0" allow="emergency" speed="29.17" length="29.99" width="3.75" shape="8239.75,6274.28 8233.75,6266.77 8230.16,6260.27 8227.33,6254.34 8223.59,6248.58"/>
<lane id=":-25378_0_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="29.17" length="29.99" width="3.75" shape="8242.20,6271.95 8235.83,6264.83 8231.40,6259.12 8227.71,6253.99 8223.59,6248.58"/>
<lane id=":-25378_0_2" index="2" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="29.17" length="29.99" width="3.75" shape="8244.91,6269.36 8238.62,6262.32 8234.25,6256.69 8230.61,6251.60 8226.51,6246.22"/>
</edge>
<edge id=":-25386_0" function="internal">
<lane id=":-25386_0_0" index="0" allow="emergency" speed="15.28" length="28.55" width="3.00" shape="11270.23,6723.63 11267.32,6732.11 11266.37,6738.87 11265.80,6744.93 11264.00,6751.33"/>
@ -112,9 +112,9 @@
<lane id=":-25605_3_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="26.39" length="86.56" width="3.75" shape="10978.46,9016.24 10898.44,8982.90"/>
</edge>
<edge id=":-25652_0" function="internal">
<lane id=":-25652_0_0" index="0" allow="emergency" speed="26.39" length="31.12" width="3.00" shape="7621.20,5610.68 7615.06,5607.42 7608.63,5605.18 7601.35,5602.52 7592.66,5598.03"/>
<lane id=":-25652_0_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="26.39" length="31.12" width="3.75" shape="7621.20,5610.68 7594.43,5595.15"/>
<lane id=":-25652_0_2" index="2" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="26.39" length="31.12" width="3.75" shape="7623.32,5607.58 7596.40,5591.96"/>
<lane id=":-25652_0_0" index="0" allow="emergency" speed="29.17" length="31.12" width="3.00" shape="7621.20,5610.68 7615.06,5607.42 7608.63,5605.18 7601.35,5602.52 7592.66,5598.03"/>
<lane id=":-25652_0_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="29.17" length="31.12" width="3.75" shape="7621.20,5610.68 7594.43,5595.15"/>
<lane id=":-25652_0_2" index="2" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="29.17" length="31.12" width="3.75" shape="7623.32,5607.58 7596.40,5591.96"/>
</edge>
<edge id=":-25769_0" function="internal">
<lane id=":-25769_0_0" index="0" allow="emergency" speed="18.05" length="51.46" width="3.00" shape="10868.78,7480.53 10875.13,7466.91 10880.42,7453.58 10884.67,7441.83 10887.90,7432.97"/>
@ -557,8 +557,8 @@
<lane id=":J66_0_4" index="4" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="25.00" length="59.34" width="3.75" shape="16760.63,15610.56 16713.54,15574.67"/>
</edge>
<edge id=":J67_0" function="internal">
<lane id=":J67_0_0" index="0" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="22.22" length="0.30" width="3.75" shape="8151.30,6155.54 8151.11,6155.29"/>
<lane id=":J67_0_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="22.22" length="0.30" width="3.75" shape="8154.32,6153.32 8154.15,6153.09"/>
<lane id=":J67_0_0" index="0" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="27.78" length="0.30" width="3.75" shape="8151.30,6155.54 8151.11,6155.29"/>
<lane id=":J67_0_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="27.78" length="0.30" width="3.75" shape="8154.32,6153.32 8154.15,6153.09"/>
</edge>
<edge id=":J68_0" function="internal">
<lane id=":J68_0_0" index="0" allow="emergency" speed="22.22" length="74.42" width="3.00" shape="18310.73,16302.67 18295.49,16312.06 18278.23,16324.20 18261.86,16336.01 18249.28,16344.41"/>
@ -591,8 +591,8 @@
<lane id=":J70_2_1" index="1" speed="22.22" length="158.45" width="3.75" shape="17596.80,16637.48 17742.21,16574.21"/>
</edge>
<edge id=":J71_0" function="internal">
<lane id=":J71_0_0" index="0" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="22.22" length="0.30" width="3.75" shape="7707.24,5672.55 7707.17,5672.49 7707.13,5672.44 7707.09,5672.39 7707.03,5672.33"/>
<lane id=":J71_0_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="22.22" length="0.30" width="3.75" shape="7709.50,5669.56 7709.43,5669.50 7709.40,5669.45 7709.36,5669.40 7709.29,5669.34"/>
<lane id=":J71_0_0" index="0" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="27.78" length="0.30" width="3.75" shape="7707.24,5672.55 7707.17,5672.49 7707.13,5672.44 7707.09,5672.39 7707.03,5672.33"/>
<lane id=":J71_0_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="27.78" length="0.30" width="3.75" shape="7709.50,5669.56 7709.43,5669.50 7709.40,5669.45 7709.36,5669.40 7709.29,5669.34"/>
</edge>
<edge id=":J73_0" function="internal">
<lane id=":J73_0_0" index="0" allow="emergency" speed="16.66" length="98.83" width="3.00" shape="17669.74,16546.72 17686.65,16561.44 17710.52,16580.63 17733.18,16598.36 17746.46,16608.70"/>
@ -914,16 +914,16 @@
<lane id="G1523_AM6.6_2" index="2" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="30.56" length="99.61" width="3.75" shape="8313.32,6341.97 8302.63,6329.74 8263.38,6288.75 8244.91,6269.36"/>
</edge>
<edge id="G1523_AM7" from="-25378" to="J67" name="G1523_AM7" priority="14" type="highway.motorway" spreadType="center" shape="8225.05,6247.40 8194.47,6209.77 8162.77,6167.86 8158.01,6161.50 8152.72,6154.31">
<lane id="G1523_AM7_0" index="0" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="22.22" length="117.76" width="3.75" shape="8223.59,6248.58 8192.99,6210.93 8161.27,6168.99 8156.50,6162.62 8151.30,6155.54" changeLeft="emergency" changeRight="emergency"/>
<lane id="G1523_AM7_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="22.22" length="117.76" width="3.75" shape="8226.51,6246.22 8195.95,6208.61 8164.27,6166.73 8159.52,6160.38 8154.32,6153.32" changeRight="emergency"/>
<lane id="G1523_AM7_0" index="0" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="27.78" length="117.76" width="3.75" shape="8223.59,6248.58 8192.99,6210.93 8161.27,6168.99 8156.50,6162.62 8151.30,6155.54" changeLeft="emergency" changeRight="emergency"/>
<lane id="G1523_AM7_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="27.78" length="117.76" width="3.75" shape="8226.51,6246.22 8195.95,6208.61 8164.27,6166.73 8159.52,6160.38 8154.32,6153.32" changeRight="emergency"/>
</edge>
<edge id="G1523_AM7.1" from="J67" to="J71" name="G1523_AM7.1" priority="14" type="highway.motorway" spreadType="center" shape="8152.72,6154.31 8060.61,6026.89 8000.96,5951.30 7981.78,5929.15 7946.56,5889.56 7918.13,5857.58 7900.52,5837.79 7883.14,5819.66 7852.78,5791.14 7806.02,5749.28 7781.89,5728.03 7745.64,5699.18 7708.25,5670.96">
<lane id="G1523_AM7.1_0" index="0" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="22.22" length="659.64" width="3.75" shape="8151.11,6155.29 8059.11,6028.02 7999.51,5952.50 7980.37,5930.39 7945.16,5890.81 7916.73,5858.83 7899.14,5839.06 7881.82,5820.99 7851.51,5792.52 7804.78,5750.68 7780.69,5729.47 7744.49,5700.66 7707.24,5672.55" changeLeft="emergency"/>
<lane id="G1523_AM7.1_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="22.22" length="659.64" width="3.75" shape="8154.15,6153.09 8062.11,6025.76 8002.41,5950.10 7983.19,5927.91 7947.96,5888.31 7919.53,5856.33 7901.90,5836.52 7884.46,5818.33 7854.05,5789.76 7807.26,5747.88 7783.09,5726.59 7746.79,5697.70 7709.50,5669.56" changeLeft="emergency" changeRight="emergency"/>
<lane id="G1523_AM7.1_0" index="0" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="27.78" length="659.64" width="3.75" shape="8151.11,6155.29 8059.11,6028.02 7999.51,5952.50 7980.37,5930.39 7945.16,5890.81 7916.73,5858.83 7899.14,5839.06 7881.82,5820.99 7851.51,5792.52 7804.78,5750.68 7780.69,5729.47 7744.49,5700.66 7707.24,5672.55" changeLeft="emergency"/>
<lane id="G1523_AM7.1_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="27.78" length="659.64" width="3.75" shape="8154.15,6153.09 8062.11,6025.76 8002.41,5950.10 7983.19,5927.91 7947.96,5888.31 7919.53,5856.33 7901.90,5836.52 7884.46,5818.33 7854.05,5789.76 7807.26,5747.88 7783.09,5726.59 7746.79,5697.70 7709.50,5669.56" changeLeft="emergency" changeRight="emergency"/>
</edge>
<edge id="G1523_AM7.2" from="J71" to="-25652" name="G1523_AM7.2" priority="14" type="highway.motorway" spreadType="center" shape="7708.28,5670.93 7695.79,5661.48 7686.89,5654.66 7675.91,5646.32 7665.73,5638.87 7652.25,5629.28 7640.69,5621.54 7631.36,5615.36 7622.26,5609.13">
<lane id="G1523_AM7.2_0" index="0" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="22.22" length="105.80" width="3.75" shape="7707.03,5672.33 7694.65,5662.97 7685.75,5656.15 7674.79,5647.82 7664.63,5640.39 7651.18,5630.82 7639.65,5623.10 7630.31,5616.92 7621.20,5610.68" changeLeft="emergency"/>
<lane id="G1523_AM7.2_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="22.22" length="105.80" width="3.75" shape="7709.29,5669.34 7696.93,5659.99 7688.03,5653.17 7677.03,5644.82 7666.83,5637.35 7653.32,5627.74 7641.73,5619.98 7632.41,5613.80 7623.32,5607.58" changeLeft="emergency"/>
<lane id="G1523_AM7.2_0" index="0" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="27.78" length="105.80" width="3.75" shape="7707.03,5672.33 7694.65,5662.97 7685.75,5656.15 7674.79,5647.82 7664.63,5640.39 7651.18,5630.82 7639.65,5623.10 7630.31,5616.92 7621.20,5610.68" changeLeft="emergency"/>
<lane id="G1523_AM7.2_1" index="1" allow="private emergency authority army vip passenger hov taxi bus coach delivery truck trailer motorcycle evehicle custom1 custom2" speed="27.78" length="105.80" width="3.75" shape="7709.29,5669.34 7696.93,5659.99 7688.03,5653.17 7677.03,5644.82 7666.83,5637.35 7653.32,5627.74 7641.73,5619.98 7632.41,5613.80 7623.32,5607.58" changeLeft="emergency"/>
</edge>
<edge id="G1523_AM8" from="-25652" to="J82" name="G1523_AM8" priority="-1" type="highway.motorway" shape="7597.38,5590.36 7545.41,5558.38 7511.77,5536.78 7467.04,5508.59 7429.92,5486.28 7381.49,5458.81 7340.09,5434.64 7279.28,5400.18 7221.78,5373.20 7173.84,5354.10 7135.81,5337.71 7097.06,5321.87 7082.11,5316.08">
<lane id="G1523_AM8_0" index="0" allow="emergency" speed="30.56" length="583.97" width="3.00" acceleration="1" shape="7592.66,5598.03 7540.62,5566.00 7506.94,5544.37 7462.32,5516.25 7425.38,5494.05 7377.00,5466.61 7335.60,5442.44 7275.14,5408.18 7218.20,5381.46 7170.39,5362.41 7132.33,5346.01 7093.73,5330.23 7079.00,5324.53" changeLeft="emergency passenger"/>

View File

@ -279,34 +279,31 @@ def _plot_episode_heatmap(
step_to_col = {step: idx for idx, step in enumerate(step_values)}
panels = []
if has_action:
active_edge_ids = {
str(row["edge_id"])
for row in edge_rows
if bool(row.get("action_applied", True))
}
ordered_edge_ids = [edge_id for edge_id in edge_ids if edge_id in active_edge_ids]
if not ordered_edge_ids and active_edge_ids:
ordered_edge_ids = list(edge_ids)
if not ordered_edge_ids:
ordered_edge_ids = [
str(row["edge_id"])
for row in sorted(edge_rows, key=lambda item: int(item["edge_index"]))
if bool(row.get("action_applied", True))
]
ordered_edge_ids = list(dict.fromkeys(ordered_edge_ids))
if not ordered_edge_ids:
ordered_edge_ids = []
edge_to_row = {edge_id: idx for idx, edge_id in enumerate(ordered_edge_ids)}
action_grid = np.full((len(ordered_edge_ids), num_steps), np.nan, dtype=np.float32)
for row in edge_rows:
edge_id = str(row["edge_id"])
if edge_id not in edge_to_row:
continue
if not bool(row.get("action_applied", True)):
continue
row_idx = edge_to_row[edge_id]
col_idx = step_to_col[int(row["step"])]
action_grid[row_idx, col_idx] = _safe_float(row["action_speed_kmh"])
if ordered_edge_ids:
panels.append(build_action_panel(action_grid, ordered_edge_ids, f"{title_prefix} Applied VSL (km/h)"))
panels.append(
build_action_panel(
action_grid,
ordered_edge_ids,
f"{title_prefix} Segment Speed Limit (km/h)",
ylabel="Corridor Segment",
)
)
if has_detector:
ordered_cells = []

View File

@ -36,13 +36,18 @@ def get_action_norm():
return action_cmap, colors.BoundaryNorm(get_action_boundaries(), action_cmap.N, clip=True)
def build_action_panel(grid, row_labels: Sequence[str], title: str) -> Dict:
def build_action_panel(
grid,
row_labels: Sequence[str],
title: str,
ylabel: str = "Corridor Segment",
) -> Dict:
action_cmap, action_norm = get_action_norm()
return {
"grid": grid,
"row_labels": row_labels,
"title": title,
"ylabel": "Controlled Edge",
"ylabel": ylabel,
"cmap": action_cmap,
"norm": action_norm,
"width_ratio": 0.8,