我正在使用以下脚本从PTV Vissim中的交叉点的链接1和链接3获取“所有车辆”对象。
def main():
TimeDiff = 1
DistLimit=200.00
SpeedLimit=47.00
DesiredSpeed=50
#Get All the vehicle objects on link 1 and 3.
Vehicles1= Vissim.Net.Links.ItemByKey(1).Vehs.GetAll()
Vehicles3= Vissim.Net.Links.ItemByKey(3).Vehs.GetAll()
#Iterate through every vehicle in link 1.
for Vehicles1 in Vehicles1:
#Get attribute vehicle. (Atime1 = Arrival Time of Vehicle at Intersection)
ArrTime=Vehicles1.AttValue("ATime1")
DesSpeed = Vehicles1.AttValue("DesSpeed")
Current_Speed1=Vehicles1.AttValue("Speed")
#Check if there any Vehicles on link 3.
if len(Vehicles3)>0:
#Iterate through every vehicle in link 3.
for Vehicles3 in Vehicles2:
#Get attribute of vehicles on link 3. (Atime3 = Arrival Time of Vehicle at Intersection
ArrTime3=Vehicles3.AttValue("ATime3")
DesSpeed = Vehicles3.AttValue("DesSpeed")
DistSigHead2=Vehicles3.AttValue("DistanceToSigHead")
OrgDesSpeed = Vehicles3.AttValue("OrgDesSpeed")
if (ArrTime2-ArrTime)<TimeDiff:
Current_Speed1=Vehicles3.AttValue("Speed")
newDesSpeed=Current_Speed1-2
Vehicles3.SetAttValue("DesSpeed", newDesSpeed)
if DistSigHead2 ==0:
Vehicles3.SetAttValue("DesSpeed", DesiredSpeed)
该脚本能够获取所有车辆对象并执行给定条件。但是for循环仅在车辆进入链接1或3时检查车辆一次,并将其属性与另一条链接上的车辆进行比较。我想检查链接1和3中每个时间步中的每辆车,并比较到达时间。我认为我没有正确应用for循环。任何人,在这方面请给我一些建议。
在此方面您的帮助和指导将受到高度赞赏。 谢谢。
答案 0 :(得分:0)
此行在逻辑上看起来是错误的,尽管它不会产生错误:
车辆1中的车辆1:
现在,如下所示重新编写脚本:
旧脚本:
function cleanDB() {
runQuery(`...query`);
}
function runQuery(query) {
const session = driver.session();
return session
.writeTransaction(tx => tx.run(query))
.then(result => {
session.close();
return result;
})
.catch(error => {
session.close();
return { error };
});
}