decogo.model.constraints¶
This module stores constraint data.
Classes
|
This class contains both local and global linear constraints, obj function. |
|
A class for storing the linear constraint. |
|
A class for nonlinear constraint. |
|
This class stores the linear objective function. |
|
This class stores linear constraints from argument Pyomo model. |
|
This class stores the variable data. |
- class decogo.model.constraints.VarDomain(upper_bound, lower_bound, type)[source]¶
This class stores the variable data.
- Parameters:
_upper_bound (float) – Upper bound of the variable
_lower_bound (float) – Lower bound of the variable
_type (str) – Type of the variable, i.e. real, integer, binary
- property upper_bound¶
Gets the upper bound of the variable
- property lower_bound¶
Gets the lower bound of the variable
- property type¶
Gets the type of the variable
- class decogo.model.constraints.LinearConstraint(lhs, relation, rhs, block_sizes, const=0, block_id=None)[source]¶
A class for storing the linear constraint.
- Parameters:
lhs (SparseBlockVector) – Coefficients of right hand side of constraint
relation (str) – Constraint relation
rhs (float) – Right hand side value of constraint
is_local (bool) – Indicates of constraint is local, i.e. non zero values of right hand are within the same block
block_id (int or None) – If constraint is local, then block is is assigned, otherwise it is None
- eval(x)[source]¶
Computes violation of constraint
- Parameters:
x (BlockVector) – Given point to evaluate
- Returns:
Violation of the constraint
- Return type:
float
- class decogo.model.constraints.NonLinearConstraint(expr, orig_var_names_in_block)[source]¶
A class for nonlinear constraint. This class stores original nonlinear Pyomo expression
- Parameters:
expr (Expression) – Original Pyomo expression of nonlinear constraint
orig_var_names_in_block (list) – Original variable names from the input Pyomo model
_fun (Expression) – Function \(f(x)\), where \(f(x)\) is the function from the constraint \(f(x) \leq b\)
relation (str or None) – Relation of the constraint, i.e equality or inequality
_vars_objects (list or None) – Pyomo variable objects from the parameter expr and is used only for OA solver
gradient (dict) – Gradient computed symbolically and is used only in OA solver
- _decompose()[source]¶
Decomposes the nonlinear constraint \(f(x) \leq b\), into function (left hand side), relation and right hand side. If \(f( x) \geq b\), then the expression is reverted and represented as \(b \leq f(x)\)
- eval(x)[source]¶
Evaluates violation of the constraint
- Parameters:
x (list) – Given point to evaluate
- Returns:
Violation and value of the constraint
- Return type:
(float, float)
- compute_gradient_at_point(x)[source]¶
Evaluates already computed gradient at given point
- Parameters:
x (list) – Given point to evaluate
- Returns:
Gradient with the respect to variables
- Return type:
dict
- _assign_values_to_vars(x)[source]¶
Internal method used for evaluation of nonlinear function represented with Pyomo variables. This method exploits the property that Var objects are mutable objects, one has to be careful with that. It uses the list of variable objects in the attributes. Since these objects are mutable objects, any changes of variable value will be also effective in all expressions where these variables are contained. So it is enough to assign the value of variable in one place. However this looks very dangerous.
- Parameters:
x (list) – Given evaluation point
- class decogo.model.constraints.ObjectiveFunction(coef, block_sizes, const)[source]¶
This class stores the linear objective function.
- Parameters:
c (SparseBlockVector) – Linear objective function, stores the coefficients in sparse format
const (float) – Constant value of objective value
- eval(x)[source]¶
Evaluates the objective function \(\sum_\limits{k \in K} c_k x_k\)
- Parameters:
x (BlockVector) – Given point for evaluation
- Returns:
the value of the objective function for \(x\)
- Return type:
float
- class decogo.model.constraints.CutPool(block_sizes=[], blocks=[], obj=None, global_cuts=[], local_cuts={})[source]¶
This class contains both local and global linear constraints, obj function.
- Parameters:
block_sizes (list) – Number of variables in block
blocks (list) – List of original variable names block-wise
obj (ObjectiveFunction) – Objective function
global_cuts (list) – List of global constraints
local_cuts (dict) – Stores the list of local cuts block-wise
- __init__(block_sizes=[], blocks=[], obj=None, global_cuts=[], local_cuts={})[source]¶
Constructor method
- add_lin_local_constr(coeff, relation, b, block_sizes)[source]¶
Adds linear local constraint
- Parameters:
coeff (list) – Coefficients of left hand side
relation (str) – Constraint relation
b (float) – Right hand side of the constraint
block_sizes (list) – Number of variables block-wise
- property num_of_cuts¶
Gets total number of all linear constraints
- Returns:
Number of all linear constraint
- Return type:
int
- property num_blocks¶
Gets total number of blocks
- Returns:
Number of blocks
- Return type:
int
- property num_of_global_cuts¶
Gets the number of linear global constraints
- Returns:
Number of global constraints only
- Return type:
int
- property num_of_local_cuts¶
Gets the number of linear local constraints block-wise
- Returns:
Number of local constraints block-wise
- Return type:
int
- evaluate_violation_global_constraints(point)[source]¶
Evaluates violation of all global constraints
- Parameters:
point (BlockVector) – Given point to evaluate
- Returns:
Violation vector, which corresponds to violation of each global constraint
- Return type:
ndarray
- class decogo.model.constraints.PyomoCutPool(model, blocks)[source]¶
This class stores linear constraints from argument Pyomo model.
- Parameters:
model (ConcreteModel) – Input Pyomo model
blocks (list) – List of original variable names block-wise
- __init__(model, blocks)[source]¶
Constructor method
- Raises:
ValueError – If objective function is not linear
- _read_constraint_object(con_obj)[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)