Hello Jakob,
As per your recommendation I created simulation with fewer vehicles and
plenty of road space.
- The vehicles were able to exceed speed limit.

I even changed the color of vehicle after they reached certain speed as an
identifier. I guess this makes it clear that the vehicles can exceed speed
limit.

However, the code (attached herewith) instructs the vehicle to reach the
speed of 20.4m/s from 5m/s in 15.4s (took the difference of speeds and
assigned the value in milliseconds to slowdown). The transition took 20
time steps instead of expected 16 time steps (enough gap between the
vehicles). The desired acceleration was 1m/s^2 but vehicles never
accelerated at that rate. Can this be fixed?

The simulation I am running the vehicles are not able to exceed the speed
limit.
- Is there a check on the extent to which vehicle can exceed the speed
limit when there is vehicle ahead of it?
- I also stored the speedfactor of the vehicle for every time step. Once
it's set to certain value it remains the same.

I am of the notion (previously shared) that if space after of the vehicle
is more than safe distance, the vehicle should be able to travel as fast as
it can or is being asked using Traci commands. Please suggest. Thanks.
#Updated algorithm to take care of vehicles stuck after RED phase
#TraCI

import os           #OS module which provides function for interacting with OS
import sys          #to communicate with other software
import optparse     #a python module to write command line tools
import subprocess   #allows to communicate b/w pyhton script and cmd.exe
import random

#check for environment variables
'''
if 'sumo-0.28.0' in os.environ:
    tools = os.path.join(os.environ['sumo-0.28.0'], 'tools')
    sys.path.append(tools)
else:
    sys.exit("please declare environment variables 'sumo-0.28.0'")
'''
#try:
#    sys.path.append(os.path.join(os.path.dirname(
#        __file__), '..', '..', '..', '..', "tools"))  # tutorial in tests
#    sys.path.append(os.path.join(os.environ.get("sumo-0.28.0", os.path.join(
#        os.path.dirname(__file__), "..", "..", "..")), "tools"))  # tutorial 
in docs
#    from sumolib import checkBinary
try:
    sys.path.append(os.path.join(os.environ.get("SUMO_HOME"), "tools"))
    from sumolib import checkBinary
except ImportError:
    sys.exit(
        "please declare environment variable 'SUMO_HOME' as the root directory 
of your sumo installation (it should contain folders 'bin', 'tools' and 
'docs')")

now_port = 9538
now_period = 6
op_path = 'C:/Users/vr2002/Music/sumo-win64-0.28.0/sumo-0.28.0/Outputs/'

sumoBinary = 
"C:/Users/vr2002/Music/sumo-win64-0.28.0/sumo-0.28.0/bin/sumo-gui.exe"
# sumoBinary is a variable which holds the path to sumo-gui, you can any name 
for this variable
op_path_file = op_path + 'sing_veh_S' + str(now_port) + 'P' + str(now_period)
sumoProcess = subprocess.Popen([sumoBinary, "-c", 
"sing_veh.sumo.cfg","--remote-port", str(now_port),
                                            "--emission-output", "EMS.xml",
                                            "--tripinfo-output", 
"SummaryOP.xml", "--fcd-output", "Trace.xml",
                                            "--output-prefix", op_path_file], 
stdout=sys.stdout, stderr=sys.stderr)
import traci
traci.init(now_port)
step = 0
while traci.simulation.getMinExpectedNumber() > 0:
    traci.simulationStep()
    veh_IDs_ab = traci.edge.getLastStepVehicleIDs("AB")
    for veh in veh_IDs_ab:
        u = traci.vehicle.getSpeed(veh)
        if u >= 20.4:
            sf_org = traci.vehicle.getSpeedFactor(veh)
            traci.vehicle.setSpeedFactor(veh, 1.2)
            sf_new = traci.vehicle.getSpeedFactor(veh)
            traci.vehicle.setSpeed(veh, 20.4)
            achieved = 1
            traci.vehicle.setColor(veh, (1,1,1,0))

        else:
            sf_org = traci.vehicle.getSpeedFactor(veh)
            traci.vehicle.setSpeedFactor(veh, 1.2)
            sf_new = traci.vehicle.getSpeedFactor(veh)
            time_accel = 20.4 - u
            time_accel_ms = int(1000*time_accel)
            traci.vehicle.slowDown(veh, 20.4, time_accel_ms)
            achieved = 0

        with open ("sing_veh_control.txt", 'a') as opt1:
            opt1.write('\n' + "Veh_ID %s" %veh + " current speed %s" %u + " 
speed factor org%s" %sf_org +
                       " speed factor NEW %s" %sf_new + " Achieved %s" 
%achieved)

    step += 1
traci.close() # moving this command here closes each simulation before a new 
simulation begins :)

