yaocptool.methods.base package

Submodules

yaocptool.methods.base.discretizationschemebase module

class DiscretizationSchemeBase(solution_method)[source]

Bases: object

__init__(solution_method)[source]

Base class for discretization methods. A discretization class transforms and OCP into a NLP

create_initial_guess(p=None, theta=None)[source]

Create an initial guess for the optimal control problem using problem.x_0, problem.y_guess, problem.u_guess, and a given p and theta (for p_opt and theta_opt) if they are given. If y_guess or u_guess are None the initial guess uses a vector of zeros of appropriate size. If no p or theta is given, an vector of zeros o appropriate size is used.

Parameters:
  • p – Optimization parameters
  • theta – Optimization theta
Returns:

create_initial_guess_with_simulation(u=None, p=None, theta=None)[source]

Create an initial guess for the optimal control problem using by simulating with a given control u, and a given p and theta (for p_opt and theta_opt) if they are given. If no u is given the value of problem.u_guess is used, or problem.u_past, then a vector of zeros of appropriate size is used. If no p or theta is given, an vector of zeros o appropriate size is used.

Parameters:
  • u – Control initial guess
  • p – Optimization parameters
  • theta – Optimization theta
Returns:

degree
degree_control
delta_t
discretize(x_0=None, p=None, theta=None, last_u=None)[source]

Discretize the OCP, returning a Optimization Problem

Parameters:
  • x_0 – initial condition
  • p – parameters
  • theta – theta parameters
  • last_u – last applied control
Returns:

finite_elements
get_system_at_given_times(x, y, u, time_dict=None, p=None, theta=None, functions=None, start_at_t_0=False)[source]
model
Return type:SystemModel
problem
Return type:OptimalControlProblem
set_data_to_optimization_result_from_raw_data(optimization_result, raw_solution_dict)[source]

Set the raw data received from the solver and put it in the Optimization Result object :type optimization_result: yaocptool.methods.optimizationresult.OptimizationResult :type raw_solution_dict: dict

time_breakpoints
time_interpolation_controls
unpack_decision_variables(decision_variables)[source]

Return a structured data from the decision variables vector

Returns: (x_data, y_data, u_data, p_opt, eta)

Parameters:decision_variables – DM
Returns:tuple
vectorize(vector)[source]

yaocptool.methods.base.optimizationresult module

class OptimizationResult(**kwargs)[source]

Bases: object

__init__(**kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

dataset
first_control()[source]

Return the first element of the control vector

Return type:DM
get_variable(var_type, indices)[source]

Get all the data for a variable (var_type

Parameters:
  • var_type (str) – variable type (‘x’, ‘y’, ‘u’
  • of int indices (int|list) – variable indices
is_collocation
is_valid
plot
to_dataset()[source]
Return a dataset with the data of x, y, and u
Return type:DataSet

yaocptool.methods.base.solutionmethodinterface module

Created on

@author: Marco Aurelio Schmitz de Aguiar

class SolutionMethodInterface[source]

Bases: object

prepare()[source]

Perform pre solve check, check for sizes and types. If it fails raise an Exception

solve()[source]

Method that will solve the yaoctool.modelling.OptimalControlProblem and return a yaocptool.modelling.OptimizationResult,

yaocptool.methods.base.solutionmethodsbase module

class SolutionMethodsBase(problem, **kwargs)[source]

Bases: yaocptool.methods.base.solutionmethodinterface.SolutionMethodInterface

__init__(problem, **kwargs)[source]
Parameters:
  • problem (OptimalControlProblem) –
  • integrator_type (str) – str
  • solution_method (str) – str
  • degree (int) – discretization polynomial degree
  • degree_control (int) –
  • discretization_scheme (str) – (‘multiple-shooting’ | ‘collocation’)
  • initial_guess_heuristic (str) – ‘simulation’ or ‘problem_info’
  • last_control_as_parameter (bool) – Default: False, if set to True, the last control will be an parameter for the NLP generated from the OCP. This is useful for MPCs, where the initial condition changes every iteration.
call_solver(initial_guess=None, p=None, theta=None, x_0=None, last_u=None, initial_guess_dict=None)[source]
static collocation_points(degree, cp='radau', with_zero=False)[source]
create_control_approximation()[source]

Parametrize the control variable, accordingly to the ‘degree_control’ attribute. If degree_control == 1, then a piecewise constant control will be used (most common). If degree_control > 1, then a piecewise polynomial approximation will be used with order ‘degree_control’.

Returns:
create_optimization_problem()[source]
create_optimization_result(raw_solution_dict, p, theta, x_0)[source]
create_variable_polynomial_approximation(size, degree, name='var_appr', tau=None, point_at_t0=False)[source]
delta_t
model
prepare()[source]

Perform pre solve check, check for sizes and types. If it fails raise an Exception

solve(initial_guess=None, p=None, theta=None, x_0=None, last_u=None, initial_guess_dict=None)[source]
Parameters:
  • initial_guess – Initial guess
  • p – Parameters values
  • theta – Theta values
  • x_0 – Initial condition value
  • last_u – Last control value
  • initial_guess_dict – Initial guess as dict
Return type:

OptimizationResult

time_breakpoints
unvec(vector, degree=None)[source]

Unvectorize ‘vector’ a vectorized matrix, assuming that it was a matrix with ‘degree’ number of columns :type vector: DM a vector (flattened matrix) :type degree: int

Module contents