2

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?

user620842
  • 271
  • 1
  • 7
  • You may find the following link useful: https://or.stackexchange.com/questions/797/how-to-model-a-mixed-integer-linear-programming-formulation-in-python-using-guro – Mostafa Jan 28 '21 at 05:37

1 Answers1

4
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)
Oguz Toragay
  • 8,652
  • 2
  • 13
  • 41