I am currently learning how to use Gurobi for Python using their official tutorial found here. In this example, they appear to formulate the objective by simply specifying a cost dictionary to the obj argument in addVars. However, I am not sure how to formulate more complicated objectives such as the example below:

I have formulated the cost to be $$\min\sum_{i=1}^{v}\sum_{j=1}^{w}\left[c_{ij}\sum_{k=1}^{p} x_{ijk}\right]$$ where $c_{ij}$ represents the fixed cost of shipping 1 unit of product from vineyard $i$ to winery $j$ and $x_{ijk}$ represents the amount of product $i$ shipped from vineyard $j$ to winery $k$.

The goal of this toy model is to minimize the cost of shipping while using up all the supply at the vineyards. However, I am having a hard time formulating the objective. I cannot simply use obj= because the cost of shipping isn't multiplied by each individual decision variable. The tutorial does not showcase more complicated examples of constructing objectives using obj argument.

How can I formulate my objective properly using Gurobi in Python?


1 Answer 1

obj = (gb.quicksum(gb.quicksum(c[i,j]*gb.quicksum(x[i,j,k] for k in P)) for j in W) for i in V)
m.setObjective(obj, GRB.MINIMIZE)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.