61 m_decision_variables.emplace_back();
62 return m_decision_variables.back();
74 m_decision_variables.reserve(m_decision_variables.size() + rows * cols);
78 for (
int row = 0; row < rows; ++row) {
79 for (
int col = 0; col < cols; ++col) {
80 m_decision_variables.emplace_back();
81 vars(row, col) = m_decision_variables.back();
108 m_decision_variables.reserve(m_decision_variables.size() +
109 (rows * rows + rows) / 2);
113 for (
int row = 0; row < rows; ++row) {
114 for (
int col = 0; col <= row; ++col) {
115 m_decision_variables.emplace_back();
116 vars(row, col) = m_decision_variables.back();
117 vars(col, row) = m_decision_variables.back();
171 m_f = -std::move(objective);
181 m_equality_constraints.reserve(m_equality_constraints.size() +
184 std::back_inserter(m_equality_constraints));
194 m_equality_constraints.reserve(m_equality_constraints.size() +
195 constraint.constraints.size());
196 std::ranges::copy(constraint.constraints,
197 std::back_inserter(m_equality_constraints));
207 m_inequality_constraints.reserve(m_inequality_constraints.size() +
210 std::back_inserter(m_inequality_constraints));
220 m_inequality_constraints.reserve(m_inequality_constraints.size() +
221 constraint.constraints.size());
222 std::ranges::copy(constraint.constraints,
223 std::back_inserter(m_inequality_constraints));
233 return m_f.value().type();
235 return ExpressionType::NONE;
245 if (!m_equality_constraints.empty()) {
246 return std::ranges::max(m_equality_constraints, {}, &Variable::type)
249 return ExpressionType::NONE;
259 if (!m_inequality_constraints.empty()) {
260 return std::ranges::max(m_inequality_constraints, {}, &Variable::type)
263 return ExpressionType::NONE;
278 [[maybe_unused]]
bool spy =
false);
287 template <
typename F>
289 { callback(info) } -> std::same_as<void>;
292 m_iteration_callbacks.emplace_back(
293 [=, callback = std::forward<F>(callback)](
const IterationInfo& info) {
307 template <
typename F>
309 { callback(info) } -> std::same_as<bool>;
312 m_iteration_callbacks.emplace_back(std::forward<F>(callback));
326 std::optional<Variable> m_f;
336 m_iteration_callbacks;
338 void print_exit_conditions([[maybe_unused]]
const Options& options);
339 void print_problem_analysis();
This class allows the user to pose a constrained nonlinear optimization problem in natural mathematic...
Definition problem.hpp:47
void clear_callbacks()
Clears the registered callbacks.
Definition problem.hpp:318
void subject_to(const EqualityConstraints &constraint)
Tells the solver to solve the problem while satisfying the given equality constraint.
Definition problem.hpp:180
VariableMatrix decision_variable(int rows, int cols=1)
Create a matrix of decision variables in the optimization problem.
Definition problem.hpp:73
Problem() noexcept=default
Construct the optimization problem.
void maximize(Variable &&objective)
Tells the solver to maximize the output of the given objective function.
Definition problem.hpp:169
ExitStatus solve(const Options &options=Options{}, bool spy=false)
Solve the optimization problem.
ExpressionType equality_constraint_type() const
Returns the type of the highest order equality constraint.
Definition problem.hpp:244
void subject_to(InequalityConstraints &&constraint)
Tells the solver to solve the problem while satisfying the given inequality constraint.
Definition problem.hpp:219
void minimize(const Variable &cost)
Tells the solver to minimize the output of the given cost function.
Definition problem.hpp:133
VariableMatrix symmetric_decision_variable(int rows)
Create a symmetric matrix of decision variables in the optimization problem.
Definition problem.hpp:100
void subject_to(EqualityConstraints &&constraint)
Tells the solver to solve the problem while satisfying the given equality constraint.
Definition problem.hpp:193
void maximize(const Variable &objective)
Tells the solver to maximize the output of the given objective function.
Definition problem.hpp:155
void add_callback(F &&callback)
Adds a callback to be called at the beginning of each solver iteration.
Definition problem.hpp:291
ExpressionType cost_function_type() const
Returns the cost function's type.
Definition problem.hpp:231
void add_callback(F &&callback)
Adds a callback to be called at the beginning of each solver iteration.
Definition problem.hpp:311
void minimize(Variable &&cost)
Tells the solver to minimize the output of the given cost function.
Definition problem.hpp:144
void subject_to(const InequalityConstraints &constraint)
Tells the solver to solve the problem while satisfying the given inequality constraint.
Definition problem.hpp:206
ExpressionType inequality_constraint_type() const
Returns the type of the highest order inequality constraint.
Definition problem.hpp:258
An autodiff variable pointing to an expression node.
Definition variable.hpp:40
A matrix of autodiff variables.
Definition variable_matrix.hpp:29
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition SmallVector.h:1198
Definition expression_graph.hpp:11
ExpressionType
Expression type.
Definition expression_type.hpp:18
ExitStatus
Solver exit status.
Definition exit_status.hpp:16
A vector of equality constraints of the form cₑ(x) = 0.
Definition variable.hpp:538
gch::small_vector< Variable > constraints
A vector of scalar equality constraints.
Definition variable.hpp:540
A vector of inequality constraints of the form cᵢ(x) ≥ 0.
Definition variable.hpp:599
gch::small_vector< Variable > constraints
A vector of scalar inequality constraints.
Definition variable.hpp:601
Solver iteration information exposed to an iteration callback.
Definition iteration_info.hpp:13
Solver options.
Definition options.hpp:15
#define SLEIPNIR_DLLEXPORT
Definition symbol_exports.hpp:34