23#ifndef OR_TOOLS_SAT_INTEGER_SEARCH_H_
24#define OR_TOOLS_SAT_INTEGER_SEARCH_H_
31#include "absl/container/flat_hash_set.h"
32#include "absl/types/span.h"
34#include "ortools/sat/cp_model.pb.h"
42#include "ortools/sat/sat_parameters.pb.h"
129 const std::vector<Literal>& assumptions,
Model*
model);
173 const std::vector<IntegerVariable>& vars,
Model*
model);
190 const std::vector<IntegerVariable>& vars,
Model*
model);
202 const std::vector<BooleanOrIntegerVariable>& vars,
203 const std::vector<IntegerValue>& values,
Model*
model);
218 value_selection_heuristics,
266 incomplete_heuristics,
283 LiteralIndex* decision);
292 must_process_conflict_ =
true;
312 const SatParameters& parameters_;
324 bool must_process_conflict_ =
false;
344 static const int kTestLimitPeriod = 20;
345 static const int kLogPeriod = 1000;
346 static const int kSyncPeriod = 50;
350 void LogStatistics();
354 std::vector<BooleanVariable> bool_vars_;
355 std::vector<IntegerVariable> int_vars_;
367 const SatParameters parameters_;
375 int64_t num_literals_probed_ = 0;
376 int64_t num_bounds_shaved_ = 0;
377 int64_t num_bounds_tried_ = 0;
378 int64_t num_at_least_one_probed_ = 0;
379 int64_t num_at_most_one_probed_ = 0;
382 int num_logs_remaining_ = 0;
383 int num_syncs_remaining_ = 0;
384 int num_test_limit_remaining_ = 0;
387 bool use_shaving_ =
false;
388 int trail_index_at_start_of_iteration_ = 0;
389 int integer_trail_index_at_start_of_iteration_ = 0;
392 double active_limit_;
394 absl::flat_hash_set<BooleanVariable> probed_bool_vars_;
395 absl::flat_hash_set<LiteralIndex> shaved_literals_;
397 int current_int_var_ = 0;
398 int current_bool_var_ = 0;
399 int current_bv1_ = 0;
400 int current_bv2_ = 0;
401 int random_pair_of_bool_vars_probed_ = 0;
402 int random_triplet_of_bool_vars_probed_ = 0;
403 std::vector<std::vector<Literal>> tmp_dnf_;
404 std::vector<Literal> tmp_literals_;
SatSolver::Status Probe()
ContinuousProber(const CpModelProto &model_proto, Model *model)
The model_proto is just used to construct the lists of variable to probe.
An helper class to share the code used by the different kind of search.
IntegerSearchHelper(Model *model)
bool TakeDecision(Literal decision)
LiteralIndex GetDecisionLiteral(const BooleanOrIntegerLiteral &decision)
bool GetDecision(const std::function< BooleanOrIntegerLiteral()> &f, LiteralIndex *decision)
bool BeforeTakingDecision()
void NotifyThatConflictWasFoundDuringGetDecision()
SatSolver::Status SolveIntegerProblem()
void ConfigureSearchHeuristics(Model *model)
const LiteralIndex kNoLiteralIndex(-1)
std::function< BooleanOrIntegerLiteral()> DisjunctivePrecedenceSearchHeuristic(Model *model)
std::vector< std::function< BooleanOrIntegerLiteral()> > CompleteHeuristics(absl::Span< const std::function< BooleanOrIntegerLiteral()> > incomplete_heuristics, const std::function< BooleanOrIntegerLiteral()> &completion_heuristic)
std::function< BooleanOrIntegerLiteral()> BoolPseudoCostHeuristic(Model *model)
std::function< BooleanOrIntegerLiteral()> SequentialValueSelection(std::vector< std::function< IntegerLiteral(IntegerVariable)> > value_selection_heuristics, std::function< BooleanOrIntegerLiteral()> var_selection_heuristic, Model *model)
std::function< BooleanOrIntegerLiteral()> IntegerValueSelectionHeuristic(std::function< BooleanOrIntegerLiteral()> var_selection_heuristic, Model *model)
IntegerLiteral SplitAroundLpValue(IntegerVariable var, Model *model)
const IntegerVariable kNoIntegerVariable(-1)
IntegerLiteral AtMinValue(IntegerVariable var, IntegerTrail *integer_trail)
SatSolver::Status SolveIntegerProblemWithLazyEncoding(Model *model)
std::function< BooleanOrIntegerLiteral()> PseudoCost(Model *model)
std::function< BooleanOrIntegerLiteral()> SchedulingSearchHeuristic(Model *model)
A simple heuristic for scheduling models.
IntegerLiteral SplitDomainUsingBestSolutionValue(IntegerVariable var, Model *model)
std::function< BooleanOrIntegerLiteral()> FirstUnassignedVarAtItsMinHeuristic(const std::vector< IntegerVariable > &vars, Model *model)
std::function< BooleanOrIntegerLiteral()> SatSolverHeuristic(Model *model)
Returns the BooleanOrIntegerLiteral advised by the underlying SAT solver.
std::function< bool()> RestartEveryKFailures(int k, SatSolver *solver)
A restart policy that restarts every k failures.
bool LinearizedPartIsLarge(Model *model)
IntegerLiteral SplitAroundGivenValue(IntegerVariable var, IntegerValue value, Model *model)
IntegerLiteral ChooseBestObjectiveValue(IntegerVariable var, Model *model)
If a variable appear in the objective, branch on its best objective value.
const BooleanVariable kNoBooleanVariable(-1)
SatSolver::Status ResetAndSolveIntegerProblem(const std::vector< Literal > &assumptions, Model *model)
std::function< bool()> SatSolverRestartPolicy(Model *model)
A restart policy that uses the underlying sat solver's policy.
std::function< BooleanOrIntegerLiteral()> LpPseudoCostHeuristic(Model *model)
IntegerLiteral GreaterOrEqualToMiddleValue(IntegerVariable var, IntegerTrail *integer_trail)
std::function< BooleanOrIntegerLiteral()> MostFractionalHeuristic(Model *model)
Choose the variable with most fractional LP value.
std::function< BooleanOrIntegerLiteral()> CumulativePrecedenceSearchHeuristic(Model *model)
std::function< BooleanOrIntegerLiteral()> UnassignedVarWithLowestMinAtItsMinHeuristic(const std::vector< IntegerVariable > &vars, Model *model)
std::function< BooleanOrIntegerLiteral()> FollowHint(const std::vector< BooleanOrIntegerVariable > &vars, const std::vector< IntegerValue > &values, Model *model)
std::function< BooleanOrIntegerLiteral()> SequentialSearch(std::vector< std::function< BooleanOrIntegerLiteral()> > heuristics)
In SWIG mode, we don't want anything besides these top-level includes.
LiteralIndex boolean_literal_index
BooleanOrIntegerLiteral(LiteralIndex index)
BooleanOrIntegerLiteral()=default
IntegerLiteral integer_literal
BooleanOrIntegerLiteral(IntegerLiteral i_lit)
std::vector< std::function< bool()> > callbacks
std::function< BooleanOrIntegerLiteral()> fixed_search
Fixed search, built from above building blocks.
std::function< BooleanOrIntegerLiteral()> heuristic_search
std::vector< std::function< bool()> > restart_policies
std::function< BooleanOrIntegerLiteral()> user_search
Contains the search specified by the user in CpModelProto.
std::vector< std::function< BooleanOrIntegerLiteral()> > decision_policies
std::function< BooleanOrIntegerLiteral()> hint_search
std::function< BooleanOrIntegerLiteral()> next_decision_override
std::function< BooleanOrIntegerLiteral()> integer_completion_search
Default integer heuristic that will fix all integer variables.
int policy_index
Index in the vectors above that indicate the current configuration.