14 #ifndef OR_TOOLS_SAT_LINEAR_PROPAGATION_H_
15 #define OR_TOOLS_SAT_LINEAR_PROPAGATION_H_
24 #include "absl/container/inlined_vector.h"
25 #include "absl/types/span.h"
49 bool empty()
const {
return left_ == right_; }
50 bool Contains(
int id)
const {
return pos_[id] != -1; }
54 void Reorder(absl::Span<const int> order);
66 std::vector<int> pos_;
67 std::vector<int> queue_;
71 std::vector<int> tmp_positions_;
72 std::vector<int> tmp_order_;
107 absl::Span<const Literal> enforcement,
112 std::vector<Literal>* reason)
const;
117 EnforcementId
id, absl::Span<const Literal> literal_reason,
118 absl::Span<const IntegerLiteral> integer_reason);
123 absl::Span<Literal> GetSpan(EnforcementId
id);
124 absl::Span<const Literal> GetSpan(EnforcementId
id)
const;
129 LiteralIndex ProcessIdOnTrue(
Literal watched, EnforcementId
id);
141 std::vector<Literal> buffer_;
148 std::vector<std::pair<EnforcementId, EnforcementStatus>> untrail_stack_;
149 int rev_stack_size_ = 0;
150 int64_t rev_stamp_ = 0;
156 std::vector<Literal> temp_literals_;
157 std::vector<Literal> temp_reason_;
175 void AddConstraint(absl::Span<const Literal> enforcement_literals,
176 absl::Span<const IntegerVariable> vars,
177 absl::Span<const IntegerValue> coeffs,
188 struct ConstraintInfo {
189 unsigned int enf_status : 2;
190 bool all_coeffs_are_one : 1;
191 unsigned int initial_size : 29;
193 EnforcementId enf_id;
196 IntegerValue rev_rhs;
199 #if !defined(_MSC_VER)
200 static_assert(
sizeof(ConstraintInfo) == 24,
201 "ERROR_ConstraintInfo_is_not_well_compacted");
204 absl::Span<IntegerValue> GetCoeffs(
const ConstraintInfo& info);
205 absl::Span<IntegerVariable> GetVariables(
const ConstraintInfo& info);
208 ABSL_MUST_USE_RESULT
bool PropagateOneConstraint(
int id);
209 ABSL_MUST_USE_RESULT
bool ReportConflictingCycle();
210 ABSL_MUST_USE_RESULT
bool DisassembleSubtree(
int root_id,
int num_pushed);
212 void ClearPropagatedBy();
213 void CanonicalizeConstraint(
int id);
214 void AddToQueueIfNeeded(
int id);
215 void AddWatchedToQueue(IntegerVariable
var);
216 void SetPropagatedBy(IntegerVariable
var,
int id);
217 std::string ConstraintDebugString(
int id);
228 const int watcher_id_;
231 int previous_level_ = 0;
239 std::vector<ConstraintInfo> infos_;
245 std::vector<IntegerVariable> variables_buffer_;
246 std::vector<IntegerValue> coeffs_buffer_;
247 std::vector<IntegerValue> buffer_of_ones_;
250 std::vector<IntegerValue> max_variations_;
253 std::vector<IntegerLiteral> integer_reason_;
254 std::vector<IntegerValue> reason_coeffs_;
255 std::vector<Literal> literal_reason_;
258 std::vector<bool> in_queue_;
261 int rev_at_false_size_ = 0;
262 std::vector<int> in_queue_and_at_false_;
267 var_to_constraint_ids_;
274 std::vector<int> id_to_propagation_count_;
277 struct DissasembleQueueEntry {
281 std::vector<DissasembleQueueEntry> disassemble_queue_;
282 std::vector<std::pair<int, IntegerVariable>> disassemble_branch_;
283 std::vector<std::pair<IntegerVariable, IntegerValue>> disassemble_candidates_;
284 std::vector<int> tmp_to_reorder_;
286 std::vector<int> disassemble_reverse_topo_order_;
291 std::vector<bool> pq_was_added_;
292 bool pq_in_heap_form_ =
false;
293 std::vector<int> pq_;
294 std::vector<int> pq_to_clean_;
299 int64_t num_extra_scans_ = 0;
302 int64_t num_pushes_ = 0;
303 int64_t num_enforcement_pushes_ = 0;
304 int64_t num_simple_cycles_ = 0;
305 int64_t num_complex_cycles_ = 0;
306 int64_t num_scanned_ = 0;
307 int64_t num_explored_in_disassemble_ = 0;
308 int64_t num_reordered_ = 0;
309 int64_t num_bool_aborts_ = 0;
310 int64_t num_ignored_ = 0;
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
void ReorderDense(absl::Span< const int > order)
void SortByPos(absl::Span< int > elements)
void Reorder(absl::Span< const int > order)
bool Contains(int id) const
bool Propagate(Trail *trail) final
EnforcementId Register(absl::Span< const Literal > enforcement, std::function< void(EnforcementStatus)> callback=nullptr)
ABSL_MUST_USE_RESULT bool PropagateWhenFalse(EnforcementId id, absl::Span< const Literal > literal_reason, absl::Span< const IntegerLiteral > integer_reason)
EnforcementPropagator(Model *model)
EnforcementStatus Status(EnforcementId id) const
void AddEnforcementReason(EnforcementId id, std::vector< Literal > *reason) const
void Untrail(const Trail &trail, int trail_index) final
void SetLevel(int level) final
~LinearPropagator() override
void AddConstraint(absl::Span< const Literal > enforcement_literals, absl::Span< const IntegerVariable > vars, absl::Span< const IntegerValue > coeffs, IntegerValue upper_bound)
LinearPropagator(Model *model)
Class that owns everything related to a particular optimization model.
DEFINE_STRONG_INDEX_TYPE(ClauseIndex)
std::ostream & operator<<(std::ostream &os, const BoolVar &var)
Collection of objects used to extend the Constraint Solver library.