ctm-dqn/test_edge_env.py

26 lines
770 B
Python

"""测试基于边的VSL环境"""
import yaml
from sumo_edge_vsl_environment import SUMOEdgeVSLEnvironment
import numpy as np
with open('config_sumo_vsl.yaml', 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
env = SUMOEdgeVSLEnvironment(config)
state = env.reset(seed=42)
print(f"状态维度: {state.shape}")
print(f"动作维度: {env.num_edges} 条边,每条边 {env.num_speed_actions} 个速度档位")
# 测试一步
action = np.array([4] * env.num_edges) # 所有边都用最高限速
state, reward, done, info = env.step(action)
print(f"\n第一步结果:")
print(f" 奖励: {reward:.2f}")
print(f" 吞吐量: {info['throughput']:.1f} veh/h")
print(f" 平均速度: {info['mean_speed_kmh']:.1f} km/h")
env.close()
print("\n测试成功!")