68 typedef absl::FunctionRef<void(ClauseId, absl::Span<const Literal>)>
104 CHECK_LT(2 * num_vars, std::numeric_limits<int32_t>::max());
106 return BooleanVariable(num_vars);
135 bool shared =
false);
151 bool use_upper_bound, Coefficient upper_bound,
152 std::vector<Literal>* enforcement_literals,
153 std::vector<LiteralWithCoeff>* cst);
156 bool use_upper_bound, Coefficient upper_bound,
157 std::vector<LiteralWithCoeff>* cst) {
158 std::vector<Literal> enforcement_literals;
160 upper_bound, &enforcement_literals, cst);
176 owned_propagators_.push_back(std::move(propagator));
184 decision_policy_->SetAssignmentPreference(literal, weight);
187 return decision_policy_->AllPreferences();
190 return decision_policy_->ResetDecisionHeuristic();
235 const std::vector<Literal>& assumptions,
236 int64_t max_number_of_conflicts = -1);
285 std::optional<ConflictCallback> callback = std::nullopt);
303 Literal true_literal,
int* first_propagation_index =
nullptr);
329 if (trail_->NumReimplicationsOnLastUntrail() > 0) {
341 std::optional<ConflictCallback> callback = std::nullopt);
384 template <
typename Output>
390 if (num_processed_fixed_variables_ < trail_->Index()) {
393 clauses_propagator_->DeleteRemovedClauses();
398 binary_implication_graph_->ExtractAllBinaryClauses(out);
399 for (
SatClause* clause : clauses_propagator_->AllClausesInCreationOrder()) {
400 if (!clauses_propagator_->IsRemovable(clause)) {
401 out->AddClause(clause->AsSpan());
415 const std::vector<LiteralWithTrailIndex>&
Decisions()
const {
416 return trail_->Decisions();
498 bool minimize_new_clauses_only =
false);
505 current - deterministic_time_at_last_advanced_time_limit_);
506 deterministic_time_at_last_advanced_time_limit_ = current;
514 return trail_->Decisions()[0].trail_index;
516 return trail_->Index();
533 std::optional<ConflictCallback> callback = std::nullopt);
536 clauses_propagator_->EnsureNewClauseIndexInitialized();
540 trail_->EnableChronologicalBacktracking(value);
558 Status SolveInternal(
TimeLimit* time_limit, int64_t max_number_of_conflicts);
567 bool ClauseIsValidUnderDebugAssignment(
568 absl::Span<const Literal> clause)
const;
569 bool PBConstraintIsValidUnderDebugAssignment(
570 absl::Span<const LiteralWithCoeff> cst, Coefficient rhs)
const;
578 Status SolveInternal(
int assumption_level);
595 Status ReapplyDecisionsUpTo(
int level,
596 int* first_propagation_index =
nullptr);
599 bool IsMemoryLimitReached()
const;
602 bool SetModelUnsat();
605 int AssignmentLevel(BooleanVariable var)
const {
612 UpperBoundedLinearConstraint* ReasonPbConstraintOrNull(
613 BooleanVariable var)
const;
624 bool ResolvePBConflict(BooleanVariable var,
625 MutableUpperBoundedLinearConstraint* conflict,
630 bool AddProblemClauseInternal(ClauseId
id,
631 absl::Span<const Literal> literals);
636 bool AddLinearConstraintInternal(
637 const std::vector<Literal>& enforcement_literals,
638 const std::vector<LiteralWithCoeff>& cst, Coefficient rhs,
639 Coefficient max_value);
642 void CanonicalizeLinear(std::vector<LiteralWithCoeff>* cst,
643 Coefficient* bound_shift, Coefficient* max_value);
651 int AddLearnedClauseAndEnqueueUnitPropagation(
652 ClauseId clause_id, absl::Span<const Literal> literals,
bool is_redundant,
653 int min_lbd_of_subsumed_clauses);
657 void EnqueueNewDecision(Literal literal);
660 void InitializePropagators();
664 int ComputeMaxTrailIndex(absl::Span<const Literal> clause)
const;
678 void ComputeFirstUIPConflict(
679 int max_trail_index, std::vector<Literal>* conflict,
680 std::vector<Literal>* reason_used_to_infer_the_conflict);
686 std::pair<bool, int> SubsumptionsInConflictResolution(
687 ClauseId learned_conflict_id, absl::Span<const Literal> conflict,
688 absl::Span<const Literal> reason_used);
692 void AppendLratProofForFixedLiterals(absl::Span<const Literal> literals,
693 std::vector<ClauseId>* clause_ids);
694 void AppendLratProofForFailingClause(std::vector<ClauseId>* clause_ids);
695 void AppendLratProofFromReasons(absl::Span<const Literal> reasons,
696 std::vector<ClauseId>* clause_ids);
701 void ComputeUnionOfReasons(absl::Span<const Literal>
input,
702 std::vector<Literal>* literals);
708 void ComputePBConflict(
int max_trail_index, Coefficient initial_slack,
709 MutableUpperBoundedLinearConstraint* conflict,
710 int* backjump_level);
721 void MinimizeConflict(std::vector<Literal>* conflict,
722 std::vector<ClauseId>* clause_ids);
723 void MinimizeConflictSimple(std::vector<Literal>* conflict,
724 std::vector<ClauseId>* clause_ids);
725 void MinimizeConflictRecursively(std::vector<Literal>* conflict,
726 std::vector<ClauseId>* clause_ids);
729 bool CanBeInferredFromConflictVariables(BooleanVariable variable);
730 void AppendInferenceChain(BooleanVariable variable,
731 std::vector<ClauseId>* clause_ids);
738 bool IsConflictValid(absl::Span<const Literal> literals);
742 int ComputePropagationLevel(absl::Span<const Literal> literals);
757 int ComputeLbd(absl::Span<const Literal> literals);
761 void CleanClauseDatabaseIfNeeded();
765 void BumpReasonActivities(absl::Span<const Literal> literals);
766 void BumpClauseActivity(SatClause* clause);
767 void RescaleClauseActivities(
double scaling_factor);
768 void UpdateClauseActivityIncrement();
770 std::string DebugString(
const SatClause& clause)
const;
771 std::string StatusString(
Status status)
const;
772 std::string RunningStatisticsString()
const;
776 std::unique_ptr<Model> owned_model_;
778 BooleanVariable num_variables_ = BooleanVariable(0);
779 ClauseIdGenerator* clause_id_generator_;
783 BinaryImplicationGraph* binary_implication_graph_;
784 ClauseManager* clauses_propagator_;
785 EnforcementPropagator* enforcement_propagator_;
786 PbConstraints* pb_constraints_;
789 std::vector<SatPropagator*> propagators_;
790 std::vector<SatPropagator*> non_empty_propagators_;
793 std::vector<SatPropagator*> external_propagators_;
794 SatPropagator* last_propagator_ =
nullptr;
797 std::vector<std::unique_ptr<SatPropagator>> owned_propagators_;
800 bool track_binary_clauses_;
801 BinaryClauseManager binary_clauses_;
806 SatParameters* parameters_;
807 RestartPolicy* restart_;
808 SatDecisionPolicy* decision_policy_;
812 VariablesAssignment debug_assignment_;
816 int last_decision_or_backtrack_trail_index_ = 0;
819 int assumption_level_ = 0;
820 std::vector<Literal> assumptions_;
825 int num_processed_fixed_variables_ = 0;
826 double deterministic_time_of_last_fixed_variables_cleanup_ = 0.0;
835 bool model_is_unsat_ =
false;
838 double clause_activity_increment_;
842 int num_learned_clause_before_cleanup_ = 0;
844 int64_t minimization_by_propagation_threshold_ = 0;
853 std::vector<int> min_trail_index_per_level_;
856 std::vector<BooleanVariable> dfs_stack_;
857 std::vector<BooleanVariable> variable_to_process_;
860 std::vector<Literal> tmp_literals_;
862 std::vector<ClauseId> tmp_clause_ids_;
863 std::vector<ClauseId> tmp_clause_ids_for_1uip_;
864 std::vector<ClauseId> tmp_clause_ids_for_minimization_;
865 absl::flat_hash_set<ClauseId> tmp_clause_id_set_;
872 std::vector<Literal> learned_conflict_;
873 std::vector<Literal> reason_used_to_infer_the_conflict_;
874 std::vector<Literal> extra_reason_literals_;
876 std::vector<SatClause*> subsumed_clauses_;
878 std::vector<int> subsuming_lrat_index_;
879 CompactVectorVector<int, Literal> subsuming_clauses_;
880 CompactVectorVector<int, SatClause*> subsuming_groups_;
887 int min_lbd_of_subsumed_clauses;
888 std::vector<Literal> clause;
890 std::vector<NewClauses> learned_clauses_;
897 bool block_clause_deletion_ =
false;
901 VariableWithSameReasonIdentifier same_reason_identifier_;
904 bool is_relevant_for_core_computation_;
907 MutableUpperBoundedLinearConstraint pb_conflict_;
912 double deterministic_time_at_last_advanced_time_limit_ = 0;
914 LratProofHandler* lrat_proof_handler_ =
nullptr;
916 mutable StatsGroup stats_;