Hi,
I had issues with load-state / save-state recently so I ran a simple
test to validate it. it goes as follows: (1) start simulation; (2) save
it after 5 minutes; (3) stop sumo; (4) start sumo from saved state; & go
to step (2) to repeat...

If load/save state works correctly, one would expect similar results as
in standard uninterrupted simulation. I don't require identical behavior
(due to the seed of pseudorandom number generator), but the results
indicate that something goes wrong. See enclosed plot. The green line is
number of vehicles in LuST for first 12 hours of simulation. The blue
line is number of vehicles in the simulation interrupted with saved &
loaded states. It diverges: although not in the plot, after about 18
hours of simulation there are some 50000 vehicles!

Other problems:
1) Saving/loading states also seem to cause plenty of emergency stops,
usually due to red light.
2) Saving/loading states also seem to cause many collisions
3) Strangely, classical teleportations due to jam, yield, or wrong lane
are scarce.

Could you please take a look at this and verify whether there is a
problem? I have enclosed the script that generated the plot, you
can run it to reproduce the problem. Use "python
save-state-load-state.py <path-to-scenario> <path-to-sumo-home>". I
assume it works the same with any scenario. I tested it on r20617.

Thank you,
Matej.



import argparse
import sys
import os
import subprocess
import matplotlib.pyplot as plt

# parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('scenario', help='SUMO scenario configuration file')
parser.add_argument('sumo-home', help='path to SUMO_HOME folder')
parser.add_argument('--sumo-bin', help='SUMO binary to invoke', default='sumo')
args = vars(parser.parse_args())

sys.path.append(os.path.join(args['sumo-home'], 'tools'))
env = os.environ.copy()
env['SUMO_HOME'] = args['sumo-home']
import traci

state_fname = 'sumo-state.xml'
port = 55002
step = 300 # 5 minutes
lastsavedtime = 0
teleports = 0
estops = 0
v = []
v2 = []

#prepare initial state
proc = subprocess.Popen([args['sumo_bin'], '--start', '-c', args['scenario']] +
                        '--remote-port {} --no-step-log' \
                            .format(str(port)).strip().split(' '), env=env, 
                        stdout=subprocess.PIPE)
tad=traci.connect(port)
tad.simulation.saveState(state_fname)
tad.close()
proc.wait()

# start reference run
proc2 = subprocess.Popen([args['sumo_bin'], '--start', '-c', args['scenario']] +
                             '--remote-port {} --begin {} --no-step-log --load-state' \
                            .format(str(port+1), lastsavedtime)
                         .strip().split(' ') + [state_fname], env=env, 
                         stdout=subprocess.PIPE)
tad2 = traci.connect(port+1)

# simulate
while(1):
    proc = subprocess.Popen([args['sumo_bin'], '--start', '-c', args['scenario']] +
                                 '--remote-port {} --begin {} --no-step-log --load-state' \
                                .format(str(port), lastsavedtime)
                            .strip().split(' ') + [state_fname], env=env, 
                            stdout=subprocess.PIPE)
    tad = traci.connect(port)
    tad.simulationStep()
    tad2.simulationStep()
    while(tad.simulation.getCurrentTime()/1000.0<lastsavedtime+step):
        tad.simulationStep()
        tad2.simulationStep()

    v.append(len(tad.vehicle.getIDList()))
    v2.append(len(tad2.vehicle.getIDList()))
    tad.simulation.saveState(state_fname)
    lastsavedtime = tad.simulation.getCurrentTime()/1000.0
    
    if(len(tad.vehicle.getIDList())==0 or lastsavedtime>10000.0):
        tad.close()
        tad2.close()
        proc.wait()
        proc2.wait()
        break               

    tad.close()
    proc.wait()

    for line in iter(proc.stdout.readline, ''):
        w = line.split(' ')
        if len(w)>0 and w[0] == 'Emergency' and w[1]=='Stops:':
            estops = estops + int(w[2])
        if len(w)>0 and w[0] == 'Teleports:':
            teleports = teleports + int(w[1])

    print 'Got {} ({}) vehicles, {} emergency stops and {} teleports at time {} ({})'.format(v[-1], v2[-1], estops, teleports, lastsavedtime, tad2.simulation.getCurrentTime()/1000.0)

# plot
fig = plt.figure(figsize=(9,9))
plt.plot(range(len(v)), v, range(len(v2)), v2)
plt.savefig('vehicles-in-time.svg')

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
sumo-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sumo-user

Reply via email to