placo::problem#
- class placo.Expression(v: ndarray)#
An expression is a linear combination of decision variables of the form Ax + b that can be conveniently manipulated using operators.
- A: ndarray#
Expression A matrix, in Ax + b.
- b: ndarray#
Expression b vector, in Ax + b.
- cols() int #
Number of cols in A.
- Returns:
number of cols in A
- static from_double(value: float) Expression #
Builds an expression from a double (A will be zero, the expression is only one row)
- Parameters:
value – value
- Returns:
expression
- static from_vector(v: ndarray) Expression #
Builds an expression from a vector (A will be zeros)
- Parameters:
v – vector
- Returns:
expression
- is_scalar() bool #
checks if the expression is a scalar
- Returns:
true if the expression is a scalar
- mean() Expression #
Reduces a multi-rows expression to the mean of its items.
- Returns:
expression
- multiply(M: ndarray) Expression #
Multiply an expression on the left by a given matrix M.
- Parameters:
M – matrix
- Returns:
expression
- piecewise_add(f: float) Expression #
Adds the expression element by element to another expression.
- Parameters:
f
- Returns:
- rows() int #
Number of rows in A.
- Returns:
number of rows in A
- slice(start: int, rows: int = -1) Expression #
Slice rows from a given expression.
- Parameters:
start – start row
rows – number of rows (default: -1, all rows)
- Returns:
a sliced expression
- sum() Expression #
Reduces a multi-rows expression to the sum of its items.
- Returns:
expression
- value(x: ndarray) ndarray #
Retrieve the expression value, given a decision variable. This can be used after a problem is solved to retrieve a specific expression value.
- Parameters:
x
- Returns:
- class placo.Integrator(variable: Variable, X0: Expression, order: int, dt: float)#
Integrator can be used to efficiently build expressions and values over a decision variable that is integrated over time with a given linear system.
Creates an integrator able to build expressions and values over a decision variable. With this constructor, a continuous system matrix will be used (see below)
- Parameters:
variable – variable to integrate
X0 – x0 (initial state)
order – order
dt – delta time
- A: ndarray#
The discrete system matrix such that $X_{k+1} = A X_k + B u_k$.
- B: ndarray#
The discrete system matrix such that $X_{k+1} = A X_k + B u_k$.
- M: ndarray#
The continuous system matrix.
- expr(step: int, diff: int = -1) Expression #
Builds an expression for the given step and differentiation.
- Parameters:
step – the step
diff – differentiation (if -1, the expression will be a vector of size order with all orders)
- Returns:
an expression
- expr_t(t: float, diff: int = -1) Expression #
Builds an expression for the given time and differentiation.
- Parameters:
t – the time
diff – differentiation (if -1, the expression will be a vector of size order with all orders)
- Returns:
an expression
- final_transition_matrix: ndarray#
Caching the discrete matrix for the last step.
- get_trajectory() IntegratorTrajectory #
Retrieve a trajectory after a solve.
- Returns:
trajectory
- t_start: float#
Time offset for the trajectory.
- static upper_shift_matrix(order: int) ndarray #
Builds a matrix M so that the system differential equation is dX = M X.
- Returns:
the matrix M
- value(t: float, diff: int) float #
Computes.
- Parameters:
t
diff
- Returns:
- class placo.IntegratorTrajectory#
The trajectory can be detached after a solve to retrieve the continuous trajectory produced by the solver.
- duration() float #
Trajectory duration.
- Returns:
duration
- value(t: float, diff: int) float #
Gets the value of the trajectory at a given time and differentiation.
- Parameters:
t – time
diff – differentiation
- Returns:
the value
- class placo.PolygonConstraint#
Provides convenient helpers to build 2D polygon belonging constraints.
- static in_polygon(expression_x: Expression, expression_y: Expression, polygon: list[ndarray], margin: float = 0.0) ProblemConstraint #
- static in_polygon_xy(expression_xy: Expression, polygon: list[ndarray], margin: float = 0.0) ProblemConstraint #
Given a polygon, produces inequalities so that the given point lies inside the polygon. WARNING: Polygon must be clockwise (meaning that the exterior of the shape is on the trigonometric normal of the vertices)
- class placo.Problem#
A problem is an object that has variables and constraints to be solved by a QP solver.
- add_constraint(constraint: ProblemConstraint) ProblemConstraint #
Adds a given constraint to the problem.
- Parameters:
constraint
- Returns:
The constraint
- add_limit(expression: Expression, target: ndarray) ProblemConstraint #
Adds a limit, “absolute” inequality constraint (abs(Ax + b) <= t)
- Parameters:
expression
target
- Returns:
The constraint
- add_variable(size: int = 1) Variable #
Adds a n-dimensional variable to a problem.
- Parameters:
size – dimension of the variable
- Returns:
variable
- clear_constraints() None #
Clear all the constraints.
- clear_variables() None #
Clear all the variables.
- determined_variables: int#
Number of determined variables.
- dump_status() None #
- free_variables: int#
Number of free variables to solve.
- n_equalities: int#
Number of equalities.
- n_inequalities: int#
Number of inequality constraints.
- n_variables: int#
Number of problem variables that need to be solved.
- rewrite_equalities: bool#
If set to true, a QR factorization will be performed on the equality constraints, and the QP will be called with free variables only.
- slack_variables: int#
Number of slack variables in the solver.
- slacks: ndarray#
Computed slack variables.
- solve() None #
Solves the problem, raises QPError in case of failure.
- use_sparsity: bool#
If set to true, some sparsity optimizations will be performed when building the problem Hessian. This optimization is generally not useful for small problems.
- class placo.ProblemConstraint#
Represents a constraint to be enforced by a Problem.
- configure(type: str, weight: float = 1.0) None #
Configures the constraint.
- Parameters:
priority – priority
weight – weight
- expression: Expression#
The constraint expression (Ax + b)
- is_active: bool#
This flag will be set by the solver if the constraint is active in the optimal solution.
- priority: any#
Constraint priority.
- weight: float#
Constraint weight (for soft constraints)
- class placo.QPError(message: str = '')#
Exception raised by Problem in case of failure.
- what() str #
- class placo.Sparsity#
Internal helper to check the column sparsity of a matrix.
- add_interval(start: int, end: int) None #
Adds an interval to the sparsity, this will compute the union of intervals.
- Parameters:
start – interval start
end – interval end
- static detect_columns_sparsity(M: ndarray) Sparsity #
Helper to detect columns sparsity.
- Parameters:
M – given matrix
- Returns:
sparsity
- intervals: list[SparsityInterval]#
Intervals of non-sparse columns.
- print_intervals() None #
Print intervals.
- class placo.SparsityInterval#
An interval is a range of columns that are not sparse.
- end: int#
End of interval.
- start: int#
Start of interval.
- class placo.Variable#
Represents a variable in a Problem.
- expr(start: int = -1, rows: int = -1) Expression #
Builds an expression from a variable.
- Parameters:
start – start row (default: 0)
rows – number of rows (default: -1, all rows)
- Returns:
expression
- k_end: int#
End offset in the Problem.
- k_start: int#
Start offset in the Problem.
- value: ndarray#
Variable value, populated by Problem after a solve.