Skip to content

Commit 5858e39

Browse files
committed
fix ComputePrimalFeasibility
1 parent 00476e2 commit 5858e39

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

highs/pdlp/hipdlp/pdhg.cc

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void PDLPSolver::preprocessLp() {
181181
break;
182182
}
183183
}
184-
184+
num_eq_rows_ = nEqs;
185185
scaling_.passLp(&processed_lp);
186186
unscaled_processed_lp_ = processed_lp; // store for postsolve
187187

@@ -663,21 +663,16 @@ std::vector<double> PDLPSolver::ComputeLambda(
663663

664664
std::pair<double, double> PDLPSolver::ComputePrimalFeasibility(
665665
const std::vector<double>& x, const std::vector<double>& Ax_vector) {
666-
double primal_feasibility_squared = 0.0;
667666
std::vector<double> primal_residual(lp_.num_row_, 0.0);
668667

669-
// Compute Ax - rhs (where rhs is row_lower_ for our formulation)
668+
// Compute Ax - rhs
670669
for (HighsInt i = 0; i < lp_.num_row_; ++i) {
671670
primal_residual[i] = Ax_vector[i] - lp_.row_lower_[i];
672671

673672
// For inequality constraints (Ax >= b), project to negative part
674-
if (lp_.row_lower_[i] != lp_.row_upper_[i]) {
675-
// This is an inequality constraint
673+
if (i >= num_eq_rows_) {
676674
primal_residual[i] = std::min(0.0, primal_residual[i]);
677675
}
678-
// For equality constraints, keep the full residual
679-
680-
primal_feasibility_squared += primal_residual[i] * primal_residual[i];
681676
}
682677

683678
// Apply scaling if needed
@@ -688,15 +683,9 @@ std::pair<double, double> PDLPSolver::ComputePrimalFeasibility(
688683
}
689684
}
690685

691-
double primal_feasibility = sqrt(primal_feasibility_squared);
692-
693-
// Compute norm of rhs for relative tolerance
694-
double rhs_norm = 0.0;
695-
for (HighsInt i = 0; i < lp_.num_row_; ++i) {
696-
rhs_norm += lp_.row_lower_[i] * lp_.row_lower_[i];
697-
}
698-
rhs_norm = sqrt(rhs_norm);
699-
686+
double primal_feasibility = linalg::vector_norm(primal_residual);
687+
double rhs_norm = linalg::vector_norm(lp_.row_lower_); // why don't need to rescale?
688+
700689
return std::make_pair(primal_feasibility, rhs_norm);
701690
}
702691

0 commit comments

Comments
 (0)