Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci/lanearea/override/runner.py
169689 views
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
4
# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.
5
# This program and the accompanying materials are made available under the
6
# terms of the Eclipse Public License 2.0 which is available at
7
# https://www.eclipse.org/legal/epl-2.0/
8
# This Source Code may also be made available under the following Secondary
9
# Licenses when the conditions for such availability set forth in the Eclipse
10
# Public License 2.0 are satisfied: GNU General Public License, version 2
11
# or later which is available at
12
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
13
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
14
15
# @file runner.py
16
# @author Michael Behrisch
17
# @author Daniel Krajzewicz
18
# @date 2011-03-04
19
20
21
from __future__ import print_function
22
from __future__ import absolute_import
23
import os
24
import sys
25
26
if "SUMO_HOME" in os.environ:
27
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))
28
import traci # noqa
29
import sumolib # noqa
30
31
traci.start([sumolib.checkBinary('sumo'), "-c", "sumo.sumocfg"] + sys.argv[1:])
32
33
loopID = "detect_0"
34
35
36
def check():
37
t = traci.simulation.getTime()
38
print("step", t)
39
if int(t) == t:
40
# only report at full seconds to simplify comparison of different step-lengths
41
for detID in traci.lanearea.getIDList():
42
print(" examining", detID)
43
print(" pos", traci.lanearea.getPosition(detID))
44
print(" length", traci.lanearea.getLength(detID))
45
print(" lane", traci.lanearea.getLaneID(detID))
46
print(" vehNum", traci.lanearea.getLastStepVehicleNumber(detID))
47
print(" haltNum", traci.lanearea.getLastStepHaltingNumber(detID))
48
print(" meanSpeed", traci.lanearea.getLastStepMeanSpeed(detID))
49
print(" vehIDs", traci.lanearea.getLastStepVehicleIDs(detID))
50
print(" occupancy", traci.lanearea.getLastStepOccupancy(detID))
51
print(" jamLengthVeh", traci.lanearea.getJamLengthVehicle(detID))
52
print(" jamLengthMet", traci.lanearea.getJamLengthMeters(detID))
53
54
55
def ovr(vehNumber):
56
print("override %s" % vehNumber)
57
traci.lanearea.overrideVehicleNumber(loopID, vehNumber)
58
59
60
for step in range(3):
61
check()
62
traci.simulationStep()
63
ovr(0)
64
65
for step in range(3):
66
check()
67
traci.simulationStep()
68
ovr(1)
69
70
for step in range(3):
71
check()
72
traci.simulationStep()
73
ovr(4)
74
75
for step in range(3):
76
check()
77
traci.simulationStep()
78
ovr(10)
79
80
for step in range(3):
81
check()
82
traci.simulationStep()
83
ovr(-1)
84
85
for step in range(3):
86
check()
87
traci.simulationStep()
88
89
traci.close()
90
91