[Python API] Not adding Var into the Model (addVar())

336 views
Skip to first unread message

Hexin Liu

unread,
Oct 23, 2018, 6:07:23 PM10/23/18
to Gurobi Optimization
Please somebody help...

mdl=Model('SI')

x0
=mdl.addVar(lb=0,name='x0')

Now if invoke x0, output :<gurobi.Var *Awaiting Model Update*>, which is good.

But, Invoke mdl, output: <gurobi.Model Continuous instance Structured Investment: 0 constrs, 0 vars, Parameter changes: LogFile=gurobi.log, CSIdleTimeout=1800>

Also, try x0+1, output AttributeError: b"Index out of range for attribute 'VarName'" instead of a Linear Expression

Again, try, mdl.getVars(), output [ ], an empty list.

Could anybody help me

zinc...@gurobi.com

unread,
Oct 23, 2018, 6:10:02 PM10/23/18
to Gurobi Optimization
You can force model update 

>> mdl.update()

to see the respective changes.

Robert Luce

unread,
Oct 24, 2018, 4:26:55 AM10/24/18
to Gurobi Optimization
Indeed you need to call Model.update() to populate the model with any queued changes, see also the section "Lazy Updates" here:


Robert

Hexin Liu

unread,
Oct 25, 2018, 4:57:04 PM10/25/18
to Gurobi Optimization
Thank you Robert! 

Hexin Liu

unread,
Oct 25, 2018, 4:57:04 PM10/25/18
to Gurobi Optimization
Thank you! Exactly what is needed
Reply all
Reply to author
Forward
0 new messages