22#include "absl/log/check.h"
28#include "ortools/sat/boolean_problem.pb.h"
39static const int kMaxLubyIndex = 30;
40static const int kMaxBoost = 30;
45bool InternalLoadStateProblemToSatSolver(
const ProblemState& problem_state,
46 sat::SatSolver* sat_solver) {
47 const bool first_time = (sat_solver->NumVariables() == 0);
49 sat_solver->SetNumVariables(
50 problem_state.original_problem().num_variables());
53 sat_solver->Backtrack(0);
57 for (VariableIndex
var(0);
var < problem_state.is_fixed().
size(); ++
var) {
58 if (problem_state.is_fixed()[
var]) {
59 if (!sat_solver->AddUnitClause(
60 sat::Literal(sat::BooleanVariable(
var.value()),
61 problem_state.fixed_values()[
var]))) {
79 problem_state.original_problem(),
80 problem_state.lower_bound() != std::numeric_limits<int64_t>::min(),
81 sat::Coefficient(problem_state.lower_bound()),
82 problem_state.upper_bound() != std::numeric_limits<int64_t>::max(),
83 sat::Coefficient(problem_state.upper_bound() - 1), sat_solver)) {
88 sat_solver->TrackBinaryClauses(
true);
89 if (!sat_solver->AddBinaryClauses(problem_state.NewlyAddedBinaryClauses())) {
92 sat_solver->ClearNewlyAddedBinaryClauses();
100 if (InternalLoadStateProblemToSatSolver(problem_state, sat_solver)) {
111 CHECK(
nullptr != solver);
112 CHECK(
nullptr != info);
121 ? propagation_trail.
Index()
122 : solver->
Decisions().front().trail_index;
123 for (
int trail_index = 0; trail_index < root_size; ++trail_index) {
141 const VariableIndex bop_var_id(
var.value());
150 : value_(initial_value), num_changes_(0) {}
156 const double factor = 1.0 + 1.0 / (num_changes_ / 2.0 + 1);
157 value_ = std::min(1.0 - (1.0 - value_) / factor, value_ * factor);
162 const double factor = 1.0 + 1.0 / (num_changes_ / 2.0 + 1);
163 value_ = std::max(value_ / factor, 1.0 - (1.0 - value_) * factor);
169LubyAdaptiveParameterValue::LubyAdaptiveParameterValue(
double initial_value)
177void LubyAdaptiveParameterValue::Reset() {
181 for (
int i = 0; i < difficulties_.size(); ++i) {
182 difficulties_[i].Reset();
186void LubyAdaptiveParameterValue::IncreaseParameter() {
188 difficulties_[luby_msb].Increase();
191void LubyAdaptiveParameterValue::DecreaseParameter() {
193 difficulties_[luby_msb].Decrease();
196double LubyAdaptiveParameterValue::GetParameterValue()
const {
198 return difficulties_[luby_msb].value();
201bool LubyAdaptiveParameterValue::BoostLuby() {
203 return luby_boost_ >= kMaxBoost;
206void LubyAdaptiveParameterValue::UpdateLuby() {
208 luby_value_ =
sat::SUniv(luby_id_) << luby_boost_;
AdaptiveParameterValue(double initial_value)
Initial value is in [0..1].
const BopSolution & solution() const
const std::vector< BinaryClause > & NewlyAddedBinaryClauses()
void ClearNewlyAddedBinaryClauses()
bool IsModelUnsat() const
int CurrentDecisionLevel() const
const std::vector< Decision > & Decisions() const
const Trail & LiteralTrail() const
bool VariableIsAssigned(BooleanVariable var) const
Returns true iff the given variable is assigned.
int NumberOfVariables() const
bool LiteralIsTrue(Literal literal) 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)
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)
Loads a BooleanProblem into a given SatSolver instance.
In SWIG mode, we don't want anything besides these top-level includes.
int MostSignificantBitPosition64(uint64_t n)
std::vector< sat::BinaryClause > binary_clauses
New binary clauses.
std::vector< sat::Literal > fixed_literals
Vector of all literals that have been fixed.