13#ifndef INCLUDE_PIPAL_ITERATE_HXX
14#define INCLUDE_PIPAL_ITERATE_HXX
22 template <
typename Real>
42 z.
H.resize(i.
nV, i.
nV);
43 if (this->
m_bfgs) {z.
H.setIdentity();}
51 z.
kkt_.setConstant(p.
opt_err_mem, std::numeric_limits<Real>::infinity());
57 z.
A.resize(i.
nA, i.
nA);
66 z.
lI.setConstant(i.
nI, 0.5);
93 template <
typename Real>
112 if (i.
vi > 0)
return 4;
115 if (z.
err > 0)
return 5;
124 template <
typename Real>
147 this->
m_problem->constraints(x_orig, c_orig);
153 z.
f = std::numeric_limits<Real>::quiet_NaN();
154 z.
cE.setConstant(i.
nE, std::numeric_limits<Real>::quiet_NaN());
155 z.
cI.setConstant(i.
nI, std::numeric_limits<Real>::quiet_NaN());
156 z.
fu = std::numeric_limits<Real>::quiet_NaN();
157 z.
cEu.setConstant(i.
nE, std::numeric_limits<Real>::quiet_NaN());
158 z.
cIu.setConstant(i.
nI, std::numeric_limits<Real>::quiet_NaN());
163 if (i.
nE > 0) {z.
cE = c_orig(i.
I6) - i.
b6;}
166 if (i.
nI > 0) {z.
cI.setZero(i.
nI);}
197 if (i.
nE > 0) {z.
cE = (z.
cEs*z.
cE).matrix();}
198 if (i.
nI > 0) {z.
cI = (z.
cIs*z.
cI).matrix();}
212 template <
typename Real>
235 this->
m_problem->objective_gradient(x_orig, g_orig);
236 this->
m_problem->constraints_jacobian(x_orig, J_orig);
246 z.
g << g_orig(i.
I1), g_orig(i.
I3), g_orig(i.
I4), g_orig(i.
I5);
255 col_offset += i.
I1.size();
257 col_offset += i.
I3.size();
259 col_offset += i.
I4.size();
268 for (
Integer k{0}; k < i.
n3; ++k) {z.
JI.coeffRef(k, i.
n1+k) = -1.0;}
272 for (
Integer k{0}; k < i.
n4; ++k) {z.
JI.coeffRef(i.
n3+k, tmp+k) = 1.0;}
277 z.
JI.coeffRef(tmp_row+k, tmp_col+k) = -1.0;
278 z.
JI.coeffRef(tmp_row+i.
n5+k, tmp_col+k) = 1.0;
284 col_offset += i.
I1.size();
286 col_offset += i.
I3.size();
288 col_offset += i.
I4.size();
294 col_offset += i.
I1.size();
296 col_offset += i.
I3.size();
298 col_offset += i.
I4.size();
304 col_offset += i.
I1.size();
306 col_offset += i.
I3.size();
308 col_offset += i.
I4.size();
313 col_offset += i.
I1.size();
315 col_offset += i.
I3.size();
317 col_offset += i.
I4.size();
326 for (
Integer k{0}; k < z.
JE.outerSize(); ++k) {
328 it.valueRef() *= z.
cEs[it.row()];
333 for (
Integer k{0}; k < z.
JI.outerSize(); ++k) {
335 it.valueRef() *= z.
cIs[it.row()];
349 template <
typename Real>
372 this->
m_problem->lagrangian_hessian(x_orig, l_orig, H_orig);
382 Integer row_offset{0}, col_offset{0};
384 col_offset += i.
I1.size();
386 col_offset += i.
I3.size();
388 col_offset += i.
I4.size();
390 row_offset += i.
I1.size();
393 col_offset += i.
I1.size();
395 col_offset += i.
I3.size();
397 col_offset += i.
I4.size();
399 row_offset += i.
I3.size();
402 col_offset += i.
I1.size();
404 col_offset += i.
I3.size();
406 col_offset += i.
I4.size();
408 row_offset += i.
I4.size();
411 col_offset += i.
I1.size();
413 col_offset += i.
I3.size();
415 col_offset += i.
I4.size();
419 for (
Integer i{0}; i < z.
H.rows(); ++i) {(void) z.
H.coeffRef(i, i);}
432 template <
typename Real>
444 kkt.head(i.
nV) = rho*z.
g;
447 if (i.
nE > 0) {kkt.head(i.
nV) += (z.
lE.matrix().transpose()*z.
JE).transpose();}
448 if (i.
nI > 0) {kkt.head(i.
nV) += (z.
lI.matrix().transpose()*z.
JI).transpose();}
452 kkt.segment(i.
nV, 2*i.
nE) << z.
r1*(1.0 + z.
lE) - mu, z.
r2*(1.0 - z.
lE) - mu;
455 kkt.segment(i.
nV+2*i.
nE, 2*i.
nI) << z.
s1*z.
lI - mu, z.
s2*(1.0 - z.
lI) - mu;
460 kkt *= (1.0 / std::max(1.0, (rho*z.
g).template lpNorm<Eigen::Infinity>()));
464 return kkt.template lpNorm<Eigen::Infinity>();
471 template <
typename Real>
488 template <
typename Real>
523 template <
typename Real>
536 z.
phi -= z.
mu * r_all.log().sum() - r_all.sum();
540 z.
phi -= z.
mu * s_all.log().sum() - z.
s2.sum();
548 template <
typename Real>
561 z.
A.coeffRef(i.
nV+j, i.
nV+j) = (1.0 + z.
lE(j))/z.
r1(j);
562 z.
A.coeffRef(i.
nV+i.
nE+j, i.
nV+i.
nE+j) = (1.0 - z.
lE(j))/z.
r2(j);
575 z.
A.coeffRef(offset+j, offset+j) = z.
lI(j)/z.
s1(j);
576 z.
A.coeffRef(offset+i.
nI+j, offset+i.
nI+j) = (1.0 - z.
lI(j))/z.
s2(j);
603 z.
A.coeffRef(offset+j, offset+j) = -z.
shift22;
610 z.
A.coeffRef(offset+j, offset+j) = -z.
shift22;
636 z.
H.diagonal().array() += z.
shift;
639 z.
A.makeCompressed();
646 template <
typename Real>
660 if (i.
nE > 0) {z.
b.head(i.
nV) += (z.
lE.matrix().transpose()*z.
JE).transpose();}
661 if (i.
nI > 0) {z.
b.head(i.
nV) += (z.
lI.matrix().transpose()*z.
JI).transpose();}
667 tmp << 1.0 + z.
lE - z.
mu * z.
r1.cwiseInverse(), 1.0 - z.
lE - z.
mu * z.
r2.cwiseInverse();
668 z.
b.segment(i.
nV, 2*i.
nE) = tmp;
673 tmp << z.
lI - z.
mu * z.
s1.cwiseInverse(), 1.0 - z.
lI - z.
mu * z.
s2.cwiseInverse();
674 z.
b.segment(i.
nV + 2*i.
nE, 2*i.
nI) = tmp;
686 template <
typename Real>
709 Real row_inf_norm{0.0};
710 for (
Integer c{0}; c < z.
JE.outerSize(); ++c) {
712 if (it.row() == j) {row_inf_norm = std::max(row_inf_norm, std::abs(it.value()));}
722 Real row_inf_norm{0.0};
723 for (
Integer c{0}; c < z.
JI.outerSize(); ++c) {
725 if (it.row() == j) {row_inf_norm = std::max(row_inf_norm, std::abs(it.value()));}
736 template <
typename Real>
748 z.
r1 = 0.5*((z.
mu - z.
cE) + (z.
cE.square() + z.
mu*z.
mu).sqrt());
749 z.
r2 = 0.5*((z.
mu + z.
cE) + (z.
cE.square() + z.
mu*z.
mu).sqrt());
760 z.
s1 = 0.5*((2.0*z.
mu - z.
cI) + (z.
cI.square() + 4.0*z.
mu*z.
mu).sqrt());
761 z.
s2 = 0.5*((2.0*z.
mu + z.
cI) + (z.
cI.square() + 4.0*z.
mu*z.
mu).sqrt());
774 template <
typename Real>
785 x(i.
I1) = z.
x.head(i.
n1);
787 x(i.
I3) = z.
x.segment(i.
n1, i.
n3);
796 template <
typename Real>
811 z.
A.coeffRef(diag, diag) = 1.0;
815 diag = i.
nV+2*i.
nE+k;
816 z.
A.coeffRef(diag, diag) = 1.0;
826 row = i.
nV+2*i.
nE+2*i.
nI+k, col = i.
nV+k;
827 z.
A.coeffRef(row, col) = 1.0;
828 z.
A.coeffRef(row, col+i.
nE) = -1.0;
838 row = i.
nV+3*i.
nE+2*i.
nI+k, col = i.
nV+2*i.
nE+k;
839 z.
A.coeffRef(row, col) = 1.0;
840 z.
A.coeffRef(row, col+i.
nI) = -1.0;
860 template <
typename Real>
871 if (i.
nE > 0) {z.
cE = cE; z.
r1 = r1; z.
r2 = r2; z.
lE = lE;}
872 if (i.
nI > 0) {z.
cI = cI; z.
s1 = s1; z.
s2 = s2; z.
lI = lI;}
894 template <
typename Real>
901 "Pipal::Solver::bfgsUpdate(...): update condition yáµ€s > 0 not satisfied");
905 z.
H -= (x * x.transpose()).sparseView() / (s.dot(x));
906 z.
H -= (y * y.transpose()).sparseView() / (y.dot(s));
916 template <
typename Real>
939 if (this->
m_counter.k % this->m_parameter.bfgs_update_freq == 0) {
958 template <
typename Real>
984 z.
v > std::max({1.0, z.v_, p.infeas_max}))
1002 template <
typename Real>
1015 if (i.
nE > 0) {z.
lE += a.
d*d.
lE;}
1016 if (i.
nI > 0) {z.
lI += a.
d*d.
lI;}
1026 template <
typename Real>
1036 if (i.
nE > 0) {vec = cE;}
1039 if (vec.size() > 0) {
1042 vec = std::move(tmp);
1049 return vec.template lpNorm<1>();
#define PIPAL_ASSERT(COND, MSG)
Definition Types.hxx:50
Real evalKKTError(Real const rho, Real const mu)
Compute the infinity-norm of the KKT optimality vector.
Definition Iterate.hxx:433
void evalMerit()
Compute the merit function value for the current iterate.
Definition Iterate.hxx:524
void incrementFactorizationCount()
Increment the matrix factorization counter.
Definition Solver.hxx:173
Acceptance< Real > m_acceptance
Definition Solver.hxx:43
ProblemPtr m_problem
Definition Solver.hxx:49
Real evalViolation(Array< Real > const &cE, Array< Real > const &cI) const
Compute the 1-norm feasibility violation from equality/inequality values.
Definition Iterate.hxx:1027
Input< Real > m_input
Definition Solver.hxx:44
void initNewtonMatrix()
Reserve and initialize the internal sparse Newton matrix structure.
Definition Iterate.hxx:797
void evalDependent()
Evaluate quantities that depend on penalty/interior parameters.
Definition Solver.hxx:154
void incrementGradientCount()
Increment the gradient evaluation counter.
Definition Solver.hxx:183
void bfgsUpdate(Vector< Real > const &s, Vector< Real > const &y)
Browder-Broyden-Fletcher-Goldfarb-Shanno (BFGS) update for the Hessian approximation.
Definition Iterate.hxx:895
Direction< Real > m_direction
Definition Solver.hxx:45
void buildIterate()
Initialize an Iterate object for a given problem/input.
Definition Iterate.hxx:23
void evalInfeasibility(Iterate< Real > &z) const
Compute scaled and unscaled feasibility violations.
Definition Solver.hxx:103
void incrementHessianCount()
Increment the Hessian evaluation counter.
Definition Solver.hxx:188
void incrementFunctionCount()
Increment the function evaluation counter.
Definition Solver.hxx:178
void updateIterate()
Update the iterate after a trial step is accepted.
Definition Iterate.hxx:917
void evalNewtonRhs()
Build the right-hand side vector for the Newton system.
Definition Iterate.hxx:647
Iterate< Real > m_iterate
Definition Solver.hxx:46
bool m_bfgs
Definition Solver.hxx:53
void evalSlacks()
Compute internal slack variables from current iterate.
Definition Iterate.hxx:737
Counter m_counter
Definition Solver.hxx:42
void updatePoint()
Apply a step to the primal and dual variables of the iterate.
Definition Iterate.hxx:1003
void evalXOriginal(Vector< Real > &x)
Reconstruct the full primal vector in the original variable ordering.
Definition Iterate.hxx:775
void evalNewtonMatrix()
Assemble and (attempt to) factorize the Newton system matrix.
Definition Iterate.hxx:549
void setMuMaxExpZero()
Force mu exponent increases to use zero as maximum exponent.
Definition Solver.hxx:125
void evalGradients()
Evaluate objective gradient and constraint Jacobian.
Definition Iterate.hxx:213
Parameter< Real > m_parameter
Definition Solver.hxx:48
void setPrimals(Vector< Real > const &x, Array< Real > const &r1, Array< Real > const &r2, Array< Real > const &s1, Array< Real > const &s2, Array< Real > const &lE, Array< Real > const &lI, Real const f, Array< Real > const &cE, Array< Real > const &cI, Real const phi)
Set primal/dual blocks and associated quantities on an iterate.
Definition Iterate.hxx:861
void evalKKTErrors()
Compute the three KKT error measures used by the solver.
Definition Iterate.hxx:472
void evalLambdaOriginal(Vector< Real > &l) const
Reconstruct multipliers in the original variable/constraint space.
Definition Iterate.hxx:489
Integer checkTermination() const
Check termination criteria for the solver.
Definition Iterate.hxx:94
void evalFunctions()
Evaluate objective and constraint functions at the current iterate.
Definition Iterate.hxx:125
void evalHessian()
Evaluate the Hessian of the Lagrangian and assemble internal H.
Definition Iterate.hxx:350
void evalScalings()
Evaluate scaling multipliers for objective and constraints.
Definition Iterate.hxx:687
void updateParameters()
Update penalty and interior-point parameters based on KKT errors.
Definition Iterate.hxx:959
Namespace for the Pipal library.
Definition Acceptance.hxx:16
Eigen::SparseMatrix< Real > SparseMatrix
Definition Types.hxx:114
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > Matrix
Definition Types.hxx:113
PIPAL_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Types.hxx:110
Eigen::Array< Real, Eigen::Dynamic, 1 > Array
Definition Types.hxx:115
static void insert_block(SparseMatrix< Real > &mat, SparseMatrix< Real > const &blk, Integer const row_offset, Integer const col_offset)
Insert a sparse block into a sparse matrix at the specified offsets.
Definition Types.hxx:150
Eigen::Vector< Real, Eigen::Dynamic > Vector
Definition Types.hxx:112
struct Counter { Integer f{0}; Integer g{0}; Integer H{0}; Integer k{0}; Integer M{0}; Counter()=default; Counter(Counter const &)=delete; Counter &operator=(Counter const &)=delete; } Counter
Internal counters for solver statistics.
Definition Types.hxx:285
Class for managing the acceptance criteria of the solver.
Definition Types.hxx:486
Real d
Definition Types.hxx:489
Real p
Definition Types.hxx:488
Real p0
Definition Types.hxx:487
Class for managing the current search direction of the solver.
Definition Types.hxx:446
Array< Real > s2
Definition Types.hxx:454
Array< Real > lI
Definition Types.hxx:455
Array< Real > r2
Definition Types.hxx:451
Array< Real > r1
Definition Types.hxx:450
Array< Real > lE
Definition Types.hxx:452
Vector< Real > x
Definition Types.hxx:447
Array< Real > s1
Definition Types.hxx:453
Class for managing the current iterate of the solver.
Definition Types.hxx:377
Array< Real > cEs
Definition Types.hxx:414
Real rho
Definition Types.hxx:381
Array< Real > cE
Definition Types.hxx:389
Real v
Definition Types.hxx:401
Integer Hnnz
Definition Types.hxx:400
Real shift
Definition Types.hxx:407
Real mu
Definition Types.hxx:383
Array< Real > lI
Definition Types.hxx:398
SparseMatrix< Real > H
Definition Types.hxx:399
Array< Real > cIu
Definition Types.hxx:417
Array< Real > r1
Definition Types.hxx:387
Vector< Real > x
Definition Types.hxx:380
Real shift22
Definition Types.hxx:419
SparseMatrix< Real > JE
Definition Types.hxx:390
Array< Real > s2
Definition Types.hxx:394
Real fu
Definition Types.hxx:385
Array< Real > lE
Definition Types.hxx:392
Integer JEnnz
Definition Types.hxx:391
Array< Real > cI
Definition Types.hxx:395
Real v0
Definition Types.hxx:403
SparseMatrix< Real > A
Definition Types.hxx:418
Integer Annz
Definition Types.hxx:406
Vector< Real > b
Definition Types.hxx:408
SparseMatrix< Real > JI
Definition Types.hxx:396
Real fs
Definition Types.hxx:413
Real vu
Definition Types.hxx:402
Array< Real > cIs
Definition Types.hxx:416
Integer JInnz
Definition Types.hxx:397
LDLT ldlt
Definition Types.hxx:405
Real f
Definition Types.hxx:384
Real v_
Definition Types.hxx:420
Array< Real > cEu
Definition Types.hxx:415
Integer err
Definition Types.hxx:411
Vector< Real > kkt_
Definition Types.hxx:410
Vector< Real > kkt
Definition Types.hxx:409
Array< Real > s1
Definition Types.hxx:393
bool cut_
Definition Types.hxx:421
Array< Real > r2
Definition Types.hxx:388
Vector< Real > g
Definition Types.hxx:386
Real phi
Definition Types.hxx:404
Internal parameters for the solver algorithm.
Definition Types.hxx:229
static constexpr Real rho_min
Definition Types.hxx:244
static constexpr Real rho_factor
Definition Types.hxx:245
static constexpr Real grad_max
Definition Types.hxx:231
static constexpr Real shift_factor2
Definition Types.hxx:241
static constexpr Real mu_min
Definition Types.hxx:248
static constexpr Real shift_max
Definition Types.hxx:242
Integer iter_max
Definition Types.hxx:259
static constexpr Real rho_init
Definition Types.hxx:243
static constexpr Real slack_min
Definition Types.hxx:238
static constexpr Real mu_factor_exp
Definition Types.hxx:250
static constexpr Real shift_min
Definition Types.hxx:239
static constexpr Integer opt_err_mem
Definition Types.hxx:234
static constexpr Real mu_init
Definition Types.hxx:247
static constexpr Real shift_factor1
Definition Types.hxx:240
Real opt_err_tol
Definition Types.hxx:258
static constexpr Real mu_factor
Definition Types.hxx:249