将无策略评估调整为基于traci的最高限速设置以对比

This commit is contained in:
Zihan Ye 2026-04-14 01:04:39 +08:00
parent f230d57efa
commit 79000996f4
1 changed files with 9 additions and 3 deletions

View File

@ -483,6 +483,12 @@ def select_deterministic_action(model_name: str, agent, state: np.ndarray) -> np
return action return action
def select_no_control_action(env: SUMOEdgeVSLEnvironment) -> np.ndarray:
if env.num_controlled_edges <= 0:
return np.zeros(0, dtype=np.int64)
return np.full(env.num_controlled_edges, env.action_dim - 1, dtype=np.int64)
def resolve_logged_action_info( def resolve_logged_action_info(
model_name: str, model_name: str,
env: SUMOEdgeVSLEnvironment, env: SUMOEdgeVSLEnvironment,
@ -491,7 +497,7 @@ def resolve_logged_action_info(
edge_idx: int, edge_idx: int,
action_speed_kmh: float, action_speed_kmh: float,
) -> Tuple[int, float]: ) -> Tuple[int, float]:
if model_name == BASELINE_NAME or not action_applied_mask[edge_idx]: if not action_applied_mask[edge_idx]:
return -1, action_speed_kmh return -1, action_speed_kmh
controlled_idx = edge_idx - env.controlled_edge_start_index controlled_idx = edge_idx - env.controlled_edge_start_index
if action is None or controlled_idx < 0 or controlled_idx >= len(action): if action is None or controlled_idx < 0 or controlled_idx >= len(action):
@ -550,8 +556,8 @@ def evaluate_single_model(
while True: while True:
if model_name == BASELINE_NAME: if model_name == BASELINE_NAME:
action = None action = select_no_control_action(env)
next_state, reward, done, info = env.step(action=None, apply_control=False) next_state, reward, done, info = env.step(action, apply_control=True)
else: else:
action = select_deterministic_action(model_name, agent, state) action = select_deterministic_action(model_name, agent, state)
next_state, reward, done, info = env.step(action, apply_control=True) next_state, reward, done, info = env.step(action, apply_control=True)