decogo.pyomo_input_model.input_model

This modules construct user-defined Pyomo minlp input model for refactory CG algorithm.

Classes

PyomoInputModel(model)

This class implement user-defined input model for Pyomo MINLP problems.

PyomoOriginalProblem(sub_models, cuts, settings)

This class implement user-defined primal heuristis for pyomo MINLP problems.

PyomoSubModel(model, vars_in_block, block_id)

Container class which stores the variables from the single block and local nonlinear constraints.

PyomoSubProblems(sub_models, cuts, block_id, ...)

Container class for managing all sub-problems

class decogo.pyomo_input_model.input_model.PyomoInputModel(model)[source]

This class implement user-defined input model for Pyomo MINLP problems.

Parameters
  • model (ConcreteModel) – Input Pyomo model

  • blocks (list) – List (blockwise) of original string names of variables

  • block_sizes (list) – List of variable numbers per sub-model

  • sense (int) – Indicates the the problem is minimization (1) or maximization (-1)

  • sub_problems (list) – list of SubProblems blockwise

  • original_problem (PyomoOriginalProblem) – container of original problem

  • cuts (decogo.model.constraints.CutPool) – container of linear constraints

  • sub_models (list) – list of containers for variables from a single block and local nonlinear constraints blockwise

__init__(model)[source]
_construct_cut_pool()[source]

An abstract method for generating the parameters of cut_pool

Returns

block_sizes, blocks, obj, global_cuts, local_cuts

Return type

tuple

_read_constraint_object(con_obj, local_cuts, global_cuts)[source]

Reads Pyomo constraints, detects if the constraint is linear. If yes, then it creates the linear constraint

Parameters

con_obj (Constraint) – Pyomo constraint object

_get_linear_term_data(expr)[source]

Recursive function for reading and getting data for linear terms

Parameters

expr (Expression) – Linear expression to parse

Returns

List of coefficients and constant

Return type

(list, int)

_get_variable_index_by_name(var_name)[source]

Get variable index from the list of blocks for sparse vector initialization

Parameters

var_name (str) – Original variable name

Returns

Pair of indices: block id and index in the block

Return type

(int, int)

static _remove_unpicklable_objects_pyomo_model(model)[source]

Removes unpicklable objects from Pyomo model object. This is because multiprocessing is based on serialization and some objects cannot be serialized (pickled). This method does the following:

  • removes objects Port and Arcs, since they contain weakref objects

  • sets to None the ‘rule’ property for Constraint, Objective and Param, since it might contain lambda function

  • sets to None property ‘initialize’ and ‘_init_values._init’ for Set, since it might contain lambda function

Parameters

model (ConcreteModel) – Pyomo model

__abstractmethods__ = frozenset({})
_abc_impl = <_abc_data object>
class decogo.pyomo_input_model.input_model.PyomoOriginalProblem(sub_models, cuts, settings)[source]

This class implement user-defined primal heuristis for pyomo MINLP problems.

Parameters
  • cuts (CutPool) – Container which stores all linear constraints (global and local) and objective function

  • sub_models (list) – List of sub-models

  • nlp_problem (NlpProblem) – NLP master problem

  • mip_projection_master_problem – MIP projection master problem

  • nlp_resource_projection_problem (NlpResourceProjectionProblem) – NLP projection master problem

__init__(sub_models, cuts, settings)[source]

Constructor method

local_solve_fast(start_point, result, problem, iter=None)[source]

Abstract method for fast solving original problem non-optimal/heuristically/locally

Parameters
  • start_point (ndarray) – Starting point for the solver, defaults to None

  • result (Results) – stores and makes some manipulations with the CG results

  • problem (DecomposedProblem) – stores all problem objects

  • iter (int) – index of iterations in main algorithm

local_solve(start_point, result, problem, iter=None)[source]

Abstract method for solving original problem non-optimal/heuristically/locally

Parameters
  • start_point (ndarray) – Starting point for the solver, defaults to None

  • result (Results) – stores and makes some manipulations with the CG results

  • problem (DecomposedProblem) – stores all problem objects

  • iter (int) – index of iterations in main algorithm

nlp_solve(solver_name, point_to_fix=None, start_point=None, cut_direction=None)[source]

Solves NlpProblem. Solved mostly with fixed integer variables

Parameters
  • solver_name (str) – External solver name

  • point_to_fix (BlockVector) – Point to be fixed using the integer variables

  • start_point (BlockVector) – Point for the warm start for the external solver

  • cut_direction (BlockVector) – Objective direction

Returns

Solution point, objective value, flag if the solution point is feasible

Return type

tuple

solve_mip_proj_problem(solver_name, point_to_project, target_value=inf, pool_solutions=100)[source]

Solves MipProjectionMasterProblem

Parameters
  • solver_name (str) – External solver name

  • point_to_project (BlockVector) – Point to project from, it is in the original space

Returns

Solution point, objective value

Return type

tuple

solve_nlp_resource_proj_problem(solver_name, point_to_project, target_value=inf, start_point=None)[source]

Solves NlpResourceProjectionProblem

Parameters
  • solver_name (str) – External solver name

  • point_to_project (BlockVector) – Point to project from, it is in the image space

  • start_point (BlockVector) – Starting point for external solver

Returns

Solution point, objective value, flag indicating if the solution point is infeasible, slack value of the soft fixing of target cut

Return type

tuple

__abstractmethods__ = frozenset({})
_abc_impl = <_abc_data object>
class decogo.pyomo_input_model.input_model.PyomoSubModel(model, vars_in_block, block_id)[source]

