Anas Musah
Anas Musah

Reputation: 9

Pyomo: Value Error: No value for uninitialized NumericValue object fo[1,1_C1]

This link https://github.com/amianAA/ALNS contains an ALNS algorithm which was written to optimise MINLP railroad network models (applied to Madrid's network). Though the comments were written in spanish but I believe that wont be much problem since google translate would be of help in this regard. When I ran the ALNP.py file, it worked perfectly until this stage of the code in the madridALNS.py file wherein the whole model was developed with the aid of Pyomo:

 #1 // output flow from each origin "wo" equal to demand of the destination origin pair "w"
 def resd1_rule(model,w):
    wo=model.tabla[w,'wo']
    expr=0
    for l in model.L:
        if model.b[wo,l]==1:
            expr += model.fo[w,l]
        if expr!=0:
            return (expr + model.h[w]==model.tabla[w,'g']*model.factorg)
        else:
            return Constraint.Skip
 model.restr1 = Constraint(model.W,rule=resd1_rule)

The madridALNS.dat file contains data for fill of the model. The error I immediately encountered was:

 ERROR: evaluating expression: No value for uninitialized NumericValue object
fo[1,1_C1]
    (expression: fo[1,1_C1] + fo[1,2_C2] + fo[1,7_C10] + fo[1,3_C3] +
    fo[1,4_C4] + fo[1,6_C8])
ERROR: evaluating object as numeric value: fo[1,1_C1] + fo[1,2_C2] +
fo[1,7_C10] + fo[1,3_C3] + fo[1,4_C4] + fo[1,6_C8]
    (object: <class 'pyomo.core.kernel.expr_coopr3._SumExpression'>)
No value for uninitialized NumericValue object fo[1,1_C1]
ERROR: evaluating expression: No value for uninitialized NumericValue object
fo[1,1_C1]
    (expression: fo[1,1_C1] + fo[1,2_C2] + fo[1,7_C10] + fo[1,3_C3] +
    fo[1,4_C4] + fo[1,6_C8]  ==  0.0)
ERROR: Rule failed when generating expression for constraint restr1 with index
1: ValueError: No value for uninitialized NumericValue object fo[1,1_C1]
ERROR: Constructing component 'restr1' from data=None failed:
    ValueError: No value for uninitialized NumericValue object fo[1,1_C1]
Traceback (most recent call last):
File "ALNS.py", line 16, in <module>
instance = model.create_instance('madridALNS.dat')
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/base/PyomoModel.py", line 723, in create_instance
profile_memory=profile_memory )
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/base/PyomoModel.py", line 806, in load
profile_memory=profile_memory)
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/base/PyomoModel.py", line 870, in _load_model_data
self._initialize_component(modeldata, namespaces, component_name, profile_memory)
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/base/PyomoModel.py", line 925, in _initialize_component
declaration.construct(data)
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/base/constraint.py", line 793, in construct
ndx)
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/base/misc.py", line 61, in apply_indexed_rule
return rule(model, index)
 File "/home/bunmalik/Desktop/project/codes/codes/ALNS/ALNS-master/madridALNS.py", line 120, in resd1_rule
if expr!=0:
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/kernel/expr_coopr3.py", line 533, in __nonzero__
return bool(self())
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/kernel/expr_coopr3.py", line 208, in __call__
exception=exception))
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/kernel/expr_coopr3.py", line 545, in _apply_operation
return next(values) == next(values)
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/kernel/expr_coopr3.py", line 217, in _evaluate_arglist
yield value(arg, exception=exception)
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/kernel/numvalue.py", line 161, in value
tmp = numeric(exception=exception)
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/kernel/expr_coopr3.py", line 208, in __call__
exception=exception))
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/kernel/expr_coopr3.py", line 812, in _apply_operation
return sum(c*next(values) for c in self._coef) + self._const
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/kernel/expr_coopr3.py", line 812, in <genexpr>
return sum(c*next(values) for c in self._coef) + self._const
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/kernel/expr_coopr3.py", line 217, in _evaluate_arglist
yield value(arg, exception=exception)
 File "/usr/local/lib/python3.5/dist-packages/pyomo/core/kernel/numvalue.py", line 170, in value
% (obj.name,))

I am solving similar optimization problem in my project work. However, I am new to Pyomo. Please could someone come to my aid to resolve the error. Thanks in advance

Upvotes: 0

Views: 2367

Answers (1)

Qi Chen
Qi Chen

Reputation: 1718

Two comments with this model:

  1. The immediate issue is that the stack trace implicates the if expr!=0: line. Here, the inequality operator makes Pyomo evaluate the value of expr. Since some of the variables involved in the expression are uninitialized and do not have values, the No value for uninitialized NumericValue object error is observed.
  2. I hope that model.b[wo,l] is a parameter. If it is a variable, then you might be trying to express disjunctive logic within a Constraint declaration, which is not typically supported within an algebraic modeling language. For more on that, you'll want to look into Pyomo.GDP. If it is a parameter, then you're fine as is.

Upvotes: 1

Related Questions