opengen.builder package

Submodules

opengen.builder.optimizer_builder module

class opengen.builder.optimizer_builder.OpEnOptimizerBuilder(problem, metadata=<opengen.config.meta.OptimizerMeta object>, build_configuration=<opengen.config.build_config.BuildConfiguration object>, solver_configuration=<opengen.config.solver_config.SolverConfiguration object>)

Bases: object

Builder for code generation

This class is a builder that can be used to generate code for a parametric optimizer.

__init__(problem, metadata=<opengen.config.meta.OptimizerMeta object>, build_configuration=<opengen.config.build_config.BuildConfiguration object>, solver_configuration=<opengen.config.solver_config.SolverConfiguration object>)

Constructor of OpEnOptimizerBuilder

Parameters:
Returns:

New instance of OpEnOptimizerBuilder.

build()

Generate code and build project

Raises:
  • Exception – if the build process fails

  • Exception – if there some parameters have wrong, inadmissible or incompatible values

Returns:

Dictionary with information that can be used for debugging

enable_tcp_interface(tcp_server_configuration=<opengen.config.tcp_server_config.TcpServerConfiguration object>)

This method is deprecated and should not be used

This method will be removed in a future release! Use BuildConfiguration.with_tcp_interface_config instead

with_generate_not_build_flag(flag)

Whether to build (or just generate code)

If set to true, the code will be generated, but it will not be build (mainly for debugging purposes)

Parameters:

flag – generate and not build

Returns:

Current builder object

with_problem(problem)

Specify problem

Parameters:

problem – optimization problem data

Returns:

Current builder object

with_verbosity_level(verbosity_level)

Specify the verbosity level

Parameters:

verbosity_level – level of verbosity (0,1,2,3)

Returns:

Current builder object

opengen.builder.optimizer_builder.make_dir_if_not_exists(directory)

opengen.builder.problem module

class opengen.builder.problem.Problem(u, p, cost)

Bases: object

Definition of an optimization problem

Provides the cost function, constraints and additional ALM/penalty-type constraints.

__init__(u, p, cost)

Construct an optimization problem

param u:

decision variable (CasADi variable)

param p:

parameter (CasADi variable)

param cost:

cost function (CasADi function of u and p)

Example:
>>> import casadi.casadi as cs
>>> import opengen as og
>>> # Define u and p
>>> u = cs.SX.sym('u', 5)
>>> p = cs.SX.sym('p', 2)
>>> # Cost function
>>> phi = og.functions.rosenbrock(u, p)
>>> # Define optimization problem
>>> problem = og.builder.Problem(u, p, phi)
property alm_set_c

Set C in the definition of constraints: F1(u, p) in C

property alm_set_y

Set Y for the Lagrange multipliers

property constraints

Hard constraints; set U

property cost_function

Cost function as a CaADi symbol

property decision_variables

Decision variables (CasADi symbol)

dim_constraints_aug_lagrangian()

Not implemented yet

dim_constraints_penalty()

Number of penalty-type constraints

dim_decision_variables()

Number of decision variables

Returns:

number of decision variables

dim_parameters()

Number of parameters

property parameter_variables

Parameter variables (CasADi symbol)

property penalty_function

Penalty function, g

property penalty_mapping_f1

ALM mapping F1 as a CasADi symbol

property penalty_mapping_f2

Penalty-type mapping F2 as a CasADi symbol

property preconditioning_coefficients

Preconditioning coefficients w = (w_cost, w1, w2)

to_dict()
property w1

Vector of preconditioning coefficients of F1 (ALM constraints) This is a CasADi symbol (SX or MX)

property w2

Vector of preconditioning coefficients of F2 (PM constraints) This is a CasADi symbol (SX or MX)

property w_cost

Preconditioning coefficient of the cost function This is a CasADi symbol (SX or MX)

with_aug_lagrangian_constraints(mapping_f1, set_c, set_y=None)

Constraints: F1(u, p) in C

Parameters:
  • mapping_f1 – mapping of the form F1: R^{n} x R^{p} –> R^{n1}

  • set_c – a convex closed set C

  • set_y – a compact subset of C*, the convex conjugate of C

Returns:

Current object (self)

with_constraints(u_constraints)

Specify or update the constraints of the problem

Args:
param u_constraints:

constraints on the decision variable; must be a Constraint object (such as opengen.constraints.ball2.Ball2 and opengen.constraints.rectangle.Rectangle)

Returns:
return:

Current object

with_penalty_constraints(penalty_constraints)

Constraints to for the penalty method

Specify the constraints to be treated with the penalty method (that is, function F2(u; p))

Parameters:

penalty_constraints – a function c(u, p), of the decision variable u and the parameter vector p, which corresponds to the constraints c(u, p)

Returns:

Current object (self)

opengen.builder.ros_builder module

class opengen.builder.ros_builder.RosBuilder(meta, build_config, solver_config)

Bases: object

Code generation for ROS-related files

For internal use

__init__(meta, build_config, solver_config)
build()

Build ROS-related files

opengen.builder.ros_builder.get_ros_template(name)
opengen.builder.ros_builder.get_template(name)
opengen.builder.ros_builder.make_dir_if_not_exists(directory)

opengen.builder.set_y_calculator module

class opengen.builder.set_y_calculator.SetYCalculator(set_c)

Bases: object

This class is intended for internal use by the solver

LARGE_NUM = 1000000000000.0

A large number

__init__(set_c)

Construct a set Y calculator given set C

obtain()

Computes and returns set Y

The computation of Y is supported only when C is a rectangle or a compact set

Returns:

set Y

Return type:

Constraint

Module contents