"""可视化测试:无策略控制""" 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("仿真结束")