Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci/chargingstation/basic/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 Jakob Erdmann
17
# @author Mirko Barthauer
18
# @date 2020-03-16
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'),
32
'-n', 'input_net2.net.xml',
33
'-a', 'input_additional2.add.xml',
34
'-r', 'input_routes.rou.xml',
35
'--no-step-log',
36
])
37
38
print("chargingstations", traci.chargingstation.getIDList())
39
print("chargingstation count", traci.chargingstation.getIDCount())
40
print("stop attributes before setting values:")
41
for stop in traci.chargingstation.getIDList():
42
print(" stop=%s lane=%s startPos=%s endPos=%s name=%s power=%.0f efficiency=%.2f chargeDelay=%.2f chargeInTransit=%d" % ( # noqa
43
stop,
44
traci.chargingstation.getLaneID(stop),
45
traci.chargingstation.getStartPos(stop),
46
traci.chargingstation.getEndPos(stop),
47
traci.chargingstation.getName(stop),
48
traci.chargingstation.getChargingPower(stop),
49
traci.chargingstation.getEfficiency(stop),
50
traci.chargingstation.getChargeDelay(stop),
51
traci.chargingstation.getChargeInTransit(stop))
52
)
53
# setter functions
54
print("stop attributes after setting values:")
55
for stop in traci.chargingstation.getIDList():
56
traci.chargingstation.setChargingPower(stop, 50000.)
57
traci.chargingstation.setEfficiency(stop, 1.)
58
traci.chargingstation.setChargeDelay(stop, 0.)
59
traci.chargingstation.setChargeInTransit(stop, True)
60
print(" stop=%s power=%.0f efficiency=%.2f chargeDelay=%.2f chargeInTransit=%d" % (
61
stop,
62
traci.chargingstation.getChargingPower(stop),
63
traci.chargingstation.getEfficiency(stop),
64
traci.chargingstation.getChargeDelay(stop),
65
traci.chargingstation.getChargeInTransit(stop))
66
)
67
68
for step in range(50):
69
if step % 5 == 0:
70
print("time:", traci.simulation.getTime())
71
for stop in traci.chargingstation.getIDList():
72
print(" stop=%s vC=%s vIDs=%s" % (
73
stop,
74
traci.chargingstation.getVehicleCount(stop),
75
traci.chargingstation.getVehicleIDs(stop)))
76
traci.simulationStep()
77
78
traci.close()
79
80