Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci/bugs/ticket1433/runner.py
169708 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2009-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file runner.py
15
# @author Laura Bieker-Walz
16
# @date 2020-09-04
17
18
from __future__ import absolute_import
19
from __future__ import print_function
20
21
import os
22
import sys
23
import subprocess
24
25
# we need to import python modules from the $SUMO_HOME/tools directory
26
if 'SUMO_HOME' in os.environ:
27
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
28
29
from sumolib import checkBinary # noqa
30
import traci # noqa
31
32
33
def run():
34
"""execute the TraCI control loop"""
35
step = 0
36
while traci.simulation.getMinExpectedNumber() > 0:
37
traci.simulationStep()
38
step += 1
39
ids = traci.simulation.getDepartedIDList()
40
# print(ids)
41
if "1" in ids:
42
traci.vehicle.setRoute("1", ["4/1to3/1", "3/1to2/1", "2/1to1/1"])
43
traci.close()
44
sys.stdout.flush()
45
46
47
# this is the main entry point of this script
48
if __name__ == "__main__":
49
50
sumoBinary = checkBinary('sumo')
51
# prepare state
52
subprocess.call([sumoBinary, "-c", "sumo.sumocfg"] + sys.argv[1:])
53
54
args = [sumoBinary, "-n", "input_net.net.xml",
55
"-a", "input_routes.rou.xml",
56
"--load-state", "input_state.xml",
57
"--no-step-log",
58
"--begin", "9"]
59
60
args += sys.argv[1:]
61
62
traci.start(args)
63
run()
64
65