robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
split_kkt_residual.hxx
Go to the documentation of this file.
1#ifndef ROBOTOC_SPLIT_KKT_RESIDUAL_HXX_
2#define ROBOTOC_SPLIT_KKT_RESIDUAL_HXX_
3
5
6#include <cmath>
7
8
9namespace robotoc {
10
11inline void SplitKKTResidual::setContactDimension(const int dimf) {
12 assert(dimf >= 0);
13 assert(dimf <= P_full_.size());
14 dimf_ = dimf;
15}
16
17
19 assert(dims >= 0);
20 assert(dims <= P_full_.size());
21 dims_ = dims;
22}
23
24
25inline Eigen::VectorBlock<Eigen::VectorXd> SplitKKTResidual::Fq() {
26 return Fx.head(dimv_);
27}
28
29
30inline const Eigen::VectorBlock<const Eigen::VectorXd>
32 return Fx.head(dimv_);
33}
34
35
36inline Eigen::VectorBlock<Eigen::VectorXd> SplitKKTResidual::Fv() {
37 return Fx.tail(dimv_);
38}
39
40
41inline const Eigen::VectorBlock<const Eigen::VectorXd>
43 return Fx.tail(dimv_);
44}
45
46
47inline Eigen::VectorBlock<Eigen::VectorXd> SplitKKTResidual::P() {
48 return P_full_.head(dims_);
49}
50
51
52inline const Eigen::VectorBlock<const Eigen::VectorXd> SplitKKTResidual::P() const {
53 return P_full_.head(dims_);
54}
55
56
57inline Eigen::VectorBlock<Eigen::VectorXd> SplitKKTResidual::lq() {
58 return lx.head(dimv_);
59}
60
61
62inline const Eigen::VectorBlock<const Eigen::VectorXd>
64 return lx.head(dimv_);
65}
66
67
68inline Eigen::VectorBlock<Eigen::VectorXd> SplitKKTResidual::lv() {
69 return lx.tail(dimv_);
70}
71
72
73inline const Eigen::VectorBlock<const Eigen::VectorXd>
75 return lx.tail(dimv_);
76}
77
78
79inline Eigen::VectorBlock<Eigen::VectorXd> SplitKKTResidual::lf() {
80 return lf_full_.head(dimf_);
81}
82
83
84inline const Eigen::VectorBlock<const Eigen::VectorXd>
86 return lf_full_.head(dimf_);
87}
88
89
90inline double SplitKKTResidual::KKTError() const {
91 double err = 0;
92 err += Fx.squaredNorm();
93 if (P().size() > 0) {
94 err += P().squaredNorm();
95 }
96 err += lx.squaredNorm();
97 err += lu.squaredNorm();
98 err += la.squaredNorm();
99 err += ldv.squaredNorm();
100 if (lf().size() > 0) {
101 err += lf().squaredNorm();
102 }
103 return err;
104}
105
106
107template <int p=1>
109 double feasibility = Fx.template lpNorm<p>();
110 if (dims_ > 0) {
111 feasibility += P().template lpNorm<p>();
112 }
113 return feasibility;
114}
115
116
117template <int p=1>
119 double feasibility = 0;
120 feasibility += lx.template lpNorm<p>();
121 feasibility += la.template lpNorm<p>();
122 feasibility += ldv.template lpNorm<p>();
123 if (lf().size() > 0)
124 feasibility += lf().template lpNorm<p>();
125 feasibility += lu.template lpNorm<p>();
126 return feasibility;
127}
128
129
131 Fx.setZero();
132 if (P().size() > 0) {
133 P().setZero();
134 }
135 lx.setZero();
136 la.setZero();
137 ldv.setZero();
138 lu.setZero();
139 if (lf().size() > 0) {
140 lf().setZero();
141 }
142 h = 0.0;
143}
144
145
146inline int SplitKKTResidual::dimf() const {
147 return dimf_;
148}
149
150
151inline int SplitKKTResidual::dims() const {
152 return dims_;
153}
154
155} // namespace robotoc
156
157#endif // ROBOTOC_SPLIT_KKT_RESIDUAL_HXX_
Eigen::VectorBlock< Eigen::VectorXd > Fq()
Residual in the state equation w.r.t. the configuration q.
Definition: split_kkt_residual.hxx:25
Eigen::VectorXd lu
KKT residual w.r.t. the control input torques u. Size is Robot::dimu().
Definition: split_kkt_residual.hpp:151
Eigen::VectorBlock< Eigen::VectorXd > lf()
KKT residual w.r.t. the stack of the contact forces f.
Definition: split_kkt_residual.hxx:79
double dualFeasibility() const
Returns the lp norm of the dual feasibility. Default norm is l1-norm. You can also specify l-infty no...
Definition: split_kkt_residual.hxx:118
double KKTError() const
Returns the squared norm of the KKT residual, that is, the primal and dual residual.
Definition: split_kkt_residual.hxx:90
void setSwitchingConstraintDimension(const int dims)
Sets the dimension of the switching constraint.
Definition: split_kkt_residual.hxx:18
Eigen::VectorBlock< Eigen::VectorXd > lv()
KKT residual w.r.t. the joint velocity v.
Definition: split_kkt_residual.hxx:68
Eigen::VectorBlock< Eigen::VectorXd > Fv()
Residual in the state equation w.r.t. the velocity v.
Definition: split_kkt_residual.hxx:36
void setContactDimension(const int dimf)
Sets contact status, i.e., set dimension of the contact forces.
Definition: split_kkt_residual.hxx:11
Eigen::VectorBlock< Eigen::VectorXd > P()
Residual in the switching constraint.
Definition: split_kkt_residual.hxx:47
Eigen::VectorXd ldv
KKT residual w.r.t. the impact change in the velocity ddv. Size is Robot::dimv().
Definition: split_kkt_residual.hpp:145
Eigen::VectorXd Fx
Residual in the state equation. Size is 2 * Robot::dimv().
Definition: split_kkt_residual.hpp:71
double primalFeasibility() const
Returns the lp norm of the primal feasibility, i.e., the constraint violation. Default norm is l1-nor...
Definition: split_kkt_residual.hxx:108
int dims() const
Returns the dimension of the stack of the contact forces at the current contact status.
Definition: split_kkt_residual.hxx:151
Eigen::VectorXd lx
KKT Residual w.r.t. the state x. Size is 2 * Robot::dimv().
Definition: split_kkt_residual.hpp:112
Eigen::VectorBlock< Eigen::VectorXd > lq()
KKT residual w.r.t. the configuration q.
Definition: split_kkt_residual.hxx:57
void setZero()
Sets the split KKT residual zero.
Definition: split_kkt_residual.hxx:130
double h
KKT residual w.r.t. the switching time, that is, this is the value of the Hamiltonian.
Definition: split_kkt_residual.hpp:169
int dimf() const
Returns the dimension of the stack of the contact forces at the current contact status.
Definition: split_kkt_residual.hxx:146
Eigen::VectorXd la
KKT residual w.r.t. the acceleration a. Size is Robot::dimv().
Definition: split_kkt_residual.hpp:139
Definition: constraint_component_base.hpp:17