Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
An helper class to share the code used by the different kind of search. More...
#include <integer_search.h>
Public Member Functions | |
IntegerSearchHelper (Model *model) | |
bool | BeforeTakingDecision () |
bool | GetDecision (const std::function< BooleanOrIntegerLiteral()> &f, LiteralIndex *decision) |
LiteralIndex | GetDecisionLiteral (const BooleanOrIntegerLiteral &decision) |
void | NotifyThatConflictWasFoundDuringGetDecision () |
bool | TakeDecision (Literal decision) |
SatSolver::Status | SolveIntegerProblem () |
An helper class to share the code used by the different kind of search.
Definition at line 270 of file integer_search.h.
|
explicit |
Definition at line 1320 of file integer_search.cc.
bool operations_research::sat::IntegerSearchHelper::BeforeTakingDecision | ( | ) |
Executes some code before a new decision. Returns false if model is UNSAT.
If we pushed root level deductions, we restart to incorporate them.
The rest only trigger at level zero.
Definition at line 1333 of file integer_search.cc.
bool operations_research::sat::IntegerSearchHelper::GetDecision | ( | const std::function< BooleanOrIntegerLiteral()> & | f, |
LiteralIndex * | decision ) |
Calls the decision heuristics and extract a non-fixed literal.
Returns false if a conflict was found while trying to take a decision.
Definition at line 1387 of file integer_search.cc.
LiteralIndex operations_research::sat::IntegerSearchHelper::GetDecisionLiteral | ( | const BooleanOrIntegerLiteral & | decision | ) |
Inner function used by GetDecision(). It will create a new associated literal if needed.
Convert integer decision to literal one if needed.
Definition at line 1362 of file integer_search.cc.
|
inline |
Functions passed to GetDecision() might call this to notify a conflict was detected.
Definition at line 291 of file integer_search.h.
SatSolver::Status operations_research::sat::IntegerSearchHelper::SolveIntegerProblem | ( | ) |
Tries to find a feasible solution to the current model.
This function continues from the current state of the solver and loop until all variables are instantiated (i.e. the next decision is kNoLiteralIndex) or a search limit is reached. It uses the heuristic from the SearchHeuristics class in the model to decide when to restart and what next decision to take.
Each time a restart happen, this increment the policy index modulo the number of heuristics to act as a portfolio search.
Main search loop.
If needed, restart and switch decision_policy.
No decision means that we reached a leave of the search tree and that we have a feasible solution.
Tricky: If the time limit is reached during the final propagation when all variables are fixed, there is no guarantee that the propagation responsible for testing the validity of the solution was run to completion. So we cannot report a feasible solution.
Save the current polarity of all Booleans in the solution. It will be followed for the next SAT decisions. This is known to be a good policy for optimization problem. Note that for decision problem we don't care since we are just done as soon as a solution is found.
This idea is kind of "well known", see for instance the "LinSBPS" submission to the maxSAT 2018 competition by Emir Demirovic and Peter Stuckey where they show it is a good idea and provide more references.
In multi-thread, we really only want to save the LP relaxation for thread with high linearization level to avoid to pollute the repository with sub-par lp solutions.
Definition at line 1450 of file integer_search.cc.
bool operations_research::sat::IntegerSearchHelper::TakeDecision | ( | Literal | decision | ) |
Tries to take the current decision, this might backjump. Returns false if the model is UNSAT.
Update the implied bounds each time we enqueue a literal at level zero. This is "almost free", so we might as well do it.
Update the pseudo costs.
Definition at line 1424 of file integer_search.cc.