Optimisation Formatters#

Solver Formatting Functions. This file provides easier to use functions to interface with in creating variables and constraints for the optimiser.

nemglo.backend.optimiser_formatters.create_timeseries_vars(self, var_name, lb, ub, solver_type='continuous')#

Creates a series of variables, one for each interval timestamp. Variable is defined by a name, lower bound, upper bound and variable type.

Parameters
  • var_name (str) – Variable name, used to reference and call variable within the optimiser.

  • lb (float) – Lower bound parameter for minimum possible value of variable.

  • ub (float) – Upper bound parameter for maximum possible value of variable.

  • solver_type (['binary','continuous'], optional) – Variable type. The default is ‘continuous’.

nemglo.backend.optimiser_formatters.create_var(self, var_name, lb, ub, solver_type='continuous')#

Create a single variable. Variable is defined by a name, lower bound, upper bound and variable type.

Parameters
  • var_name (str) – Variable name, used to reference and call variable within the optimiser.

  • lb (float) – Lower bound parameter for minimum possible value of variable.

  • ub (float) – Upper bound parameter for maximum possible value of variable.

  • solver_type (['binary','continuous'], optional) – Variable type. The default is ‘continuous’.

nemglo.backend.optimiser_formatters.create_constr_rhs(self, constr_name, constr_type='<=', rhs_value=0.0)#

Create the right-hand side of a single constrant. This generates a unique constraint ID for the new constraint. Constrant RHS is defined by a name, contraint/inequality type and RHS value.

Parameters
  • constr_name (str) – Constraint name, used to reference and call constraint within the optimiser.

  • constr_type (['<=','==','>=']) – In/equality type for the constraint. The default is ‘<=’.

  • rhs_value (float) – Defined static value for the RHS of the constraint. The default is 0.0.

nemglo.backend.optimiser_formatters.create_constr_rhs_on_interval(self, constr_name, constr_type='<=', rhs_value=0.0, intervals=[])#

Create the right-hand side for a set of new constraints corresponding to each interval. This generates unique constraint IDs for consequtive intervals. Constrant RHS is defined by a name, contraint/inequality type and RHS value.

Parameters
  • constr_name (str) – Constraint name, used to reference and call constraint within the optimiser.

  • constr_type (['<=','==','>=']) – In/equality type for the constraint. The default is ‘<=’.

  • rhs_value (float) – Defined static value for the RHS of the constraint. The default is 0.0.

nemglo.backend.optimiser_formatters.create_constr_rhs_on_interval_dynamicvar(self, constr_name, constr_type, rhs_var_id_series, intervals=[])#

Create the right-hand side for a set of new constraints corresponding to each interval with a dynamic RHS variable. The RHS is defined by a variable ID corresponding to each interval. This function generates unique constraint IDs for consequtive intervals. Constrant RHS is defined by a name, contraint/inequality type and series of variable IDs for the RHS.

Parameters
  • constr_name (str) – Constraint name, used to reference and call constraint within the optimiser.

  • constr_type (['<=','==','>=']) – In/equality type for the constraint. The default is ‘<=’.

  • rhs_var_id_series (pd.DataFrame()) – Dataframe containing interval column and variable_id column.

nemglo.backend.optimiser_formatters.create_constr_rhs_dynamicvar(self, constr_name, constr_type, rhs_var_id)#

Create the right-hand side as a dynamic variable ID for a single new constraint. This function generates a unique constraint ID. Constrant RHS is defined by a name, contraint/inequality type and variable ID integer for the RHS.

Parameters
  • constr_name (str) – Constraint name, used to reference and call constraint within the optimiser.

  • constr_type (['<=','==','>=']) – In/equality type for the constraint. The default is ‘<=’.

  • rhs_var_id (int) – Variable ID for parameter to sit on the RHS.

nemglo.backend.optimiser_formatters.create_constr_lhs_sum_intervals(self, constr_name, constr_rhs, coefficient_map=1)#

** IN-DEVELOPMENT ** Create definitions for the LHS of a defined single constraint (by a previous RHS formulation), mapping a set of variables for all intervals to be summated on the LHS with coefficients of 1. The RHS arugment must already be defined.

Parameters
  • constr_name (str) – Constraint name, used to reference and call constraint within the optimiser.

  • constr_rhs (pd.DataFrame()) – The dataframe entry for the corresponding RHS constraint. In the form of, self._constr_rhs[{var_name}]

  • coefficient_map (int) – The LHS coefficient mapped to each LHS variable. The default is 1.

nemglo.backend.optimiser_formatters.create_constr_lhs_on_interval(self, constr_name, constr_rhs, coefficient_map)#

Create definitions for the LHS of a defined set of RHS constraints corresponding to each interval (by previous RHS formulation). The mapping of LHS variables and coefficients may either be a single variable applied to all intervals of the RHS constraint set, or a different (interval-specific) variable corresponding to interval-specific RHS constraints. The coefficient map parameter allows multiple LHS variables to be considered in a single function call.

Parameters
  • constr_name (str) – Constraint name, used to reference and call constraint within the optimiser.

  • constr_rhs (pd.DataFrame()) – The dataframe entry for the corresponding RHS constraint. In the form of, self._constr_rhs[{constr_name}]

  • coefficient_map (dict) – Defines the matching coefficients to each variable ID set. The same coefficient must be applied to all LHS variables of the same name for all intervals. In the form of, {‘{var_name_1}’: 1, ‘{var_name_2}’: -1}

