95 std::function<f_sig>
f;
99 std::function<g_sig>
g;
115 std::function<grad_f_sig>
grad_f, std::function<g_sig>
g,
117 std::function<grad_gi_sig>
grad_gi,
119 std::function<hess_L_sig>
hess_L)
120 :
n(
n),
m(
m),
C(std::move(
C)),
D(std::move(
D)),
f(std::move(
f)),
134 virtual std::shared_ptr<ParamWrapper>
clone()
const = 0;
156 assert(
p.size() ==
wrapper->param.size());
160 assert(
p.size() ==
wrapper->param.size());
179 std::chrono::nanoseconds
f{};
181 std::chrono::nanoseconds
g{};
193 a.grad_f +=
b.grad_f;
195 a.grad_g_prod +=
b.grad_g_prod;
196 a.grad_gi +=
b.grad_gi;
197 a.hess_L_prod +=
b.hess_L_prod;
198 a.hess_L +=
b.hess_L;
205 a.grad_f +=
b.grad_f;
207 a.grad_g_prod +=
b.grad_g_prod;
208 a.grad_gi +=
b.grad_gi;
209 a.hess_L_prod +=
b.hess_L_prod;
210 a.hess_L +=
b.hess_L;
218template <
class ProblemT>
234 std::shared_ptr<EvalCounter>
evaluations = std::make_shared<EvalCounter>();
240template <
class ProblemT>
244 const static auto timed = [](
auto &time,
const auto &
f) ->
decltype(
f()) {
245 if constexpr (std::is_same_v<
decltype(
f()),
void>) {
246 auto t0 = std::chrono::steady_clock::now();
248 auto t1 = std::chrono::steady_clock::now();
251 auto t0 = std::chrono::steady_clock::now();
253 auto t1 = std::chrono::steady_clock::now();
261 return timed(ev->time.f, [&] { return f(x); });
266 timed(ev->time.grad_f, [&] { grad_f(x, grad); });
270 timed(ev->time.g, [&] { g(x, gx); });
276 timed(ev->time.grad_g_prod, [&] { grad_g_prod(x, y, grad); });
281 timed(ev->time.grad_g_prod, [&] { grad_gi(x, i, grad); });
287 timed(ev->time.hess_L_prod, [&] { hess_L_prod(x, y, v, Hv); });
292 timed(ev->time.hess_L, [&] { hess_L(x, y, H); });
virtual void wrap(Problem &)=0
virtual ~ParamWrapper()=default
virtual std::shared_ptr< ParamWrapper > clone() const =0
Moves the state constraints in the set C to the set D, resulting in an unconstraint inner problem.
ProblemOnlyD(Problem &&p)
ProblemOnlyD(const Problem &p)
ProblemWithCounters(const ProblemWithCounters &)=delete
ProblemWithCounters & operator=(ProblemWithCounters &&)=default
std::shared_ptr< EvalCounter > evaluations
ProblemWithCounters(ProblemWithCounters &&)=default
ProblemWithCounters & operator=(const ProblemWithCounters &)=delete
static void attach_counters(ProblemWithCounters &)
ProblemWithCounters(const ProblemT &p)
ProblemWithCounters(ProblemT &&p)
const vec & get_param() const
std::shared_ptr< ParamWrapper > wrapper
ProblemWithParam & operator=(ProblemWithParam &&)=default
ProblemWithParam(const ProblemWithParam &o)
ProblemWithParam & operator=(const ProblemWithParam &o)
ProblemWithParam(ProblemWithParam &&)=default
InnerStatsAccumulator< PolymorphicInnerSolverWrapper::Stats > & operator+=(InnerStatsAccumulator< PolymorphicInnerSolverWrapper::Stats > &acc, const PolymorphicInnerSolverWrapper::Stats &s)
Eigen::Ref< const vec > crvec
Default type for immutable references to vectors.
constexpr real_t NaN
Not a number.
EvalCounter operator+(EvalCounter a, const EvalCounter &b)
realvec vec
Default type for vectors.
Eigen::Ref< mat > rmat
Default type for mutable references to matrices.
double real_t
Default floating point type.
Eigen::Ref< vec > rvec
Default type for mutable references to vectors.
std::chrono::nanoseconds grad_gi
std::chrono::nanoseconds f
std::chrono::nanoseconds g
struct alpaqa::EvalCounter::EvalTimer time
std::chrono::nanoseconds hess_L
std::chrono::nanoseconds grad_f
std::chrono::nanoseconds grad_g_prod
std::chrono::nanoseconds hess_L_prod
Problem description for minimization problems.
Box C
Constraints of the decision variables, .
std::function< hess_L_sig > hess_L
Hessian of the Lagrangian function .
void(crvec x, crvec y, crvec v, rvec Hv) hess_L_prod_sig
Signature of the function that evaluates the Hessian of the Lagrangian multiplied by a vector .
std::function< f_sig > f
Cost function .
std::function< grad_gi_sig > grad_gi
Gradient of a specific constraint .
unsigned int m
Number of constraints, dimension of g(x) and z.
void(crvec x, rvec grad_fx) grad_f_sig
Signature of the function that evaluates the gradient of the cost function .
Problem(unsigned int n, unsigned int m)
std::function< grad_f_sig > grad_f
Gradient of the cost function .
unsigned int n
Number of decision variables, dimension of x.
void(crvec x, unsigned i, rvec grad_gi) grad_gi_sig
Signature of the function that evaluates the gradient of one specific constraints .
std::function< hess_L_prod_sig > hess_L_prod
Hessian of the Lagrangian function times vector .
std::function< g_sig > g
Constraint function .
real_t(crvec x) f_sig
Signature of the function that evaluates the cost .
void(crvec x, crvec y, rmat H) hess_L_sig
Signature of the function that evaluates the Hessian of the Lagrangian .
Problem(unsigned n, unsigned int m, Box C, Box D, std::function< f_sig > f, std::function< grad_f_sig > grad_f, std::function< g_sig > g, std::function< grad_g_prod_sig > grad_g_prod, std::function< grad_gi_sig > grad_gi, std::function< hess_L_prod_sig > hess_L_prod, std::function< hess_L_sig > hess_L)
Box D
Other constraints, .
std::function< grad_g_prod_sig > grad_g_prod
Gradient of the constraint function times vector .
void(crvec x, crvec y, rvec grad_gxy) grad_g_prod_sig
Signature of the function that evaluates the gradient of the constraints times a vector .
void(crvec x, rvec gx) g_sig
Signature of the function that evaluates the constraints .