I would like to crate an constraint-equation that depends on 4 sets. For that I use the following code:
#Equations for calculating the total generation from renewable energy sources (RES)
def RESgenerationTotalRule (model, index_BT1, index_BT2, index_BT3, t):
return model.variable_RESGenerationTotal [t] == sum (model.param_pvGenerationNominal_BT1 [index_BT1, t] * SetUpScenarios.pvPeaksOfBuildings[index_BT1] + model.param_windAssignedNominal_BT1 [index_BT1, t] * SetUpScenarios.maximalPowerOfWindTurbine for index_BT1 in model.set_buildings_BT1) + sum (model.param_pvGenerationNominal_BT2 [index_BT2, t] * SetUpScenarios.pvPeaksOfBuildings[index_BT2] + model.param_windAssignedNominal_BT2 [index_BT2, t] * SetUpScenarios.maximalPowerOfWindTurbine for index_BT2 in model.set_buildings_BT2) + sum (model.param_pvGenerationNominal_BT3 [index_BT3, t] * SetUpScenarios.pvPeaksOfBuildings[index_BT3] + model.param_windAssignedNominal_BT3 [index_BT3, t] * SetUpScenarios.maximalPowerOfWindTurbine for index_BT3 in model.set_buildings_BT3)
model.constraint_RESgenerationTotal = pyo.Constraint(model.set_buildings_BT1, model.set_buildings_BT2, model.set_buildings_BT3,model.set_timeslots, rule = RESgenerationTotalRule)
model.constraint_RESgenerationTotal.pprint()
Basically I have the 4 sets model.set_buildings_BT1, model.set_buildings_BT2, model.set_buildings_BT3,model.set_timeslots
. When all of those sets are non-empty, the equation is defined. Howeever, if one of the 3 sets model.set_buildings_BT1, model.set_buildings_BT2, model.set_buildings_BT3
is empty, I get and equations Size of 0 and the equation is not defined. How can I implement in Pyomo that - even if some sets are empty - the equation should be defined because it still makes sense to define it. The equation consists of 3 sums; one for each of the 3 sets model.set_buildings_BT1, model.set_buildings_BT2, model.set_buildings_BT3
. If one out of those 3 sets in empty, the sum for this set should just not be considered (or set to 0). Any idea how I can do that? I appreciate every comment.
Update: I tried another solution
#Equations for calculating the total generation from renewable energy sources (RES)
def RESgenerationTotalRule (model, t):
return model.variable_RESGenerationTotal [t] == sum (model.param_pvGenerationNominal_BT1 [index_BT1, t] * SetUpScenarios.pvPeaksOfBuildings[index_BT1] + model.param_windAssignedNominal_BT1 [index_BT1, t] * SetUpScenarios.maximalPowerOfWindTurbine for index_BT1 in model.set_buildings_BT1) + sum (model.param_pvGenerationNominal_BT2 [index_BT2, t] * SetUpScenarios.pvPeaksOfBuildings[index_BT2] + model.param_windAssignedNominal_BT2 [index_BT2, t] * SetUpScenarios.maximalPowerOfWindTurbine for index_BT2 in model.set_buildings_BT2) + sum (model.param_pvGenerationNominal_BT3 [index_BT3, t] * SetUpScenarios.pvPeaksOfBuildings[index_BT3] + model.param_windAssignedNominal_BT3 [index_BT3, t] * SetUpScenarios.maximalPowerOfWindTurbine for index_BT3 in model.set_buildings_BT3)
model.constraint_RESgenerationTotal = pyo.Constraint(model.set_timeslots, rule = RESgenerationTotalRule)
model.constraint_RESgenerationTotal.pprint()
Here it is also the case that when the 3 sets are non-empty, the equation is defined and when one of those sets is not empty, I get an error message (opposed to the size 0 equation from the other approach) stating "IndexError: index 3 is out of bounds for axis 0 with size 3"
Here is the equation that I want to implement in Pyomo with the 3 independant sets BT1, BT2 and BT3. If one set is empty (or even 2) the equation should also be created