title: Pyomo: Build an abstract model
body: <p>I am trying to do optimization with Pyomo (solver Ipopt).</p>
  <p>I have 2 sets (j for the numbers of generator and t for times),6 indexed parameters (A,B,C,Pmin,Pmax :indexed on model.J, Demand indexed on model.T)</p>
  <p>What I want to do is generate 24 different costs base on 24 different demands.</p>
  <p>After I ran the code, this error appeared:</p>
  <p><strong>TypeError: P_LoadgenBalance() takes 1 positional argument but 2 were given.</strong></p>
  <p>I don’t know why this error occurs,Hope you can help me with it. Thanks for your help!</p>
  <p>Vivi</p>
  <pre><code>from pyomo.environ import *
  import matplotlib.pyplot as plt
  import numpy as np
  </code></pre>
  <pre><code># create a model
  model = AbstractModel()
  
  #     There are ten generators with different values of ABC.
  #     Minimizing the costs and find the optimal dispatch for 24 different demands changed with time  
  #     obj：Cost= sum(ap^2 +bp+c)
  #     constraints: sum_i P(i,t)  &gt;= load(t) , (Pmin =&lt; P =&lt; Pmax).
  
  # declare decision variables
  
  model.M = Param(mutable=True)
  model.T = RangeSet(model.M)
  model.N = Param(mutable=True)
  model.J = RangeSet(model.N)
  model.A = Param(model.J)
  model.B = Param(model.J)
  model.C = Param(model.J)
  model.D = Param(model.J)
  model.E = Param(model.J)
  model.F = Param(model.J)
  model.P_min = Param(model.J, within=PositiveReals)
  model.P_max = Param(model.J, within=PositiveReals)
  model.demand = Param(model.T)
  model.emission_value = Param(initialize=1000000, mutable=True)
  
  # declare constraints_Pbounds (Pmin =&lt; P =&lt; Pmax)
  
  def Pbounds(model, j,t):
      return (model.P_min[j], model.P_max[j])
  model.P = Var(model.J, model.T, bounds=Pbounds, domain=NonNegativeReals)
  
  # declare constraints_P_LoadgenBalance  ( sum P &gt;= demand)
  
  def P_LoadgenBalance(model,t):
      return sum(model.P[j,t] for j in model.J  ) &gt;= model.demand[t]
  model.P_LoadgenBalance = Constraint(model.T, rule=P_LoadgenBalance)
  
  
  # declare objective_cost
  
  def obj_cost(model):
       return sum(model.A[j]* model.P[j,t] ** 2 + model.B[j] * model.P[j,t] + model.C[j] for j in model.J for t in model.T) 
  model.cost= Objective(rule=obj_cost, sense=minimize)
  
  # declare objective_emission
  
  def obj_emission(model):
        return sum(model.E[j]* model.P[j,t] ** 2 + model.D[j] * model.P[j,t] + model.F[j] for j in model.J for t in model.T) 
  model.emission= Objective(rule=obj_emission, sense=minimize)
  </code></pre>
  <pre><code>model.emission.deactivate()
  opt = SolverFactory('Ipopt')
  instance = model.create_instance(&quot;E:\pycharm_project\END-10units.dat&quot;)
  results = opt.solve(instance)
  
  print(value(instance.cost)
  </code></pre>
  <p>Data file</p>
  <pre><code>param M:=24;
  param N:=10;
  # Creating Parameters A, B, C,D,E,F, P_min, P_max:
  param : A B C D E F P_min P_max:=
  1   0.0148  12.1    82  2.15    3.59    -11.4   80  200
  2   0.0289  12.6    49  3.63    2.02    -3.65   120 320
  3   0.0135  13.2    100 3.3     4.7     -4.04   50  150
  4   0.0127  13.9    105 3.73    1.61    -13.44  250 520
  5   0.0261  13.5    72  2.27    2.29    -4.41   80  280
  6   0.0212  15.4    29  2.37    2.77    -8.61   50  150
  7   0.0382  14      32  2.03    4.86    -8.91   30  120
  8   0.0393  13.5    40  2.4     3.32    -31.74  30  110
  9   0.0396  15      25  2.5     4.03    -19.14  20  80
  10  0.051   14.3    15  3.43    3.27    -21.02  20  60
  
  param demand:=
  1 600
  2 650
  3 680
  4 651
  5 630
  6 650
  7 810
  8 820
  9 883
  10 893
  11 888
  12 901
  13 892
  14 875
  15 843
  16 877
  17 880
  18 904
  19 865
  20 855
  21 766
  22 733
  23 688
  24 654;
  </code></pre>