Hi, I have attached both the .py and .txt files below.
On Tue, Mar 30, 2021 at 4:50 AM <[email protected]> wrote: > Hi Abdullah, > > > > I cannot see your .py file. Would you please send it as a .txt file? > > > > Regards, > > Giuliana > > > > *Von:* sumo-user <[email protected]> *Im Auftrag von *. > Abdullah > *Gesendet:* Montag, 29. März 2021 16:50 > *An:* Sumo project User discussions <[email protected]> > *Betreff:* [sumo-user] Using traci.simulation.loadState increases memory > usage > > > > Hi, > > > > I have noticed that if I use traci.simulation.loadState multiple times > then my memory usage increases significantly. I have attached a simple code > below, where cars are being added to the network and after every 5 seconds, > a state is being saved and loaded back up. If I do this multiple times, it > increases my memory usage. You can try the same code again by commenting > out line 47 and it will drastically reduce the memory usage. Is there > something I am doing wrong and is there a way around this? > > > > -- > > Thank you. > > Abdullah > _______________________________________________ > sumo-user mailing list > [email protected] > To unsubscribe from this list, visit > https://www.eclipse.org/mailman/listinfo/sumo-user > -- Thank you. Abdullah
import os
import sys, gc
import optparse
import time
import json
import numpy as np
import random
# we need to import some 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 # Checks for the binary in environ vars
import traci
def add_vehicle():
additional_route_ID = traci.route.getIDList()
no_of_cars = 60 - traci.simulation.getMinExpectedNumber()
for i in range(no_of_cars):
routeID = random.choice(additional_route_ID)
while True:
additional_veh_ID = random.randint(0,10000000)
vehID = "addtionVehical."+str(additional_veh_ID)
try:
traci.vehicle.add(vehID, routeID, "car")
break
except:
pass
def run():
print('saving')
step = 0
traci.start([checkBinary('sumo'), "-c", "config.sumocfg", "--step-length",
"0.5", '--save-state.rng', "--step-method.ballistic", "--no-step-log",
"--no-warnings", "--tripinfo-output", "tripinfo.xml"])
simulation_time = 10*60 # increasing this increases Memory usage
while step <= simulation_time:
print(step)
add_vehicle() # adding vehicles to the network
traci.simulationStep()
step += traci.simulation.getDeltaT()
if step % 5 == 0:
for _ in range(200):
traci.simulation.saveState('saved_state')
# Save state and work on it and then load back the state
traci.simulation.loadState('saved_state') # this uses a lot of
memory, comment it to see the difference
traci.close()
# main entry point
if __name__ == "__main__":
run()
traci_demo.py
Description: Binary data
_______________________________________________ sumo-user mailing list [email protected] To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
