A logistics company needs to optimize its warehouse storage by selecting a subset of products to store that maximizes profit while considering space constraints and product compatibility. The warehouse has a total capacity of 500 cubic meters. There are 8 products available, each with a specific volume, profit, and compatibility restrictions (some products cannot be stored together due to safety or regulatory reasons). The products and their attributes are as follows:

| Product ID | Volume (m³) | Profit ($) | Incompatible Products |
|------------|-------------|------------|------------------------|
| 1          | 80          | 1200       | 3, 5                   |
| 2          | 60          | 900        | 4                      |
| 3          | 40          | 700        | 1, 6                   |
| 4          | 70          | 1100       | 2, 7                   |
| 5          | 50          | 800        | 1                      |
| 6          | 30          | 500        | 3                      |
| 7          | 90          | 1300       | 4                      |
| 8          | 20          | 300        | None                   |

Problem type: ILP (Small: 8 variables, 11 constraints, 28 nonzeros)

Mathematical model:
Set:
1. Products
The set of available products, \( P = \{1, 2, 3, 4, 5, 6, 7, 8\} \)

Parameter:
1. WarehouseCapacity
500
2. Volume
[80, 60, 40, 70, 50, 30, 90, 20]
3. Profit
[1200, 900, 700, 1100, 800, 500, 1300, 300]
4. IncompatiblePairs
{(1,3), (1,5), (2,4), (3,1), (3,6), (4,2), (4,7), (5,1), (6,3), (7,4)}

Decision variable:
1. ProductSelected
Binary variable \( x_p \in \{0, 1\} \) for all \( p \in P \), where \( x_p = 1 \) if product \( p \) is selected for storage, and \( x_p = 0 \) otherwise

Objective:
Maximize total profit from selected products
max: \sum_{p\in P}Profit_p \cdot x_p

Constraint:
1. Total volume of selected products must not exceed warehouse capacity
\sum_{p\in P}Volume_p \cdot x_p \leq WarehouseCapacity
2. Incompatible products cannot be selected together
x_p + x_q \leq 1, \forall (p,q) \in IncompatiblePairs

Type:
Binary, Linear, Linear
ILP

Gurobi implementation:
import gurobipy as gp
from gurobipy import GRB


def solve_warehouse_optimization(
    products=[1, 2, 3, 4, 5, 6, 7, 8],
    volume={1: 80, 2: 60, 3: 40, 4: 70, 5: 50, 6: 30, 7: 90, 8: 20},
    profit={
        1: 1200,
        2: 900,
        3: 700,
        4: 1100,
        5: 800,
        6: 500,
        7: 1300,
        8: 300
    },
    warehouse_capacity=500,
    incompatible_pairs=[(1, 3), (1, 5), (2, 4), (3, 1), (3, 6), (4, 2),
                        (4, 7), (5, 1), (6, 3), (7, 4)]
):
    """
    Solves the warehouse storage optimization problem.
    """
    model = gp.Model("Warehouse_Storage_Optimization")

    # Decision Variables
    x = model.addVars(products, vtype=GRB.BINARY, name="select")

    # Objective Function
    model.setObjective(gp.quicksum(profit[p] * x[p] for p in products),
                       GRB.MAXIMIZE)

    # Constraints
    model.addConstr(
        gp.quicksum(volume[p] * x[p] for p in products) <= warehouse_capacity,
        "Capacity")

    for (p, q) in incompatible_pairs:
        model.addConstr(x[p] + x[q] <= 1, f"Incompatible_{p}_{q}")

    # Solve the Model
    model.optimize()

    # Return results
    if model.status == GRB.OPTIMAL:
        return {"status": "optimal", "obj": model.ObjVal}
    else:
        return {"status": f"{model.status}"}


if __name__ == "__main__":
    result = solve_warehouse_optimization()
    print(result)


Solution status: OPTIMAL
Optimal objective value: 4200