Exemplo n.º 1
0
    def setUpClass(cls) -> None:
        surface = jit.GeometricSurface(jit.DistanceMetric.MANHATTAN)
        origin = jit.Service(surface.get_or_create_position([0, 0]))
        vehicle = jit.Vehicle(
            identifier="TEST",
            origin=origin,
        )
        fleet = jit.Fleet({vehicle})

        trips = [
            jit.Trip(
                identifier="TEST_1",
                origin=jit.Service(
                    position=surface.get_or_create_position([0, 0]),
                    earliest=0.0,
                    latest=10.0,
                ),
                destination=jit.Service(
                    position=surface.get_or_create_position([1, 1]), ),
            ),
            jit.Trip(
                identifier="TEST_2",
                origin=jit.Service(
                    position=surface.get_or_create_position([1, 1]),
                    earliest=0.0,
                    latest=20.0,
                ),
                destination=jit.Service(
                    position=surface.get_or_create_position([10, 10]), ),
            ),
        ]
        job = jit.Job(set(trips), jit.DialARideObjective)
        route = jit.Route(vehicle)

        pickup_stop = jit.Stop(vehicle, surface.get_or_create_position([0, 0]),
                               route.current_stop)
        delivery_stop = jit.Stop(vehicle,
                                 surface.get_or_create_position([1, 1]),
                                 pickup_stop)

        cls.planned_trip = jit.PlannedTrip(
            vehicle=vehicle,
            trip=trips[0],
            pickup=pickup_stop,
            delivery=delivery_stop,
        )
        route.append_planned_trip(cls.planned_trip)

        cls.stop = route.stops[1]
        conjecture = jit.TailInsertionStrategy()
        cls.route = conjecture.compute(route, trips[1])[0]
        cls.planning = jit.Planning({cls.route})
        cls.algorithm = jit.NaiveAlgorithm(fleet, job)
        cls.result = jit.Result(cls.algorithm, cls.planning, 0.0)
Exemplo n.º 2
0
    def _build_route_3(cls, vehicle: jit.Vehicle,
                       surface: jit.Surface) -> jit.Route:
        route = jit.Route(vehicle)

        trip = jit.Trip(
            identifier="TEST_3",
            origin=jit.Service(
                position=surface.get_or_create_position([0, 0]),
                earliest=1.0,
                latest=20.0,
            ),
            destination=jit.Service(position=surface.get_or_create_position(
                [10, 10]), ),
            timeout=1.0,
        )

        pickup_stop = jit.Stop(vehicle, surface.get_or_create_position([0, 0]),
                               route.current_stop)
        delivery_stop = jit.Stop(vehicle,
                                 surface.get_or_create_position([10, 10]),
                                 pickup_stop)

        planned_trip = jit.PlannedTrip(
            vehicle=vehicle,
            trip=trip,
            pickup=pickup_stop,
            delivery=delivery_stop,
        )
        route.append_planned_trip(planned_trip)
        return route
Exemplo n.º 3
0
    def test_trip_with_capacity(self):
        identifier = str()
        capacity = 3
        origin = jit.Service(
            position=generate_one_position(),
            earliest=0.0,
        )
        destination = jit.Service(position=generate_one_position())

        distance = origin.distance_to(destination)
        duration = origin.time_to(destination)

        trip = jit.Trip(identifier=identifier,
                        origin=origin,
                        destination=destination,
                        capacity=capacity)

        self.assertEqual(origin.position, trip.origin_position)
        self.assertEqual(destination.position, trip.destination_position)
        self.assertEqual(0, trip.origin_earliest)
        self.assertEqual(trip.origin_latest, jit.MAX_FLOAT)
        self.assertEqual(0, trip.origin_duration)
        self.assertEqual(capacity, trip.capacity)
        self.assertEqual(distance, trip.distance)
        self.assertEqual(duration, trip.duration(trip.origin_earliest))
Exemplo n.º 4
0
def generate_one_trip(
    identifier: str = None,
    origin_position: jit.Position = None,
    destination_position: jit.Position = None,
    earliest: float = None,
    earliest_min: float = 0,
    earliest_max: float = 86400,
    timeout: float = None,
    timeout_min: float = 1800,
    timeout_max: float = 7200,
    load_time: float = None,
    load_time_min: float = 300,
    load_time_max: float = 900,
    capacity: float = None,
    capacity_min: int = 1,
    capacity_max: int = 3,
    *args,
    **kwargs,
) -> jit.Trip:
    if identifier is None:
        identifier = f"{randint(1, 999):0d}"
    if origin_position is None:
        origin_position = generate_one_position(*args, **kwargs)
    if destination_position is None:
        destination_position = generate_one_position(*args, **kwargs)
    if earliest is None:
        earliest = uniform(earliest_min, earliest_max)
    if timeout is None:
        timeout = uniform(timeout_min, timeout_max)
    if capacity is None:
        capacity = randint(capacity_min, capacity_max)
    if load_time is None:
        load_time = uniform(load_time_min, load_time_max)

    return jit.Trip(
        identifier,
        origin=jit.Service(
            position=origin_position,
            earliest=earliest,
            latest=earliest + timeout,
            duration=load_time,
        ),
        destination=jit.Service(position=destination_position, ),
        capacity=capacity,
    )
Exemplo n.º 5
0
    def test_as_tuple(self):
        identifier = str(0)
        origin = jit.Service(
            position=generate_one_position(),
            earliest=100,
            latest=200,
            duration=2,
        )
        destination = jit.Service(
            position=generate_one_position(),
            earliest=1000,
            latest=2000,
            duration=20,
        )
        capacity = 44
        on_time_bonus = 3
        timeout = 100
        trip = jit.Trip(
            identifier=identifier,
            origin=origin,
            destination=destination,
            capacity=capacity,
            on_time_bonus=on_time_bonus,
            timeout=timeout,
        )

        expected = (
            ("identifier", identifier),
            ("origin", tuple(origin)),
            ("destination", tuple(destination)),
            ("on_time_bonus", on_time_bonus),
            ("capacity", capacity),
            ("timeout", trip.timeout),
        )

        self.assertEqual(expected, tuple(trip))