Path: blob/main/tests/complex/traci/chargingstation/basic/runner.py
169689 views
#!/usr/bin/env python1# -*- coding: utf-8 -*-2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo3# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.4# This program and the accompanying materials are made available under the5# terms of the Eclipse Public License 2.0 which is available at6# https://www.eclipse.org/legal/epl-2.0/7# This Source Code may also be made available under the following Secondary8# Licenses when the conditions for such availability set forth in the Eclipse9# Public License 2.0 are satisfied: GNU General Public License, version 210# or later which is available at11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1314# @file runner.py15# @author Jakob Erdmann16# @author Mirko Barthauer17# @date 2020-03-16181920from __future__ import print_function21from __future__ import absolute_import22import os23import sys2425if "SUMO_HOME" in os.environ:26sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))27import traci # noqa28import sumolib # noqa2930traci.start([sumolib.checkBinary('sumo'),31'-n', 'input_net2.net.xml',32'-a', 'input_additional2.add.xml',33'-r', 'input_routes.rou.xml',34'--no-step-log',35])3637print("chargingstations", traci.chargingstation.getIDList())38print("chargingstation count", traci.chargingstation.getIDCount())39print("stop attributes before setting values:")40for stop in traci.chargingstation.getIDList():41print(" stop=%s lane=%s startPos=%s endPos=%s name=%s power=%.0f efficiency=%.2f chargeDelay=%.2f chargeInTransit=%d" % ( # noqa42stop,43traci.chargingstation.getLaneID(stop),44traci.chargingstation.getStartPos(stop),45traci.chargingstation.getEndPos(stop),46traci.chargingstation.getName(stop),47traci.chargingstation.getChargingPower(stop),48traci.chargingstation.getEfficiency(stop),49traci.chargingstation.getChargeDelay(stop),50traci.chargingstation.getChargeInTransit(stop))51)52# setter functions53print("stop attributes after setting values:")54for stop in traci.chargingstation.getIDList():55traci.chargingstation.setChargingPower(stop, 50000.)56traci.chargingstation.setEfficiency(stop, 1.)57traci.chargingstation.setChargeDelay(stop, 0.)58traci.chargingstation.setChargeInTransit(stop, True)59print(" stop=%s power=%.0f efficiency=%.2f chargeDelay=%.2f chargeInTransit=%d" % (60stop,61traci.chargingstation.getChargingPower(stop),62traci.chargingstation.getEfficiency(stop),63traci.chargingstation.getChargeDelay(stop),64traci.chargingstation.getChargeInTransit(stop))65)6667for step in range(50):68if step % 5 == 0:69print("time:", traci.simulation.getTime())70for stop in traci.chargingstation.getIDList():71print(" stop=%s vC=%s vIDs=%s" % (72stop,73traci.chargingstation.getVehicleCount(stop),74traci.chargingstation.getVehicleIDs(stop)))75traci.simulationStep()7677traci.close()787980