ctm-dqn/test_gui_no_control.py

36 lines
988 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""可视化测试:无策略控制"""
import yaml
from sumo_vsl_environment import SUMOVSLEnvironment
import numpy as np
with open('config_sumo_vsl.yaml', 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
# 启用GUI
config['sumo']['gui'] = True
env = SUMOVSLEnvironment(config)
state = env.reset(seed=42)
print("开始运行无策略仿真固定120 km/h限速...")
print("按Ctrl+C停止")
try:
for step in range(60):
# 无策略所有zone都使用最高限速120 km/h = action 4
action = np.array([4] * env.num_control_zones)
state, reward, done, info = env.step(action)
if step % 10 == 0:
print(f"Step {step}: 吞吐量={info['throughput']:.1f} veh/h, "
f"平均速度={info['mean_speed_kmh']:.1f} km/h, "
f"车辆数={info['num_vehicles']}")
if done:
break
except KeyboardInterrupt:
print("\n用户中断")
env.close()
print("仿真结束")