示例#1
0
def test_Dispatcher():
    clock = Clock()
    router = LinearRouter(clock)

    fleet = Fleet(clock, router)
    vehicle = Vehicle(clock)
    fleet.infleet(vehicle, Position(13.3764, 52.5461))

    cnt = Dispatcher()

    cnt.step()

    booking = Booking(clock, Position(13.4014, 52.5478),
                      Position(13.3764, 52.5461))

    itinerary = Itinerary(101, vehicle)
    itinerary.move_to(Position(13.4014, 52.5478))
    itinerary.pickup(booking)
    itinerary.dropoff(booking)

    cnt.dispatch(itinerary)
    cnt.step()

    assert vehicle.is_moving
    assert booking.is_waiting_pickup()

    booking.set_pickup()

    cnt.dispatch(itinerary)
    cnt.step()

    assert booking.is_waiting_dropoff()
示例#2
0
def test_Dispatcher_3():
    clock = Clock()
    router = LinearRouter(clock)

    fleet = Fleet(clock, router)
    vehicle = Vehicle(clock)
    fleet.infleet(vehicle, Position(13.3764, 52.5461))

    cnt = Dispatcher()

    booking = Booking(clock, Position(13.4014, 52.5478),
                      Position(13.3764, 52.5461))

    itinerary = Itinerary(101, vehicle)
    job1 = itinerary.pickup(booking)
    job2 = itinerary.move_to(Position(13.4014, 52.5478))
    job3 = itinerary.dropoff(booking)

    cnt.dispatch(itinerary)
    cnt.step()

    # finish 2 jobs in 1 step
    assert itinerary.current_job is job2

    assert booking.is_waiting_dropoff()
示例#3
0
def test_Dispatcher_2():
    clock = Clock()
    router = LinearRouter(clock)

    fleet = Fleet(clock, router)
    vehicle = Vehicle(clock)
    fleet.infleet(vehicle, GeographicPosition(13.3764, 52.5461))

    cnt = Dispatcher()

    booking = Booking(
        clock,
        GeographicPosition(13.4014, 52.5478),
        GeographicPosition(13.3764, 52.5461),
    )

    itinerary = Itinerary(101, vehicle)
    job1 = itinerary.pickup(booking)
    job2 = itinerary.dropoff(booking)

    cnt.dispatch(itinerary)
    cnt.step()

    # finish 2 jobs in 1 step
    assert itinerary.current_job is None

    assert booking.is_complete()
示例#4
0
def create_fleet(num_vehicles, clock, cell_fn) -> Fleet:
    router = CityBlockRouter(clock)
    fleet = Fleet(clock, router)

    for i in range(num_vehicles):
        vehicle = Vehicle(clock)
        fleet.infleet(vehicle, Cell(*cell_fn()))

    return fleet
示例#5
0
def create_fleet(clock):
    # use LinearRouter router to move vehicles
    router = routers.LinearRouter(clock=clock)

    fleet = Fleet(clock, router)

    vehicle = Vehicle(clock)
    fleet.infleet(vehicle, Position(13.4021, 52.5471))

    return fleet
示例#6
0
def create_scenario(config):
    clock = Clock(
        time_step=config["simulation"]["clock_step"],
        time_unit="s",
        starting_time=config["simulation"]["starting_time"],
    )

    if config["fleet"]["router"] == "linear":
        fleet_router = routers.LinearRouter(
            clock=clock, speed=config["routers"]["linear"]["speed"]
        )

    elif config["fleet"]["router"] == "osrm":
        fleet_router = routers.OSRMRouter(
            clock=clock, server=config["routers"]["osrm"]["server"]
        )

    else:
        logging.warning("Unknown router. Fallback to linear")
        fleet_router = routers.LinearRouter(
            clock=clock, speed=config["routers"]["linear"]["speed"]
        )

    logging.info(f"Fleet router {fleet_router}")

    fleet_router = routers.CachingRouter(fleet_router)

    fleet = Fleet(clock, fleet_router)
    fleet.infleet_from_geojson(
        config["fleet"]["vehicles"],
        config["fleet"]["stations"],
        geofence_file=config.get("geofence"),
        seed=config["simulation"].get("fleet_seed"),
    )

    max_pending_time = clock.time_to_clock_time(
        config["bookings"]["max_pending_time"], "m"
    )
    booking_service = BookingService(clock, max_pending_time)

    demand = create_demand_model(config, clock=clock, map_matcher=fleet_router)

    dispatcher = Dispatcher()

    context = Context(clock, fleet, booking_service, dispatcher)

    return context, demand