Ejemplo n.º 1
0
 def setScenarioData(self):
     """
   Method to setup the scenario data for scenario tree construction
   @ In, None
   @ Out, None
 """
     MCKP.setScenarioData(self)
Ejemplo n.º 2
0
 def __init__(self):
     """
   Constructor
   @ In, None
   @ Out, None
 """
     MCKP.__init__(self)
Ejemplo n.º 3
0
 def createModel(self):
     """
   This method is used to create pyomo model.
   @ In, None
   @ Out, model, pyomo.AbstractModel, abstract pyomo model
 """
     model = MCKP.createModel(self)
     return model
Ejemplo n.º 4
0
 def addAdditionalSets(self, model):
     """
   Add specific Sets for MCKP problems
   @ In, model, pyomo model instance, pyomo abstract model
   @ Out, model, pyomo model instance, pyomo abstract model
 """
     model = MCKP.addAdditionalSets(self, model)
     return model
Ejemplo n.º 5
0
 def addAdditionalSets(self, model):
     """
   Add specific Sets for MCKP problems
   @ In, model, pyomo model instance, pyomo abstract model
   @ Out, model, pyomo model instance, pyomo abstract model
 """
     model = MCKP.addAdditionalSets(self, model)
     model.sigma = pyomo.Set(ordered=True)
     return model
Ejemplo n.º 6
0
 def initialize(self, initDict):
     """
   Mehod to initialize
   @ In, initDict, dict, dictionary of preprocessed input data
     {
       'Sets':{setName: list of setValues},
       'Parameters':{paramName:{setsIndex:paramValue}} or {paramName:{'None':paramValue}},
       'Settings':{xmlTag:xmlVal},
       'Meta':{paramName:{setIndexName:indexDim}} or {paramName:None},
       'Uncertainties':{paramName:{'scenarios':{scenarioName:{setIndex:uncertaintyVal}}, 'probabilities': [ProbVals]}}
     }
   @ Out, None
 """
     MCKP.initialize(self, initDict)
     if self.uncertainties is None:
         raise IOError(
             'Uncertainty data is required by "{}", but not provided!'.
             format(self.name))
Ejemplo n.º 7
0
 def addAdditionalParams(self, model):
     """
   Add specific Params for MCKP problems
   @ In, model, pyomo model instance, pyomo abstract model
   @ Out, model, pyomo model instance, pyomo abstract model
 """
     model = MCKP.addAdditionalParams(self, model)
     model._lambda = pyomo.Param(within=pyomo.UnitInterval, mutable=True)
     model.alpha = pyomo.Param(within=pyomo.UnitInterval, mutable=True)
     return model
Ejemplo n.º 8
0
 def pysp_scenario_tree_model_callback(self):
     """
   scenario tree instance creation callback
   @ In, None
   @ Out, treeModel, Instance, pyomo scenario tree model for two stage stochastic programming,
     extra variables 'y[*,*]' is used to define the priorities of investments,
     'gamma' and 'nu[*]' is used for the distributionally robust optimization counter-part.
 """
     treeModel = MCKP.pysp_scenario_tree_model_callback(self)
     # additional variables:
     firstStage = treeModel.Stages.first()
     treeModel.StageVariables[firstStage].add('gamma')
     treeModel.StageVariables[firstStage].add('nu[*]')
     return treeModel
Ejemplo n.º 9
0
 def addVariables(self, model):
     """
   Add variables for DROMCKP problems
   @ In, model, pyomo model instance, pyomo abstract model
   @ Out, model, pyomo model instance, pyomo abstract model
 """
     model = MCKP.addVariables(self, model)
     # variables for robust optimization
     model.gamma = pyomo.Var(within=pyomo.NonNegativeReals)
     ## the following two definitions are not equivalent for mckp, not sure why?
     ## From the definition of dual problem, nu should be non-negative
     model.nu = pyomo.Var(model.sigma, within=pyomo.NonNegativeReals)
     # model.nu = pyomo.Var(model.sigma)
     return model
