14 #ifndef OR_TOOLS_SAT_UTIL_H_
15 #define OR_TOOLS_SAT_UTIL_H_
25 #if !defined(__PORTABLE_PLATFORM__)
26 #include "google/protobuf/descriptor.h"
28 #include "absl/container/btree_set.h"
29 #include "absl/container/inlined_vector.h"
30 #include "absl/random/bit_gen_ref.h"
31 #include "absl/random/random.h"
32 #include "absl/types/span.h"
35 #include "ortools/sat/sat_parameters.pb.h"
89 int64_t& x0, int64_t& y0);
120 int64_t base,
const std::vector<int64_t>& coeffs,
121 const std::vector<int64_t>& lbs,
const std::vector<int64_t>& ubs,
122 int64_t rhs, int64_t* new_rhs);
137 :
absl::BitGenRef(deterministic_random_) {
138 const auto& params = *
model->GetOrCreate<SatParameters>();
139 deterministic_random_.seed(params.random_seed());
140 if (params.use_absl_random()) {
141 absl_random_ = absl::BitGen(absl::SeedSeq({params.random_seed()}));
142 absl::BitGenRef::operator=(absl::BitGenRef(absl_random_));
155 absl::BitGen absl_random_;
190 const absl::btree_set<LiteralIndex>& processed,
int relevant_prefix_size,
191 std::vector<Literal>* literals);
213 void AddChoices(absl::Span<const int64_t> choices);
222 int64_t
Bound()
const {
return bound_; }
226 void AddChoicesInternal(absl::Span<const int64_t> values);
228 static constexpr
int kMaxComplexityPerAdd = 50;
232 int64_t current_max_;
233 std::vector<int64_t> sums_;
234 std::vector<bool> expanded_sums_;
235 std::vector<int64_t> filtered_values_;
260 const std::vector<int64_t>& coeffs,
261 const std::vector<int64_t>& costs,
const Domain& rhs);
264 Result InternalSolve(int64_t num_values,
const Domain& rhs);
267 std::vector<Domain> domains_;
268 std::vector<int64_t> coeffs_;
269 std::vector<int64_t> costs_;
276 std::vector<std::vector<State>> var_activity_states_;
284 : average_(initial_average) {}
288 void Reset(
double reset_value);
293 void AddData(
double new_record);
296 double average_ = 0.0;
297 int64_t num_records_ = 0;
307 : decaying_factor_(decaying_factor) {
308 DCHECK_GE(decaying_factor, 0.0);
309 DCHECK_LE(decaying_factor, 1.0);
318 void AddData(
double new_record);
321 double average_ = 0.0;
322 int64_t num_records_ = 0;
323 const double decaying_factor_;
336 explicit Percentile(
int record_limit) : record_limit_(record_limit) {}
347 std::deque<double> records_;
348 const int record_limit_;
360 std::vector<std::vector<int64_t>>* tuples);
380 absl::Span<const int64_t> domain_sizes,
381 std::vector<std::vector<int64_t>>* tuples);
388 if (std::isnan(
value))
return 0;
395 return static_cast<int64_t
>(
value);
407 template <
typename IntType,
bool ceil>
409 static_assert(std::numeric_limits<IntType>::is_integer,
410 "CeilOfRatio is only defined for integral types");
411 DCHECK_NE(0, denominator) <<
"Division by zero is not supported.";
413 <<
"Dividing " << numerator <<
"by -1 is not supported: it would SIGFPE";
415 const IntType rounded_toward_zero = numerator / denominator;
416 const bool needs_round = (numerator % denominator) != 0;
417 const bool same_sign = (numerator >= 0) == (denominator >= 0);
420 return rounded_toward_zero +
static_cast<IntType
>(same_sign && needs_round);
422 return rounded_toward_zero -
423 static_cast<IntType
>(!same_sign && needs_round);
427 template <
typename IntType>
429 return CeilOrFloorOfRatio<IntType, true>(numerator, denominator);
432 template <
typename IntType>
434 return CeilOrFloorOfRatio<IntType, false>(numerator, denominator);
We call domain any subset of Int64 = [kint64min, kint64max].
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
Result Solve(const std::vector< Domain > &domains, const std::vector< int64_t > &coeffs, const std::vector< int64_t > &costs, const Domain &rhs)
void AddData(double new_record)
int64_t NumRecords() const
ExponentialMovingAverage(double decaying_factor)
double CurrentAverage() const
void AddData(double new_record)
int64_t NumRecords() const
IncrementalAverage(double initial_average)
double CurrentAverage() const
void Reset(double reset_value)
int64_t CurrentMax() const
void AddChoices(absl::Span< const int64_t > choices)
void Reset(int64_t bound)
void AddMultiples(int64_t coeff, int64_t max_value)
MaxBoundedSubsetSum(int64_t bound)
Class that owns everything related to a particular optimization model.
ModelRandomGenerator(Model *model)
ModelSharedTimeLimit(Model *model)
double GetPercentile(double percent)
int64_t NumRecords() const
Percentile(int record_limit)
void AddRecord(double record)
void RandomizeDecisionHeuristic(absl::BitGenRef random, SatParameters *parameters)
int64_t ClosestMultiple(int64_t value, int64_t base)
IntType CeilOfRatio(IntType numerator, IntType denominator)
void CompressTuples(absl::Span< const int64_t > domain_sizes, std::vector< std::vector< int64_t >> *tuples)
std::vector< std::vector< absl::InlinedVector< int64_t, 2 > > > FullyCompressTuples(absl::Span< const int64_t > domain_sizes, std::vector< std::vector< int64_t >> *tuples)
bool IsNegatableInt64(absl::int128 x)
int64_t PositiveMod(int64_t x, int64_t m)
IntType FloorOfRatio(IntType numerator, IntType denominator)
int64_t CeilSquareRoot(int64_t a)
bool SolveDiophantineEquationOfSizeTwo(int64_t &a, int64_t &b, int64_t &cte, int64_t &x0, int64_t &y0)
std::string FormatCounter(int64_t num)
int64_t FloorSquareRoot(int64_t a)
constexpr int64_t kTableAnyValue
int64_t SafeDoubleToInt64(double value)
int64_t ModularInverse(int64_t x, int64_t m)
int64_t ProductWithModularInverse(int64_t coeff, int64_t mod, int64_t rhs)
int MoveOneUnprocessedLiteralLast(const absl::btree_set< LiteralIndex > &processed, int relevant_prefix_size, std::vector< Literal > *literals)
IntType CeilOrFloorOfRatio(IntType numerator, IntType denominator)
bool LinearInequalityCanBeReducedWithClosestMultiple(int64_t base, const std::vector< int64_t > &coeffs, const std::vector< int64_t > &lbs, const std::vector< int64_t > &ubs, int64_t rhs, int64_t *new_rhs)
Collection of objects used to extend the Constraint Solver library.
std::mt19937_64 random_engine_t
std::vector< int64_t > solution