commonpower.modeling.robust_constraints.RobustConstraintBuilder

class RobustConstraintBuilder(entity: Node)[source]

Bases: object

Utility class to expand robust constraints into multiple scenarios with corresponding constraints.

High level approach: 1. Identify all uncertain parameters in the given model elements.

This could be elements based on data providers with uncertain forecasts or uncertain parameters (as defined by their config or uncertainty bounds).

  1. Check which variables are affected by uncertainties in robust constraints,

    these become uncertain variables.

  2. Iterate over all robust constraints and propage uncertainties through them.

    E.g. some variable var1 is identified as uncertain in the first pass because it is used in a robust constraint with uncertain parameters. In the next pass, we identify another variable var2 as uncertain because it is used in a robust constraint with var1, etc.

  3. For each uncertain variable, create a number of scenarios based on the number of uncertainties

    associated with that variable. Each scenario essentially duplicates the original constraint with a unique realization of existing uncertainties. We assume that: - uncertainties are independent from each other - constraints are monotonic with respect to each individual uncertainty which means that

    we can enclose the original constraint with lower and upper bounds for each uncertainty.

  4. Delete the original robust constraints from the model elements,

    add the expanded constraints and all necessary additional variables.

Parameters:

entity (Node) – Entity instance to associate the builder with.

Methods

expand_robust_constraints

Expands all robust constraints into multiple scenario constraints.

_expand_robust_constraint(sig: _RobustConstraintSignature, n_scenarios: int | None = None, uncertainty_index: int = 0) list[ModelElement][source]

Expands a robust constraint into multiple scenario constraints. To this end, we create a ConstraintScenario object which maps variables to their corresponding scenario variables. This object is then used in the constraint expressions to retrieve the correct pyomo elements.

Parameters:
  • sig (RobustConstraintSignature) – Signature of the robust constraint.

  • n_scenarios (int, optional) – Number of scenarios if the signature is part of a MultiConstraintSignature. Defaults to None.

  • uncertainty_index (int, optional) – For MultiConstraintSignatures, this is the index of the first uncertainty of the given signature in the list of all uncertainties of the MultiConstraintSignature. Defaults to 0.

Returns:

list[ModelElement] – List of expanded constraints.

_get_bounds_for_uncertain_param(el: ModelElement) list[ModelElement][source]

Create lower and upper bound variables for uncertain parameters.

Parameters:

el (ModelElement) – Uncertain parameter element.

Returns:

list[ModelElement] – List of lower and upper bound elements.

_get_robust_variables() list[ModelElement][source]

Creates all necessary additional variables to represent all scenarios and bounds of robust constraints.

Returns:

list[ModelElement] – List of additional variables.

_get_scenario_bound_constraints(s_id: int, expand_var_mapping: str, sig: _RobustConstraintSignature) list[ModelElement][source]

Create lower and upper bound constraints for scenario variables. These make sure that all scenario variables are constrained within the bound variables. This is a seperate function because we cannot define expressions in loops (they override each other).

Parameters:
  • s_id (int) – Scneario id.

  • expand_var_mapping (str) – Scenario variable name.

  • sig (RobustConstraintSignature) – Signature of the robust constraint.

Returns:

list[ModelElement] – List of lower and upper bound constraints.

_get_scenario_vars(el: ModelElement, n_scenarios: int) list[ModelElement][source]

Creates scenario variables (el1_scn_1, el1_scn_2, …) for uncertain variables. Also creates lower and upper bound variables.

Parameters:
  • el (ModelElement) – Uncertain variable element.

  • n_scenarios (int) – Number of scenarios.

Returns:

list[ModelElement] – List of scenario variables.

expand_robust_constraints() None[source]

Expands all robust constraints into multiple scenario constraints. This function will add the expanded constraints to the model elements of the builder’s associated entity. The original robust constraints are removed from the model elements.