WPILibC++ 2025.1.1
|
This class allows the user to pose a constrained nonlinear optimization problem in natural mathematical notation and solve it. More...
Public Member Functions | |
OptimizationProblem () noexcept=default | |
Construct the optimization problem. | |
Variable | DecisionVariable () |
Create a decision variable in the optimization problem. | |
VariableMatrix | DecisionVariable (int rows, int cols=1) |
Create a matrix of decision variables in the optimization problem. | |
VariableMatrix | SymmetricDecisionVariable (int rows) |
Create a symmetric matrix of decision variables in the optimization problem. | |
void | Minimize (const Variable &cost) |
Tells the solver to minimize the output of the given cost function. | |
void | Minimize (Variable &&cost) |
Tells the solver to minimize the output of the given cost function. | |
void | Maximize (const Variable &objective) |
Tells the solver to maximize the output of the given objective function. | |
void | Maximize (Variable &&objective) |
Tells the solver to maximize the output of the given objective function. | |
void | SubjectTo (const EqualityConstraints &constraint) |
Tells the solver to solve the problem while satisfying the given equality constraint. | |
void | SubjectTo (EqualityConstraints &&constraint) |
Tells the solver to solve the problem while satisfying the given equality constraint. | |
void | SubjectTo (const InequalityConstraints &constraint) |
Tells the solver to solve the problem while satisfying the given inequality constraint. | |
void | SubjectTo (InequalityConstraints &&constraint) |
Tells the solver to solve the problem while satisfying the given inequality constraint. | |
SolverStatus | Solve (const SolverConfig &config=SolverConfig{}) |
Solve the optimization problem. | |
template<typename F > requires requires(F callback, const SolverIterationInfo& info) { { callback(info) } -> std::same_as<void>; } | |
void | Callback (F &&callback) |
Sets a callback to be called at each solver iteration. | |
template<typename F > requires requires(F callback, const SolverIterationInfo& info) { { callback(info) } -> std::same_as<bool>; } | |
void | Callback (F &&callback) |
Sets a callback to be called at each solver iteration. | |
This class allows the user to pose a constrained nonlinear optimization problem in natural mathematical notation and solve it.
This class supports problems of the form:
minₓ f(x) subject to cₑ(x) = 0 cᵢ(x) ≥ 0
where f(x) is the scalar cost function, x is the vector of decision variables (variables the solver can tweak to minimize the cost function), cᵢ(x) are the inequality constraints, and cₑ(x) are the equality constraints. Constraints are equations or inequalities of the decision variables that constrain what values the solver is allowed to use when searching for an optimal solution.
The nice thing about this class is users don't have to put their system in the form shown above manually; they can write it in natural mathematical form and it'll be converted for them.
|
defaultnoexcept |
Construct the optimization problem.
|
inline |
Sets a callback to be called at each solver iteration.
The callback for this overload should return void.
callback | The callback. |
|
inline |
Sets a callback to be called at each solver iteration.
The callback for this overload should return bool.
callback | The callback. Returning true from the callback causes the solver to exit early with the solution it has so far. |
|
inlinenodiscard |
Create a decision variable in the optimization problem.
|
inlinenodiscard |
Create a matrix of decision variables in the optimization problem.
rows | Number of matrix rows. |
cols | Number of matrix columns. |
|
inline |
Tells the solver to maximize the output of the given objective function.
Note that this is optional. If only constraints are specified, the solver will find the closest solution to the initial conditions that's in the feasible set.
objective | The objective function to maximize. |
|
inline |
Tells the solver to maximize the output of the given objective function.
Note that this is optional. If only constraints are specified, the solver will find the closest solution to the initial conditions that's in the feasible set.
objective | The objective function to maximize. |
|
inline |
Tells the solver to minimize the output of the given cost function.
Note that this is optional. If only constraints are specified, the solver will find the closest solution to the initial conditions that's in the feasible set.
cost | The cost function to minimize. |
|
inline |
Tells the solver to minimize the output of the given cost function.
Note that this is optional. If only constraints are specified, the solver will find the closest solution to the initial conditions that's in the feasible set.
cost | The cost function to minimize. |
|
inline |
Solve the optimization problem.
The solution will be stored in the original variables used to construct the problem.
config | Configuration options for the solver. |
|
inline |
Tells the solver to solve the problem while satisfying the given equality constraint.
constraint | The constraint to satisfy. |
|
inline |
Tells the solver to solve the problem while satisfying the given inequality constraint.
constraint | The constraint to satisfy. |
|
inline |
Tells the solver to solve the problem while satisfying the given equality constraint.
constraint | The constraint to satisfy. |
|
inline |
Tells the solver to solve the problem while satisfying the given inequality constraint.
constraint | The constraint to satisfy. |
|
inlinenodiscard |
Create a symmetric matrix of decision variables in the optimization problem.
Variable instances are reused across the diagonal, which helps reduce problem dimensionality.
rows | Number of matrix rows. |