yaocptool.optimization package

Submodules

yaocptool.optimization.abstract_optimization_problem module

class AbstractOptimizationProblem(name='optimization_problem', **kwargs)[source]

Bases: object

__init__(name='optimization_problem', **kwargs)[source]
Abstract Optimization Problem class Optimization problem
\[ \begin{align}\begin{aligned}\begin{split}\\min_x f(x, p)\end{split}\\\begin{split}\\textrm{s.t.:} g_{lb} \leq g(x,p) \leq g_{ub}\end{split}\\Object attributes: x -> optimization variables g -> constraint\end{aligned}\end{align} \]
Parameters:
  • name (str) – Optimization problem name
  • kwargs (dict) –
create_parameter(name, size=1)[source]
Create parameter for in the Optimization Problem
Parameters:
  • name (str) – variable name
  • size (int) – number of rows
Returns:

created variable

Return type:

MX|SX

create_variable(name, size=1, lb=-inf, ub=inf)[source]

Create an optimization variable

Parameters:
  • name (str) – Name of the optimization variable.
  • size (int) – Size of the variable (default = 1)
  • lb (MX|SX) – Lower bound of the variable. If the given ‘size’ is greater than one but a scalar is passed as lower bound, a vector of lb of size ‘size’ will be used as a lower bound. (default = [-inf]*size)
  • ub (MX|SX) – Upper bound of the variable. If the given ‘size’ is greater than one but a scalar is passed as upper bound, a vector of ub of size ‘size’ will be used as a upper bound. (default = [inf]*size)
Returns:

Return the variable

Return type:

MX

get_default_call_dict()[source]

Return a dictionary of the settings that will be used on calling the solver The keys are: - ‘lbx’: lower bound on the variables - ‘ubx’: upper bound on the variables - ‘lbg’: lower bound on the constraints - ‘ubg’: upper bound on the constraints

Returns:dict with default values
Return type:dict
get_problem_dict()[source]

Return the optimization problem in a Python dict form (CasADi standard). The dictionary keys are: f-> objective function g-> constraints x-> variables p-> parameters

Returns:optimization problem as a dict
Return type:dict
get_solver()[source]
Get optimization solver
Returns:
include_constraint(expr)[source]

Includes an inequality or inequality to the optimization problem, Example: opt_problem.include_constraint(1 <= x**2) opt_problem.include_constraint(x + y == 1) Due to limitations on CasADi it does not allows for double inequalities (e.g.: 0 <= x <= 1)

Parameters:expr (casadi.MX) – equality or inequality expression
include_equality(expr, rhs=None)[source]

Include a equality with the following form expr = rhs

Parameters:
  • expr – expression, this is the only term that should contain symbolic variables
  • rhs – right hand side, by default it is a vector of zeros with same size of expr. If the ‘expr’ size is greater than one but a scalar is passed as ‘rhs’, a vector of ‘rhs’ with size of ‘expr’ will be used as right hand side. (default = [0]*size)
include_inequality(expr, lb=None, ub=None)[source]

Include inequality to the problem with the following form lb <= expr <= ub

Parameters:
  • expr – expression for the inequality, this is the only term that should contain symbolic variables
  • lb – Lower bound of the inequality. If the ‘expr’ size is greater than one but a scalar is passed as lower bound, a vector of lb with size of ‘expr’ will be used as a lower bound. (default = [-inf]*size)
  • ub – Upper bound of the inequality. If the ‘expr’ size is greater than one but a scalar is passed as upper bound, a vector of ub with size of ‘expr’ will be used as a upper bound. (default = [inf]*size)
include_parameter(par)[source]
Include parameter for in the Optimization Problem
Parameters:par (MX|SX) – parameter to be included
include_variable(variable, lb=-inf, ub=inf)[source]

Include a symbolic variable in the optimization problem

Parameters:
  • variable – variable to be included
  • lb – Lower bound of the variable. If the given variable size is greater than one but a scalar is passed as lower bound, a vector of lb with size of the given variable will be used as a lower bound. (default = [-inf]*size)
  • ub – Upper bound of the variable. If the given variable size is greater than one but a scalar is passed as upper bound, a vector of ub with size of the given variable will be used as a upper bound. (default = [inf]*size)
set_objective(expr)[source]
Set objective function
Parameters:expr (MX|SX) – objective function
solve(initial_guess, call_dict=None, p=None, lam_x=None, lam_g=None)[source]
Parameters:
  • initial_guess – Initial guess
  • call_dict – a dictionary containing ‘lbx’, ‘ubx’, ‘lbg’, ‘ubg’. If not given, the one obtained with self.get_default_call_dict will be used.
  • p – parameters
  • lam_x
  • lam_g
Returns:

dictionary with solution

yaocptool.optimization.nonlinear_problem module

class NonlinearOptimizationProblem(**kwargs)[source]

Bases: yaocptool.optimization.abstract_optimization_problem.AbstractOptimizationProblem

__init__(**kwargs)[source]
Nonlinear Optimization Problem class Optimization problem
\[ \begin{align}\begin{aligned}\begin{split}\\min_x f(x, p)\end{split}\\\begin{split}\\textrm{s.t.:} g_{lb} \leq g(x,p) \leq g_{ub}\end{split}\end{aligned}\end{align} \]

Object attributes: x -> optimization variables g -> constraint

yaocptool.optimization.quadratic_problem module

class QuadraticOptimizationProblem(**kwargs)[source]

Bases: yaocptool.optimization.abstract_optimization_problem.AbstractOptimizationProblem

__init__(**kwargs)[source]
Quadratic Optimization Problem class Optimization problem
\[ \begin{align}\begin{aligned}\min_x &f(x, p)\\\textrm{s.t.:} &g_{lb} \leq g(x,p) \leq g_{ub}\end{aligned}\end{align} \]

Object attributes: x -> optimization variables g -> constraint

Module contents