Ejemplo n.º 10
0
 def addVariables(self, model):
     """
   Add variables for CVaRMCKP problems
   @ In, model, pyomo model instance, pyomo abstract model
   @ Out, model, pyomo model instance, pyomo abstract model
 """
     model = MCKP.addVariables(self, model)
     # variables for CVaR optimization
     model.nu = pyomo.Var(domain=pyomo.NonNegativeReals)
     model.u = pyomo.Var(domain=pyomo.Reals)
     # variables to retrieve additional information
     model.cvar = pyomo.Var(domain=pyomo.Reals)
     model.expectProfit = pyomo.Var(domain=pyomo.Reals)
     return model
Ejemplo n.º 11
0
 def addAdditionalParams(self, model):
     """
   Add specific Params for MCKP problems
   @ In, model, pyomo model instance, pyomo abstract model
   @ Out, model, pyomo model instance, pyomo abstract model
 """
     model = MCKP.addAdditionalParams(self, model)
     model.epsilon = pyomo.Param(within=pyomo.NonNegativeReals,
                                 mutable=True)
     model.prob = pyomo.Param(model.sigma,
                              within=pyomo.UnitInterval,
                              mutable=True)
     # model.dist will be changed on the fly via scenario callback functions
     model.dist = pyomo.Param(model.sigma, mutable=True)
     return model
Ejemplo n.º 12
0
    def addAdditionalConstraints(self, model):
        """
      Add specific constraints for DROMCKP problems
      @ In, model, pyomo model instance, pyomo abstract model
      @ Out, model, pyomo model instance, pyomo abstract model
    """
        model = MCKP.addAdditionalConstraints(self, model)

        ## model.dist will be changed on the fly
        def constraintWasserstein(model, i):
            expr = pyomo.summation(model.net_present_values, model.x)
            return -model.gamma * model.dist[i] + model.nu[i] <= expr

        model.constraintWassersteinDistance = pyomo.Constraint(
            model.sigma, rule=constraintWasserstein)
        return model
Ejemplo n.º 13
0
 def pysp_scenario_tree_model_callback(self):
     """
   scenario tree instance creation callback
   @ In, None
   @ Out, treeModel, Instance, pyomo scenario tree model for two stage stochastic programming,
     extra variables 'y[*,*]' is used to define the priorities of investments,
     'u' and 'nu' is used for CVaR optimization counter-part.
     'cvar' is used to retrieve the calculated CVaR value
     'expectProfit' is used to retrieve the expect profit under CVaR optimization
 """
     treeModel = MCKP.pysp_scenario_tree_model_callback(self)
     # additional variables:
     firstStage = treeModel.Stages.first()
     secondStage = treeModel.Stages.last()
     treeModel.StageVariables[firstStage].add('u')
     treeModel.StageVariables[secondStage].add('nu')
     treeModel.StageVariables[secondStage].add('cvar')
     treeModel.StageVariables[secondStage].add('expectProfit')
     return treeModel
Ejemplo n.º 14
0
    def addAdditionalConstraints(self, model):
        """
      Add specific constraints for CVaRMCKP problems
      @ In, model, pyomo model instance, pyomo abstract model
      @ Out, model, pyomo model instance, pyomo abstract model
    """
        model = MCKP.addAdditionalConstraints(self, model)

        def cvarConstraint(model):
            return model.nu + pyomo.summation(model.net_present_values,
                                              model.x) + model.u >= 0

        model.cvarConstraint = pyomo.Constraint(rule=cvarConstraint)

        ## used to retrieve additional information from the optimization
        def expectProfit(model):
            """
        Method to compute the expect profit of stochastic programming
        @ In, model, instance, pyomo abstract model instance
        @ Out, expr, pyomo.expression, constraint to compute the expect profit
      """
            return model.expectProfit - pyomo.summation(
                model.net_present_values, model.x) == 0

        model.computeExpectProfit = pyomo.Constraint(rule=expectProfit)

        def cvar(model):
            """
        Method to compute the conditional value at risk
        @ In, model, instance, pyomo abstract model instance
        @ Out, expr, pyomo.expression, constraint to compute the CVaR
      """
            return model.cvar - model.u + 1. / (1. -
                                                model.alpha) * model.nu == 0

        model.computeCVAR = pyomo.Constraint(rule=cvar)

        return model