when is model.update() required?

4,375 views
Skip to first unread message

CraigSchmidt

unread,
Feb 16, 2010, 8:27:05 AM2/16/10
to Gurobi Optimization
This is a fairly basic question. When exactly is a call to
model.update() required?

The documenation just says:

"Process any pending model modifications. "
http://www.gurobi.com/html/doc/refman/node340.html

However, the example mip1.py

http://www.gurobi.com/html/doc/exampletour/node70.html

only calls it after adding variables. Does it need to be called after
adding constraints? After changing bounds on a variable?

Thanks,
Craig

Angelos Tsoukalas

unread,
Feb 16, 2010, 8:53:44 AM2/16/10
to gur...@googlegroups.com
Hi Craig,

Not a complete answer, and it's better to wait for the experts, but in my experience what is more important is before
what you call it. When what you want to do next depends on the changes you should do the update.
For example if you add a variable and then a constraint that includes the variable, if you dont update between the two
you will get an error because you add a constraint involving a variable that is not yet in the model.

When you run optimize the model is updated automatically which is why in the example the update is not need to be called.

Cheers,

Angelos

Greg Glockner

unread,
Feb 16, 2010, 12:06:33 PM2/16/10
to gur...@googlegroups.com
Angelos is correct: call the update() method when you need to reference another model element. For example, call update() after creating a variable so that you can use that variable in building a constraint. For best performance, don't call update() unnecessarily. And note that update() is called automatically when you use the optimize() method.

Reply all
Reply to author
Forward
0 new messages