Skip to content

Commit

Permalink
pdlp: export from google3
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Jul 18, 2023
1 parent 8f5f186 commit 22e59eb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
27 changes: 15 additions & 12 deletions ortools/pdlp/primal_dual_hybrid_gradient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2293,8 +2293,15 @@ InnerStepOutcome Solver::TakeMalitskyPockStep() {
}

InnerStepOutcome Solver::TakeAdaptiveStep() {
bool force_numerical_termination = false;
for (bool accepted_step = false; !accepted_step;) {
InnerStepOutcome outcome = InnerStepOutcome::kSuccessful;
int inner_iterations = 0;
for (bool accepted_step = false; !accepted_step; ++inner_iterations) {
if (inner_iterations >= 60) {
LogInnerIterationLimitHit();
ResetAverageToCurrent();
outcome = InnerStepOutcome::kForceNumericalTermination;
break;
}
const double primal_step_size = step_size_ / primal_weight_;
const double dual_step_size = step_size_ * primal_weight_;
NextSolutionAndDelta next_primal_solution =
Expand All @@ -2306,11 +2313,11 @@ InnerStepOutcome Solver::TakeAdaptiveStep() {
if (movement == 0.0) {
LogNumericalTermination();
ResetAverageToCurrent();
force_numerical_termination = true;
outcome = InnerStepOutcome::kForceNumericalTermination;
break;
} else if (movement > kDivergentMovement) {
LogNumericalTermination();
force_numerical_termination = true;
outcome = InnerStepOutcome::kForceNumericalTermination;
break;
}
VectorXd next_dual_product = TransposedMatrixVectorProduct(
Expand All @@ -2335,7 +2342,7 @@ InnerStepOutcome Solver::TakeAdaptiveStep() {
accepted_step = true;
}
const double total_steps_attempted =
num_rejected_steps_ + iterations_completed_ + 1;
num_rejected_steps_ + inner_iterations + iterations_completed_ + 1;
// Our step sizes are a factor 1 - (`total_steps_attempted` + 1)^(-
// `step_size_reduction_exponent`) smaller than they could be as a margin to
// reduce rejected steps.
Expand All @@ -2362,14 +2369,10 @@ InnerStepOutcome Solver::TakeAdaptiveStep() {
// step, we overall decrease `step_size_`. When `step_size_` is
// sufficiently small we stop having rejected steps.
step_size_ = std::min(first_term, second_term);
if (!accepted_step) {
++num_rejected_steps_;
}
}
if (force_numerical_termination) {
return InnerStepOutcome::kForceNumericalTermination;
}
return InnerStepOutcome::kSuccessful;
// `inner_iterations` is incremented for the accepted step.
num_rejected_steps_ += inner_iterations - 1;
return outcome;
}

InnerStepOutcome Solver::TakeConstantSizeStep() {
Expand Down
3 changes: 2 additions & 1 deletion ortools/pdlp/solvers.proto
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,12 @@ message AdaptiveLinesearchParams {
// The step size reduction exponent defines a step size given by
// (1 - (total_steps_attempted + 1)^(-step_size_reduction_exponent)) *
// step_size_limit where step_size_limit is the maximum allowed step size at
// the current iteration.
// the current iteration. This should be between 0.1 and 1.
optional double step_size_reduction_exponent = 1 [default = 0.3];

// The step size growth exponent defines a step size given by (1 +
// (total_steps_attempted + 1)^(-step_size_growth_exponent)) * step_size_.
// This should be between 0.1 and 1.
optional double step_size_growth_exponent = 2 [default = 0.6];
}

Expand Down
11 changes: 7 additions & 4 deletions ortools/pdlp/solvers_proto_validation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,18 @@ absl::Status ValidateAdaptiveLinesearchParams(
if (std::isnan(params.step_size_reduction_exponent())) {
return InvalidArgumentError("step_size_reduction_exponent is NAN");
}
if (params.step_size_reduction_exponent() <= 0) {
if (params.step_size_reduction_exponent() < 0.1 ||
params.step_size_reduction_exponent() > 1.0) {
return InvalidArgumentError(
"step_size_reduction_exponent must be positive");
"step_size_reduction_exponent must be between 0.1 and 1.0 inclusive");
}
if (std::isnan(params.step_size_growth_exponent())) {
return InvalidArgumentError("step_size_growth_exponent is NAN");
}
if (params.step_size_growth_exponent() <= 0) {
return InvalidArgumentError("step_size_growth_exponent must be positive");
if (params.step_size_growth_exponent() < 0.1 ||
params.step_size_growth_exponent() > 1.0) {
return InvalidArgumentError(
"step_size_growth_exponent must be between 0.1 and 1.0 inclusive");
}
return OkStatus();
}
Expand Down
14 changes: 14 additions & 0 deletions ortools/pdlp/solvers_proto_validation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ TEST(ValidateAdaptiveLinesearchParams, BadReductionExponent) {
EXPECT_EQ(status_low.code(), absl::StatusCode::kInvalidArgument);
EXPECT_THAT(status_low.message(), HasSubstr("step_size_reduction_exponent"));

AdaptiveLinesearchParams params_high;
params_high.set_step_size_reduction_exponent(2.0);
const absl::Status status_high =
ValidateAdaptiveLinesearchParams(params_high);
EXPECT_EQ(status_high.code(), absl::StatusCode::kInvalidArgument);
EXPECT_THAT(status_high.message(), HasSubstr("step_size_reduction_exponent"));

AdaptiveLinesearchParams params_nan;
params_nan.set_step_size_reduction_exponent(
std::numeric_limits<double>::quiet_NaN());
Expand All @@ -271,6 +278,13 @@ TEST(ValidateAdaptiveLinesearchParams, BadGrowthExponent) {
EXPECT_EQ(status_low.code(), absl::StatusCode::kInvalidArgument);
EXPECT_THAT(status_low.message(), HasSubstr("step_size_growth_exponent"));

AdaptiveLinesearchParams params_high;
params_high.set_step_size_growth_exponent(2.0);
const absl::Status status_high =
ValidateAdaptiveLinesearchParams(params_high);
EXPECT_EQ(status_high.code(), absl::StatusCode::kInvalidArgument);
EXPECT_THAT(status_high.message(), HasSubstr("step_size_growth_exponent"));

AdaptiveLinesearchParams params_nan;
params_nan.set_step_size_growth_exponent(
std::numeric_limits<double>::quiet_NaN());
Expand Down

0 comments on commit 22e59eb

Please sign in to comment.