robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
constraint_component_base.hpp
Go to the documentation of this file.
1#ifndef ROBOTOC_CONSTRAINT_COMPONENT_BASE_HPP_
2#define ROBOTOC_CONSTRAINT_COMPONENT_BASE_HPP_
3
4#include <memory>
5
6#include "Eigen/Core"
7
15
16
17namespace robotoc {
18
24enum class KinematicsLevel {
28};
29
34class ConstraintComponentBase : public std::enable_shared_from_this<ConstraintComponentBase> {
35public:
44 ConstraintComponentBase(const double barrier_param=1.0e-03,
45 const double fraction_to_boundary_rule=0.995);
46
51
56
61
66
70 ConstraintComponentBase& operator=(ConstraintComponentBase&&) noexcept = default;
71
76 virtual KinematicsLevel kinematicsLevel() const = 0;
77
82 virtual void allocateExtraData(ConstraintComponentData& data) const = 0;
83
92 virtual bool isFeasible(Robot& robot, const ContactStatus& contact_status,
94 const SplitSolution& s) const = 0;
95
103 virtual void setSlack(Robot& robot, const ContactStatus& contact_status,
105 const SplitSolution& s) const = 0;
106
115 virtual void evalConstraint(Robot& robot, const ContactStatus& contact_status,
117 const SplitSolution& s) const = 0;
118
130 virtual void evalDerivatives(Robot& robot, const ContactStatus& contact_status,
132 const SplitSolution& s,
133 SplitKKTResidual& kkt_residual) const = 0;
134
146 virtual void condenseSlackAndDual(const ContactStatus& contact_status,
148 SplitKKTMatrix& kkt_matrix,
149 SplitKKTResidual& kkt_residual) const = 0;
150
158 virtual void expandSlackAndDual(const ContactStatus& contact_status,
160 const SplitDirection& d) const = 0;
161
166 virtual int dimc() const = 0;
167
173
180 double maxSlackStepSize(const ConstraintComponentData& data) const;
181
188 double maxDualStepSize(const ConstraintComponentData& data) const;
189
195 static void updateSlack(ConstraintComponentData& data, const double step_size);
196
202 static void updateDual(ConstraintComponentData& data, const double step_size);
203
208 virtual double getBarrierParam() const final;
209
214 virtual double getFractionToBoundaryRule() const final;
215
220 virtual void setBarrierParam(const double barrier_param) final;
221
228 const double fraction_to_boundary_rule) final;
229
236 template <typename Derived>
237 std::shared_ptr<Derived> as_shared_ptr();
238
239protected:
246
255 const int start,
256 const int size) const;
257
265 template <int Size>
267 const int start) const;
268
276 double computeComplementarySlackness(const double slack,
277 const double dual) const;
278
284
292 const int start, const int size);
293
300 template <int Size>
302 const int start);
303
313 static double computeCondensingCoeffcient(const double slack,
314 const double dual,
315 const double residual,
316 const double cmpl);
317
324
333 const int start, const int size);
334
342 template <int Size>
344 const int start);
345
355 static double computeDualDirection(const double slack, const double dual,
356 const double dslack, const double cmpl);
357
363 template <typename VectorType>
364 double logBarrier(const Eigen::MatrixBase<VectorType>& slack) const;
365
366private:
367 double barrier_, fraction_to_boundary_rule_;
368
369};
370
371} // namespace robotoc
372
373#include "robotoc/constraints/constraint_component_base.hxx"
374
375#endif // ROBOTOC_CONSTRAINT_COMPONENT_BASE_HPP_
Base class for constraint components.
Definition: constraint_component_base.hpp:34
static void updateDual(ConstraintComponentData &data, const double step_size)
Updates the dual variable according to the step size.
Definition: constraint_component_base.hxx:32
virtual bool isFeasible(Robot &robot, const ContactStatus &contact_status, ConstraintComponentData &data, const SplitSolution &s) const =0
Checks whether the current solution s is feasible or not.
double logBarrier(const Eigen::MatrixBase< VectorType > &slack) const
Computes the log barrier function of the slack variable.
Definition: constraint_component_base.hxx:128
virtual void allocateExtraData(ConstraintComponentData &data) const =0
Allocates extra data in ConstraintComponentData.
virtual int dimc() const =0
Returns the size of the constraint.
ConstraintComponentBase & operator=(const ConstraintComponentBase &)=default
Default copy operator.
virtual double getFractionToBoundaryRule() const final
Gets the margin parameter of the fraction-to-boundary-rule.
void setSlackAndDualPositive(ConstraintComponentData &data) const
Sets the slack and dual variables positive.
static void computeDualDirection(ConstraintComponentData &data)
Computes the direction of the dual variable from slack, primal residual, complementary slackness,...
Definition: constraint_component_base.hxx:101
virtual KinematicsLevel kinematicsLevel() const =0
Checks the kinematics level of the constraint component.
virtual void expandSlackAndDual(const ContactStatus &contact_status, ConstraintComponentData &data, const SplitDirection &d) const =0
Expands the slack and dual, i.e., computes the directions of the slack and dual variables from the di...
void computeComplementarySlackness(ConstraintComponentData &data) const
Computes the residual in the complementarity slackness between the slack and dual variables.
Definition: constraint_component_base.hxx:50
std::shared_ptr< Derived > as_shared_ptr()
Gets the shared ptr of this object as the specified type. If this fails in dynamic casting,...
Definition: constraint_component_base.hxx:40
virtual ~ConstraintComponentBase()
Destructor.
Definition: constraint_component_base.hpp:50
ConstraintComponentBase(ConstraintComponentBase &&) noexcept=default
Default move constructor.
virtual void setBarrierParam(const double barrier_param) final
Sets the barrier parameter.
double maxDualStepSize(const ConstraintComponentData &data) const
Computes and returns the maximum step size by applying fraction-to-boundary-rule to the direction of ...
Definition: constraint_component_base.hxx:19
ConstraintComponentBase(const double barrier_param=1.0e-03, const double fraction_to_boundary_rule=0.995)
Constructor.
static void updateSlack(ConstraintComponentData &data, const double step_size)
Updates the slack variable according to the step size.
Definition: constraint_component_base.hxx:25
virtual double getBarrierParam() const final
Gets the barrier parameter.
virtual void condenseSlackAndDual(const ContactStatus &contact_status, ConstraintComponentData &data, SplitKKTMatrix &kkt_matrix, SplitKKTResidual &kkt_residual) const =0
Condenses the slack and dual variables, i.e., factorizes the condensed Hessians and KKT residuals....
ConstraintComponentBase(const ConstraintComponentBase &)=default
Default copy constructor.
virtual void evalConstraint(Robot &robot, const ContactStatus &contact_status, ConstraintComponentData &data, const SplitSolution &s) const =0
Computes the primal residual, residual in the complementary slackness, and the log-barrier function o...
virtual void setSlack(Robot &robot, const ContactStatus &contact_status, ConstraintComponentData &data, const SplitSolution &s) const =0
Sets the slack variables of each constraint components.
virtual void setFractionToBoundaryRule(const double fraction_to_boundary_rule) final
Sets the margin parameter of the fraction-to-boundary-rule.
static void computeCondensingCoeffcient(ConstraintComponentData &data)
Computes the coefficient of the condensing.
Definition: constraint_component_base.hxx:75
virtual void evalDerivatives(Robot &robot, const ContactStatus &contact_status, ConstraintComponentData &data, const SplitSolution &s, SplitKKTResidual &kkt_residual) const =0
Computes the derivatives of the priaml residual, i.e., the Jacobian of the inequality constraint,...
double maxSlackStepSize(const ConstraintComponentData &data) const
Computes and returns the maximum step size by applying fraction-to-boundary-rule to the direction of ...
Definition: constraint_component_base.hxx:13
Data used in constraint components. Composed by slack, dual (Lagrange multiplier),...
Definition: constraint_component_data.hpp:17
Contact status of robot model.
Definition: contact_status.hpp:32
Dynamics and kinematics model of robots. Wraps pinocchio::Model and pinocchio::Data....
Definition: robot.hpp:32
Newton direction of the solution to the optimal control problem split into a time stage.
Definition: split_direction.hpp:20
The KKT matrix split into a time stage.
Definition: split_kkt_matrix.hpp:18
KKT residual split into each time stage.
Definition: split_kkt_residual.hpp:18
Solution to the optimal control problem split into a time stage.
Definition: split_solution.hpp:20
Definition: constraint_component_base.hpp:17
KinematicsLevel
Kinematics level of the constraint component used in ConstraintComponentBase.
Definition: constraint_component_base.hpp:24