I wish to implement an electrical device powered by a PV curve in the pyomo.gdp (General Disjunctive programming) extension. In per unit system, the device needs at least 50% of the PV's peak power.So, there are two disjunct states, ON and OFF. The optimiser shall maximise the usage (power P) of the device at all hours, in the simple example simply setting it equal to P_PV.I know the BigM method would work here, but for later, more complex work, I really need the gdp capabilities, so I wish to understand and get the gdp syntax for disjunct for time arrays running.
My main problem is how to have implement the disjuncts for the device´s ON-state and OFF-state.I have looked at all online examples I could find:
1.) The "SolverMax" blog post on the topic of disjuncts: SolverMax Post2.) The pyomo documentation's examples for disjunctions: Pyomo doc examples3.) The "SolverMax" authors have cleared out the same doubt I have at stack exchange. Of course my current approach is to adapt to their syntax using rule based disjunctions StackExchange post
I closely followed the solution approach prsented in 3. and tried hard to debug. Just, I am stuck with the error message:
"ValueError: The model ('Disjunct_ON_OFF_modes') contains the following active components that the LP writer does not know how to process:<class 'pyomo.gdp.disjunct.Disjunct'>:disjunct_ON[0]disjunct_ON[1]...disjunct_ON[9]disjunct_OFF[0]disjunct_OFF[1]...disjunct_OFF[10]"
Here is my full code:
from pyomo.environ import *import numpy as npfrom pyomo.gdp import *# GENERATING PV INPUT DATA (synthetic dummy data)--------------------------pv_out_pu = 1*np.sin(np.pi/12 * np.arange(0,10,1)) #pu - per unit systemfor i in range(len(pv_out_pu)): if pv_out_pu[i]<0: # night hours, zero irradiance pv_out_pu[i]=0 # negative values are set to zero# Create a ConcreteModelmodel = ConcreteModel("Disjunct_ON_OFF_modes")# Define a set of indicesmodel.t = Set(initialize=range(10)) # 10 hoursmodel.P_PV = Var(model.t, bounds=(0, 1))model.P_device = Var(model.t, bounds=(0, 1))model.PV_CAPACITY = Param(initialize=1) #at the moment just for data type conversion# A.- right place for general constraints?def constr_pv_out(model, t): # setting the model variable to the numpy value return model.P_PV[t] == model.PV_CAPACITY * pv_out_pu[t]model.constr_pv_out = Constraint(model.t, rule=constr_pv_out)def constr_P_device_by_PV(model, t): return model.P_device[t] <= model.P_PV[t]model.constr_device_by_pv = Constraint(model.t, rule=constr_P_device_by_PV)# Define disjunct_ON and disjunct_OFF as 'Disjuncts' using a rule using constraint-specific constraintsdef ON_rule(d,i): # DISJUNCT ON #model =d.model() # not sure if needed d.constr1_x = Constraint(expr=model.P_device[i]>=0.5) # threshold: 50 % in per unit system neededmodel.disjunct_ON = Disjunct(model.t, rule=ON_rule)def OFF_rule(d,i): # DISJUNCT OFF #model =d.model() d.constr_x = Constraint(expr=model.P_device[i]<=0.499) #d.constr_device_by_pv = Constraint(expr=model.P_device[i] <= model.P_PV[i]) # B.- right place for constraints? #d.constr_pv = Constraint(expr=model.P_PV[i] <= model.PV_CAPACITY * pv_out_pu[i])model.disjunct_OFF = Disjunct(model.t, rule=OFF_rule)def ON_OFF_Disjunction_rule(model, i): # DISJUNCTION ON or OFF for each timestep return [model.disjunct_ON[i], model.disjunct_OFF[i]]model.ON_OFF_Disjunction = Disjunction(model.t, rule=ON_OFF_Disjunction_rule)def Objective_fcn(model): return sum(model.P_device[t] for t in model.t)model.obj = Objective(rule=Objective_fcn, sense=maximize)model.pprint()# Apply transformation and solveTransformationFactory('gdp.bigm').apply_to(model)solver=SolverFactory('gurobi')results = solver.solve(model, tee=True)
Also, as commented in the code, I am unsure if I have to put general constraints in each Disjunct. I believe not, it should actually only be the constraint which applies in the respective disjunct, so the 50% threshold, right?Thanks in advance!