Ejemplo n.º 1
0
def test_create():
    vehicle = "111"
    clock = Clock()
    clock.tick()
    clock.tick()
    itinerary = Itinerary(clock.now, vehicle)

    assert itinerary.created_at == clock.now
    assert itinerary.next_jobs == []
    assert itinerary.current_job is None
    assert itinerary.jobs_to_complete == []
    # itinerary without jobs
    assert itinerary.is_completed()
    assert itinerary.vehicle == vehicle
Ejemplo n.º 2
0
def test_move_vehicle():
    init_pos = Position(13.3764, 52.5461)
    dest1 = Position(13.4014, 52.5478)

    clock = Clock()
    router = LinearRouter(clock)

    engine = VehicleEngine(init_pos, router, clock)

    v = Vehicle(clock)
    v.install_engine(engine)

    v.move_to(dest1)
    assert v.engine.is_moving()
    assert v.state == States.moving_to

    v.step()
    assert v.state == States.moving_to
    assert v.engine.is_moving()

    clock.tick()
    v.step()

    assert v.engine.is_moving()

    for _ in range(1000):
        clock.tick()
        v.step()

        if not v.engine.is_moving():
            assert v.position == dest1
            assert v.state == States.idling
        else:
            assert v.position != dest1
            assert v.destination == dest1
            assert v.state == States.moving_to
Ejemplo n.º 3
0
    itinerary = Itinerary(clock.now, vehicle)
    itinerary.move_to(booking.pickup)
    itinerary.pickup(booking)
    itinerary.move_to(booking.dropoff)
    itinerary.dropoff(booking)

    dispatcher = Dispatcher()
    dispatcher.dispatch(itinerary)

    print(
        f"\nStart simulation at {clock.to_datetime()} ({clock.now} clock time)"
    )

    # run simulation - all state changes and movements will happen here
    # the order of steps in important: fleet -> dispatcher -> clock
    while not itinerary.is_completed():
        fleet.step()
        dispatcher.step()
        clock.tick()

    print(f"Stop simulation at {clock.to_datetime()} ({clock.now} clock time)")

    print("\nObject states after simulation:")
    print(f'Booking state is "{booking.state.value}"')
    print(f'Vehicle state is "{vehicle.state.value}"')

    fleet.stop_vehicles()

    print("\nSimulation state changes log:")
    print(simulation_logs.logs)