def main(): road = Road(SPEED_LIMIT, TRAFFIC_DENSITY, LANE_SPEEDS) road.update_width = AMOUNT_OF_ROAD_VISIBLE road.populate_traffic() ego_config = config = { 'speed_limit': SPEED_LIMIT, 'num_lanes': len(LANE_SPEEDS), 'goal': GOAL, 'max_acceleration': MAX_ACCEL } road.add_ego(2, 0, ego_config) timestep = 0 while road.get_ego().s <= GOAL[0]: timestep += 1 if timestep > 150: print "Taking too long to reach goal. Go faster!" break road.advance() print road time.sleep(float(1.0) / FRAMES_PER_SECOND) ego = road.get_ego() if ego.lane == GOAL[1]: print "You got to the goal in {} seconds!".format(timestep) else: print "You missed the goal. You are in lane {} instead of {}.".format( ego.lane, GOAL[1])
def run_simulation(VISUALIZE=True): road = Road(SPEED_LIMIT, TRAFFIC_DENSITY, LANE_SPEEDS, AMOUNT_OF_ROAD_VISIBLE) road.populate_traffic() ego_config = { 'speed_limit': SPEED_LIMIT, 'num_lanes': len(LANE_SPEEDS), 'goal': GOAL, 'max_acceleration': MAX_ACCEL, } # Ego begins travelling at lane #2. road.add_ego(2, 0, ego_config) timestep = 0 while road.get_ego().s <= GOAL[0]: timestep += 1 if timestep > 150: # simulation time limit if VISUALIZE: print("Taking too long to reach goal. Go faster!") break road.advance() if VISUALIZE: print(road) time.sleep(float(1.0) / FRAMES_PER_SECOND) # Completed to the goal distance ego = road.get_ego() if VISUALIZE: if ego.lane == GOAL[1]: print("You got to the goal in %d seconds!" % timestep) else: print("You missed the goal. " "You are in lane %d instead of %d." % (ego.lane, GOAL[1])) return timestep, ego.lane
def run_simulation(VISUALIZE=True): road = Road(SPEED_LIMIT, TRAFFIC_DENSITY, LANE_SPEEDS, AMOUNT_OF_ROAD_VISIBLE) road.populate_traffic() ego_config = { 'speed_limit': SPEED_LIMIT, 'num_lanes': len(LANE_SPEEDS), 'goal': GOAL, 'max_acceleration': MAX_ACCEL } # ego car starts at lane 2, s=0, goal is s=300, lane 0 road.add_ego(2, 0, ego_config) timestep = 0 # only check if reached GOAL s, if reached check if reached GOAL lane # each iteration advance() on sec while road.get_ego().s <= GOAL[0]: timestep += 1 if timestep > 150: if VISUALIZE: print("Taking too long to reach goal. Go faster!") break road.advance() if VISUALIZE: print(road) time.sleep(float(1.0) / FRAMES_PER_SECOND) ego = road.get_ego() if VISUALIZE: if ego.lane == GOAL[1]: print("You got to the goal in {} seconds!".format(timestep)) else: print("You missed the goal. You are in lane {} instead of {}.".format(ego.lane, GOAL[1])) return timestep, ego.lane