hi, all
i want to create a set of constraints, as following:
Pg[0] <= Pmax[0]
Pg[1] <= Pmax[1]
Pg[3] <= Pmax[3]
Pg[4] <= Pmax[4]
Pg[5] <= Pmax[5]
and, my code is as following:
import pyomo.environ as pyo
model = pyo.ConcreteModel()
Ngen = 5
Pmax = [40, 170, 520, 200, 100]
model.Ngen = pyo.Set(dimen=Ngen)
model.Pg = pyo.Var(model.Ngen)
def Co1(model):
return ((model.Pg[ii] for ii in model.Ngen) <= (Pmax[jj] for jj in range(Ngen)))
model.Co1 = pyo.Constraint(rule=Co1)
but, the Python Console tells me:
" TypeError: '<=' not supported between instances of 'generator' and 'generator' "
HOW DO I RECORRECT this?
and the other quesiton, if the Pmax is not a list, but a numpy-ndarray. somethings will different?
thanks a lot!
def Co1(model,ii):
return model.Pg[ii] <= model.Pmax[ii]
model.Co1 = pyo.Constraint(model.Ngen, rule=Co1)import pyomo.environ as pyo
import pyomo.opt as SolverFactory
model = pyo.AbstractModel()
Ngen = 5
pg = [10, 12, 13, 12, 15]
rg = [0., 0., 0., 0., 0.]
sumPd = 1000
Pmax = [40, 170, 520, 200, 100]
Pmin = [5, 20, 50, 20, 10]
model.Ngen = pyo.Set(dimen=Ngen)
model.Pg = pyo.Var(model.Ngen,domain=pyo.NonNegativeReals)
model.Rg = pyo.Var(model.Ngen,domain=pyo.NonNegativeReals)
model.Pmax = pyo.Param(model.Ngen,initialize=Pmax)
model.Pmin = pyo.Param(model.Ngen,initialize=Pmin)
model.pg = pyo.Param(model.Ngen,initialize=pg)
model.rg = pyo.Param(model.Ngen,initialize=rg)
def ObjRule(model, ii):
return (sum(model.Pg[ii] * model.pg[ii] + model.Rg[ii] * model.rg[ii]))
model.Obj = pyo.Objective(model.Ngen, rule=ObjRule)
def Co1(model, ii):
return (model.Pmin[ii] <= model.Pg[ii] <= model.Pmax[ii])
model.co1 = pyo.Constraint(model.Ngen, rule=Co1)
def Co2(model, ii):
return (model.Pg[ii] + model.Rg[ii] <= model.Pmax[ii])
model.co2 = pyo.Constraint(model.Ngen, rule=Co2)
def Co3(model, ii):
return (sum(model.Pg[ii]) == sumPd)
model.co3 = pyo.Constraint(model.Ngen, rule=Co3)
instance = model.create_instance()
opt = pyo.SolverFactory('glpk')
opt.solve(instance)
def ObjRule(model):
return (sum(model.Pg[ii] * model.pg[ii] + model.Rg[ii] * model.rg[ii] for ii in model.Ngen))
model.Obj = pyo.Objective(rule=ObjRule)
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/a0e040a0-2103-4998-baa5-c0f4c7b67334%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo...@googlegroups.com.
The problem is that your entire model is indexed by an empty Set. You are declaring
model.Ngen = pyo.Set(dimen=5)
The “dimen” keyword tells Set to expect that each member of the Set will be a tuple with 5 elements. However, you never actually provide any data to the Set. I think what you want is a Set with 5 members, 0 through 4. You can get that one of two ways:
model.Ngen = pyo.Set(initialize=range(5))
or
model.Ngen = pyo.RangeSet(0,4)
Also note that you are not initializing your Params incorrectly. The Param initialize keyword expects a dictionary mapping index to value and not a list. As written, each Param will get a value that is itself a list.
john
To unsubscribe from this group and stop receiving emails from it, send an email to
pyomo-forum...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyomo-forum/b8358f70-d9cb-45e8-a9d0-9153a046098b%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "Pyomo Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyomo-forum/Sb6BMYibbNc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyomo-forum...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/ef803b51a8a844179a7cacbb822ec044%40ES02AMSNLNT.srn.sandia.gov.