title: How can i avoid the getting this error in pyomo "Error retrieving component Pd[1]: The component has not been constructed."
body: <p>I am new to pyomo. I am trying to run a simple maximization problem, but i keep getting this error message: <code>Error retrieving component Pd[1]: The component has not been constructed.</code> . Only the last 5 constraints give me this problem, the first three constraints work fine.
  I'm using this command on the IPython console to run it <code>!pyomo --solver-manager=neos --solver=cbc battpyomo.py battpyomo.dat</code></p>
  
  <p>On the data file, I only define the set T and parameter p.</p>
  
  <p>set T :=
  1
  2
  3
  4
  5
  6
  7
  8
  9;</p>
  
  <p>param:  p   :=<br>
  1       51.12<br>
  2       48.79<br>
  3       39.56<br>
  4       36.27<br>
  5       36.16<br>
  6       34.90<br>
  7       33.33<br>
  8       21.16<br>
  9       24.42;</p>
  
  <p>Here's the code for battbyomo.py:</p>
  
  <pre><code>from pyomo.environ import *
  
  model = AbstractModel()
  
  ########Sets#########
  #Hours
  model.T = Set()
  
  #########Parameters##########
  #Price
  model.p = Param(model.T,within=PositiveReals)
  #Variable OM cost Discharge
  model.VOMd = Param(initialize=15)
  #Varaible OM cost Charge
  model.VOMc = Param(initialize=10)
  #State of Charge min
  model.SOCmin = Param(initialize=5)
  #State of charge max
  model.SOCmax = Param(initialize=25)
  #ESS efficiency
  model.m = Param(initialize=0.99)
  #Max discharge rate
  model.Pdmax = Param(initialize=20)
  #Max charge rate
  model.Pcmax = Param(initialize=20)
  #Initial State of Charge
  model.SOCini = Param(initialize=25)
  
  ###########Variables##########
  #Power discharged
  model.Pd = Var(model.T, within=NonNegativeIntegers)
  #Power charged
  model.Pc= Var(model.T, within=NonNegativeIntegers)
  #Charging Status
  model.Uc = Var(model.T, within=NonNegativeIntegers)
  #Discharging status
  model.Ud = Var(model.T, within=NonNegativeIntegers)
  #State of Charge
  model.SOC = Var(model.T, within=NonNegativeIntegers)
  
  #######Objective##########
  def profit_rule(model):
      return sum(model.Pd[i]*model.p[i]-model.Pd[i]*model.VOMd-model.Pc[i]*model.p[i]-model.Pc[i]*model.VOMc for i in model.T)
  model.profit = Objective(rule=profit_rule, sense = maximize)    
  
  #######Constraints##########
  
  def status_rule(model,i):
      return (model.Ud[i] + model.Uc[i] &lt;= 1)
  model.status = Constraint(model.T,rule=status_rule)
  
  def Cmax_rule(model,i):
      return model.Pc[i] &lt;= model.Pcmax*model.Uc[i]
  model.Cmax = Constraint(model.T,rule=Cmax_rule)
  
  def Dmax_rule(model,i):
      return model.Pd[i] &lt;= model.Pdmax*model.Ud[i]
  model.Dmax = Constraint(model.T,rule=Dmax_rule)
  
  def Dlim_rule(module,i):
      return model.Pd[i] &lt;= model.SOC[i] - model.SOCmin
  model.Dlim = Constraint(model.T,rule=Dlim_rule)
  
  def Clim_rule(module,i):
      return model.Pc[i] &lt;= model.SOCmax-model.SOC[i]
  model.Clim = Constraint(model.T,rule=Clim_rule)
  
  def Smin_rule(module,i):
      return model.SOC[i] &gt;= model.SOCmin
  model.Smin = Constraint(model.T,rule=Smin_rule)
  
  def Smax_rule(module,i):
      return model.SOC[i] &lt;= model.SOCmax
  model.Smax = Constraint(model.T,rule=Smax_rule)
  
  def E_rule(module,i):
      if i == 1:
          return model.SOC[i] == model.SOCini + model.Pc[i]*model.m -model.Pd[i]
      else:
          return model.SOC[i] == model.SOC[i-1] + model.Pc[i]*model.m - model.Pd[i]
  model.E = Constraint(model.T,rule=E_rule)
  </code></pre>