Attachment: sing_veh.sumo.cfg
Description: Binary data

<?xml version="1.0" encoding="UTF-8"?>
<routes>
	<vTypeDistribution id="vdis">
		<vType id = "PCs" accel = "2.9" decel ="7.5" sigma = "0.5" length = "4.3" maxspeed = "70"  vClass = "passenger" emissionClass = "HBEFA3/PC_G_EU5" guiShape = "passenger" probability = "0.56"/>
		<vType id = "CTs" accel = "1.3" decel ="4" sigma = "0.5" length = "7.1" maxspeed = "50" color = "1,0,0" vClass = "truck"  emissionClass = "HBEFA3/LDV" guiShape = "truck" probability = "0.02"/>
		<vType id = "pass_van" color = "0,0,1" vclass = "passenger" emissionClass = "P_7_7" guiShape = "passenger/van" probability = "0.09"/>
		<vType id = "SUV" color = "0,1,1" vlcass = "passenger" emissionClass = "P_7_7" guishape = "passenger/wagon" probability = "0.12"/>
		<vType id = "del" color = "1,0,1" vlcass = "delivery" emissionClass = "P_7_7" guishape = "delivery" probability = "0.18"/>
		<vType id = "trail" color = "0,1,0" vclass = "trailer" emissionClass = "HBEFA3/HDV" guiShape = "truck" probability = "0.02"/>
	</vTypeDistribution>
	
	<route id = "LR" edges = "AB"/>
	
	<flow id = "F1200" begin = "0" end = "3200" vehsPerHour = "100" route = "LR" type = "vdis" departSpeed = "5"/>
</routes>
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 06/15/17 20:11:38 by SUMO netconvert Version 0.28.0
<?xml version="1.0" encoding="UTF-8"?>

<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/netconvertConfiguration.xsd";>

    <input>
        <node-files value="sing_veh.nod.xml"/>
        <edge-files value="sing_veh.edg.xml"/>
        <type-files value="sing_veh.typ.xml"/>
    </input>

    <output>
        <output-file value="sing_veh.net.xml"/>
    </output>

</configuration>
-->

<net version="0.27" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/net_file.xsd";>

    <location netOffset="750.00,0.00" convBoundary="0.00,0.00,1500.00,0.00" origBoundary="-750.00,0.00,750.00,0.00" projParameter="!"/>

    <type id="a" priority="1" numLanes="2" speed="17.60"/>

    <edge id="AB" from="A" to="B" priority="1" type="a">
        <lane id="AB_0" index="0" speed="17.60" length="1500.00" shape="0.00,-4.95 1500.00,-4.95"/>
        <lane id="AB_1" index="1" speed="17.60" length="1500.00" shape="0.00,-1.65 1500.00,-1.65"/>
    </edge>

    <junction id="A" type="unregulated" x="0.00" y="0.00" incLanes="" intLanes="" shape="0.00,-0.05 0.00,-6.55"/>
    <junction id="B" type="unregulated" x="1500.00" y="0.00" incLanes="AB_0 AB_1" intLanes="" shape="1500.00,-6.55 1500.00,-0.05"/>

</net>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
sumo-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sumo-user

Reply via email to