def _make_road(self) -> None: """ Make a road composed of a straight highway and a merging lane. :return: the road """ net = RoadNetwork() # Highway lanes ends = [150, 80, 80, 150] # Before, converging, merge, after c, s, n = LineType.CONTINUOUS_LINE, LineType.STRIPED, LineType.NONE y = [0, StraightLane.DEFAULT_WIDTH] line_type = [[c, s], [n, c]] line_type_merge = [[c, s], [n, s]] for i in range(2): net.add_lane("a", "b", StraightLane([0, y[i]], [sum(ends[:2]), y[i]], line_types=line_type[i])) net.add_lane("b", "c", StraightLane([sum(ends[:2]), y[i]], [sum(ends[:3]), y[i]], line_types=line_type_merge[i])) net.add_lane("c", "d", StraightLane([sum(ends[:3]), y[i]], [sum(ends), y[i]], line_types=line_type[i])) # Merging lane amplitude = 3.25 ljk = StraightLane([0, 6.5 + 4 + 4], [ends[0], 6.5 + 4 + 4], line_types=[c, c], forbidden=True) lkb = SineLane(ljk.position(ends[0], -amplitude), ljk.position(sum(ends[:2]), -amplitude), amplitude, 2 * np.pi / (2*ends[1]), np.pi / 2, line_types=[c, c], forbidden=True) lbc = StraightLane(lkb.position(ends[1], 0), lkb.position(ends[1], 0) + [ends[2], 0], line_types=[n, c], forbidden=True) net.add_lane("j", "k", ljk) net.add_lane("k", "b", lkb) net.add_lane("b", "c", lbc) road = Road(network=net, np_random=self.np_random, record_history=self.config["show_trajectories"]) road.objects.append(Obstacle(road, lbc.position(ends[2], 0))) self.road = road
def generate_merge(self, begin, amplitude_1, sin_length_1, str_length_1, amplitude_2, sin_length_2, width, reverse): l_in_1_sin = SineLane([0, begin], 0, width, -amplitude_1 * reverse, np.pi / (sin_length_1), np.pi / 2, [LineType.CONTINUOUS, LineType.CONTINUOUS], bounds=[0, sin_length_1], forbidden=False) l_in_1_str = StraightLane( l_in_1_sin.position(sin_length_1, 0), 0, width, [LineType.CONTINUOUS_LINE, LineType.CONTINUOUS], bounds=[0, str_length_1], name='lm12') l_in_out_sin = SineLane(l_in_1_str.position(str_length_1, -amplitude_2 * reverse), 0, width, amplitude_2 * reverse, np.pi / (sin_length_2), np.pi / 2, [LineType.CONTINUOUS, LineType.CONTINUOUS], bounds=[0, sin_length_2], forbidden=False) l = LanesConcatenation([l_in_1_sin, l_in_1_str, l_in_out_sin]) return l
def make_straight(self): lm10 = StraightLane(np.array([0, 0]), 0, 4.0, [LineType.CONTINUOUS_LINE, LineType.STRIPED], bounds=[0, 500]) l1 = LanesConcatenation([lm10]) lm20 = StraightLane(l1.position(0, 4), 0, 4.0, [LineType.STRIPED, LineType.STRIPED], bounds=[0, 500]) l2 = LanesConcatenation([lm20]) # lm30 = StraightLane(l2.position(0,4), 0, 4.0, [LineType.STRIPED, LineType.STRIPED],bounds=[0,100]) # lm31 = StraightLane(lm30.position(0,0), 0, 4.0, [LineType.STRIPED, LineType.STRIPED],bounds=[0,500]) # l3 = LanesConcatenation([lm30,lm31]) lm30 = StraightLane(l2.position(0, 4), 0, 4.0, [LineType.STRIPED, LineType.STRIPED], bounds=[0, 500]) l3 = LanesConcatenation([lm30]) amplitude = 4.5 lm40 = StraightLane(l3.position(0, 4), 0, 4.0, [LineType.STRIPED, LineType.CONTINUOUS_LINE], bounds=[200, 400]) lm41 = SineLane(lm40.position(400, amplitude), 0, 4.0, -amplitude, 2 * np.pi / (2 * 50), np.pi / 2, [LineType.CONTINUOUS, LineType.CONTINUOUS], bounds=[0, 50], forbidden=True) lm42 = StraightLane( lm41.position(50, 0), 0, 4.0, [LineType.CONTINUOUS_LINE, LineType.CONTINUOUS_LINE], bounds=[0, 50], forbidden=True) l4 = LanesConcatenation([lm40, lm41, lm42]) road = Road([l1, l2, l3, l4]) # road = Road([ l3]) # road = Road([lm0,lm2]) # todo !!!!!!!!!!! how to do with Obstacle in lane.vehicles obstacle = Obstacle(road, lm40.position(0, 0)) road.vehicles.append(obstacle) road.lanes[3].vehicles.append(obstacle) self.road = road
def _make_road(self): net = RoadNetwork() lane = SineLane([0, 0], [500, 0], amplitude=5, pulsation=2 * np.pi / 100, phase=0, width=10, line_types=[LineType.STRIPED, LineType.STRIPED]) net.add_lane("a", "b", lane) other_lane = StraightLane( [50, 50], [115, 15], line_types=[LineType.STRIPED, LineType.STRIPED], width=10) net.add_lane("c", "d", other_lane) self.lanes = [other_lane, lane] self.lane = self.lanes.pop(0) net.add_lane( "d", "a", StraightLane([115, 15], [115 + 20, 15 + 20 * (15 - 50) / (115 - 50)], line_types=[LineType.NONE, LineType.STRIPED], width=10)) road = Road(network=net, np_random=self.np_random, record_history=self.config["show_trajectories"]) self.road = road
def _create_circuit(self): circular_radius = 50 line_types = [LineType.STRIPED, LineType.CONTINUOUS] circular_lane_1 = CircularLane(center=(0.0, 0.0), radius=circular_radius, start_phase=0, end_phase=math.pi * 0.5, speed_limit=self.speed_limit, width=self.circuit_width, line_types=line_types) circular_lane_2 = CircularLane( center=(0.0, 0.0), radius=circular_radius, start_phase=math.pi * 0.5, end_phase=math.pi, speed_limit=self.speed_limit, width=self.circuit_width, line_types=line_types, ) circular_lane_start = circular_lane_1.position(0, 0) circular_lane_end = circular_lane_2.position(circular_lane_2.length, 0) sine_lane = SineLane( circular_lane_end, circular_lane_start, amplitude=10, pulsation=2 * math.pi / (circular_radius * 2), phase=0, speed_limit=self.speed_limit, width=self.circuit_width, line_types=line_types, ) self._add_lane('start', 'int1', circular_lane_1) self._add_lane('int1', 'int2', circular_lane_2) self._add_lane('int2', 'end', sine_lane)
def make_road(self): # Circle lanes: (s)outh/(e)ast/(n)orth/(w)est (e)ntry/e(x)it. center = [0, 0] # [m] radius = 30 # [m] alpha = 20 # [deg] net = RoadNetwork() radii = [radius, radius+4] n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED line = [[c, s], [n, c]] for lane in [0, 1]: net.add_lane("se", "ex", CircularLane(center, radii[lane], rad(90-alpha), rad(alpha), line_types=line[lane])) net.add_lane("ex", "ee", CircularLane(center, radii[lane], rad(alpha), rad(-alpha), line_types=line[lane])) net.add_lane("ee", "nx", CircularLane(center, radii[lane], rad(-alpha), rad(-90+alpha), line_types=line[lane])) net.add_lane("nx", "ne", CircularLane(center, radii[lane], rad(-90+alpha), rad(-90-alpha), line_types=line[lane])) net.add_lane("ne", "wx", CircularLane(center, radii[lane], rad(-90-alpha), rad(-180+alpha), line_types=line[lane])) net.add_lane("wx", "we", CircularLane(center, radii[lane], rad(-180+alpha), rad(-180-alpha), line_types=line[lane])) net.add_lane("we", "sx", CircularLane(center, radii[lane], rad(180-alpha), rad(90+alpha), line_types=line[lane])) net.add_lane("sx", "se", CircularLane(center, radii[lane], rad(90+alpha), rad(90-alpha), line_types=line[lane])) # Access lanes: (r)oad/(s)ine access = 200 # [m] dev = 120 # [m] a = 5 # [m] delta_st = 0.20*dev # [m] delta_en = dev-delta_st w = 2*np.pi/dev net.add_lane("ser", "ses", StraightLane([2, access], [2, dev/2], line_types=[s, c])) net.add_lane("ses", "se", SineLane([2+a, dev/2], [2+a, dev/2-delta_st], a, w, -np.pi/2, line_types=[c, c])) net.add_lane("sx", "sxs", SineLane([-2-a, -dev/2+delta_en], [-2-a, dev/2], a, w, -np.pi/2+w*delta_en, line_types=[c, c])) net.add_lane("sxs", "sxr", StraightLane([-2, dev / 2], [-2, access], line_types=[n, c])) net.add_lane("eer", "ees", StraightLane([access, -2], [dev / 2, -2], line_types=[s, c])) net.add_lane("ees", "ee", SineLane([dev / 2, -2-a], [dev / 2 - delta_st, -2-a], a, w, -np.pi / 2, line_types=[c, c])) net.add_lane("ex", "exs", SineLane([-dev / 2 + delta_en, 2+a], [dev / 2, 2+a], a, w, -np.pi / 2 + w * delta_en, line_types=[c, c])) net.add_lane("exs", "exr", StraightLane([dev / 2, 2], [access, 2], line_types=[n, c])) net.add_lane("ner", "nes", StraightLane([-2, -access], [-2, -dev / 2], line_types=[s, c])) net.add_lane("nes", "ne", SineLane([-2 - a, -dev / 2], [-2 - a, -dev / 2 + delta_st], a, w, -np.pi / 2, line_types=[c, c])) net.add_lane("nx", "nxs", SineLane([2 + a, dev / 2 - delta_en], [2 + a, -dev / 2], a, w, -np.pi / 2 + w * delta_en, line_types=[c, c])) net.add_lane("nxs", "nxr", StraightLane([2, -dev / 2], [2, -access], line_types=[n, c])) road = Road(network=net) self.road = road
def _make_road(self) -> None: # Circle lanes: (s)outh/(e)ast/(n)orth/(w)est (e)ntry/e(x)it. center = [0, 0] # [m] radius = 20 # [m] alpha = 24 # [deg] net = RoadNetwork() radii = [radius, radius + 4] n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED line = [[c, s], [n, c]] for lane in [0, 1]: net.add_lane( "se", "ex", CircularLane(center, radii[lane], np.deg2rad(90 - alpha), np.deg2rad(alpha), clockwise=False, line_types=line[lane])) net.add_lane( "ex", "ee", CircularLane(center, radii[lane], np.deg2rad(alpha), np.deg2rad(-alpha), clockwise=False, line_types=line[lane])) net.add_lane( "ee", "nx", CircularLane(center, radii[lane], np.deg2rad(-alpha), np.deg2rad(-90 + alpha), clockwise=False, line_types=line[lane])) net.add_lane( "nx", "ne", CircularLane(center, radii[lane], np.deg2rad(-90 + alpha), np.deg2rad(-90 - alpha), clockwise=False, line_types=line[lane])) net.add_lane( "ne", "wx", CircularLane(center, radii[lane], np.deg2rad(-90 - alpha), np.deg2rad(-180 + alpha), clockwise=False, line_types=line[lane])) net.add_lane( "wx", "we", CircularLane(center, radii[lane], np.deg2rad(-180 + alpha), np.deg2rad(-180 - alpha), clockwise=False, line_types=line[lane])) net.add_lane( "we", "sx", CircularLane(center, radii[lane], np.deg2rad(180 - alpha), np.deg2rad(90 + alpha), clockwise=False, line_types=line[lane])) net.add_lane( "sx", "se", CircularLane(center, radii[lane], np.deg2rad(90 + alpha), np.deg2rad(90 - alpha), clockwise=False, line_types=line[lane])) # Access lanes: (r)oad/(s)ine access = 170 # [m] dev = 85 # [m] a = 5 # [m] delta_st = 0.2 * dev # [m] delta_en = dev - delta_st w = 2 * np.pi / dev net.add_lane( "ser", "ses", StraightLane([2, access], [2, dev / 2], line_types=(s, c))) net.add_lane( "ses", "se", SineLane([2 + a, dev / 2], [2 + a, dev / 2 - delta_st], a, w, -np.pi / 2, line_types=(c, c))) net.add_lane( "sx", "sxs", SineLane([-2 - a, -dev / 2 + delta_en], [-2 - a, dev / 2], a, w, -np.pi / 2 + w * delta_en, line_types=(c, c))) net.add_lane( "sxs", "sxr", StraightLane([-2, dev / 2], [-2, access], line_types=(n, c))) net.add_lane( "eer", "ees", StraightLane([access, -2], [dev / 2, -2], line_types=(s, c))) net.add_lane( "ees", "ee", SineLane([dev / 2, -2 - a], [dev / 2 - delta_st, -2 - a], a, w, -np.pi / 2, line_types=(c, c))) net.add_lane( "ex", "exs", SineLane([-dev / 2 + delta_en, 2 + a], [dev / 2, 2 + a], a, w, -np.pi / 2 + w * delta_en, line_types=(c, c))) net.add_lane( "exs", "exr", StraightLane([dev / 2, 2], [access, 2], line_types=(n, c))) net.add_lane( "ner", "nes", StraightLane([-2, -access], [-2, -dev / 2], line_types=(s, c))) net.add_lane( "nes", "ne", SineLane([-2 - a, -dev / 2], [-2 - a, -dev / 2 + delta_st], a, w, -np.pi / 2, line_types=(c, c))) net.add_lane( "nx", "nxs", SineLane([2 + a, dev / 2 - delta_en], [2 + a, -dev / 2], a, w, -np.pi / 2 + w * delta_en, line_types=(c, c))) net.add_lane( "nxs", "nxr", StraightLane([2, -dev / 2], [2, -access], line_types=(n, c))) net.add_lane( "wer", "wes", StraightLane([-access, 2], [-dev / 2, 2], line_types=(s, c))) net.add_lane( "wes", "we", SineLane([-dev / 2, 2 + a], [-dev / 2 + delta_st, 2 + a], a, w, -np.pi / 2, line_types=(c, c))) net.add_lane( "wx", "wxs", SineLane([dev / 2 - delta_en, -2 - a], [-dev / 2, -2 - a], a, w, -np.pi / 2 + w * delta_en, line_types=(c, c))) net.add_lane( "wxs", "wxr", StraightLane([-dev / 2, -2], [-access, -2], line_types=(n, c))) road = Road(network=net, np_random=self.np_random, record_history=self.config["show_trajectories"]) self.road = road
def make_roads(self): net = RoadNetwork() n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED net.add_lane( "s1", "ex", StraightLane(np.array([0, 0]), np.array([100, 0]), line_types=[c, s])) net.add_lane( "ex", "em", StraightLane(np.array([100, 0]), np.array([200, 0]), line_types=[c, s])) net.add_lane( "em", "x1", StraightLane(np.array([200, 0]), np.array([300, 0]), line_types=[c, s])) # lm10 = StraightLane(np.array([0, 0]), 0, 4.0, [LineType.CONTINUOUS_LINE, LineType.STRIPED],bounds=[0,300]) # l1 = LanesConcatenation([lm10]) net.add_lane( "s1", "ex", StraightLane(np.array([0, 4]), np.array([100, 4]), line_types=[s, s])) net.add_lane( "ex", "em", StraightLane(np.array([100, 4]), np.array([200, 4]), line_types=[s, s])) net.add_lane( "em", "x1", StraightLane(np.array([200, 4]), np.array([300, 4]), line_types=[s, s])) # lm20 = StraightLane(l1.position(0,4), 0, 4.0, [LineType.STRIPED, LineType.STRIPED],bounds=[0,300]) # l2 = LanesConcatenation([lm20]) net.add_lane( "s1", "ex", StraightLane(np.array([0, 8]), np.array([100, 8]), line_types=[s, c])) # lm30 = StraightLane(l2.position(0,4), 0, 4.0, [LineType.STRIPED, LineType.CONTINUOUS_LINE],bounds=[0,100]) net.add_lane( "ex", "em", StraightLane(np.array([100, 8]), np.array([200, 8]), line_types=[s, n])) net.add_lane( "em", "x1", StraightLane(np.array([200, 8]), np.array([300, 8]), line_types=[s, c])) # lm31 = StraightLane(lm30.position(0,0), 0, 4.0, [LineType.STRIPED, LineType.STRIPED],bounds=[0,300]) # l3 = LanesConcatenation([lm30,lm31]) amplitude = 4.5 net.add_lane( "s2", "ee", StraightLane(np.array([0, 8 + 3 * amplitude]), np.array([50, 8 + 3 * amplitude]), line_types=[c, c], forbidden=True)) # lm40 = StraightLane(l3.position(0,2*amplitude+4), 0, 4.0, [LineType.CONTINUOUS_LINE, LineType.CONTINUOUS_LINE],bounds=[0,50]) net.add_lane( "ee", "ex", SineLane(np.array([50, 8 + 2 * amplitude]), np.array([100, 8 + 2 * amplitude]), amplitude, 2 * np.pi / (2 * 50), np.pi / 2, line_types=[c, c], forbidden=True)) # lm41 = SineLane(lm40.position(50, -amplitude), 0, 4.0, amplitude, 2 * np.pi / (2*50), np.pi / 2, # [LineType.CONTINUOUS, LineType.CONTINUOUS], bounds=[0, 50], forbidden=True) net.add_lane( "ex", "over", StraightLane(np.array([100, 8 + amplitude]), np.array([200, 8 + amplitude]), line_types=[s, c], forbidden=True)) # net.add_lane("over", "x1", # SineLane(np.array([200, 8 + amplitude/2]), np.array([220, 8 + amplitude/2]), amplitude/2, # 2 * np.pi / (2 * 50), np.pi / 2, line_types=[c, c], forbidden=True)) # lm42 = StraightLane(lm41.position(50,0), 0, 4.0, [LineType.STRIPED, LineType.CONTINUOUS_LINE],bounds=[0,150],forbidden=True) # l4 = LanesConcatenation([lm40,lm41,lm42]) # road = Road([l1,l2,l3,l4]) # road = Road([ l3]) # road = Road([lm0,lm2]) road = Road(network=net, np_random=self.np_random) road.vehicles.append(Obstacle(road, [200, 8 + amplitude])) self.road = road
def _make_road(self) -> None: """ Make a road composed of a straight highway and a merging lane. :return: the road ljk = StraightLane([0, 6.5 + 4 + 4], [ends[0], 6.5 + 4 + 4], line_types=[c, c], forbidden=True) lke = SineLane(ljk.position(ends[0], -amplitude), ljk.position(sum(ends[:2]), -amplitude), amplitude, 2 * np.pi / (2*ends[1]), np.pi / 2, line_types=[c, c], forbidden=True) net.add_lane("j", "k", ljk) net.add_lane("k", "b", lke) #net.add_lane("e", "c", lbc) road = Road(network=net, np_random=self.np_random, record_history=self.config["show_trajectories"]) #road.objects.append(Obstacle(road, lbc.position(ends[2], 0))) self.road = road Make a road composed of a straight highway and a merging lane. :return: the road """ net = RoadNetwork() # Highway lanes ends = [90, 155, 180] # Before, converging, merge, after c, s, n = LineType.CONTINUOUS_LINE, LineType.STRIPED, LineType.NONE y = [18.9, 21.2, 25.5] #line_type = [[c, s], [n, c]] #line_type_merge=[[s,s],[n,c]] line_type_merge = [[c, n], [s, c]] #line_type_highway=[[c,s],[n,c]] #line_type_merge = [[c, s], [n, s]] line_type = [c, c] #amplitude = 2 #ljk = StraightLane([0,6.85],[183,6.85],line_types=[c,c], forbidden=True) #lbc = SineLane(ljk.position(182,amplitude), ljk.position(218, amplitude), # -amplitude, 2 * np.pi / 72, np.pi / 2, line_types=[c, n], forbidden=True) #net.add_lane("b", "c", lbc) #net.add_lane("a", "b", StraightLane([0, 6.85], [183, 6.85], line_types=[c,n])) ''' for i in range(2): net.add_lane("a", "c", StraightLane([0, y[i]], [218, y[i]], line_types=line_type_merge[i])) net.add_lane("c", "d", StraightLane([218, y[i]], [400, y[i]], line_types=line_type_highway[i])) #net.add_lane("e", "c", lbc) road = Road(network=net, np_random=self.np_random, record_history=self.config["show_trajectories"]) ''' amplitude = 2.15 lmn = StraightLane([0, y[0]], [90, y[0]], 2.2, line_types=[c, n], forbidden=True) lab = StraightLane([0, y[1]], [90, y[1]], 2.2, line_types=[c, n], forbidden=True) net.add_lane( "m", "n", StraightLane([0, y[0]], [90, y[0]], 2.2, line_types=line_type_merge[0])) net.add_lane( "a", "b", StraightLane([0, y[1]], [90, y[1]], 2.2, line_types=line_type_merge[1])) net.add_lane( "d", "e", StraightLane([155, y[2]], [180, y[2]], 2.2, line_types=line_type)) lnd = SineLane(lmn.position(90, amplitude), lmn.position(155, amplitude), -amplitude, 2 * np.pi / 130, np.pi / 2, 2.2, line_types=[c, n], forbidden=True) lbd = SineLane(lab.position(90, amplitude), lab.position(155, amplitude), -amplitude, 2 * np.pi / 130, np.pi / 2, 2.2, line_types=[s, c], forbidden=False) net.add_lane("n", "d", lnd) net.add_lane("b", "d", lbd) #road.objects.append(Obstacle(road, lbc.position(ends[2], 0))) road = Road(network=net, np_random=self.np_random, record_history=self.config["show_trajectories"]) self.road = road road.objects.append(Obstacle(road, lnd.position(65, 0)))
def make_sin(self): # amplitude = 4.5 amplitude = 9.0 lm10 = StraightLane(np.array([0, 0]), 0, 5.0, [LineType.CONTINUOUS_LINE, LineType.STRIPED], bounds=[0, 400]) lm11 = SineLane(lm10.position(400, amplitude), 0, 5.0, -amplitude, 2 * np.pi / (2 * 50), np.pi / 2, [LineType.CONTINUOUS, LineType.STRIPED], bounds=[0, 250]) lm12 = StraightLane(lm11.position(250, 0), 0, 5.0, [LineType.CONTINUOUS_LINE, LineType.STRIPED], bounds=[0, 50]) l1 = LanesConcatenation([lm10, lm11, lm12]) lm20 = StraightLane(lm10.position(0, 5), 0, 5.0, [LineType.STRIPED, LineType.STRIPED], bounds=[0, 400]) lm21 = SineLane(lm20.position(400, amplitude), 0, 5.0, -amplitude, 2 * np.pi / (2 * 50), np.pi / 2, [LineType.STRIPED, LineType.STRIPED], bounds=[0, 250]) lm22 = StraightLane(lm21.position(250, 0), 0, 5.0, [LineType.STRIPED, LineType.STRIPED], bounds=[0, 50]) l2 = LanesConcatenation([lm20, lm21, lm22]) lm30 = StraightLane(lm20.position(0, 5), 0, 5.0, [LineType.STRIPED, LineType.STRIPED], bounds=[0, 400]) lm31 = SineLane(lm30.position(400, amplitude), 0, 5.0, -amplitude, 2 * np.pi / (2 * 50), np.pi / 2, [LineType.STRIPED, LineType.STRIPED], bounds=[0, 250]) lm32 = StraightLane(lm31.position(250, 0), 0, 5.0, [LineType.STRIPED, LineType.STRIPED], bounds=[0, 50]) l3 = LanesConcatenation([lm30, lm31, lm32]) lm40 = StraightLane(lm30.position(0, 5), 0, 5.0, [LineType.STRIPED, LineType.CONTINUOUS_LINE], bounds=[0, 400]) lm41 = SineLane(lm40.position(400, amplitude), 0, 5.0, -amplitude, 2 * np.pi / (2 * 50), np.pi / 2, [LineType.STRIPED, LineType.CONTINUOUS], bounds=[0, 250]) lm42 = StraightLane( lm41.position(250, 0), 0, 5.0, [LineType.STRIPED, LineType.CONTINUOUS_LINE], bounds=[0, 50], ) l4 = LanesConcatenation([lm40, lm41, lm42]) road = Road([l1, l2, l3, l4]) # road = Road([ l3]) # road = Road([lm0,lm2]) # todo !!!!!!!!!!! how to do with Obstacle in lane.vehicles obstacle = Obstacle(road, lm40.position(0, 0)) road.vehicles.append(obstacle) road.lanes[3].vehicles.append(obstacle) self.road = road
def make_road(self): """ Make a road composed of a straight highway and a merging lane. :return: the road """ amp = 3.25 str_len = 150 sin_len = 100 width = 4 net = RoadNetwork() n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED net.add_lane( "s1", "inter1", SineLane([0, 0], [sin_len, 0], -amp * 1, np.pi / sin_len, np.pi / 2, line_types=[c, c], forbidden=False)) net.add_lane( "s1", "inter1", SineLane([0, width], [sin_len, width], -amp * 1, np.pi / sin_len, np.pi / 2, line_types=[c, c], forbidden=False)) net.add_lane( "s2", "inter1", SineLane([0, 2 * amp + 2 * width], [sin_len, 2 * amp + 2 * width], -amp * -1, np.pi / sin_len, np.pi / 2, line_types=[c, c], forbidden=False)) net.add_lane( "s2", "inter1", SineLane([0, 2 * amp + 3 * width], [sin_len, 2 * amp + 3 * width], -amp * -1, np.pi / sin_len, np.pi / 2, line_types=[c, c], forbidden=False)) net.add_lane( "inter1", "inter2", StraightLane([sin_len, amp], [sin_len + str_len, amp], line_types=[c, s])) net.add_lane( "inter1", "inter2", StraightLane([sin_len, amp + width], [sin_len + str_len, amp + width], line_types=[s, s])) net.add_lane( "inter1", "inter2", StraightLane([sin_len, amp + 2 * width], [sin_len + str_len, amp + 2 * width], line_types=[s, s])) net.add_lane( "inter1", "inter2", StraightLane([sin_len, amp + 3 * width], [sin_len + str_len, amp + 3 * width], line_types=[s, c])) net.add_lane( "inter2", "e1", SineLane([sin_len + str_len, 0], [2 * sin_len + str_len, 0], amp * 1, np.pi / sin_len, np.pi / 2, line_types=[c, c], forbidden=False)) net.add_lane( "inter2", "e1", SineLane([sin_len + str_len, width], [2 * sin_len + str_len, width], amp * 1, np.pi / sin_len, np.pi / 2, line_types=[c, c], forbidden=False)) net.add_lane( "inter2", "e2", SineLane([sin_len + str_len, 2 * width + 2 * amp], [2 * sin_len + str_len, 2 * width + 2 * amp], amp * -1, np.pi / sin_len, np.pi / 2, line_types=[c, c], forbidden=False)) net.add_lane( "inter2", "e2", SineLane([sin_len + str_len, 3 * width + 2 * amp], [2 * sin_len + str_len, 3 * width + 2 * amp], amp * -1, np.pi / sin_len, np.pi / 2, line_types=[c, c], forbidden=False)) road = Road(network=net, np_random=self.np_random) # road.vehicles.append(Obstacle(road, [0, 12])) self.road = road
def make_road2(self): """ Make a road composed of a straight highway and a merging lane. :return: the road """ net = RoadNetwork() # pre-processing ends = [150, 80, 80, 150] c, s, n = LineType.CONTINUOUS_LINE, LineType.STRIPED, LineType.NONE W = StraightLane.DEFAULT_WIDTH # Highway lanes ptr_LB, ptr_UB = 0, ends[0] + ends[ 1] # Miss what is relevant only for merging lane net.add_lane("a", "b", StraightLane([ptr_LB, W], [ptr_UB, W], line_types=[c, s])) # Lane 1 net.add_lane("a", "b", StraightLane([ptr_LB, W], [ptr_UB, W], line_types=[n, c])) # Lane 2 ptr_LB, ptr_UB = ptr_UB, ptr_UB + ends[1] net.add_lane("b", "c", StraightLane([ptr_LB, W], [ptr_UB, W], line_types=[c, s])) net.add_lane("b", "c", StraightLane([ptr_LB, W], [ptr_UB, W], line_types=[n, s])) ptr_LB, ptr_UB = ptr_UB, ptr_UB + ends[2] net.add_lane("c", "d", StraightLane([ptr_LB, W], [ptr_UB, W], line_types=[c, s])) net.add_lane("c", "d", StraightLane([ptr_LB, W], [ptr_UB, W], line_types=[n, c])) # Crossing Lane # TBA # Merging lane amplitude = 3.25 offset = 6.5 ljk = StraightLane([0, offset + 2 * W], [ends[0], offset + 2 * W], line_types=[c, c], forbidden=True) if 1: lkb = SineLane(ljk.position(ends[0], -amplitude), ljk.position(sum(ends[:2]), -amplitude), amplitude, 2 * np.pi / (2 * ends[1]), np.pi / 2, line_types=[c, c], forbidden=True) else: lkb = StraightLane([ends[0], offset + 2 * W], [ends[0] + ends[1], 2 * W], line_types=[c, c], forbidden=True) lbc = StraightLane(lkb.position(ends[1], 0), lkb.position(ends[1], 0) + [ends[2], 0], line_types=[n, c], forbidden=True) net.add_lane("j", "k", ljk) net.add_lane("k", "b", lkb) net.add_lane("b", "c", lbc) road = Road(network=net) # road.vehicles.append(Obstacle(road, lbc.position(ends[2], 0))) self.road = road
def _make_road(self): # Circle lanes: (s)outh/(e)ast/(n)orth/(w)est (e)ntry/e(x)it. center = [0, 0] # [m] radius = 30 # [m] alpha = 20 # [deg] net = RoadNetwork() radii = [radius, radius + 4] n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED line = [[c, s], [n, c]] # r = [] # bounds = [30 * 50 * np.pi / 180, 30 * 40 * np.pi / 180, 34 * 50 * np.pi / 180, 34 * 40 * np.pi / 180] # bounds = [30 * 2 * np.pi, 34 * 2 * np.pi ] for lane in [0, 1]: net.add_lane( "se", "ex", CircularLane(center, radii[lane], rad(90 - alpha), rad(alpha), line_types=line[lane])) net.add_lane( "ex", "ee", CircularLane(center, radii[lane], rad(alpha), rad(-alpha), line_types=line[lane])) net.add_lane( "ee", "nx", CircularLane(center, radii[lane], rad(-alpha), rad(-90 + alpha), line_types=line[lane])) net.add_lane( "nx", "ne", CircularLane(center, radii[lane], rad(-90 + alpha), rad(-90 - alpha), line_types=line[lane])) net.add_lane( "ne", "wx", CircularLane(center, radii[lane], rad(-90 - alpha), rad(-180 + alpha), line_types=line[lane])) net.add_lane( "wx", "we", CircularLane(center, radii[lane], rad(-180 + alpha), rad(-180 - alpha), line_types=line[lane])) net.add_lane( "we", "sx", CircularLane(center, radii[lane], rad(180 - alpha), rad(90 + alpha), line_types=line[lane])) net.add_lane( "sx", "se", CircularLane(center, radii[lane], rad(90 + alpha), rad(90 - alpha), line_types=line[lane])) """ lane = 0 net.add_lane("se", "ex", CircularLane(center, radii[lane], rad(90 - alpha), rad(alpha), line_types=line[lane])) net.add_lane("ex", "ee", CircularLane(center, radii[lane], rad(alpha), rad(-alpha), line_types=line[lane])) net.add_lane("ee", "nx", CircularLane(center, radii[lane], rad(-alpha), rad(-90 + alpha), line_types=line[lane])) net.add_lane("nx", "ne", CircularLane(center, radii[lane], rad(-90 + alpha), rad(-90 - alpha), line_types=line[lane])) net.add_lane("ne", "wx", CircularLane(center, radii[lane], rad(-90 - alpha), rad(-180 + alpha), line_types=line[lane])) net.add_lane("wx", "we", CircularLane(center, radii[lane], rad(-180 + alpha), rad(-180 - alpha), line_types=line[lane])) net.add_lane("we", "sx", CircularLane(center, radii[lane], rad(180 - alpha), rad(90 + alpha), line_types=line[lane])) net.add_lane("sx", "se", CircularLane(center, radii[lane], rad(90 + alpha), rad(90 - alpha), line_types=line[lane])) lane = 1 # net.add_lane("se", "ex", # CircularLane(center, radii[lane], rad(90 - alpha), rad(alpha), line_types=line[lane])) net.add_lane("ser", "exb", CircularLane(center, radii[lane], rad(90 - alpha + 8), rad(alpha - 2), line_types=line[lane])) net.add_lane("exb", "exl", CircularLane(center, radii[lane], rad(alpha - 2), rad(alpha - 7), line_types=line[lane])) net.add_lane("eel", "exr", CircularLane(center, radii[lane], rad(-180 + alpha + 165), rad(-180 + alpha + 155), line_types=line[lane])) # net.add_lane("ex", "ee", CircularLane(center, radii[lane], rad(alpha), rad(-alpha), line_types=line[lane])) # net.add_lane("ee", "nx", # CircularLane(center, radii[lane], rad(-alpha), rad(-90 + alpha), line_types=line[lane])) net.add_lane("eer", "nxb", CircularLane(center, radii[lane], rad(-180 + alpha + 147), rad(-180 + alpha + 65), line_types=line[lane])) net.add_lane("nxb", "nxl", CircularLane(center, radii[lane], rad(-180 + alpha + 65), rad(-180 + alpha + 60), line_types=line[lane])) # net.add_lane("nx", "ne", # CircularLane(center, radii[lane], rad(-90 + alpha), rad(-90 - alpha), line_types=line[lane])) net.add_lane("nxr", "nel", CircularLane(center, radii[lane], rad(-180 + alpha + 58), rad(-180 + alpha + 48), line_types=line[lane])) net.add_lane("ner", "wxb", CircularLane(center, radii[lane], rad(-180 + alpha + 45), rad(-180 + alpha + 5), line_types=line[lane])) # net.add_lane("ner", "wxb", # CircularLane(center, radii[lane], rad(-90 - alpha), rad(-180 + alpha), line_types=line[lane])) net.add_lane("wxb", "wxl", CircularLane(center, radii[lane], rad(-180 + alpha + 5), rad(-180 + alpha - 7), line_types=line[lane])) # net.add_lane("wx", "we", # CircularLane(center, radii[lane], rad(-180 + alpha), rad(-180 - alpha), line_types=line[lane])) net.add_lane("wxr", "wel", CircularLane(center, radii[lane], rad(-180 + alpha - 15), rad(-180 - alpha + 15), line_types=line[lane])) # net.add_lane("we", "sx", # CircularLane(center, radii[lane], rad(180 - alpha), rad(90 + alpha - 5), line_types=line[lane])) net.add_lane("wer", "sxb", CircularLane(center, radii[lane], rad(180 - alpha + 7), rad(90 + alpha + 5), line_types=line[lane])) net.add_lane("sxb", "sxl", CircularLane(center, radii[lane], rad(95 + alpha), rad(90 + alpha - 7), line_types=line[lane])) net.add_lane("sxr", "sel", CircularLane(center, radii[lane], rad(90 + alpha - 15), rad(90 - alpha + 15), line_types=line[lane])) """ # Access lanes: (r)oad/(s)ine access = 200 # [m] dev = 120 # [m] a = 5 # [m] delta_st = 0.20 * dev # [m] delta_en = dev - delta_st w = 2 * np.pi / dev net.add_lane( "ser", "ses", StraightLane([2, access], [2, dev / 2], line_types=[s, c])) net.add_lane( "ses", "se", SineLane([2 + a, dev / 2], [2 + a, dev / 2 - delta_st], a, w, -np.pi / 2, line_types=[c, c])) net.add_lane( "sx", "sxs", SineLane([-2 - a, -dev / 2 + delta_en], [-2 - a, dev / 2], a, w, -np.pi / 2 + w * delta_en, line_types=[c, c])) net.add_lane( "sxs", "sxr", StraightLane([-2, dev / 2], [-2, access], line_types=[n, c])) net.add_lane( "eer", "ees", StraightLane([access, -2], [dev / 2, -2], line_types=[s, c])) net.add_lane( "ees", "ee", SineLane([dev / 2, -2 - a], [dev / 2 - delta_st, -2 - a], a, w, -np.pi / 2, line_types=[c, c])) net.add_lane( "ex", "exs", SineLane([-dev / 2 + delta_en, 2 + a], [dev / 2, 2 + a], a, w, -np.pi / 2 + w * delta_en, line_types=[c, c])) net.add_lane( "exs", "exr", StraightLane([dev / 2, 2], [access, 2], line_types=[n, c])) net.add_lane( "ner", "nes", StraightLane([-2, -access], [-2, -dev / 2], line_types=[s, c])) net.add_lane( "nes", "ne", SineLane([-2 - a, -dev / 2], [-2 - a, -dev / 2 + delta_st], a, w, -np.pi / 2, line_types=[c, c])) net.add_lane( "nx", "nxs", SineLane([2 + a, dev / 2 - delta_en], [2 + a, -dev / 2], a, w, -np.pi / 2 + w * delta_en, line_types=[c, c])) net.add_lane( "nxs", "nxr", StraightLane([2, -dev / 2], [2, -access], line_types=[n, c])) net.add_lane( "wer", "wes", StraightLane([-access, 2], [-dev / 2, 2], line_types=[s, c])) net.add_lane( "wes", "we", SineLane([-dev / 2, 2 + a], [-dev / 2 + delta_st, 2 + a], a, w, -np.pi / 2, line_types=[c, c])) net.add_lane( "wx", "wxs", SineLane([dev / 2 - delta_en, -2 - a], [-dev / 2, -2 - a], a, w, -np.pi / 2 + w * delta_en, line_types=[c, c])) net.add_lane( "wxs", "wxr", StraightLane([-dev / 2, -2], [-access, -2], line_types=[n, c])) road = Road(network=net, np_random=self.np_random) self.road = road
def make_roads(self): net = RoadNetwork() n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED net.add_lane( "s1", "inter1", StraightLane(np.array([0, 0]), np.array([100, 0]), line_types=[c, s])) net.add_lane( "inter1", "inter2", StraightLane(np.array([100, 0]), np.array([150, 0]), line_types=[c, s])) net.add_lane( "inter2", "inter3", StraightLane(np.array([150, 0]), np.array([200, 0]), line_types=[c, s])) net.add_lane( "inter3", "x1", StraightLane(np.array([200, 0]), np.array([300, 0]), line_types=[c, s])) net.add_lane( "s1", "inter1", StraightLane(np.array([0, 4]), np.array([100, 4]), line_types=[s, s])) net.add_lane( "inter1", "inter2", StraightLane(np.array([100, 4]), np.array([150, 4]), line_types=[s, s])) net.add_lane( "inter2", "inter3", StraightLane(np.array([150, 4]), np.array([200, 4]), line_types=[s, s])) net.add_lane( "inter3", "x1", StraightLane(np.array([200, 4]), np.array([300, 4]), line_types=[s, s])) net.add_lane( "s1", "inter1", StraightLane(np.array([0, 8]), np.array([100, 8]), line_types=[s, s])) net.add_lane( "inter1", "inter2", StraightLane(np.array([100, 8]), np.array([150, 8]), line_types=[s, s])) net.add_lane( "inter2", "inter3", StraightLane(np.array([150, 8]), np.array([200, 8]), line_types=[s, c])) net.add_lane( "inter3", "x1", StraightLane(np.array([200, 8]), np.array([300, 8]), line_types=[s, c])) amplitude = 4.5 net.add_lane( "s1", "inter1", StraightLane(np.array([0, 12]), np.array([100, 12]), line_types=[s, c])) net.add_lane( "inter1", "inter2", StraightLane(np.array([100, 12]), np.array([150, 12]), line_types=[s, c])) net.add_lane( "inter2", "ee", StraightLane(np.array([150, 12]), np.array([200, 12]), line_types=[s, c], forbidden=True)) net.add_lane( "ee", "ex", SineLane(np.array([200, 12 + amplitude]), np.array([250, 12 + amplitude]), -amplitude, 2 * np.pi / (2 * 50), np.pi / 2, line_types=[c, c], forbidden=True)) net.add_lane( "ex", "x2", StraightLane(np.array([250, 17 + amplitude]), np.array([300, 17 + amplitude]), line_types=[c, c], forbidden=True)) road = Road(network=net, np_random=self.np_random) # road.vehicles.append(RedLight(road, [150, 0])) # road.vehicles.append(RedLight(road, [150, 4])) # road.vehicles.append(RedLight(road, [150, 8])) self.road = road