Skip to content

Commit 348e2c0

Browse files
committed
add projection before
1 parent 0008c67 commit 348e2c0

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

highs/pdlp/hipdlp/linalg.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ double project_non_negative(double x) {
2121
return std::max(0.0, x);
2222
}
2323

24+
void project_bounds(const HighsLp& lp, std::vector<double>& x) {
25+
for (HighsInt i = 0; i < lp.num_col_; ++i) {
26+
// Project to upper bound
27+
if (x[i] > lp.col_upper_[i]) {
28+
x[i] = lp.col_upper_[i];
29+
}
30+
// Project to lower bound
31+
if (x[i] < lp.col_lower_[i]) {
32+
x[i] = lp.col_lower_[i];
33+
}
34+
}
35+
}
36+
2437
void Ax(const HighsLp& lp, const std::vector<double>& x,
2538
std::vector<double>& result) {
2639
std::fill(result.begin(), result.end(), 0.0);

highs/pdlp/hipdlp/linalg.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace linalg {
1919
double project_box(double x, double l, double u);
2020
double project_non_negative(double y);
21+
void project_bounds(const HighsLp& lp, std::vector<double>& x);
2122

2223
// Function to compute A*x for a given HighsLp and vector x
2324
void Ax(const HighsLp& lp, const std::vector<double>& x,

highs/pdlp/hipdlp/pdhg.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,17 +377,20 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
377377
// Use member variables for iterates for cleaner state management
378378
x_current_ = x;
379379
y_current_ = y;
380+
linalg::project_bounds(lp_, x_current_);
381+
x_sum_ = x_current_;
382+
x_avg_ = x_current_;
383+
linalg::Ax(lp, x_current_, Ax_cache_);
384+
std::vector<double> Ax_avg = Ax_cache_;
385+
std::vector<double> ATy_avg(lp.num_col_, 0.0);
386+
380387
num_rejected_steps_ = 0;
381388
bool first_malitsky_iteration = true;
382389
ratio_last_two_step_sizes_ = 1.0;
383390
bool using_malitsky_averaging =
384391
(params_.step_size_strategy == StepSizeStrategy::MALITSKY_POCK);
385392
bool primal_average_initialized = false;
386393

387-
// Initialize vectors for matrix-vector products
388-
std::vector<double> Ax_avg(lp.num_row_, 0.0);
389-
std::vector<double> ATy_avg(lp.num_col_, 0.0);
390-
391394
// Store iterates at last restart for primal weight update
392395
x_at_last_restart_ = x_current_;
393396
y_at_last_restart_ = y_current_;
@@ -400,7 +403,7 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
400403
debug_pdlp_data_.ax_average_norm = 0.0;
401404
debug_pdlp_data_.aty_average_norm = 0.0;
402405
debug_pdlp_data_.x_average_norm = 0.0;
403-
debug_pdlp_data_.ax_norm = 0.0;
406+
debug_pdlp_data_.ax_norm = linalg::vector_norm(Ax_cache_);
404407

405408
for (int iter = 0; iter < params_.max_iterations; ++iter) {
406409
debugPdlpIterLog(debug_pdlp_log_file_, iter, &debug_pdlp_data_,

0 commit comments

Comments
 (0)