Skip to content

Commit

Permalink
Merge pull request #4107 from pleroy/master
Browse files Browse the repository at this point in the history
Continue with searching a slice when a solution is rejected
  • Loading branch information
pleroy authored Oct 5, 2024
2 parents 9b9d46c + a15d919 commit 8591739
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions functions/accurate_table_generator_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,14 @@ absl::StatusOr<cpp_rational> StehléZimmermannSimultaneousSliceSearch(
T);
absl::Status const& status = status_or_solution.status();
if (status.ok()) {
return status_or_solution.value();
auto const& solution = status_or_solution.value();
if (VerifyBinade01Solution<zeroes>(scaled, solution)) {
return solution;
} else if (T == 1) {
high_T_to_cover -= T;
} else {
T /= 2;
}
} else {
VLOG(3) << "Status = " << status;
if (absl::IsOutOfRange(status)) {
Expand Down Expand Up @@ -377,7 +384,14 @@ absl::StatusOr<cpp_rational> StehléZimmermannSimultaneousSliceSearch(
T);
absl::Status const& status = status_or_solution.status();
if (status.ok()) {
return status_or_solution.value();
auto const& solution = status_or_solution.value();
if (VerifyBinade01Solution<zeroes>(scaled, solution)) {
return solution;
} else if (T == 1) {
low_T_to_cover -= T;
} else {
T /= 2;
}
} else {
VLOG(3) << "Status = " << status;
if (absl::IsOutOfRange(status)) {
Expand Down Expand Up @@ -597,6 +611,7 @@ absl::StatusOr<cpp_rational> StehléZimmermannSimultaneousSearch(
Q_coefficients[1]});
VLOG(3) << "Q = " << Q;
if (Q_coefficients[1] == 0) {
LOG_IF(FATAL, Q_coefficients[0] == 0) << "Identically zero";
return absl::NotFoundError("No integer zeroes");
}

Expand Down Expand Up @@ -666,30 +681,28 @@ absl::StatusOr<cpp_rational> StehléZimmermannSimultaneousFullSearch(

absl::Status const& status = status_or_scaled_solution.status();
if (status.ok()) {
absl::MutexLock l(&lock);
// The argument returned by the slice search is scaled, so we must
// adjust it before returning.
auto const scaled_solution = status_or_scaled_solution.value();
if (VerifyBinade01Solution<zeroes>(scaled, scaled_solution)) {
absl::MutexLock l(&lock);
// The argument returned by the slice search is scaled, so we must
// adjust it before returning.
auto const solution = scaled_solution / argument_scale;
VLOG(1) << "Solution for " << starting_argument << ", slice #"
<< slice_index << " is " << solution;
// We have found a solution; we only retain it if (1) no internal error
// occurred; and (2) it closer to the `starting_argument` than any
// solution found previously.
if (status_or_solution.has_value()) {
if (status_or_solution.value().ok()) {
if (abs(solution - starting_argument) <
abs(status_or_solution.value().value() - starting_argument)) {
status_or_solution = solution;
} else {
VLOG(1) << "Solution for slice #" << slice_index
<< " discarded because there is a better one";
}
auto const solution = scaled_solution / argument_scale;
VLOG(1) << "Solution for " << starting_argument << ", slice #"
<< slice_index << " is " << solution;
// We have found a solution; we only retain it if (1) no internal error
// occurred; and (2) it closer to the `starting_argument` than any
// solution found previously.
if (status_or_solution.has_value()) {
if (status_or_solution.value().ok()) {
if (abs(solution - starting_argument) <
abs(status_or_solution.value().value() - starting_argument)) {
status_or_solution = solution;
} else {
VLOG(1) << "Solution for slice #" << slice_index
<< " discarded because there is a better one";
}
} else {
status_or_solution = solution;
}
} else {
status_or_solution = solution;
}
} else if (absl::IsNotFound(status)) {
// No solution found in this slice, go to the next one.
Expand Down

0 comments on commit 8591739

Please sign in to comment.