nemglo.backend.optimiser_formatters.create_constr_lhs_on_interval_dynamic(self, constr_name, constr_rhs, decision_vars, coefficient_list)#

Create definitions for LHS variable with a dynamic coefficient across intervals. For example used to define VRE availability where LHS arguments are dynamic coefficient (renewable trace) * single-variable across intervals (VRE capacity) == RHS dynamic variable (VRE availability)

Parameters
  • constr_name (str) – Constraint name, used to reference and call constraint within the optimiser.

  • constr_rhs (pd.DataFrame) – The dataframe entry for the corresponding RHS constraint. In the form of, self._constr_rhs[{var_name}]

  • decision_vars (pd.DataFrame) – The dataframe of variables to be used as LHS arguments. In the form of, self._var[name_cap].

  • coefficient_list (pd.Series) – Dynamic values to be applied as coefficients, ordered by consequtive intervals.

Raises

NotImplementedError – If the decision variable dataframe passed has variables for distinct intervals this error will raise. Only a single variable with non-descript interval data can be passed as decision_vars.

nemglo.backend.optimiser_formatters.create_constr_lhs_on_interval_fixed_rhs(self, constr_name, constr_rhs, decision_vars, coefficient_map)#

** IN DEVELOPMENT ** `{note} Redundancy with <create_constr_lhs_on_interval()>. Remove expression in future bug fixes. `

nemglo.backend.optimiser_formatters.create_contr_lhs_on_interval_matrix(self, constr_name, constr_rhs, coeff_matrix)#
| h2e_load | h2_production |
-2 | NaN | 1.0 |
-1 | -1.0 | NaN |

The above matrix index indicates the interval offset to apply for that row of variables, the values within the coefficents.

nemglo.backend.optimiser_formatters.create_constr_bigM_on_interval(self, constr_name, lhs_vars, rhs_bin_vars, constr_type='<=', mode='inverse', Mvalue=10000.0)#

Creates both the LHS and RHS elements in a bigM constraint formulation in one function.

Parameters
  • constr_name (str) – Constraint name, used to reference and call constraint within the optimiser.

  • lhs_vars (pd.DataFrame) – The dataframe of LHS variables (interval-specific) to form the constraint. In the form of, self._var[‘{var_name}’].

  • rhs_bin_vars (pd.DataFrame) – The dataframe of RHS variables (interval-specific) to form the constraint. In the form of, self._var[‘{var_name}’].

  • constr_type (['<=','==','>=']) – In/equality type for the constraint. The default is ‘<=’.

  • mode (['inverse','normal']) – Determines the structure of the bigM constraint formulation. ‘inverse’ structures the formulation as: LHS <= M(1-RHS). ‘normal’ structures the formulation as: LHS <= M(RHS). The default is ‘inverse’.

  • Mvalue (float, optional) – The magnitude of the bigM ‘swamping’ parameter. The default is 10000.0.

Raises

ValueError – Raised if mode parameter is passed as something other than ‘inverse’ or ‘normal’.

nemglo.backend.optimiser_formatters.create_objective_cost(self, var_name, decision_var_series, cost=1000.0)#

Creates an objective cost parameter corresponding to a decision variable or set of decision variables. If the cost is passed as a float, the single value is mapped to all decision variables. However, if passed as a pd.DataFrame with a defined interval column, the unique interval-specific costs are mapped corresponding to interval-specific variables.

Parameters
  • var_name (str) – Variable name, used to reference and call variable within the optimiser.

  • decision_var_series (pd.DataFrame) – The dataframe containing the decision variables to be costed in the objective function. In the form of, self._var[‘{var_name}’].

  • cost (float) – The corresponding cost mapped to the decision variables passed. The default is 1000.0.

nemglo.backend.optimiser_formatters.remove_element(plan, name, all_assoc=True, as_var=False, as_objective_cost=False, as_constr_lhs=False, as_constr_rhs=False, as_constr_rhs_dynamic=False, as_constr_bigM=False, as_sos_2=False)#

Remove variable and/or constraint elements from the Plan object parsed.

Parameters
  • plan (nemglo.planner.Plan) – Plan object to remove variable/constraints from.

  • name (str) – Variable or constraint name to remove. The identifier of a component object may also be used to remove that component entirely using all_assoc.

  • all_assoc (bool, optional) – Set as true to remove all associations of the name from the Plan object, in all variable and constraint attributes.

  • as_var (bool, optional) – Set as true to remove variable name from the variable attributes of Plan object, by default False.

  • as_objective_cost (bool, optional) – Set as true to remove variable name from the objective cost attributes of Plan object, by default False.

  • as_constr_lhs (bool, optional) – Set as true to remove constraint name from the LHS constraint attributes of Plan object, by default False.

  • as_constr_rhs (bool, optional) – Set as true to remove constraint name from the RHS constraint attributes of Plan object, by default False

  • as_constr_rhs_dynamic (bool, optional) – Set as true to remove constraint name from the Dynamic RHS constraint attributes of Plan object, by default False.

  • as_constr_bigM (bool, optional) – Set as true to remove constraint name from the Big M constraint attributes of Plan object, by default False.

  • as_sos_2 (bool, optional) – Set as true to remove constraint name from the SOS Type 2 constraint attributes of Plan object, by default False.