12template <
typename _Scalar>
struct ProblemTpl {
14 using Scalar = _Scalar;
32 const Manifold &manifold()
const {
return *
manifold_; }
35 ProblemTpl(U &&manifold, shared_ptr<CostType> cost,
36 const std::vector<ConstraintObject> &constraints = {})
50 int getTotalConstraintDim()
const {
return nc_total_; }
55 int nx()
const {
return manifold_->nx(); }
56 int ndx()
const {
return manifold_->ndx(); }
64 auto getSegment(VectorXs &x, std::size_t i)
const {
68 auto getConstSegment(
const VectorXs &x, std::size_t i)
const {
72 std::vector<int> getIndices()
const {
return indices_; }
74 int getIndex(std::size_t i)
const {
return indices_[i]; }
76 void evaluate(
const ConstVectorRef &x, Workspace &workspace)
const {
77 workspace.objective_value = cost().call(x);
81 workspace.cstr_values[i] = cstr.func()(x);
85 void computeDerivatives(
const ConstVectorRef &x, Workspace &workspace)
const {
86 cost().computeGradient(x, workspace.objective_gradient);
90 cstr.func().computeJacobian(x, workspace.cstr_jacobians[i]);
94 void computeHessians(
const ConstVectorRef &x, Workspace &workspace,
95 bool evaluate_all_constraint_hessians =
false)
const {
96 cost().computeHessian(x, workspace.objective_hessian);
100 !cstr.set_->disableGaussNewton() || evaluate_all_constraint_hessians;
102 cstr.func().vectorHessianProduct(x, workspace.lams_pdal[i],
103 workspace.cstr_vector_hessian_prod[i]);
110 std::vector<int> ncs_;
111 std::vector<int> indices_;
121 nr = cstr.func().
nr();
123 indices_.push_back(cursor);
132template <
typename Scalar,
typename VectorType>
133void createConstraintWiseView(
const ProblemTpl<Scalar> &prob,
134 typename math_types<Scalar>::VectorXs &input,
135 std::vector<Eigen::Ref<VectorType>> &out) {
136 static_assert(VectorType::IsVectorAtCompileTime,
137 "Function only supports compile-time vectors.");
138 out.reserve(prob.getNumConstraints());
139 for (std::size_t i = 0; i < prob.getNumConstraints(); i++) {
140 out.emplace_back(prob.getSegment(input, i));
146template <
typename Scalar>
150 data.resize(prob.getTotalConstraintDim());
152 createConstraintWiseView(prob, data, out);
160#ifdef PROXSUITE_NLP_ENABLE_TEMPLATE_INSTANTIATION
161#include "proxsuite-nlp/problem-base.txx"
#define PROXSUITE_NLP_DYNAMIC_TYPEDEFS(Scalar)
void allocateMultipliersOrResiduals(const ProblemTpl< Scalar > &prob, typename math_types< Scalar >::VectorXs &data, typename math_types< Scalar >::VectorOfRef &out)
Allocate a set of multipliers (or residuals) for a given problem instance.
int nr() const
Get function codimension.
Packs a ConstraintSetTpl and C2FunctionTpl together.
Base class for differentiable cost functions.
std::size_t getNumConstraints() const
Get the number of constraint blocks.
shared_ptr< CostType > cost_
polymorphic< Manifold > manifold_
ConstraintObjectTpl< Scalar > ConstraintObject
int nc_total_
Total number of constraints.
void addConstraint(T &&cstr)
Add a constraint to the problem, after initialization.
void reset_constraint_dim_vars()
Set values of const data members for constraint dimensions.
int getConstraintDim(std::size_t i) const
Get dimension of constraint i.
const ConstraintObject & getConstraint(const std::size_t &i) const
Get a pointer to the -th constraint pointer.
CostFunctionBaseTpl< Scalar > CostType
std::vector< ConstraintObject > constraints_
Typedefs for math (Eigen vectors, matrices) depending on scalar type.