Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci/bugs/ticket5114/runner.py
169708 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 2018-09-27
18
19
from __future__ import print_function
20
from __future__ import absolute_import
21
import os
22
import sys
23
24
if "SUMO_HOME" in os.environ:
25
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))
26
27
import traci # noqa
28
import sumolib # noqa
29
30
sumoBinary = sumolib.checkBinary('sumo')
31
traci.start([sumoBinary,
32
"-n", "input_net.net.xml",
33
"--no-step-log",
34
])
35
36
print("getDistanceRoad (no connection):",
37
traci.simulation.getDistanceRoad("gneE0", 100, "gneE1", 100, isDriving=True))
38
print("getDistanceRoad (normal to normal):",
39
traci.simulation.getDistanceRoad("gneE4", 50, "-gneE2", 50, isDriving=True))
40
print("getDistanceRoad (normal to 1st internal):",
41
traci.simulation.getDistanceRoad("gneE4", 50, ":gneJ5_4", 5, isDriving=True))
42
print("getDistanceRoad (normal to 2nd internal):",
43
traci.simulation.getDistanceRoad("gneE4", 50, ":gneJ5_7", 5, isDriving=True))
44
print("getDistanceRoad (1st internal to normal):",
45
traci.simulation.getDistanceRoad(":gneJ5_4", 5, "-gneE2", 50, isDriving=True))
46
print("getDistanceRoad (1st internal to 2nd internal):",
47
traci.simulation.getDistanceRoad(":gneJ5_4", 5, ":gneJ5_7", 5, isDriving=True))
48
print("getDistanceRoad (2nd internal to normal):",
49
traci.simulation.getDistanceRoad(":gneJ5_7", 5, "-gneE2", 50, isDriving=True))
50
print("getDistanceRoad (2nd internal to 1st internal):",
51
traci.simulation.getDistanceRoad(":gneJ5_7", 5, ":gneJ5_4", 5, isDriving=True))
52
53
traci.route.add("r", ["gneE4", "-gneE2"])
54
traci.vehicletype.setMaxSpeed("DEFAULT_VEHTYPE", 1)
55
traci.vehicle.add("v", "r")
56
traci.simulationStep()
57
58
print("getDrivingDistance (no connection):",
59
traci.vehicle.getDrivingDistance("v", "gneE1", 100))
60
print("getDrivingDistance (normal to normal):",
61
traci.vehicle.getDrivingDistance("v", "-gneE2", 50))
62
print("getDrivingDistance (normal to 1st internal):",
63
traci.vehicle.getDrivingDistance("v", ":gneJ5_4", 5))
64
print("getDrivingDistance (normal to 2nd internal):",
65
traci.vehicle.getDrivingDistance("v", ":gneJ5_7", 5))
66
while traci.vehicle.getRoadID("v") != ":gneJ5_4":
67
traci.simulationStep()
68
print("getDrivingDistance (1st internal to normal):",
69
traci.vehicle.getDrivingDistance("v", "-gneE2", 50))
70
print("getDrivingDistance (1st internal to 2nd internal):",
71
traci.vehicle.getDrivingDistance("v", ":gneJ5_7", 5))
72
while traci.vehicle.getRoadID("v") != ":gneJ5_7":
73
traci.simulationStep()
74
print("getDrivingDistance (2nd internal to normal):",
75
traci.vehicle.getDrivingDistance("v", "-gneE2", 50))
76
print("getDrivingDistance (2nd internal to 1st internal):",
77
traci.vehicle.getDrivingDistance("v", ":gneJ5_4", 5))
78
79
traci.close()
80
81