Skip to content

Commit

Permalink
randomize glop on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Apr 17, 2024
1 parent 64230c6 commit 9ed0074
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions ortools/glop/revised_simplex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "absl/random/bit_gen_ref.h"
#include "absl/random/random.h"
#include "absl/random/seed_sequences.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
Expand Down Expand Up @@ -93,15 +94,21 @@ class Cleanup {

constexpr const uint64_t kDeterministicSeed = 42;

namespace {

bool UseAbslRandom() { return false; }

} // namespace

RevisedSimplex::RevisedSimplex()
: problem_status_(ProblemStatus::INIT),
objective_(),
basis_(),
variable_name_(),
direction_(),
error_(),
deterministic_random_(kDeterministicSeed),
random_(deterministic_random_),
random_(UseAbslRandom() ? absl::BitGenRef(absl_random_)
: absl::BitGenRef(deterministic_random_)),
basis_factorization_(&compact_matrix_, &basis_),
variables_info_(compact_matrix_),
primal_edge_norms_(compact_matrix_, variables_info_,
Expand Down Expand Up @@ -3617,7 +3624,7 @@ Fractional RevisedSimplex::ComputeInitialProblemObjectiveValue() const {
void RevisedSimplex::SetParameters(const GlopParameters& parameters) {
SCOPED_TIME_STAT(&function_stats_);
deterministic_random_.seed(parameters.random_seed());

absl_random_ = absl::BitGen(absl::SeedSeq({parameters.random_seed()}));
initial_parameters_ = parameters;
parameters_ = parameters;
PropagateParameters();
Expand All @@ -3639,7 +3646,7 @@ void RevisedSimplex::DisplayIterationInfo(bool primal,
const std::string first_word = primal ? "Primal " : "Dual ";

// We display the info on each re-factorization, and it is nice to show what
// trigerred the issue. Note that we don't display normal refactorization when
// triggered the issue. Note that we don't display normal refactorization when
// we decide that it is worth it for the solve time or we reach the fixed
// refactorization period.
std::string info;
Expand Down
4 changes: 2 additions & 2 deletions ortools/glop/revised_simplex.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,9 @@ class RevisedSimplex {
// non-deterministic behavior and avoid client depending on a golden optimal
// solution which prevent us from easily changing the solver.
random_engine_t deterministic_random_;
#ifndef NDEBUG
absl::BitGen absl_random_;
#endif

// A reference to one of the above random generators. Fixed at construction.
absl::BitGenRef random_;

// Helpers for logging the solve progress.
Expand Down

0 comments on commit 9ed0074

Please sign in to comment.