title: Pyomo: Value Error: No value for uninitialized NumericValue object fo[1,1_C1]
body: <p>This link <a href="https://github.com/amianAA/ALNS" rel="nofollow noreferrer">https://github.com/amianAA/ALNS</a> 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:</p>
  
  <pre><code> #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)
  </code></pre>
  
  <p>The madridALNS.dat file contains data for fill of the model. The error I immediately encountered was:</p>
  
  <pre><code> 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: &lt;class 'pyomo.core.kernel.expr_coopr3._SumExpression'&gt;)
  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 &lt;module&gt;
  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 &lt;genexpr&gt;
  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,))
  </code></pre>
  
  <p>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</p>