Skip to content

Commit f2a782e

Browse files
committed
Replace auto with std::tie, no C++11 warning, added InitializeStepSizesPowerMetho
1 parent 22848e6 commit f2a782e

File tree

4 files changed

+52
-37
lines changed

4 files changed

+52
-37
lines changed

highs/pdlp/hipdlp/pdhg.cc

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,19 @@ void PDLPSolver::Solve(HighsLp & original_lp, const PrimalDualParams& params, st
310310

311311
// Set step sizes based on the operator norm to ensure convergence
312312
// A safe choice satisfying eta * omega * ||A||^2 < 1
313+
step::StepSizeConfig step_size = step::InitializeStepSizesPowerMethod(lp, op_norm_sq, status == HighsStatus::kOk);
313314
const double fixed_eta = 0.99 / sqrt(op_norm_sq);
314-
current_eta_ = 1.0; // Initial step size for adaptive strategy
315-
const double omega = 0.99 / sqrt(op_norm_sq);
316315
PrimalDualParams working_params = params;
317-
working_params.omega = omega;
318-
working_params.eta = fixed_eta;
319-
std::cout << "Using power method step sizes: eta = " << fixed_eta << ", omega = " << omega << std::endl;
316+
317+
working_params.omega = step_size.dual_step;
318+
working_params.eta = step_size.primal_step;
319+
current_eta_ = step_size.primal_step; // Initial step size for adaptive strategy
320+
std::cout << "Using power method step sizes: eta = " << step_size.primal_step
321+
<< ", omega = " << step_size.dual_step << std::endl;
322+
320323
printf("Initial step sizes from power method lambda = %g: primal = %g; dual = %g\n",
321-
op_norm_sq, fixed_eta/omega, fixed_eta*omega);
324+
step_size.power_method_lambda, step_size.primal_step, step_size.dual_step);
325+
322326
// --- 1. Initialization ---
323327
Initialize(lp, x, y); // Sets initial x, y and results_
324328
restart_scheme_.Initialize(params, results_);
@@ -728,44 +732,21 @@ std::tuple<double, double, double, double, double> PDLPSolver::ComputeDualityGap
728732
// For the termination criteria, you need the components of the dual objective
729733
return std::make_tuple(duality_gap, qTy, lT_lambda_plus, uT_lambda_minus, cTx);
730734
}
731-
732-
static double ComputeWeightedNorm(const std::vector<double>& x1, const std::vector<double>& y1,
733-
const std::vector<double>& x2, const std::vector<double>& y2, double omega) {
734-
double norm = 0.0;
735-
for (size_t i = 0; i < x1.size(); ++i) {
736-
double diff_x = x1[i] - x2[i];
737-
norm += (1.0 / omega) * diff_x * diff_x;
738-
}
739-
for (size_t i = 0; i < y1.size(); ++i) {
740-
double diff_y = y1[i] - y2[i];
741-
norm += omega * diff_y * diff_y;
742-
}
743-
return std::sqrt(norm);
744-
}
745-
746-
double ComputeNormalizedDualityGap(const HighsLp& lp, const std::vector<double>& x, const std::vector<double>& y, const std::vector<double>& x_ref, const std::vector<double>& y_ref, double omega, const std::vector<double>& ax, const std::vector<double>& aty){
747-
// 1. Calculate radius r = ||z - z_ref||_omega
748-
double r = ComputeWeightedNorm(x, y, x_ref, y_ref, omega);
749-
if (r < 1e-9) return 0.0;
750-
751-
// 2. Calculate Lagrangian gradient components
752-
// g_x = c - A^T * y
753-
std::vector<double> g_x(lp.num_col_, 0.0);
754-
755-
//to do
756-
return 0.0;
757-
}
758735