Container class which stores the variables from the single block and local nonlinear constraints.

Parameters
  • model (ConcreteModel) – Input Pyomo model

  • vars_in_block (list) – List of original variable names from the model

  • block_id (int) – Identifier for block

  • variables (list) – List of all variables with all necessary properties

  • block_size (int) – Number of variables in the sub-model

  • integer (bool) – Indicates if the current sub-model contains variable of integer type

  • nonlin_constr (list) – List of local nonlinear constraints stored using original Pyomo expression

__init__(model, vars_in_block, block_id)[source]

Constructor method

read_nonlinear_constraint(con_obj)[source]

Determines if the given constraint belongs to this sub-model. If yes, it adds to the list of nonlinear constraints by copying the Pyomo expression

Parameters

con_obj (ScalarConstraint or IndexedConstraint) – Pyomo constraint object

constraint_vars_in_block(expr)[source]

Checks if the Pyomo expression belongs to the current sub-model

Parameters

expr (Expression) – Pyomo expression.

compute_gradients()[source]

Computes gradients for each nonlinear constraint and stores in the constraint object

round(point)[source]

Round point to the closest integer

Parameters

point (ndarray) – Given point

Returns

New rounded point

Return type

ndarray

__abstractmethods__ = frozenset({})
_abc_impl = <_abc_data object>
class decogo.pyomo_input_model.input_model.PyomoSubProblems(sub_models, cuts, block_id, settings)[source]

Container class for managing all sub-problems

Parameters
  • minlp_sub_problem (PyomoMinlpSubProblem) – Sub-probem with linear objective

  • proj_sub_problem (PyomoProjectionSubProblem) – Pure projection sub-problem

  • resource_constrained_sub_problem (PyomoResourceConstrainedSubProblem) – Resource constrained sub-problem for checking the feasibility of the resources

  • line_search_sub_problem (PyomoLineSearchSubProblem) – Line search sub-problem

__init__(sub_models, cuts, block_id, settings)[source]

Constructor method :param approx_data:

global_solve(result, direction, start_point=None)[source]

An abstract method for solving sub-problem globally/near-optimal or calling an exact solver

Parameters
  • result (Results) – stores and makes some manipulations with the CG results

  • direction (ndarray) – Given vector

  • start_point (ndaray or None) – Starting point for the solver, defaults to None

Returns

Solution point (ndarray), primal bound, dual bound, flag if the primal bound is feasible

Return type

tuple

local_solve(result, direction, start_point=None)[source]

An abstract method for solving sub-problem non-optimal/heuristically/locally

Parameters
  • result (Results) – stores and makes some manipulations with the CG results

  • direction (ndarray) – Given vector

  • start_point (ndarray or None) – Starting point for the solver, defaults to None

Returns

Solution point (ndarray), primal bound, dual bound, flag if the primal bound is feasible

Return type

tuple

minlp_solve(solver_name, solver_options=None, start_point=None, direction=None, cell=None)[source]

Solves MinlpSubProblem

Parameters
  • solver_name (str) – External solver name

  • solver_options (list or None) – External solver options, defaults to None

  • start_point (ndarray or None) – Staring point for the solver, defaults to None

  • direction (ndarray or None) – Direction for the objective, defaults to None

  • cell (Cell or None) – Cell, defaults to None

Returns

Solution point, primal and dual bound

Return type

tuple

fixed_minlp_solve(solver_name, start_point, solver_options=None, direction=None, cell=None)[source]

Solves MinlpSubProblem with fixed integer variables

Parameters
  • solver_name (str) – External solver name

  • start_point (ndarray or None) – Staring point for the solver, and point which is used for fixing the integers

  • solver_options (list or None) – External solver options, defaults to None

  • direction (ndarray or None) – Direction for the objective, defaults to None

  • cell (Cell or None) – Cell, defaults to None

Returns

Solution point, primal and dual bound

Return type

tuple

nlp_proj_solve(solver_name, point_to_project, start_point=None)[source]

Solves ProjSubProblem

Parameters
  • solver_name (str) – External solver name

  • point_to_project (ndarray) – Projection point

  • start_point (ndarray or None) – Staring point for the solver, defaults to None

Returns

Solution point, primal bound and flag indicating the feasibility of primal solution

Return type

tuple

resource_proj_solve(solver_name, point_to_project, solver_options=None, start_point=None)[source]

Solves ResourceProjSubProblem

Parameters
  • solver_name (str) – External solver name

  • point_to_project (ndarray) – Projection point

  • start_point (ndarray or None) – Staring point for the solver, defaults to None

Returns

Solution point, primal bound and flag indicating the feasibility of primal solution

Return type

tuple

solve_line_search_subproblem(solver_name, exterior_point, interior_point)[source]

Solves LineSearchSubProblem

Parameters
  • solver_name (str) – External solver name

  • exterior_point (ndarray) – Exterior point

  • interior_point (ndarray) – Interior point

Returns

value of parameter \(\alpha\) and solution point

Return type

tuple

add_linear_constraint()[source]

Adds linear constraints to sub-problems

update_var_lower_bound(index)[source]

Updates the lower bound of variable by index

Parameters

index (tuple) – Index of the variable (block_id, index)

update_var_upper_bound(index)[source]

Updates the upper bound of variable by index

Parameters

index (tuple) – Index of the variable (block_id, index)

__abstractmethods__ = frozenset({})
_abc_impl = <_abc_data object>