Newbie - What's the diff bet setObjective and addVar(obj=xxx)

490 views
Skip to first unread message

Ahmed Kamal

unread,
Jan 21, 2016, 4:44:06 AM1/21/16
to Gurobi Optimization
Hi Folks,


Reading this model, I find

* setObjective is optimizing fixed costs of the plants
* addVar( obj= ) is optimizing transportation cost from plants to warehouses

I cannot understand how those 2 values relate to each other? i.e. is the total function being optimized the summation of both? What guarantees both fixedCost and transportationCost are being minimized together ?

Thanks!

Tobias Achterberg

unread,
Jan 22, 2016, 4:59:30 AM1/22/16
to gur...@googlegroups.com
Hi Ahmed,

you are right, this is a bug in the example!
Calling m.setObjective() will overwrite the partial objective function that has
already been initialized using the addVar(obj=...) syntax. Thus, the python
version of this example will only minimize the fixed costs but ignore the
transportation costs. Thanks for pointing this out!


Regards,

Tobias

Tobias Achterberg

unread,
Jan 22, 2016, 5:07:22 AM1/22/16
to gur...@googlegroups.com
Note that the fix is to put also use an "obj=..." argument in the addVar() calls
for the plants and then delete the m.setObjective() call.

Ahmed Kamal

unread,
Jan 25, 2016, 11:06:44 AM1/25/16
to Gurobi Optimization
Thanks a lot Tobias .. Just to be clear, are those "partial" obj=... arguments to addVar calls, are they all added together to form the final objective that will be minimized? 
If you can update this example on the website, kindly do and let me know .. Thanks again

Tobias Achterberg

unread,
Jan 25, 2016, 11:58:46 AM1/25/16
to gur...@googlegroups.com
Yes, each "obj=..." argument specifies the objective coefficient c_i of the
corresponding variable x_i. The final objective function is then sum_i c_i * x_i.

We have updated the example on our website.

Tobias

WANG BOLIN

unread,
Mar 14, 2019, 8:38:48 AM3/14/19
to Gurobi Optimization
Thanks mate your post 3 years ago helped me a lot

在 2016年1月21日星期四 UTC+8下午5:44:06,Ahmed Kamal写道:
Reply all
Reply to author
Forward
0 new messages