def add_car(self, x, y, vx, vy, v_des, p_des, direction, theta): if y < 4.: idx = self._lower_lane_next_idx self._lower_lane_next_idx += 1 if self._lower_lane_next_idx > int(self.max_veh_num / 2.): self._lower_lane_next_idx = 1 elif y > 4.: idx = self._upper_lane_next_idx self._upper_lane_next_idx += 1 if self._upper_lane_next_idx > self.max_veh_num: self._upper_lane_next_idx = int(self.max_veh_num / 2.) + 1 car = Car(idx=idx, length=self.car_length, width=self.car_width, color=random.choice(RED_COLORS), max_accel=self.car_max_accel, max_speed=self.car_max_speed, max_rotation=0., expose_level=self.car_expose_level) driver = YNYDriver(idx=idx, car=car, dt=self.dt, x_driver=IDMDriver(idx=idx, car=car, sigma=self.driver_sigma, s_des=self.s_des, s_min=self.s_min, axis=0, min_overlap=self.min_overlap, dt=self.dt), y_driver=PDDriver(idx=idx, car=car, sigma=0., axis=1, dt=self.dt)) car.set_position(np.array([x, y])) car.set_velocity(np.array([vx, vy])) car.set_rotation(theta) driver.x_driver.set_v_des(v_des) driver.x_driver.set_direction(direction) driver.y_driver.set_p_des(p_des) if np.random.rand() < self.yld: driver.set_yld(True) else: driver.set_yld(False) self._cars.append(car) self._drivers.append(driver) return car, driver
def __init__(self, v_des, y_des, x_sigma, y_sigma, **kwargs): # x_driver = PDriver(sigma=x_sigma, v_des=v_des, a_max=1.0, axis=0, **kwargs) x_driver = IDMDriver(sigma=x_sigma, v_des=10.0, s_des=1.0, s_min=0.5, axis=0, min_overlap=0., **kwargs) y_driver = PDDriver(sigma=y_sigma, p_des=y_des, a_max=1.0, axis=1, **kwargs) super(EgoDriver, self).__init__(x_driver, y_driver, **kwargs)
def add_car(self, idx, x, y, vx, vy, v_des, p_des, direction, theta): car = Car(idx=idx, length=self.car_length, width=self.car_width, color=random.choice(RED_COLORS), max_accel=self.car_max_accel, max_speed=self.car_max_speed, expose_level=self.car_expose_level) driver = TwoTDriver(idx=idx, car=car, dt=self.dt, x_driver=IDMDriver(idx=idx, car=car, sigma=self.driver_sigma, s_min=self.s_min, axis=0, min_overlap=self.min_overlap, dt=self.dt), y_driver=PDDriver(idx=idx, car=car, sigma=0., axis=1, dt=self.dt)) car.set_position(np.array([x, y])) car.set_velocity(np.array([vx, vy])) car.set_rotation(theta) driver.x_driver.set_v_des(v_des) driver.x_driver.set_direction(direction) driver.y_driver.set_p_des(p_des) driver.t1 = np.random.rand() if np.random.rand() < self.yld: driver.yld = True driver.t2 = np.random.rand() * 1.5 - 0.5 else: driver.yld = False driver.t2 = None self._cars.append(car) self._drivers.append(driver) return car, driver
def __init__(self, aggressive, x_sigma, y_sigma, car, **kwargs): self.aggressive = aggressive self.target_lane = None self.car = car if self.aggressive: v_des = np.random.uniform(0.5, 1.0) s_des = np.random.uniform(0.8, 1.0) s_min = np.random.uniform(0.4, 0.6) min_overlap = -self.car.width / 2. self.min_front_x = self.car.length + s_min self.min_back_x = self.car.length + s_min self.min_advantage = self.car.length / 2. else: v_des = np.random.uniform(0.0, 0.5) s_des = np.random.uniform(0.9, 1.1) s_min = np.random.uniform(0.5, 0.7) min_overlap = self.car.width / 2. self.min_front_x = self.car.length + s_min self.min_back_x = self.car.length + s_min self.min_advantage = self.car.length x_driver = IDMDriver(sigma=x_sigma, v_des=v_des, s_des=s_des, s_min=s_min, axis=0, min_overlap=min_overlap, car=car, **kwargs) y_driver = PDDriver(sigma=y_sigma, p_des=0., a_max=1.0, axis=1, k_p=2.0, k_d=5.0, car=car, **kwargs) self.on_target = True super(EnvDriver, self).__init__(x_driver, y_driver, car=car, **kwargs)
def __init__(self, yld=0.5, vs_actions=[0.,0.5,3.], t_actions=[-1.5,0.,1.5], desire_speed=3., speed_cost=0.01, t_cost=0.01, control_cost=0.01, collision_cost=1., outroad_cost=1., goal_reward=1., road=Road([RoadSegment([(-100.,0.),(100.,0.),(100.,8.),(-100.,8.)]), RoadSegment([(-2,-10.),(2,-10.),(2,0.),(-2,0.)])]), n_cars=3, num_updates=1, dt=0.1, **kwargs): self.yld = yld self.vs_actions = vs_actions self.t_actions = t_actions # we use target value instead of target change so system is Markovian self.rl_actions = list(itertools.product(vs_actions,t_actions)) self.num_updates = num_updates self.desire_speed = desire_speed self.speed_cost = speed_cost self.t_cost = t_cost self.control_cost = control_cost self.collision_cost = collision_cost self.outroad_cost = outroad_cost self.goal_reward = goal_reward self._collision = False self._outroad = False self._goal = False self._intentions = [] car_length=5.0 car_width=2.0 car_max_accel=10.0 car_max_speed=40.0 car_expose_level=4 cars = [Car(idx=cid, length=car_length, width=car_width, color=random.choice(BLUE_COLORS), max_accel=car_max_accel, max_speed=car_max_speed, expose_level=car_expose_level) for cid in range(n_cars) ] driver_sigma = 0.0 s_min = 2.0 min_overlap = 1.0 drivers = [] drivers.append(EgoDriver(trajectory=EgoTrajectory(),idx=0,car=cars[0],dt=dt)) for did in range(1,n_cars): driver = TwoTDriver(idx=did, car=cars[did], dt=dt, x_driver=IDMDriver(idx=did, car=cars[did], sigma=driver_sigma, s_min=s_min, axis=0, min_overlap=min_overlap, dt=dt), y_driver=PDDriver(idx=did, car=cars[did], sigma=driver_sigma, axis=1, dt=dt)) drivers.append(driver) super(TIntersection, self).__init__( road=road, cars=cars, drivers=drivers, dt=dt, **kwargs,)