예제 #1
0
파일: Qsim.py 프로젝트: xjtuwh/carstop

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
예제 #2
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
    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)
예제 #3
0
# -*- 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()