1#ifndef ROBOTOC_CONSTRAINTS_PDIPM_HXX_
2#define ROBOTOC_CONSTRAINTS_PDIPM_HXX_
15 assert(barrier_param > 0);
17 const double sqrt_barrier = std::sqrt(barrier_param);
18 for (
int i=0; i<data.
slack.size(); ++i) {
19 if (data.
slack.coeff(i) < sqrt_barrier) {
20 data.
slack.coeffRef(i) = sqrt_barrier;
23 data.
dual.array() = barrier_param / data.
slack.array();
29 assert(barrier_param > 0);
31 data.
cmpl.array() = data.
slack.array() * data.
dual.array() - barrier_param;
37 const int start,
const int size) {
38 assert(barrier_param > 0);
40 data.
cmpl.segment(start, size).array()
41 = data.
slack.segment(start, size).array()
42 * data.
dual.segment(start, size).array() - barrier_param;
50 assert(barrier_param > 0);
52 data.
cmpl.template segment<Size>(start).array()
53 = data.
slack.template segment<Size>(start).array()
54 * data.
dual.template segment<Size>(start).array() - barrier_param;
61 assert(barrier_param > 0);
62 return (slack * dual - barrier_param);
74 const int start,
const int size) {
76 data.
cond.segment(start, size).array()
77 = (data.
dual.segment(start, size).array()
78 *data.
residual.segment(start, size).array()
79 -data.
cmpl.segment(start, size).array())
80 / data.
slack.segment(start, size).array();
88 data.
cond.template segment<Size>(start).array()
89 = (data.
dual.template segment<Size>(start).array()
90 *data.
residual.template segment<Size>(start).array()
91 -data.
cmpl.template segment<Size>(start).array())
92 / data.
slack.template segment<Size>(start).array();
97 const double residual,
99 return ((dual*residual-cmpl)/slack);
105 assert(fraction_rate > 0);
106 assert(fraction_rate <= 1);
114 assert(fraction_rate > 0);
115 assert(fraction_rate <= 1);
122 const Eigen::VectorXd& vec,
123 const Eigen::VectorXd& dvec) {
125 assert(fraction_rate > 0);
126 assert(fraction_rate <= 1);
127 assert(vec.size() == dim);
128 assert(dvec.size() == dim);
129 double min_fraction_to_boundary = 1;
130 for (
int i=0; i<dim; ++i) {
131 const double fraction_to_boundary
132 = - fraction_rate * (vec.coeff(i)/dvec.coeff(i));
133 if (fraction_to_boundary > 0 && fraction_to_boundary < 1) {
134 if (fraction_to_boundary < min_fraction_to_boundary) {
135 min_fraction_to_boundary = fraction_to_boundary;
139 assert(min_fraction_to_boundary > 0);
140 assert(min_fraction_to_boundary <= 1);
141 return min_fraction_to_boundary;
146 const double var,
const double dvar) {
147 assert(fraction_rate > 0);
148 assert(fraction_rate <= 1);
149 const double fraction_to_boundary = - fraction_rate * (var/dvar);
150 if (fraction_to_boundary > 0 && fraction_to_boundary < 1) {
151 return fraction_to_boundary;
163 / data.
slack.array();
168 const int start,
const int size) {
169 data.
ddual.segment(start, size).array()
170 = - (data.
dual.segment(start, size).array()
171 *data.
dslack.segment(start, size).array()
172 +data.
cmpl.segment(start, size).array())
173 / data.
slack.segment(start, size).array();
180 data.
ddual.template segment<Size>(start).array()
181 = - (data.
dual.template segment<Size>(start).array()
182 *data.
dslack.template segment<Size>(start).array()
183 +data.
cmpl.template segment<Size>(start).array())
184 / data.
slack.template segment<Size>(start).array();
189 const double dslack,
const double cmpl) {
190 return (- (dual * dslack + cmpl) / slack);
194template <
typename VectorType>
196 const Eigen::MatrixBase<VectorType>& vec) {
197 assert(barrier_param > 0);
198 assert(vec.array().minCoeff() > 0);
199 return (- barrier_param * vec.array().log().sum());
Data used in constraint components. Composed by slack, dual (Lagrange multiplier),...
Definition: constraint_component_data.hpp:17
Eigen::VectorXd ddual
Newton direction of the dual. Size is ConstraintComponentData::dimc().
Definition: constraint_component_data.hpp:91
Eigen::VectorXd residual
Primal residual of the constraint. Size is ConstraintComponentData::dimc().
Definition: constraint_component_data.hpp:73
bool checkDimensionalConsistency() const
Check whether dimensions of slack, dual, residual, cmpl, dslack, ddual are ConstraintComponentData::d...
int dimc() const
Dimension of the constraint.
Definition: constraint_component_data.hpp:160
Eigen::VectorXd dslack
Newton direction of the slack. Size is ConstraintComponentData::dimc().
Definition: constraint_component_data.hpp:85
Eigen::VectorXd cond
Used in condensing of slack and dual. Size is ConstraintComponentData::dimc().
Definition: constraint_component_data.hpp:97
Eigen::VectorXd cmpl
Residual in the complementary slackness between slack and dual. Size is ConstraintComponentData::dimc...
Definition: constraint_component_data.hpp:79
Eigen::VectorXd slack
Slack variable of the constraint. Size is ConstraintComponentData::dimc(). All elements must be posit...
Definition: constraint_component_data.hpp:61
Eigen::VectorXd dual
Dual variable (Lagrange multiplier) of the constraint. Size is ConstraintComponentData::dimc()....
Definition: constraint_component_data.hpp:67
double fractionToBoundary(const int dim, const double fraction_rate, const Eigen::VectorXd &vec, const Eigen::VectorXd &dvec)
Applies the fraction-to-boundary-rule.
Definition: pdipm.hxx:121
void computeCondensingCoeffcient(ConstraintComponentData &data)
Computes the coefficient of the condensing.
Definition: pdipm.hxx:66
void computeComplementarySlackness(const double barrier_param, ConstraintComponentData &data)
Computes the residual in the complementarity slackness between the slack and dual variables.
Definition: pdipm.hxx:27
void computeDualDirection(ConstraintComponentData &data)
Computes the direction of the dual variable from slack, primal residual, complementary slackness,...
Definition: pdipm.hxx:159
double fractionToBoundaryDual(const double fraction_rate, const ConstraintComponentData &data)
Applies the fraction-to-boundary-rule to the directions of the dual variables.
Definition: pdipm.hxx:112
void setSlackAndDualPositive(const double barrier_param, ConstraintComponentData &data)
Sets the slack and dual variables positive.
Definition: pdipm.hxx:13
double fractionToBoundarySlack(const double fraction_rate, const ConstraintComponentData &data)
Applies the fraction-to-boundary-rule to the directions of the slack variables.
Definition: pdipm.hxx:103
double logBarrier(const double barrier_param, const Eigen::MatrixBase< VectorType > &vec)
Computes the log barrier function.
Definition: pdipm.hxx:195
Definition: constraint_component_base.hpp:17