Skip to content

Commit 57bc2bc

Browse files
committed
properly initialize PG variables
1 parent 492890a commit 57bc2bc

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/rehline.h

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,16 @@ class ReHLineSolver
371371
std::vector<Index> new_set;
372372
new_set.reserve(fv_set.size());
373373

374-
// Compute shrinking threshold
374+
// Compute shrinking threshold ub
375+
// ub is kept unchanged in each outer iteration,
376+
// and is determined by the maximum PG in the previous outer iteration (i.e., max_pg)
377+
// If the input max_pg is zero or negative, let ub be Inf (do not shrink)
378+
// This happens when:
379+
// (1) max_pg is initialized to be zero in the first iteration
380+
// (2) max_pg is negative, thus not meaningful
375381
constexpr Scalar Inf = std::numeric_limits<Scalar>::infinity();
376382
const Scalar ub = (max_pg > Scalar(0)) ? max_pg : Inf;
377-
// Compute minimum and maximum projected gradient (PG) for this round
383+
// Compute minimum and maximum projected gradient (PG) for this round (outer iteration)
378384
min_pg = Inf;
379385
max_pg = -Inf;
380386
for (auto k: fv_set)
@@ -431,7 +437,8 @@ class ReHLineSolver
431437
std::vector<std::pair<Index, Index>> new_set;
432438
new_set.reserve(fv_set.size());
433439

434-
// Compute shrinking thresholds
440+
// Compute shrinking thresholds lb and ub
441+
// More details explained in update_xi_beta()
435442
constexpr Scalar Inf = std::numeric_limits<Scalar>::infinity();
436443
const Scalar lb = (min_pg < Scalar(0)) ? min_pg : -Inf;
437444
const Scalar ub = (max_pg > Scalar(0)) ? max_pg : Inf;
@@ -497,7 +504,8 @@ class ReHLineSolver
497504
std::vector<std::pair<Index, Index>> new_set;
498505
new_set.reserve(fv_set.size());
499506

500-
// Compute shrinking thresholds
507+
// Compute shrinking thresholds lb and ub
508+
// More details explained in update_xi_beta()
501509
constexpr Scalar Inf = std::numeric_limits<Scalar>::infinity();
502510
const Scalar lb = (min_pg < Scalar(0)) ? min_pg : -Inf;
503511
const Scalar ub = (max_pg > Scalar(0)) ? max_pg : Inf;
@@ -648,10 +656,12 @@ class ReHLineSolver
648656
internal::reset_fv_set(m_fv_relu, m_L, m_n);
649657
internal::reset_fv_set(m_fv_rehu, m_H, m_n);
650658

651-
// Shrinking thresholds
652-
constexpr Scalar Inf = std::numeric_limits<Scalar>::infinity();
653-
Scalar xi_min_pg = Inf, lambda_min_pg = Inf, gamma_min_pg = Inf;
654-
Scalar xi_max_pg = -Inf, lambda_max_pg = -Inf, gamma_max_pg = -Inf;
659+
// Minimum and maximum projected gradients of dual variables in each outer iteration
660+
// These variables will be updated in update_*_beta() functions below
661+
// If some dual variables are not used, the corresponding pg variables
662+
// will always be zero, so that the related tests in pg_conv below return true values
663+
Scalar xi_min_pg = Scalar(0), lambda_min_pg = Scalar(0), gamma_min_pg = Scalar(0);
664+
Scalar xi_max_pg = Scalar(0), lambda_max_pg = Scalar(0), gamma_max_pg = Scalar(0);
655665

656666
// Main iterations
657667
Index i = 0;
@@ -720,8 +730,8 @@ class ReHLineSolver
720730
internal::reset_fv_set(m_fv_feas, m_K);
721731
internal::reset_fv_set(m_fv_relu, m_L, m_n);
722732
internal::reset_fv_set(m_fv_rehu, m_H, m_n);
723-
xi_min_pg = lambda_min_pg = gamma_min_pg = Inf;
724-
xi_max_pg = lambda_max_pg = gamma_max_pg = -Inf;
733+
xi_min_pg = lambda_min_pg = gamma_min_pg = Scalar(0);
734+
xi_max_pg = lambda_max_pg = gamma_max_pg = Scalar(0);
725735
// Also recompute beta to improve precision
726736
// set_primal();
727737
continue;

0 commit comments

Comments
 (0)