Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci/lane/internal/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
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
import traci # noqa
28
import sumolib # noqa
29
30
traci.start([sumolib.checkBinary('sumo'), "-n", "input_net3.net.xml",
31
"--no-step-log"] + sys.argv[1:])
32
for step in range(3):
33
print("step", step)
34
traci.simulationStep()
35
laneID = ":C_15_0"
36
print("examining", laneID)
37
print("length", traci.lane.getLength(laneID))
38
print("maxSpeed", traci.lane.getMaxSpeed(laneID))
39
print("width", traci.lane.getWidth(laneID))
40
print("allowed", traci.lane.getAllowed(laneID))
41
print("disallowed", traci.lane.getDisallowed(laneID))
42
print("linkNum", traci.lane.getLinkNumber(laneID))
43
if traci.isLibsumo() or traci.isLibtraci():
44
print("links", [link[:4] for link in traci.lane.getLinks(laneID)])
45
print("linksExtended", traci.lane.getLinks(laneID))
46
else:
47
print("links", traci.lane.getLinks(laneID, extended=False))
48
print("linksExtended", traci.lane.getLinks(laneID, extended=True))
49
print("shape", traci.lane.getShape(laneID))
50
print("edge", traci.lane.getEdgeID(laneID))
51
print("CO2", traci.lane.getCO2Emission(laneID))
52
print("CO", traci.lane.getCOEmission(laneID))
53
print("HC", traci.lane.getHCEmission(laneID))
54
print("PMx", traci.lane.getPMxEmission(laneID))
55
print("NOx", traci.lane.getNOxEmission(laneID))
56
print("Fuel", traci.lane.getFuelConsumption(laneID))
57
print("Noise", traci.lane.getNoiseEmission(laneID))
58
print("Elec", traci.lane.getElectricityConsumption(laneID))
59
print("meanSpeed", traci.lane.getLastStepMeanSpeed(laneID))
60
print("occupancy", traci.lane.getLastStepOccupancy(laneID))
61
print("lastLength", traci.lane.getLastStepLength(laneID))
62
print("traveltime", traci.lane.getTraveltime(laneID))
63
print("numVeh", traci.lane.getLastStepVehicleNumber(laneID))
64
print("haltVeh", traci.lane.getLastStepHaltingNumber(laneID))
65
print("vehIds", traci.lane.getLastStepVehicleIDs(laneID))
66
print("waiting time", traci.lane.getWaitingTime(laneID))
67
68
traci.lane.setAllowed(laneID, ["taxi"])
69
print("after setAllowed", traci.lane.getAllowed(laneID), traci.lane.getDisallowed(laneID))
70
traci.lane.setDisallowed(laneID, ["bus"])
71
print("after setDisallowed", traci.lane.getAllowed(laneID), traci.lane.getDisallowed(laneID))
72
traci.lane.setMaxSpeed(laneID, 42.)
73
print("after setMaxSpeed", traci.lane.getMaxSpeed(laneID))
74
traci.lane.setLength(laneID, 123.)
75
print("after setLength", traci.lane.getLength(laneID))
76
77
traci.lane.subscribe(laneID)
78
print(traci.lane.getSubscriptionResults(laneID))
79
for step in range(3, 6):
80
print("step", step)
81
print("pending", laneID, traci.lane.getPendingVehicles(laneID))
82
traci.simulationStep()
83
print(traci.lane.getSubscriptionResults(laneID))
84
traci.close()
85
86