#if not newdest == car['dest']: err += Sim.moveVehicleAlong(str(carID), 0.0, newdest) #car['dest'] = newdest # keep old destination? if laneChange and (grade == 'i' or grade == 'o'): newlane = makeRoad(route, grade, 1 - ln) err += Sim.moveVehicle(str(carID), newlane, car['lanepos']) cars['lane'] = newlane if Sim.getLaneInfo(car['lane'])[0] - carLanePos <= distance: if grade == 'i': # entering intersection #internal = next((k for i,j,k in intersectionLookUp if # i==car['lane'] and j==car['dest'])) #err += Sim.moveVehicleAlong(str(carID), distance, internal) err += Sim.moveVehicleAlong(str(carID), distance, ':') elif grade == 'o': # leaving simulation Sim.removeVehicle(str(carID)) cars['status'].iloc[carID] = 1 # somehow inform Agents that car is gone else: # going from intersection to exit lane err += Sim.moveVehicleAlong(str(carID), distance, car['dest']) elif distance > 0: err += Sim.moveVehicleAlong(str(carID), distance, car['lane']) if err == 0: # finish step Sim.end() print "iteration " + str(iteration) + " : " + str(time.time() - starttime) iteration += 1 time.sleep(.05)
#if not newdest == car['dest']: err += Sim.moveVehicleAlong(str(carID), 0.0, newdest) #car['dest'] = newdest # keep old destination? if laneChange and (grade =='i' or grade=='o'): newlane = makeRoad(route,grade,1-ln) err += Sim.moveVehicle(str(carID), newlane, car['lanepos']) cars['lane'] = newlane if Sim.getLaneInfo(car['lane'])[0] - carLanePos <= distance: if grade=='i': # entering intersection #internal = next((k for i,j,k in intersectionLookUp if # i==car['lane'] and j==car['dest'])) #err += Sim.moveVehicleAlong(str(carID), distance, internal) err += Sim.moveVehicleAlong(str(carID), distance, ':') elif grade=='o': # leaving simulation Sim.removeVehicle(str(carID)) cars['status'].iloc[carID] = 1 # somehow inform Agents that car is gone else: # going from intersection to exit lane err += Sim.moveVehicleAlong(str(carID), distance, car['dest']) elif distance > 0: err += Sim.moveVehicleAlong(str(carID), distance, car['lane']) if err == 0: # finish step Sim.end() print "iteration "+str(iteration)+" : "+str(time.time()-starttime) iteration += 1 time.sleep(.05) else:
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') if status == 0: #add vehicle info to the dataframe thisdf.add([[pos[0],pos[1],angle,VEHsize[0],VEHsize[1],lanepos]]) Sim.moveVehicleAlong(road, dist) totaldist += dist time.sleep(.05) # might guard against freeze allcars[road] = thisdf.out() Sim.removeVehicle(road) Sim.end() # now use dataframes of position+angle to find collision points collisions = WriteFrame(['lane','lane2','begin_lp','end_lp']) for an in range(len(intersectionLookUp)): for bn in range(an): print "checking "+str(an)+", "+str(bn) starta,enda,roada = intersectionLookUp[an] startb,endb,roadb = intersectionLookUp[bn] cara = allcars[roada] carb = allcars[roadb] abegin = 50 aend = -1 bbegin = 50