robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
constraints.hpp
Go to the documentation of this file.
1#ifndef ROBOTOC_CONSTRAINTS_HPP_
2#define ROBOTOC_CONSTRAINTS_HPP_
3
4#include <vector>
5#include <memory>
6#include <unordered_map>
7#include <iostream>
8
20
21
22namespace robotoc {
23
31public:
32 using ConstraintComponentBasePtr = std::shared_ptr<ConstraintComponentBase>;
34 = std::shared_ptr<ImpactConstraintComponentBase>;
35
43 Constraints(const double barrier_param=1.0e-03,
44 const double fraction_to_boundary_rule=0.995);
45
49 ~Constraints() = default;
50
54 Constraints(const Constraints&) = default;
55
59 Constraints& operator=(const Constraints&) = default;
60
64 Constraints(Constraints&&) noexcept = default;
65
69 Constraints& operator=(Constraints&&) noexcept = default;
70
76 bool exist(const std::string& name) const;
77
84 void add(const std::string& name, ConstraintComponentBasePtr constraint);
85
92 void add(const std::string& name, ImpactConstraintComponentBasePtr constraint);
93
99 void erase(const std::string& name);
100
108
116
120 void clear();
121
130 const int time_stage=-1) const;
131
140 bool isFeasible(Robot& robot, const ContactStatus& contact_status,
141 ConstraintsData& data, const SplitSolution& s) const;
142
152 bool isFeasible(Robot& robot, const ImpactStatus& impact_status,
153 ConstraintsData& data, const SplitSolution& s) const;
154
162 void setSlackAndDual(Robot& robot, const ContactStatus& contact_status,
163 ConstraintsData& data, const SplitSolution& s) const;
164
173 void setSlackAndDual(Robot& robot, const ImpactStatus& impact_status,
174 ConstraintsData& data,
175 const SplitSolution& s) const;
176
186 void evalConstraint(Robot& robot, const ContactStatus& contact_status,
187 ConstraintsData& data, const SplitSolution& s) const;
188
197 void evalConstraint(Robot& robot, const ImpactStatus& impact_status,
198 ConstraintsData& data,
199 const SplitSolution& s) const;
200
210 void linearizeConstraints(Robot& robot, const ContactStatus& contact_status,
211 ConstraintsData& data, const SplitSolution& s,
212 SplitKKTResidual& kkt_residual) const;
213
223 void linearizeConstraints(Robot& robot, const ImpactStatus& impact_status,
224 ConstraintsData& data, const SplitSolution& s,
225 SplitKKTResidual& kkt_residual) const;
226
237 void condenseSlackAndDual(const ContactStatus& contact_status,
238 ConstraintsData& data, SplitKKTMatrix& kkt_matrix,
239 SplitKKTResidual& kkt_residual) const;
240
251 void condenseSlackAndDual(const ImpactStatus& impact_status,
252 ConstraintsData& data,
253 SplitKKTMatrix& kkt_matrix,
254 SplitKKTResidual& kkt_residual) const;
255
263 void expandSlackAndDual(const ContactStatus& contact_status,
264 ConstraintsData& data, const SplitDirection& d) const;
265
273 void expandSlackAndDual(const ImpactStatus& impact_status,
274 ConstraintsData& data,
275 const SplitDirection& d) const;
276
283 double maxSlackStepSize(const ConstraintsData& data) const;
284
291 double maxDualStepSize(const ConstraintsData& data) const;
292
298 static void updateSlack(ConstraintsData& data, const double step_size);
299
305 static void updateDual(ConstraintsData& data, const double step_size);
306
311 void setBarrierParam(const double barrier_param);
312
319 void setFractionToBoundaryRule(const double fraction_to_boundary_rule);
320
325 double getBarrierParam() const;
326
332
337 std::vector<std::string> getPositionLevelConstraintList() const;
338
343 std::vector<std::string> getVelocityLevelConstraintList() const;
344
349 std::vector<std::string> getAccelerationLevelConstraintList() const;
350
355 std::vector<std::string> getImpactLevelConstraintList() const;
356
361 std::vector<std::string> getConstraintList() const;
362
366 void disp(std::ostream& os) const;
367
368 friend std::ostream& operator<<(std::ostream& os, const Constraints& constraints);
369
370 friend std::ostream& operator<<(std::ostream& os,
371 const std::shared_ptr<Constraints>& constraints);
372
373private:
374 std::vector<ConstraintComponentBasePtr> position_level_constraints_,
375 velocity_level_constraints_,
376 acceleration_level_constraints_;
377 std::vector<ImpactConstraintComponentBasePtr> impact_level_constraints_;
378 std::unordered_map<std::string, size_t> position_level_constraint_names_,
379 velocity_level_constraint_names_,
380 acceleration_level_constraint_names_,
381 impact_level_constraint_names_;
382 double barrier_, fraction_to_boundary_rule_;
383};
384
385} // namespace robotoc
386
387#endif // ROBOTOC_CONSTRAINTS_HPP_
Data for constraints. Composed of ConstraintComponentData corrensponding to the components of Constra...
Definition: constraints_data.hpp:16
Stack of the inequality constraints. Composed by constraint components that inherits ConstraintCompon...
Definition: constraints.hpp:30
std::vector< std::string > getPositionLevelConstraintList() const
Gets a list of the position-level constraints.
Constraints(const Constraints &)=default
Default copy constructor.
std::vector< std::string > getConstraintList() const
Gets a list of the constraints.
Constraints & operator=(const Constraints &)=default
Default copy operator.
void evalConstraint(Robot &robot, const ContactStatus &contact_status, ConstraintsData &data, const SplitSolution &s) const
Computes the primal residual, residual in the complementary slackness, and the log-barrier function o...
void setFractionToBoundaryRule(const double fraction_to_boundary_rule)
Sets the parameter of the fraction-to-boundary-rule for all the constraint components.
double maxDualStepSize(const ConstraintsData &data) const
Computes and returns the maximum step size by applying fraction-to-boundary-rule to the directions of...
Constraints(Constraints &&) noexcept=default
Default move constructor.
ConstraintComponentBasePtr getConstraintComponent(const std::string &name) const
Gets a constraint component. If a component of the specified name does not exist, throws an exeption.
void condenseSlackAndDual(const ContactStatus &contact_status, ConstraintsData &data, SplitKKTMatrix &kkt_matrix, SplitKKTResidual &kkt_residual) const
Condenses the slack and dual variables. linearizeConstraints() must be called before this function.
void add(const std::string &name, ConstraintComponentBasePtr constraint)
Adds a constraint component. If a component of the same name exists, throws an exeption.
void linearizeConstraints(Robot &robot, const ContactStatus &contact_status, ConstraintsData &data, const SplitSolution &s, SplitKKTResidual &kkt_residual) const
Evaluates the constraints (i.e., calls evalConstraint()) and adds the products of the Jacobian of the...
double maxSlackStepSize(const ConstraintsData &data) const
Computes and returns the maximum step size by applying fraction-to-boundary-rule to the directions of...
void erase(const std::string &name)
Erases a constraint component. If a component of the specified name does not exist,...
void setBarrierParam(const double barrier_param)
Sets the barrier parameter for all the constraint components.
double getBarrierParam() const
Gets the barrier parameter.
std::vector< std::string > getVelocityLevelConstraintList() const
Gets a list of the velocity-level constraints.
void expandSlackAndDual(const ContactStatus &contact_status, ConstraintsData &data, const SplitDirection &d) const
Expands the slack and dual, i.e., computes the directions of the slack and dual variables from the di...
static void updateSlack(ConstraintsData &data, const double step_size)
Updates the slack variables according to step_size.
bool isFeasible(Robot &robot, const ContactStatus &contact_status, ConstraintsData &data, const SplitSolution &s) const
Checks whether the current split solution s is feasible or not.
std::shared_ptr< ImpactConstraintComponentBase > ImpactConstraintComponentBasePtr
Definition: constraints.hpp:34
Constraints(const double barrier_param=1.0e-03, const double fraction_to_boundary_rule=0.995)
Constructor.
ImpactConstraintComponentBasePtr getImpactConstraintComponent(const std::string &name) const
Gets a constraint component. If a component of the specified name does not exist, throws an exeption.
std::vector< std::string > getAccelerationLevelConstraintList() const
Gets a list of the acceleration-level constraints.
ConstraintsData createConstraintsData(const Robot &robot, const int time_stage=-1) const
Creates ConstraintsData according to robot model and constraint components.
~Constraints()=default
Default destructor.
void setSlackAndDual(Robot &robot, const ContactStatus &contact_status, ConstraintsData &data, const SplitSolution &s) const
Sets the slack and dual variables of each constraint components.
void clear()
Clears constraints by removing all components.
double getFractionToBoundaryRule() const
Gets the parameter of the fraction-to-boundary-rule.
std::vector< std::string > getImpactLevelConstraintList() const
Gets a list of the impact-level constraints.
std::shared_ptr< ConstraintComponentBase > ConstraintComponentBasePtr
Definition: constraints.hpp:32
void disp(std::ostream &os) const
Displays the constraints onto a ostream.
static void updateDual(ConstraintsData &data, const double step_size)
Updates the dual variables according to step_size.
bool exist(const std::string &name) const
Checks if thsi has a constraint component of the specified name.
Contact status of robot model.
Definition: contact_status.hpp:32
Impact status of robot model. Wrapper of ContactStatus to treat impacts.
Definition: impact_status.hpp:21
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