[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[sumo-user] Defining Electric Vehicles
|
Hello,
I need to analyze the Electric Vehicles.
How I can define electric vehicles in TraCI (attached runner file)?
<vType id="typeACC" accel="2.6" decel="4.5" emergencyDecel="9" length="5" minGap="2.5" maxSpeed="8.33333" guiShape="passenger" carFollowModel="ACC" tau="1" sigma="0.5" type="ElectricVehicle" probability="0.5" color="1, 1, 0" />
Please help me in this.
Regards
Radha
#!/usr/bin/env python
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
# Copyright (C) 2009-2019 German Aerospace Center (DLR) and others.
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v20.html
# SPDX-License-Identifier: EPL-2.0
# @file runner.py
# @author Lena Kalleske
# @author Daniel Krajzewicz
# @author Michael Behrisch
# @author Jakob Erdmann
# @date 2009-03-26
# @version $Id$
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
import optparse
import random
# we need to import python modules from the $SUMO_HOME/tools directory
if 'SUMO_HOME' in os.environ:
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
sys.path.append(tools)
else:
sys.exit("please declare environment variable 'SUMO_HOME'")
from sumolib import checkBinary # noqa
import traci # noqa
def generate_routefile():
random.seed(18) # make tests reproducible
N = 2480 # number of time steps
# demand per second from different directions
pWE = 0.1
#pEW = 1. / 10
#pNS = 1. / 10
with open("data/cross.rou.xml", "w") as routes:
print("""<routes>
<vType id="typeACC" accel="2.6" decel="4.5" emergencyDecel="9" length="5" minGap="2.5" maxSpeed="8.33333" guiShape="passenger" carFollowModel="ACC" tau="1" sigma="0.5" type="ElectricVehicle" probability="0.5" color="1, 1, 0" />
<vType id="typeHD" accel="2.6" decel="4.5" emergencyDecel="9" length="5" minGap="5" maxSpeed="8.33333" guiShape="passenger" delta="4" tau="1" sigma="0.5" eClass="HBEFA3/PC_G_EU4" probability="0.5" color="1, 0, 0" />
<vTypeDistribution id="typedist1" vTypes="typeHD typeACC"/>
<route id="WN" edges="51o 1i 4o 54i" />
<route id="ES" edges="52o 2i 3o 53i" />
<route id="NE" edges="54o 4i 2o 52i" />
<route id="SW" edges="53o 3i 1o 51i" />""", file=routes)
vehNr = 0
for i in range(N):
if random.uniform(0, 1) < pWE:
print(' <vehicle id="WN_%i" type="typedist1" route="WN" depart="%i" />' % (
vehNr, i), file=routes)
vehNr += 1
if random.uniform(0, 1) < pWE:
print(' <vehicle id="ES_%i" type="typedist1" route="ES" depart="%i" />' % (
vehNr, i), file=routes)
vehNr += 1
if random.uniform(0, 1) < pWE:
print(' <vehicle id="NE_%i" type="typedist1" route="NE" depart="%i" />' % (
vehNr, i), file=routes)
vehNr += 1
if random.uniform(0, 1) < pWE:
print(' <vehicle id="SW_%i" type="typedist1" route="SW" depart="%i" />' % (
vehNr, i), file=routes)
vehNr += 1
print("</routes>", file=routes)
# The program looks like this
# <tlLogic id="0" type="static" programID="0" offset="0">
# the locations of the tls are NESW
# <phase duration="31" state="GrGr"/>
# <phase duration="6" state="yryr"/>
# <phase duration="31" state="rGrG"/>
# <phase duration="6" state="ryry"/>
# </tlLogic>
def run():
"""execute the TraCI control loop"""
step = 0
# we start with phase 2 where EW has green
traci.trafficlight.setPhase("0", 0)
while traci.simulation.getMinExpectedNumber() > 0:
traci.simulationStep()
step += 1
traci.close()
sys.stdout.flush()
def get_options():
optParser = optparse.OptionParser()
optParser.add_option("--nogui", action="store_true",
default=False, help="run the commandline version of sumo")
options, args = optParser.parse_args()
return options
# this is the main entry point of this script
if __name__ == "__main__":
options = get_options()
# this script has been called from the command line. It will start sumo as a
# server, then connect and run
if options.nogui:
sumoBinary = checkBinary('sumo')
else:
sumoBinary = checkBinary('sumo-gui')
# first, generate the route file for this simulation
generate_routefile()
# this is the normal way of using traci. sumo is started as a
# subprocess and then the python script connects and runs
traci.start([sumoBinary, "-c", "data/cross.sumocfg",
"--tripinfo-output", "tripinfo.xml"])
run()