Exemple #1
0
 def _make_road(self) -> None:
     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
Exemple #2
0
    def _make_road(self, length=800):
        """
        Make a road composed of a two-way road.

        :return: the road
        """
        net = RoadNetwork()

        # Lanes
        net.add_lane(
            "a", "b",
            StraightLane([0, 0], [length, 0],
                         line_types=(LineType.CONTINUOUS_LINE,
                                     LineType.STRIPED)))
        net.add_lane(
            "a", "b",
            StraightLane([0, StraightLane.DEFAULT_WIDTH],
                         [length, StraightLane.DEFAULT_WIDTH],
                         line_types=(LineType.NONE, LineType.CONTINUOUS_LINE)))
        net.add_lane(
            "b", "a",
            StraightLane([length, 0], [0, 0],
                         line_types=(LineType.NONE, LineType.NONE)))

        road = Road(network=net,
                    np_random=self.np_random,
                    record_history=self.config["show_trajectories"])
        self.road = road
Exemple #3
0
    def _create_road(self, spots: int = 15) -> None:
        """
        Create a road composed of straight adjacent lanes.

        :param spots: number of spots in the parking
        """
        net = RoadNetwork()
        width = 4.0
        lt = (LineType.CONTINUOUS, LineType.CONTINUOUS)
        x_offset = 0
        y_offset = 10
        length = 8
        for k in range(spots):
            x = (k - spots // 2) * (width + x_offset) - width / 2
            net.add_lane(
                "a", "b",
                StraightLane([x, y_offset], [x, y_offset + length],
                             width=width,
                             line_types=lt))
            net.add_lane(
                "b", "c",
                StraightLane([x, -y_offset], [x, -y_offset - length],
                             width=width,
                             line_types=lt))

        self.road = Road(network=net,
                         np_random=self.np_random,
                         record_history=self.config["show_trajectories"])
Exemple #4
0
    def _create_road(self, spots: int = 15) -> None:
        """
        Create a road composed of straight adjacent lanes.

        :param spots: number of parking spots
        """
        net = RoadNetwork()

        width = 4.0
        lt = (LineType.CONTINUOUS, LineType.CONTINUOUS)
        x_offset = 0
        y_offset = 12
        length = 8
        # Parking spots
        for k in range(spots):
            x = (k - spots // 2) * (width + x_offset) - width / 2
            net.add_lane(
                "a", "b",
                StraightLane([x, y_offset], [x, y_offset + length],
                             width=width,
                             line_types=lt,
                             speed_limit=5))
            net.add_lane(
                "b", "c",
                StraightLane([x, -y_offset], [x, -y_offset - length],
                             width=width,
                             line_types=lt,
                             speed_limit=5))

        self.spots = spots
        self.vehicle_starting = [x, y_offset + (length / 2)]
        self.num_middle_lanes = 0
        self.x_range = (int(spots / 2) + 1) * width

        # Generate the middle lane for the busy parking lot
        for y in np.arange(-y_offset + width, y_offset, width):
            net.add_lane(
                "d", "e",
                StraightLane([-self.x_range, y], [self.x_range, y],
                             width=width,
                             line_types=(LineType.STRIPED, LineType.STRIPED),
                             speed_limit=5))
            self.num_middle_lanes += 1

        self.road = Road(network=net,
                         np_random=self.np_random,
                         record_history=self.config["show_trajectories"])
Exemple #5
0
    def _make_road(self) -> None:
        """
        Make an 4-way intersection.

        The horizontal road has the right of way. More precisely, the levels of priority are:
            - 3 for horizontal straight lanes and right-turns
            - 1 for vertical straight lanes and right-turns
            - 2 for horizontal left-turns
            - 0 for vertical left-turns

        The code for nodes in the road network is:
        (o:outer | i:inner + [r:right, l:left]) + (0:south | 1:west | 2:north | 3:east)

        :return: the intersection road
        """
        lane_width = AbstractLane.DEFAULT_WIDTH
        right_turn_radius = lane_width + 5  # [m}
        left_turn_radius = right_turn_radius + lane_width  # [m}
        outer_distance = right_turn_radius + lane_width / 2
        access_length = 50 + 50  # [m]

        net = RoadNetwork()
        n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED
        for corner in range(4):
            angle = np.radians(90 * corner)
            is_horizontal = corner % 2
            priority = 3 if is_horizontal else 1
            rotation = np.array([[np.cos(angle), -np.sin(angle)],
                                 [np.sin(angle), np.cos(angle)]])
            # Incoming
            start = rotation @ np.array(
                [lane_width / 2, access_length + outer_distance])
            end = rotation @ np.array([lane_width / 2, outer_distance])
            net.add_lane(
                "o" + str(corner), "ir" + str(corner),
                StraightLane(start,
                             end,
                             line_types=[s, c],
                             priority=priority,
                             speed_limit=10))
            # Right turn
            r_center = rotation @ (np.array([outer_distance, outer_distance]))
            net.add_lane(
                "ir" + str(corner), "il" + str((corner - 1) % 4),
                CircularLane(r_center,
                             right_turn_radius,
                             angle + np.radians(180),
                             angle + np.radians(270),
                             line_types=[n, c],
                             priority=priority,
                             speed_limit=10))
            # Left turn
            l_center = rotation @ (np.array([
                -left_turn_radius + lane_width / 2,
                left_turn_radius - lane_width / 2
            ]))
            net.add_lane(
                "ir" + str(corner), "il" + str((corner + 1) % 4),
                CircularLane(l_center,
                             left_turn_radius,
                             angle + np.radians(0),
                             angle + np.radians(-90),
                             clockwise=False,
                             line_types=[n, n],
                             priority=priority - 1,
                             speed_limit=10))
            # Straight
            start = rotation @ np.array([lane_width / 2, outer_distance])
            end = rotation @ np.array([lane_width / 2, -outer_distance])
            net.add_lane(
                "ir" + str(corner), "il" + str((corner + 2) % 4),
                StraightLane(start,
                             end,
                             line_types=[s, n],
                             priority=priority,
                             speed_limit=10))
            # Exit
            start = rotation @ np.flip(
                [lane_width / 2, access_length + outer_distance], axis=0)
            end = rotation @ np.flip([lane_width / 2, outer_distance], axis=0)
            net.add_lane(
                "il" + str((corner - 1) % 4), "o" + str((corner - 1) % 4),
                StraightLane(end,
                             start,
                             line_types=[n, c],
                             priority=priority,
                             speed_limit=10))

        road = RegulatedRoad(network=net,
                             np_random=self.np_random,
                             record_history=self.config["show_trajectories"])
        self.road = road
 def _create_road(self) -> None:
     """Create a road composed of straight adjacent lanes."""
     self.road = Road(network=RoadNetwork.straight_road_network(self.config["lanes_count"]),
                      np_random=self.np_random, record_history=self.config["show_trajectories"])
Exemple #7
0
    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
Exemple #8
0
    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