示例#1
0
def test_product_path_solver_integration(full_problem):
    max_flight_capacity = mean(drone.max_payload for drone in full_problem.drones)

    customers = full_problem.get_customers()[:20]
    products = full_problem.products[:20]
    hubs = full_problem.warehouses[:10]

    solve_product_trips = SolveProductTrips(
        customers=customers,
        hubs=hubs,
        products=products,
        max_flight_capacity=max_flight_capacity,
        environment=full_problem.get_environment(),
    )

    product_trips = solve_product_trips.solve(Mip_Solver=MipSolver, max_seconds=60)

    assert product_trips

    customer_demand = {
        customer: {
            your_key: customer.demand[your_key]
            for your_key in products
            if your_key in customer.demand
        }
        for customer in customers
    }

    # apply trips to customers to see if everything is delivered
    for trip in product_trips["hub_to_customer"]:
        customer_demand[trip.destination][trip.product_type] -= trip.product_quantity

    for customer, demanded_products in customer_demand.items():
        for product, still_need_to_be_delivered in demanded_products.items():
            assert still_need_to_be_delivered == 0
def test_get_distance(full_problem):
    environment = full_problem.get_environment()

    place1 = Location(x=10, y=40)
    place2 = Location(x=15, y=50)
    distance = environment.get_distance(place1, place2)
    assert distance == 12
def test_warehouses_in_environment(full_problem):
    environment = full_problem.get_environment()
    for warehouse in full_problem.warehouses:
        assert warehouse in environment
def test_get_nearest_warehouse(full_problem):
    environment = full_problem.get_environment()
    place1 = Mock()
    place1.location = Location(x=10, y=30)
    nearest_warehouse = environment.get_nearest_warehouse(place1)
    assert isinstance(nearest_warehouse, WareHouse)
def test_get_all_locations(full_problem):
    environment = full_problem.get_environment()
    assert (len(list(
        environment.get_all_locations())) == full_problem.grid.n_x *
            full_problem.grid.n_y)
def test_orders_in_environment(full_problem):
    environment = full_problem.get_environment()
    for order in full_problem.orders:
        assert order in environment