759736
bool PDLPSolver::CheckConvergence(const HighsLp& lp, const std::vector<double>& x, const std::vector<double>& y, const std::vector<double>& ax_vector, const std::vector<double>& aty_vector, double epsilon, SolverResults& results) {
760737
ComputeDualSlacks(lp, aty_vector);
761738
std::vector<double> lambda = ComputeLambda(lp, y, aty_vector);
762739

763-
auto [primal_feasibility, q_norm] = ComputePrimalFeasibility(lp, x, ax_vector);
740+
double primal_feasibility, q_norm;
741+
std::tie(primal_feasibility, q_norm) = ComputePrimalFeasibility(lp, x, ax_vector);
764742
results.primal_feasibility = primal_feasibility;
765743

766-
auto [dual_feasibility, c_norm] = ComputeDualFeasibility(lp, aty_vector);
744+
double dual_feasibility, c_norm;
745+
std::tie(dual_feasibility, c_norm) = ComputeDualFeasibility(lp, aty_vector);
767746
results.dual_feasibility = dual_feasibility;
768-
auto [duality_gap, qTy, lTlambda_plus, uTlambda_minus, cTx] = ComputeDualityGap(lp, x, y, lambda);
747+
748+
double duality_gap, qTy, lTlambda_plus, uTlambda_minus, cTx;
749+
std::tie(duality_gap, qTy, lTlambda_plus, uTlambda_minus, cTx) = ComputeDualityGap(lp, x, y, lambda);
769750
results.duality_gap = duality_gap;
770751

771752
bool primal_feasible = primal_feasibility <= epsilon * (1 + q_norm);

highs/pdlp/hipdlp/pdhg.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ class PDLPSolver {
110110
std::pair<double, double> ComputeDualFeasibility(const HighsLp& lp, const std::vector<double>& ATy_vector);
111111
std::tuple<double, double, double, double, double> ComputeDualityGap(const HighsLp& lp, const std::vector<double>& x, const std::vector<double>& y, const std::vector<double>& lambda);
112112
double ComputeKKTError(const HighsLp& lp, const std::vector<double>& x, const std::vector<double>& y, const std::vector<double>& lambda, double omega);
113-
double ComputeNormalizedDualityGap(const HighsLp& lp, const std::vector<double>& x, const std::vector<double>& y, const std::vector<double>& x_ref, const std::vector<double>& y_ref, double omega, const std::vector<double>& ax, const std::vector<double>& aty);
114113
bool CheckConvergence(const HighsLp& lp, const std::vector<double>& x, const std::vector<double>& y,const std::vector<double>& ax_vector, const std::vector<double>& aty_vector, double epsilon, SolverResults& results);
115114

116115
// GPU specific functions

highs/pdlp/hipdlp/step.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ namespace step {
88

99
static constexpr double kDivergentMovement = 1e10;
1010

11+
StepSizeConfig InitializeStepSizesPowerMethod(const HighsLp& lp,
12+
double op_norm_sq,
13+
bool power_method_converged) {
14+
StepSizeConfig config;
15+
config.power_method_lambda = op_norm_sq;
16+
config.converged = power_method_converged;
17+
18+
// Compute primal weight beta = ||c||^2 / ||b||^2
19+
double cost_norm = linalg::compute_cost_norm(lp, 2.0);
20+
double rhs_norm = linalg::compute_rhs_norm(lp, 2.0);
21+
std::cout << "Cost norm: " << cost_norm << ", RHS norm: " << rhs_norm << std::endl;
22+
config.beta = cost_norm * cost_norm / (rhs_norm * rhs_norm + 1e-10);
23+
24+
// cuPDLP-C style weight initialization
25+
const double safety_factor = 0.8;
26+
double base_step = safety_factor / std::sqrt(op_norm_sq);
27+
28+
config.primal_step = base_step / std::sqrt(config.beta);
29+
config.dual_step = base_step * std::sqrt(config.beta);
30+
return config;
31+
}
32+
33+
1134
bool CheckNumericalStability(const std::vector<double>& delta_x,
1235
const std::vector<double>& delta_y,
1336
double omega) {

highs/pdlp/hipdlp/step.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515

1616
namespace step {
1717

18+
struct StepSizeConfig{
19+
double primal_step;
20+
double dual_step;
21+
double beta;
22+
double power_method_lambda;
23+
bool converged;
24+
};
25+
26+
StepSizeConfig InitializeStepSizesPowerMethod(const HighsLp& lp,
27+
double op_norm_sq,
28+
bool power_method_converged = true);
29+
1830
bool CheckNumericalStability(const std::vector<double>& delta_x,
1931
const std::vector<double>& delta_y,
2032
double omega);

0 commit comments

Comments
 (0)