本文整理汇总了Python中pyomo.environ.Constraint方法的典型用法代码示例。如果您正苦于以下问题:Python environ.Constraint方法的具体用法?Python environ.Constraint怎么用?Python environ.Constraint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ
的用法示例。
在下文中一共展示了environ.Constraint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connectSOCs
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def connectSOCs(self, pyM, esM):
"""
Declare the constraint for connecting the state of charge with the charge and discharge operation:
the change in the state of charge between two points in time has to match the values of charging and
discharging (considering the efficiencies of these processes) within the time step in between minus
the self-discharge of the storage.
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo ConcreteModel
:param esM: EnergySystemModel instance representing the energy system in which the component should be modeled.
:type esM: esM - EnergySystemModel class instance
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
SOC = getattr(pyM, 'stateOfCharge_' + abbrvName)
chargeOp, dischargeOp = getattr(pyM, 'chargeOp_' + abbrvName), getattr(pyM, 'dischargeOp_' + abbrvName)
opVarSet = getattr(pyM, 'operationVarSet_' + abbrvName)
def connectSOCs(pyM, loc, compName, p, t):
return (SOC[loc, compName, p, t+1] - SOC[loc, compName, p, t] *
(1 - compDict[compName].selfDischarge) ** esM.hoursPerTimeStep ==
chargeOp[loc, compName, p, t] * compDict[compName].chargeEfficiency -
dischargeOp[loc, compName, p, t] / compDict[compName].dischargeEfficiency)
setattr(pyM, 'ConstrConnectSOC_' + abbrvName, pyomo.Constraint(opVarSet, pyM.timeSet, rule=connectSOCs))
示例2: cyclicLifetime
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def cyclicLifetime(self, pyM, esM):
"""
Declare the constraint for limiting the number of full cycle equivalents to stay below cyclic lifetime.
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo ConcreteModel
:param esM: EnergySystemModel instance representing the energy system in which the component should be modeled.
:type esM: esM - EnergySystemModel class instance
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
chargeOp, capVar = getattr(pyM, 'chargeOp_' + abbrvName), getattr(pyM, 'cap_' + abbrvName)
capVarSet = getattr(pyM, 'designDimensionVarSet_' + abbrvName)
def cyclicLifetime(pyM, loc, compName):
return (sum(chargeOp[loc, compName, p, t] * esM.periodOccurrences[p] for p, t in pyM.timeSet) /
esM.numberOfYears <= capVar[loc, compName] *
(compDict[compName].stateOfChargeMax - compDict[compName].stateOfChargeMin) *
compDict[compName].cyclicLifetime / compDict[compName].economicLifetime[loc]
if compDict[compName].cyclicLifetime is not None else pyomo.Constraint.Skip)
setattr(pyM, 'ConstrCyclicLifetime_' + abbrvName, pyomo.Constraint(capVarSet, rule=cyclicLifetime))
示例3: intraSOCstart
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def intraSOCstart(self, pyM, esM):
"""
Declare the constraint that the (virtual) state of charge at the beginning of a typical period is zero.
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo ConcreteModel
:param esM: EnergySystemModel instance representing the energy system in which the component should be modeled.
:type esM: esM - EnergySystemModel class instance
"""
abbrvName = self.abbrvName
opVarSet = getattr(pyM, 'operationVarSet_' + abbrvName)
SOC = getattr(pyM, 'stateOfCharge_' + abbrvName)
def intraSOCstart(pyM, loc, compName, p):
return SOC[loc, compName, p, 0] == 0
setattr(pyM, 'ConstrSOCPeriodStart_' + abbrvName,
pyomo.Constraint(opVarSet, esM.typicalPeriods, rule=intraSOCstart))
示例4: operationModeSOC
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def operationModeSOC(self, pyM, esM):
"""
Declare the constraint that the state of charge [commodityUnit*h] is limited by the installed capacity
[commodityUnit*h] and the relative maximum state of charge [-].
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo ConcreteModel
:param esM: EnergySystemModel instance representing the energy system in which the component should be modeled.
:type esM: esM - EnergySystemModel class instance
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
opVar, capVar = getattr(pyM, 'stateOfCharge_' + abbrvName), getattr(pyM, 'cap_' + abbrvName)
constrSet = getattr(pyM, 'designDimensionVarSet_' + abbrvName)
# Operation [commodityUnit*h] limited by the installed capacity [commodityUnit*h] multiplied by the relative
# maximum state of charge.
def op(pyM, loc, compName, p, t):
return (opVar[loc, compName, p, t] <=
compDict[compName].stateOfChargeMax * capVar[loc, compName])
setattr(pyM, 'ConstrSOCMaxPrecise_' + abbrvName, pyomo.Constraint(constrSet, pyM.timeSet, rule=op))
示例5: operationMode1_2dim
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def operationMode1_2dim(self, pyM, esM, constrName, constrSetName, opVarName):
"""
Declare the constraint that the operation [commodityUnit*hour] is limited by the installed
capacity [commodityUnit] multiplied by the hours per time step.
Since the flow should either go in one direction or the other, the limitation can be enforced on the sum
of the forward and backward flow over the line. This leads to one of the flow variables being set to zero
if a basic solution is obtained during optimization.
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo ConcreteModel
:param esM: EnergySystemModel instance representing the energy system in which the component should be modeled.
:type esM: esM - EnergySystemModel class instance
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
opVar, capVar = getattr(pyM, opVarName + '_' + abbrvName), getattr(pyM, 'cap_' + abbrvName)
constrSet1 = getattr(pyM, constrSetName + '1_' + abbrvName)
def op1(pyM, loc, compName, p, t):
return opVar[loc, compName, p, t] + opVar[compDict[compName]._mapI[loc], compName, p, t] <= \
capVar[loc, compName] * esM.hoursPerTimeStep
setattr(pyM, constrName + '_' + abbrvName, pyomo.Constraint(constrSet1, pyM.timeSet, rule=op1))
示例6: rampUpMax
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def rampUpMax(self, pyM, esM):
"""
Ensure that conversion unit is not ramping up too fast by implementing a maximum ramping rate as share of the installed capacity.
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo Concrete Model
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
opVar= getattr(pyM, 'op_' + abbrvName)
capVar= getattr(pyM, 'cap_' + abbrvName)
constrSetRampUpMax = getattr(pyM,'opConstrSet' + 'rampUpMax_' + abbrvName)
numberOfTimeSteps = esM.numberOfTimeSteps
def rampUpMax(pyM, loc, compName, p, t):
rampRateMax = getattr(compDict[compName], 'rampUpMax')
if (t>=1): # avoid to set constraints twice
return (opVar[loc, compName, p, t]-opVar[loc, compName, p, t-1] <= rampRateMax*capVar[loc, compName])
else:
return (opVar[loc, compName, p, t]-opVar[loc, compName, p, numberOfTimeSteps-1] <= rampRateMax*capVar[loc, compName])
setattr(pyM, 'ConstrRampUpMax_' + abbrvName, pyomo.Constraint(constrSetRampUpMax, pyM.timeSet, rule=rampUpMax))
示例7: rampDownMax
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def rampDownMax(self, pyM, esM):
"""
Ensure that conversion unit is not ramping down too fast by implementing a maximum ramping rate as share of the installed capacity.
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo Concrete Model
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
opVar= getattr(pyM, 'op_' + abbrvName)
capVar= getattr(pyM, 'cap_' + abbrvName)
constrSetRampDownMax = getattr(pyM,'opConstrSet' + 'rampDownMax_' + abbrvName)
numberOfTimeSteps = esM.numberOfTimeSteps
def rampDownMax(pyM, loc, compName, p, t):
rampRateMax = getattr(compDict[compName], 'rampDownMax')
if (t>=1): # avoid to set constraints twice
return (opVar[loc, compName, p, t-1]-opVar[loc, compName, p, t] <= rampRateMax*capVar[loc, compName])
else:
return (opVar[loc, compName, p, numberOfTimeSteps-1]-opVar[loc, compName, p, t] <= rampRateMax*capVar[loc, compName])
setattr(pyM, 'ConstrRampDownMax_' + abbrvName, pyomo.Constraint(constrSetRampDownMax, pyM.timeSet, rule=rampDownMax))
示例8: segmentBigM
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def segmentBigM(self, pyM):
"""
Ensure that the continuous segment variables are zero if the respective binary variable is zero and unlimited otherwise.
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo Concrete Model
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
discretizationSegmentConVar = getattr(pyM, 'discretizationSegmentCon_' + self.abbrvName)
discretizationSegmentBinVar = getattr(pyM, 'discretizationSegmentBin_' + self.abbrvName)
discretizationSegmentVarSet = getattr(pyM, 'discretizationSegmentVarSet_' + self.abbrvName)
def segmentBigM(pyM, loc, compName, discretStep, p, t):
return discretizationSegmentConVar[loc, compName, discretStep, p, t] <= discretizationSegmentBinVar[loc, compName, discretStep, p, t] * compDict[compName].bigM
setattr(pyM, 'ConstrSegmentBigM_' + abbrvName, pyomo.Constraint(discretizationSegmentVarSet, pyM.timeSet, rule=segmentBigM))
示例9: segmentCapacityConstraint
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def segmentCapacityConstraint(self, pyM, esM):
"""
Ensure that the continuous segment variables are in sum equal to the installed capacity of the component.
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo Concrete Model
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
discretizationSegmentConVar = getattr(pyM, 'discretizationSegmentCon_' + self.abbrvName)
capVar = getattr(pyM, 'cap_' + abbrvName)
opVarSet = getattr(pyM, 'operationVarSet_' + abbrvName)
def segmentCapacityConstraint(pyM, loc, compName, p, t):
return sum(discretizationSegmentConVar[loc, compName, discretStep, p, t] for discretStep in range(compDict[compName].nSegments)) == esM.hoursPerTimeStep * capVar[loc, compName]
setattr(pyM, 'ConstrSegmentCapacity_' + abbrvName, pyomo.Constraint(opVarSet, pyM.timeSet, rule=segmentCapacityConstraint))
示例10: pointSOS2
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def pointSOS2(self, pyM):
"""
Ensure that only two consecutive point variables are non-zero while all other point variables are fixed to zero.
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo Concrete Model
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
discretizationPointConVar = getattr(pyM, 'discretizationPoint_' + self.abbrvName)
discretizationSegmentConVar = getattr(pyM, 'discretizationSegmentCon_' + self.abbrvName)
discretizationPointVarSet = getattr(pyM, 'discretizationPointVarSet_' + self.abbrvName)
def pointSOS2(pyM, loc, compName, discretStep, p, t):
points = list(range(compDict[compName].nSegments+1))
segments = list(range(compDict[compName].nSegments))
if discretStep == points[0]:
return discretizationPointConVar[loc, compName, points[0], p, t] <= discretizationSegmentConVar[loc, compName, segments[0], p, t]
elif discretStep == points[-1]:
return discretizationPointConVar[loc, compName, points[-1], p, t] <= discretizationSegmentConVar[loc, compName, segments[-1], p, t]
else:
return discretizationPointConVar[loc, compName, discretStep, p, t] <= discretizationSegmentConVar[loc, compName, discretStep-1, p, t] + discretizationSegmentConVar[loc, compName, discretStep, p, t]
setattr(pyM, 'ConstrPointSOS2_' + abbrvName, pyomo.Constraint(discretizationPointVarSet, pyM.timeSet, rule=pointSOS2))
示例11: partLoadOperationOutput
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def partLoadOperationOutput(self, pyM):
"""
Set the required input of a conversion process dependent on the part load efficency.
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo Concrete Model
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
discretizationPointConVar = getattr(pyM, 'discretizationPoint_' + self.abbrvName)
opVar, opVarSet = getattr(pyM, 'op_' + abbrvName), getattr(pyM, 'operationVarSet_' + abbrvName)
def partLoadOperationOutput(pyM, loc, compName, p, t):
nPoints = compDict[compName].nSegments+1
### TODO Store the part load levels seperately and do not use
# print(list(compDict[compName].discretizedPartLoad.keys()))
return opVar[loc, compName, p, t] == sum(discretizationPointConVar[loc, compName, discretStep, p, t] * \
compDict[compName].discretizedPartLoad[list(compDict[compName].discretizedPartLoad.keys())[0]]['xSegments'][discretStep] \
for discretStep in range(nPoints))
setattr(pyM, 'ConstrpartLoadOperationOutput_' + abbrvName, pyomo.Constraint(opVarSet, pyM.timeSet, rule=partLoadOperationOutput))
示例12: powerFlowDC
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def powerFlowDC(self, pyM):
"""
Ensure that the flow between two locations is equal to the difference between the phase angle variables at
these locations divided by the reactance of the line between these locations.
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo Concrete Model
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
phaseAngleVar = getattr(pyM, 'phaseAngle_' + self.abbrvName)
opVar, opVarSet = getattr(pyM, 'op_' + abbrvName), getattr(pyM, 'operationVarSet_' + abbrvName)
def powerFlowDC(pyM, loc, compName, p, t):
node1, node2 = compDict[compName]._mapC[loc]
return (opVar[loc, compName, p, t] - opVar[compDict[compName]._mapI[loc], compName, p, t] ==
(phaseAngleVar[node1, compName, p, t]-phaseAngleVar[node2, compName, p, t])/
compDict[compName].reactances[loc])
setattr(pyM, 'ConstrpowerFlowDC_' + abbrvName, pyomo.Constraint(opVarSet, pyM.timeSet, rule=powerFlowDC))
示例13: yearlyLimitationConstraint
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def yearlyLimitationConstraint(self, pyM, esM):
"""
Limit annual commodity imports/exports over the energySystemModel's boundaries for one or multiple
Source/Sink components.
:param esM: EnergySystemModel instance representing the energy system in which the component should be modeled.
:type esM: esM - EnergySystemModel class instance
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo ConcreteModel
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
opVar = getattr(pyM, 'op_' + abbrvName)
limitDict = getattr(pyM, 'yearlyCommodityLimitationDict_' + abbrvName)
def yearlyLimitationConstraint(pyM, key):
sumEx = -sum(opVar[loc, compName, p, t] * compDict[compName].sign *
esM.periodOccurrences[p]/esM.numberOfYears
for loc, compName, p, t in opVar if compName in limitDict[key][1])
sign = limitDict[key][0]/abs(limitDict[key][0]) if limitDict[key][0] != 0 else 1
return sign * sumEx <= sign * limitDict[key][0]
setattr(pyM, 'ConstrYearlyLimitation_' + abbrvName,
pyomo.Constraint(limitDict.keys(), rule=yearlyLimitationConstraint))
示例14: designBinFix
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def designBinFix(self, pyM):
"""
Set, if applicable, the installed capacities of a component.
:param pyM: pyomo ConcreteModel which stores the mathematical formulation of the model.
:type pyM: pyomo ConcreteModel
"""
compDict, abbrvName, dim = self.componentsDict, self.abbrvName, self.dimension
designBinVar = getattr(pyM, 'designBin_' + abbrvName)
designBinVarSet = getattr(pyM, 'designDecisionVarSet_' + abbrvName)
def designBinFix(pyM, loc, compName):
return (designBinVar[loc, compName] == compDict[compName].isBuiltFix[loc]
if compDict[compName].isBuiltFix is not None else pyomo.Constraint.Skip)
setattr(pyM, 'ConstrDesignBinFix_' + abbrvName, pyomo.Constraint(designBinVarSet, rule=designBinFix))
####################################################################################################################
# Functions for declaring time dependent constraints #
####################################################################################################################
示例15: operationMode1
# 需要导入模块: from pyomo import environ [as 别名]
# 或者: from pyomo.environ import Constraint [as 别名]
def operationMode1(self, pyM, esM, constrName, constrSetName, opVarName, factorName=None, isStateOfCharge=False):
"""
Define operation mode 1. The operation [commodityUnit*h] is limited by the installed capacity in:\n
* [commodityUnit*h] (for storages) or in
* [commodityUnit] multiplied by the hours per time step (else).\n
An additional factor can limited the operation further.
"""
compDict, abbrvName = self.componentsDict, self.abbrvName
opVar, capVar = getattr(pyM, opVarName + '_' + abbrvName), getattr(pyM, 'cap_' + abbrvName)
constrSet1 = getattr(pyM, constrSetName + '1_' + abbrvName)
factor1 = 1 if isStateOfCharge else esM.hoursPerTimeStep
def op1(pyM, loc, compName, p, t):
factor2 = 1 if factorName is None else getattr(compDict[compName], factorName)
return opVar[loc, compName, p, t] <= factor1 * factor2 * capVar[loc, compName]
setattr(pyM, constrName + '1_' + abbrvName, pyomo.Constraint(constrSet1, pyM.timeSet, rule=op1))