コード例 #1
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
コード例 #2
0
    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
コード例 #3
0
    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
コード例 #4
0
    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)))
コード例 #5
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
コード例 #6
0
    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