python - 尽管相同参数的数量不同,但结果相同
问题描述
我想通过 2 次迭代检查更改特定参数(例如 tau、accel、decel、sigma)的量对流动特性的影响。因此,我使用以下 python 脚本和 TraCI 工具来观察 tau 变化:
import traci
tau = [3, 4]
n = 2
for i in range(n):
def run():
traci.start(sumoCmd)
traci.vehicle.add('vehicle_2', 'route_1', 'emergency', '45')
for j in tau:
traci.vehicle.setTau('vehicle_2', j)
N = 200
step = 0
for step in range(N):
traci.simulationStep()
step += 1
traci.close()
sys.stdout.flush()
run()
在模拟结束时,结果并没有什么不同,这让我觉得我的代码有问题。如果你能帮助我,我将不胜感激。最好的问候,阿里
解决方案
您的主循环应该结束tau
,而不是内部循环。
您还应该只定义一次函数,然后j
作为参数传递。
import traci
tau = [3, 4]
def run(j):
traci.start(sumoCmd)
traci.vehicle.add('vehicle_2', 'route_1', 'emergency', '45')
traci.vehicle.setTau('vehicle_2', j)
N = 200
step = 0
for step in range(N):
traci.simulationStep()
traci.close()
sys.stdout.flush()
for j in tau:
没有必要step += 1
。for
循环自动增加它。
推荐阅读
- node.js - Node.js 没有创建目录
- php - Laravel 控制器充当代理
- compilation - Samba 4.9.1 密码与 CentOS7 root 密码同步
- oracle - 第一行 VS 下一行 VS rownum
- javascript - 如果相机在 instascan 中打开,输入类型不起作用
- javascript - 使用 Lodash 根据另一个对象的真实状态获取对象的值
- azure - CORS 异常:无法加载 https://login.microsoftonline.com/{TENANT_ID}/oauth2/authorize
- sql - 将数据类型 varchar 转换为日期时将 int 年份转换为字符串时出错
- sql - 如何根据日期的特定条件创建数据集?
- html - 表单重置后IE11不重新验证表单