Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci/vehicle/replaceStop/first_parameter_only/runner.py
169727 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 Jakob Erdmann
17
# @date 2017-01-23
18
19
20
from __future__ import print_function
21
from __future__ import absolute_import
22
import os
23
import sys
24
25
if "SUMO_HOME" in os.environ:
26
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))
27
28
import traci # noqa
29
import sumolib # noqa
30
import traci.constants as tc # noqa
31
32
33
def getParams(vehID, index):
34
print("stop parameters for index %s at time %s:" % (
35
index, traci.simulation.getTime()))
36
37
for p in [
38
"index",
39
"edge",
40
"lane",
41
"startPos",
42
"endPos",
43
"posLat",
44
"arrival",
45
"duration",
46
"until",
47
"extension",
48
"parking",
49
"triggered",
50
"permitted",
51
"expected",
52
"actType",
53
"tripId",
54
"split",
55
"join",
56
"line",
57
"speed",
58
"started",
59
"ended",
60
]:
61
print(p, traci.vehicle.getStopParameter(vehID, index, p))
62
63
64
sumoBinary = sumolib.checkBinary('sumo')
65
traci.start([sumoBinary,
66
"-n", "input_net4.net.xml",
67
"-a", "input_additional4.add.xml",
68
"-r", "input_routes.rou.xml",
69
"--stop-output", "stopinfos.xml",
70
"--no-step-log",
71
"--vehroute-output", "vehroutes.xml",
72
] + sys.argv[1:])
73
74
vehID = "ego"
75
76
while traci.simulation.getMinExpectedNumber() > 0:
77
if traci.simulation.getTime() == 5:
78
traci.vehicle.setStopParameter(vehID, 0, "lane", "0")
79
traci.vehicle.setStopParameter(vehID, 0, "startPos", "5")
80
traci.vehicle.setStopParameter(vehID, 0, "endPos", "50")
81
traci.vehicle.setStopParameter(vehID, 0, "posLat", "-0.5")
82
traci.vehicle.setStopParameter(vehID, 0, "arrival", "42")
83
traci.vehicle.setStopParameter(vehID, 0, "duration", "30")
84
traci.vehicle.setStopParameter(vehID, 1, "duration", "100")
85
traci.vehicle.setStopParameter(vehID, 0, "until", "0:1:40")
86
traci.vehicle.setStopParameter(vehID, 0, "extension", "10")
87
traci.vehicle.setStopParameter(vehID, 0, "parking", "false")
88
traci.vehicle.setStopParameter(vehID, 0, "triggered", "join")
89
traci.vehicle.setStopParameter(vehID, 0, "permitted", "p0 p1 p2")
90
traci.vehicle.setStopParameter(vehID, 0, "expected", "p0 p1")
91
traci.vehicle.setStopParameter(vehID, 0, "actType", "test action")
92
traci.vehicle.setStopParameter(vehID, 0, "tripId", "fancyID")
93
traci.vehicle.setStopParameter(vehID, 0, "split", "train0")
94
traci.vehicle.setStopParameter(vehID, 0, "join", "train1")
95
traci.vehicle.setStopParameter(vehID, 0, "line", "S42")
96
try:
97
traci.vehicle.setStopParameter(vehID, 0, "speed", "3")
98
except traci.TraCIException:
99
pass
100
traci.vehicle.setStopParameter(vehID, 0, "started", "0:1:23")
101
traci.vehicle.setStopParameter(vehID, 0, "ended", "0:1:42")
102
traci.vehicle.setStopParameter(vehID, 2, "onDemand", "true")
103
if traci.simulation.getTime() == 6:
104
getParams(vehID, 0)
105
if traci.simulation.getTime() == 150:
106
getParams(vehID, -1)
107
traci.simulationStep()
108
traci.close()
109
110