ValueError: No value for uninitialized NumericValue object x[2,1]

2,348 views
Skip to first unread message

Hayford Adjavor

unread,
Jun 18, 2018, 12:11:07 AM6/18/18
to Pyomo Forum
Hi team Pyomo,
I shall kindly be glad for your help in understanding how to fix the above-stated error  I am experiencing with my model. This error seems to be coming from the constraint formulation below in my model:

def constrELEVEN_rule(model, i):
    if model.x[i,1] == 1:
        return (model.K <= model.u[i] <= model.L)
model.consExBoundingB = pyo.Constraint(model.U, rule=constrELEVEN_rule)

In my model, I have defined the variable " u[i] " as ==>>  model.u = pyo.Var(model.J, within=pyo.PositiveIntegers)

And "model.J" is also defined in my model as ====>>  model.I = pyo.Set(initialize=[1,2,3,...], within=pyo.PositiveIntegers)

I have attached a snapshot of the data (.data file) for my model for your perusal. From the attached data, there's indeed a value for the arc x[2,1], but I am still getting this error message below:

  "File "C:\Users\myUsername\Anaconda2\lib\site-packages\pyomo\core\kernel\numvalue.py", line 170, in value
    % (obj.name,))

ValueError: No value for uninitialized NumericValue object x[2,1]; No value for uninitialized NumericValue object x[2,1] "

I have done all I could, but can't seem to figure it out. 

Thanks in advance for your help.
mydata_data.png

jose santiago rodriguez

unread,
Jun 18, 2018, 7:43:46 AM6/18/18
to pyomo...@googlegroups.com
The problem is the if statement in constrELEVEN_rule. There are a couple of things to consider. First, since you are using an abstract model, and there is no initial value for your variable x, the condition statement x[i, 1] == 1 cannot be evaluated in python. Second, rules in pyomo are not callbacks. Hence, having an if statement in your rule does not mean that at every iteration of the solver the if statement will be evaluated. It only means that when you construct the model it will evaluate the if statement based on the initial value provided for x and construct the model accordingly. There are some "OR tricks" that you could use to do what you want. Please look for either-or constraints and conditional constraints for mixed interger programs. Such "tricks" will let you include in your model the behavior you are looking for.


--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hayford Adjavor

unread,
Jun 18, 2018, 12:32:07 PM6/18/18
to pyomo...@googlegroups.com
Thanks for the insight, Santiago!
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages