Skip to content

Commit 6052945

Browse files
author
Apostolos Chalkis
committed
resolve PR comments
1 parent 3e922e7 commit 6052945

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

include/preprocess/analytic_center_linear_ineq.h

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ void get_hessian_grad_logbarrier(MT const& A, MT const& A_trans, VT const& b,
3838

3939
b_Ax.noalias() = b - Ax;
4040
NT *s_data = s.data();
41-
for (int i = 0; i < m; i++) {
41+
for (int i = 0; i < m; i++)
42+
{
4243
*s_data = NT(1) / b_Ax.coeff(i);
4344
s_data++;
4445
}
@@ -53,9 +54,12 @@ void get_hessian_grad_logbarrier(MT const& A, MT const& A_trans, VT const& b,
5354
/*
5455
This implementation computes the analytic center of a polytope given
5556
as a set of linear inequalities P = {x | Ax <= b}. The analytic center
56-
is the optimal solution of the following optimization problem,
57-
\min - \sum \log(b_i - a_i^Tx), where a_i is the i-th row of A.
58-
The function implements the Newton method.
57+
is the minimizer of the log barrier function i.e., the optimal solution
58+
of the following optimization problem (Convex Optimization, Boyd and Vandenberghe, Section 8.5.3),
59+
60+
\min -\sum \log(b_i - a_i^Tx), where a_i is the i-th row of A.
61+
62+
The function solves the problem by using the Newton method.
5963
6064
Input: (i) Matrix A, vector b such that the polytope P = {x | Ax<=b}
6165
(ii) The number of maximum iterations, max_iters
@@ -74,9 +78,10 @@ std::tuple<VT, bool> analytic_center_linear_ineq(MT const& A, VT const& b,
7478
VT x;
7579
bool feasibility_only = true, converged;
7680
// Compute a feasible point
77-
std::tie(x, std::ignore, converged) = max_inscribed_ball(A, b, max_iters, 1e-08, feasibility_only);
81+
std::tie(x, std::ignore, converged) = max_inscribed_ball(A, b, max_iters, 1e-08, feasibility_only);
7882
VT Ax = A * x;
79-
if(!converged || (Ax.array() > b.array()).any()) {
83+
if (!converged || (Ax.array() > b.array()).any())
84+
{
8085
std::runtime_error("The computation of the analytic center failed.");
8186
}
8287
// Initialization
@@ -86,34 +91,38 @@ std::tuple<VT, bool> analytic_center_linear_ineq(MT const& A, VT const& b,
8691
NT grad_err, rel_pos_err, rel_pos_err_temp, step;
8792
unsigned int iter = 0;
8893
converged = false;
94+
const NT tol_bnd = NT(0.01);
8995

9096
get_hessian_grad_logbarrier<MT, VT, NT>(A, A_trans, b, x, Ax, H, grad, b_Ax);
9197

9298
do {
9399
iter++;
94100
// Compute the direction
95-
d.noalias() = - H.lu().solve(grad);
101+
d.noalias() = - H.llt().solve(grad);
96102
Ad.noalias() = A * d;
97103
// Compute the step length
98-
step = std::min(NT(0.99) * get_max_step<VT, NT>(Ad, b_Ax), NT(1));
104+
step = std::min((NT(1) - tol_bnd) * get_max_step<VT, NT>(Ad, b_Ax), NT(1));
99105
step_d.noalias() = step*d;
100106
x_prev = x;
101107
x += step_d;
102108
Ax.noalias() += step*Ad;
103109

104110
// Compute the max_i\{ |step*d_i| ./ |x_i| \}
105111
rel_pos_err = std::numeric_limits<NT>::lowest();
106-
for (int i = 0; i < n; i++) {
112+
for (int i = 0; i < n; i++)
113+
{
107114
rel_pos_err_temp = std::abs(step_d.coeff(i) / x_prev.coeff(i));
108-
if (rel_pos_err_temp > rel_pos_err) {
115+
if (rel_pos_err_temp > rel_pos_err)
116+
{
109117
rel_pos_err = rel_pos_err_temp;
110-
}
118+
}
111119
}
112120

113121
get_hessian_grad_logbarrier<MT, VT, NT>(A, A_trans, b, x, Ax, H, grad, b_Ax);
114122
grad_err = grad.norm();
115123

116-
if (iter >= max_iters || grad_err <= grad_err_tol || rel_pos_err <= rel_pos_err_tol) {
124+
if (iter >= max_iters || grad_err <= grad_err_tol || rel_pos_err <= rel_pos_err_tol)
125+
{
117126
converged = true;
118127
break;
119128
}

0 commit comments

Comments
 (0)