Skip to content

Commit 02c6dfa

Browse files
committed
Wrapper now no longer uses Scaling, rather PDLPSolver::scaleProblem and PDLPSolver::unscaleSolution
1 parent da5fc73 commit 02c6dfa

File tree

6 files changed

+40
-29
lines changed

6 files changed

+40
-29
lines changed

check/TestPdlp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,12 @@ TEST_CASE("hi-pdlp", "[pdlp]") {
344344
h.setOptionValue("pdlp_restart_strategy", 0);
345345
h.setOptionValue("pdlp_step_size_strategy", 0);
346346

347-
h.setOptionValue("pdlp_iteration_limit", 15);
347+
// h.setOptionValue("pdlp_iteration_limit", 15);
348348
// h.setOptionValue("log_dev_level", kHighsLogDevLevelVerbose);
349349
HighsStatus run_status = h.run();
350350
// REQUIRE(run_status == HighsStatus::kOk);
351351
// REQUIRE(h.getModelStatus() == HighsModelStatus::kOptimal);
352+
REQUIRE(h.getInfo().pdlp_iteration_count == 11880);
352353
const bool cupdlp_test = true;
353354
if (cupdlp_test) {
354355
h.clearSolver();

highs/pdlp/HiPdlpWrapper.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,34 @@ HighsStatus solveLpHiPdlp(const HighsOptions& options, HighsTimer& timer,
6363
HighsLp preprocessed_lp;
6464
pdlp.passLp(&lp);
6565
// logger_.info("Preprocessing LP to handle ranged constraints...");
66-
pdlp.PreprocessLp();
66+
pdlp.preprocessLp();
6767

6868
// 3. Scale with HiPdlp
69-
pdlp.scaling_.ScaleProblem();
69+
pdlp.scaleProblem();
7070

7171
// 4. Solve with HiPdlp
7272
std::vector<double> x, y;
73-
pdlp.Solve(x, y);
73+
pdlp.solve(x, y);
7474

7575
// 5. Unscale with HiPdlp
76-
pdlp.scaling_.UnscaleSolution(x, y);
76+
pdlp.unscaleSolution(x, y);
7777

7878
// 6. Postprocess with HiPDLP
7979
HighsSolution pdlp_solution;
80-
// pdlp.Postsolve(presolved_lp, preprocessed_lp, x, y, pdlp_solution); //
80+
// pdlp.postprocess(presolved_lp, preprocessed_lp, x, y, pdlp_solution); //
8181
// return x, y
8282

8383
// --- Print Summary ---
84-
logger.print_summary(pdlp.GetResults(), pdlp.GetIterationCount(),
84+
logger.print_summary(pdlp.getResults(), pdlp.getIterationCount(),
8585
total_timer.read());
8686

87-
highs_info.pdlp_iteration_count = pdlp.GetIterationCount();
87+
highs_info.pdlp_iteration_count = pdlp.getIterationCount();
8888

8989
model_status = HighsModelStatus::kUnknown;
9090
highs_solution.clear();
9191
highs_basis.valid = false;
9292

93-
const TerminationStatus termination_status = pdlp.GetResults().term_code;
93+
const TerminationStatus termination_status = pdlp.getResults().term_code;
9494
switch (termination_status) {
9595
case TerminationStatus::OPTIMAL: {
9696
model_status = HighsModelStatus::kOptimal;

highs/pdlp/hipdlp/pdhg.cc

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
using namespace std;
2626

27-
int PDLPSolver::GetIterationCount() const { return final_iter_count_; }
27+
int PDLPSolver::getIterationCount() const { return final_iter_count_; }
2828

29-
void PDLPSolver::PreprocessLp() {
29+
void PDLPSolver::preprocessLp() {
3030
logger_.info(
3131
"Preprocessing LP using cupdlp formulation (slack variables for "
3232
"bounds)...");
@@ -175,7 +175,7 @@ void PDLPSolver::PreprocessLp() {
175175
std::to_string(processed_lp.num_col_) + " cols.");
176176
}
177177

178-
void PDLPSolver::Postsolve(HighsSolution& solution) {
178+
void PDLPSolver::postprocess(HighsSolution& solution) {
179179
logger_.info("Post-solving the solution...");
180180

181181
std::vector<double> x_unscaled = x_current_;
@@ -185,7 +185,7 @@ void PDLPSolver::Postsolve(HighsSolution& solution) {
185185
std::vector<double> dSlackNeg_unscaled = dSlackNeg_;
186186

187187
// 1. Unscale the solution vectors first
188-
scaling_.UnscaleSolution(x_unscaled, y_unscaled);
188+
unscaleSolution(x_unscaled, y_unscaled);
189189
const auto& row_scale = scaling_.GetRowScaling(); // Assumes getter exists
190190
const auto& col_scale = scaling_.GetColScaling(); // Assumes getter exists
191191
if (col_scale.size() == dSlackPos_unscaled.size()) {
@@ -272,7 +272,7 @@ void PDLPSolver::Postsolve(HighsSolution& solution) {
272272

273273
PDLPSolver::PDLPSolver(Logger& logger) : logger_(logger) {}
274274

275-
void PDLPSolver::Solve(std::vector<double>& x, std::vector<double>& y) {
275+
void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
276276
Timer solver_timer;
277277

278278
const HighsLp& lp = lp_;
@@ -379,7 +379,7 @@ void PDLPSolver::Solve(std::vector<double>& x, std::vector<double>& y) {
379379
// Reset to average and terminate
380380
x = x_avg_;
381381
y = y_avg_;
382-
// scaling_.UnscaleSolution(x, y);
382+
// unscalesolution(x, y);
383383
return solveReturn();
384384
}
385385
}
@@ -951,3 +951,14 @@ void PDLPSolver::setParams(const HighsOptions& options, HighsTimer& timer) {
951951
scaling_.passParams(&params_);
952952
restart_scheme_.passParams(&params_);
953953
}
954+
955+
void PDLPSolver::scaleProblem() {
956+
scaling_.passLp(&lp_);
957+
scaling_.passParams(&params_);
958+
scaling_.scaleProblem();
959+
}
960+
961+
void PDLPSolver::unscaleSolution(std::vector<double>& x,
962+
std::vector<double>& y) const {
963+
scaling_.unscaleSolution(x, y);
964+
}

highs/pdlp/hipdlp/pdhg.hpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,19 @@ class PDLPSolver {
3737
public:
3838
PDLPSolver(Logger& logger);
3939
void setParams(const HighsOptions& options, HighsTimer& timer);
40-
void PreprocessLp();
41-
void ScaleProblem(HighsLp& lp, const PrimalDualParams& params);
42-
void Solve(std::vector<double>& x, std::vector<double>& y);
43-
void Postsolve(HighsSolution& solution);
40+
void preprocessLp();
41+
void scaleProblem();
42+
void solve(std::vector<double>& x, std::vector<double>& y);
43+
void unscaleSolution(std::vector<double>& x, std::vector<double>& y) const;
44+
void postprocess(HighsSolution& solution);
4445
void setSolution(const std::vector<double>& col_value,
4546
const std::vector<double>& row_dual);
4647
void getSolution(std::vector<double>& col_value,
4748
std::vector<double>& row_dual);
4849

49-
const SolverResults& GetResults() const { return results_; }
50+
const SolverResults& getResults() const { return results_; }
5051
void passLp(const HighsLp* lp) { original_lp_ = lp; }
51-
// Scaling
52-
// ScalingParams scaling_params_;
53-
Scaling scaling_;
54-
55-
int GetIterationCount() const;
52+
int getIterationCount() const;
5653

5754
private:
5855
// Problem data
@@ -78,6 +75,8 @@ class PDLPSolver {
7875
std::vector<double>* y_ = nullptr;
7976
std::vector<double> x_current_;
8077
std::vector<double> y_current_;
78+
// Scaling
79+
Scaling scaling_;
8180
// Restart State
8281
std::vector<double> x_avg_, y_avg_;
8382
std::vector<double> x_sum_, y_sum_;

highs/pdlp/hipdlp/scaling.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void LogMatrixNorms(const HighsLp& lp, const std::string& stage) {
6565
std::cout << "-------------------------\n" << std::endl;
6666
}
6767

68-
void Scaling::ScaleProblem() {
68+
void Scaling::scaleProblem() {
6969
if (params_->scaling_method == ScalingMethod::NONE) {
7070
std::cout << "No scaling applied." << std::endl;
7171
return;
@@ -298,7 +298,7 @@ void Scaling::ApplyScaling(const std::vector<double>& col_scaling,
298298
}
299299
}
300300

301-
void Scaling::UnscaleSolution(std::vector<double>& x,
301+
void Scaling::unscaleSolution(std::vector<double>& x,
302302
std::vector<double>& y) const {
303303
if (!is_scaled_) return;
304304

highs/pdlp/hipdlp/scaling.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class Scaling {
2323
Scaling() = default;
2424

2525
void Initialize(const HighsLp& lp);
26-
void ScaleProblem();
27-
void UnscaleSolution(std::vector<double>& x, std::vector<double>& y) const;
26+
void scaleProblem();
27+
void unscaleSolution(std::vector<double>& x, std::vector<double>& y) const;
2828
void passLp(HighsLp* lp) { lp_ = lp; };
2929
void passParams(const PrimalDualParams* params) { params_ = params; };
3030

0 commit comments

Comments
 (0)