self.restart=True return self.df QLearnInfo = WriteFrame(['ID','Car Location','Lane Number','Destination Road', 'Destination Lane','Correct Lane','Speed','Collision', 'Adjacent Lane Free','Front of Line', 'Speed of Ahead Car','Distance to Ahead Car', 'Time to Nearest Vehicle']) iteration = 1 err = 0 ## run iteration while iteration <= numiter and err == 0: starttime = time.time() Sim = Sumo(configuration) ## now set up parameters and vehicles # [creation time, starting lane, destination lane, starting speed] cars = pd.DataFrame([[0., '1i_0','3o_0',20.]]) cars = cars.append([[0., '2i_0','1o_0',20.]]) cars.columns = ['time','lane','dest','speed'] ncars = cars.shape[0] cars['status'] = [-1]*ncars #-1 not created, 0 created, 1 exited, 2 crashed cars['lanepos'] = [-1]*ncars # not given to Agent but needed for calculation cars['x'] = [-1]*ncars cars['y'] = [-1]*ncars cars['angle'] = [-1]*ncars cars['ilane'] = ['']*ncars ttime = 0
# smart restart if file is saved if 'lastStart.int' in os.listdir(os.path.realpath('.')): lastStart = open('lastStart.int') iteration = int(lastStart.read()) lastStart.close() params = pd.read_csv(paramFile,header=0) else: iteration = 1 params = None ## run iteration while iteration <= options.numiter: err = 0 starttime = time.time() Sim = Sumo(configuration, options.gui) ## now set up parameters and vehicles err += Sim.createVehicle('ego','1i_0',0.) egoSpeed = 25. err += Sim.createVehicle('left','3i_1',0.) leftSpeed = 20. params_iter = pd.DataFrame([[egoSpeed, leftSpeed, 0., 0., -1., 'na']], columns=ParameterColumns) output = None ttime = 0 maxTime = 100 # seconds ## run simulation
# smart restart if file is saved if 'lastStart.int' in os.listdir(os.path.realpath('.')): lastStart = open('lastStart.int') iteration = int(lastStart.read()) lastStart.close() params = pd.read_csv(paramFile,header=0) else: iteration = 1 params = None call(['mkdir','-p',outputFolder+'/'+options.outputName]) # add folder ## run iteration while iteration <= options.numiter: err = 0 starttime = time.time() Sim = Sumo(configuration, options.gui) ## now set up parameters and vehicles err += Sim.createVehicle('ego','main_0',VEHsize[0]) #egoControl = Controllers.RearEndEgo(vehicleSpeed(), vehicleAccel()) egoControl = Controllers.RearEndRandom(vehicleSpeed(),maxdecel=.5) err += Sim.createVehicle('lead','main_0',50+VEHsize[0]) #leadControl = Controllers.RearEndBrake(vehicleSpeed(), vehicleAccel()) leadControl = Controllers.RearEndRandom(vehicleSpeed(),maxdecel=5.) # params_iter = pd.DataFrame([[egoControl.speed, leadControl.speed, # egoControl.accel, leadControl.accel, # leadControl.brakeMagnitude, leadControl.brakeTime, # -1.]], columns=ParameterColumns) params_iter = pd.DataFrame([[egoControl.speed, leadControl.speed, -1.]], columns=ParameterColumns)
# smart restart if file is saved if 'lastStart.int' in os.listdir(os.path.realpath('.')): lastStart = open('lastStart.int') iteration = int(lastStart.read()) lastStart.close() params = pd.read_csv(paramFile, header=0) else: iteration = 1 params = None ## run iteration while iteration <= options.numiter: err = 0 starttime = time.time() Sim = Sumo(configuration, options.gui) ## now set up parameters and vehicles err += Sim.createVehicle('ego', '1i_0', 0.) egoSpeed = 25. err += Sim.createVehicle('left', '3i_1', 0.) leftSpeed = 20. params_iter = pd.DataFrame([[egoSpeed, leftSpeed, 0., 0., -1., 'na']], columns=ParameterColumns) output = None ttime = 0 maxTime = 100 # seconds ## run simulation
QLearnInfo = WriteFrame([ 'ID', 'Car Location', 'Lane Number', 'Destination Road', 'Destination Lane', 'Correct Lane', 'Speed', 'Collision', 'Adjacent Lane Free', 'Front of Line', 'Speed of Ahead Car', 'Distance to Ahead Car', 'Time to Nearest Vehicle' ]) iteration = 1 err = 0 ## run iteration while iteration <= numiter and err == 0: starttime = time.time() Sim = Sumo(configuration) ## now set up parameters and vehicles # [creation time, starting lane, destination lane, starting speed] cars = pd.DataFrame([[0., '1i_0', '3o_0', 20.]]) cars = cars.append([[0., '2i_0', '1o_0', 20.]]) cars.columns = ['time', 'lane', 'dest', 'speed'] ncars = cars.shape[0] cars['status'] = [ -1 ] * ncars #-1 not created, 0 created, 1 exited, 2 crashed cars['lanepos'] = [ -1 ] * ncars # not given to Agent but needed for calculation cars['x'] = [-1] * ncars
# -*- coding: utf-8 -*- """ Created on Tue Nov 17 20:13:37 2015 @author: motro """ from sumoMethods import Sumo configuration = 'emptyhighway' sim = Sumo(configuration, gui=True) sim.createVehicle('a','main_0',40) [lane,lanex,xy] = sim.getVehicleState('a') print 'a, 0: '+str(xy[0]) sim.createVehicle('b','main_0') [lane,lanex,xy] = sim.getVehicleState('b') print 'b, 0: '+str(xy[0]) sim.moveVehicleAlong('b',38) [lane,lanex,xy] = sim.getVehicleState('a') print 'a, 1: '+str(xy[0]) [lane,lanex,xy] = sim.getVehicleState('b') print 'b, 1: '+str(xy[0]) sim.end()
self.restart=True def add(self, newrows): if self.restart: self.df = pd.DataFrame(newrows) self.restart=False else: self.df = self.df.append(newrows) def out(self): if self.colnames is not None: self.df.columns = self.colnames #self.df.to_csv(fileName, sep=',', header=True, index=False) self.restart=True return self.df err = 0 Sim = Sumo(configuration,gui=True) # first gather the possible positions/angles of each intersection lane allcars = {} for start, end, road in intersectionLookUp: print "at "+road err += Sim.createVehicle(road, start, 90.) err += Sim.moveVehicleAlong(road, 0.1, end) thisdf = WriteFrame(['x','y','angle','length','width','lp']) dist = 1. status = -1 totaldist = 0 while status < 1 and totaldist < 50: lane,lanepos,pos,angle = Sim.getVehicleState(road) status = (lane[1]=='o')-(lane[1]=='i')