30 static const int kMaxLubyIndex = 30;
31 static const int kMaxBoost = 30;
36 bool InternalLoadStateProblemToSatSolver(
const ProblemState& problem_state,
37 sat::SatSolver* sat_solver) {
38 const bool first_time = (sat_solver->NumVariables() == 0);
40 sat_solver->SetNumVariables(
41 problem_state.original_problem().num_variables());
44 sat_solver->Backtrack(0);
48 for (VariableIndex
var(0);
var < problem_state.is_fixed().size(); ++
var) {
49 if (problem_state.is_fixed()[
var]) {
50 if (!sat_solver->AddUnitClause(
51 sat::Literal(sat::BooleanVariable(
var.value()),
52 problem_state.fixed_values()[
var]))) {
70 problem_state.original_problem(),
79 sat_solver->TrackBinaryClauses(
true);
80 if (!sat_solver->AddBinaryClauses(problem_state.NewlyAddedBinaryClauses())) {
83 sat_solver->ClearNewlyAddedBinaryClauses();
91 if (InternalLoadStateProblemToSatSolver(problem_state, sat_solver)) {
102 CHECK(
nullptr != solver);
103 CHECK(
nullptr != info);
112 ? propagation_trail.
Index()
113 : solver->
Decisions().front().trail_index;
114 for (
int trail_index = 0; trail_index < root_size; ++trail_index) {
125 CHECK(solution !=
nullptr);
129 for (sat::BooleanVariable
var(0);
var < solution->
Size(); ++
var) {
132 const VariableIndex bop_var_id(
var.value());
141 : value_(initial_value), num_changes_(0) {}
147 const double factor = 1.0 + 1.0 / (num_changes_ / 2.0 + 1);
148 value_ =
std::min(1.0 - (1.0 - value_) / factor, value_ * factor);
153 const double factor = 1.0 + 1.0 / (num_changes_ / 2.0 + 1);
154 value_ =
std::max(value_ / factor, 1.0 - (1.0 - value_) * factor);
172 for (
int i = 0; i < difficulties_.size(); ++i) {
173 difficulties_[i].Reset();
179 difficulties_[luby_msb].Increase();
184 difficulties_[luby_msb].Decrease();
189 return difficulties_[luby_msb].value();
194 return luby_boost_ >= kMaxBoost;
199 luby_value_ =
sat::SUniv(luby_id_) << luby_boost_;
AdaptiveParameterValue(double initial_value)
void SetValue(VariableIndex var, bool value)
LubyAdaptiveParameterValue(double initial_value)
double GetParameterValue() const
const BopSolution & solution() const
const Trail & LiteralTrail() const
const std::vector< BinaryClause > & NewlyAddedBinaryClauses()
bool IsModelUnsat() const
int CurrentDecisionLevel() const
const std::vector< Decision > & Decisions() const
void ClearNewlyAddedBinaryClauses()
bool VariableIsAssigned(BooleanVariable var) const
bool LiteralIsTrue(Literal literal) const
int NumberOfVariables() const
BopOptimizerBase::Status LoadStateProblemToSatSolver(const ProblemState &problem_state, sat::SatSolver *sat_solver)
void SatAssignmentToBopSolution(const sat::VariablesAssignment &assignment, BopSolution *solution)
void ExtractLearnedInfoFromSatSolver(sat::SatSolver *solver, LearnedInfo *info)
std::tuple< int64_t, int64_t, const double > Coefficient
bool AddObjectiveConstraint(const LinearBooleanProblem &problem, bool use_lower_bound, Coefficient lower_bound, bool use_upper_bound, Coefficient upper_bound, SatSolver *solver)
bool LoadBooleanProblem(const LinearBooleanProblem &problem, SatSolver *solver)
Collection of objects used to extend the Constraint Solver library.
int MostSignificantBitPosition64(uint64_t n)
std::vector< sat::Literal > fixed_literals
std::vector< sat::BinaryClause > binary_clauses