14 #ifndef OR_TOOLS_SAT_PRECEDENCES_H_
15 #define OR_TOOLS_SAT_PRECEDENCES_H_
22 #include "absl/container/inlined_vector.h"
23 #include "absl/strings/string_view.h"
24 #include "absl/types/span.h"
63 watcher_id_(watcher_->Register(this)) {
88 IntegerVariable offset_var);
95 IntegerValue offset,
Literal l);
100 IntegerVariable offset_var,
124 std::vector<IntegerPrecedences>* output);
126 std::vector<Literal>* literal_reason,
127 std::vector<IntegerLiteral>* integer_reason)
const;
156 const std::vector<IntegerVariable>& vars,
157 std::vector<FullIntegerPrecedence>* output);
171 DEFINE_STRONG_INDEX_TYPE(OptionalArcIndex);
176 int AddGreaterThanAtLeastOneOfConstraintsFromClause(
177 const absl::Span<const Literal> clause,
Model*
model);
183 int AddGreaterThanAtLeastOneOfConstraintsWithClauseAutoDetection(
188 IntegerVariable tail_var;
189 IntegerVariable head_var;
192 IntegerVariable offset_var;
195 absl::InlinedVector<Literal, 6> presence_literals;
199 mutable bool is_marked;
207 void AdjustSizeFor(IntegerVariable i);
208 void AddArc(IntegerVariable
tail, IntegerVariable
head, IntegerValue offset,
209 IntegerVariable offset_var,
210 absl::Span<const Literal> presence_literals);
214 bool EnqueueAndCheck(
const ArcInfo&
arc, IntegerValue new_head_lb,
216 IntegerValue ArcOffset(
const ArcInfo&
arc)
const;
220 void PropagateOptionalArcs(
Trail* trail);
238 void InitializeBFQueueWithModifiedNodes();
239 bool BellmanFordTarjan(
Trail* trail);
240 bool DisassembleSubtree(
int source,
int target,
241 std::vector<bool>* can_be_skipped);
243 std::vector<Literal>* must_be_all_true,
244 std::vector<Literal>* literal_reason,
245 std::vector<IntegerLiteral>* integer_reason);
246 void CleanUpMarkedArcsAndParents();
250 bool NoPropagationLeft(
const Trail& trail)
const;
283 impacted_potential_arcs_;
292 bool operator<(
const SortedVar& other)
const {
296 std::vector<SortedVar> tmp_sorted_vars_;
297 std::vector<IntegerPrecedences> tmp_precedences_;
307 literal_to_new_impacted_arcs_;
311 std::vector<Literal> literal_reason_;
312 std::vector<IntegerLiteral> integer_reason_;
317 std::deque<int> bf_queue_;
318 std::vector<bool> bf_in_queue_;
319 std::vector<bool> bf_can_be_skipped_;
320 std::vector<ArcIndex> bf_parent_arc_of_;
323 std::vector<int> tmp_vector_;
326 int64_t num_cycles_ = 0;
327 int64_t num_pushes_ = 0;
328 int64_t num_enforcement_pushes_ = 0;
338 IntegerVariable i2) {
344 IntegerVariable i1, IntegerVariable i2, IntegerValue offset) {
356 IntegerVariable i1, IntegerVariable i2, IntegerValue offset,
Literal l) {
361 IntegerVariable i1, IntegerVariable i2, IntegerVariable offset_var) {
362 AddArc(i1, i2, IntegerValue(0), offset_var, {});
366 IntegerVariable i1, IntegerVariable i2, IntegerValue offset,
367 IntegerVariable offset_var, absl::Span<const Literal> presence_literals) {
368 AddArc(i1, i2, offset, offset_var, presence_literals);
389 a,
b, IntegerValue(offset));
402 IntegerVariable
a, IntegerVariable
b, int64_t ub,
403 const std::vector<Literal>& enforcement_literals) {
424 IntegerVariable
a, IntegerVariable
b, IntegerVariable c, int64_t ub,
425 const std::vector<Literal>& enforcement_literals) {
429 enforcement_literals);
462 IntegerVariable
a, IntegerVariable
b, int64_t offset,
Literal is_le) {
void SetPropagatorPriority(int id, int priority)
void RegisterWatcher(SparseBitset< IntegerVariable > *p)
Class that owns everything related to a particular optimization model.
void AddPrecedenceReason(int arc_index, IntegerValue min_offset, std::vector< Literal > *literal_reason, std::vector< IntegerLiteral > *integer_reason) const
void ComputeFullPrecedences(bool call_compute_precedences, const std::vector< IntegerVariable > &vars, std::vector< FullIntegerPrecedence > *output)
void AddConditionalPrecedence(IntegerVariable i1, IntegerVariable i2, Literal l)
void AddConditionalPrecedenceWithOffset(IntegerVariable i1, IntegerVariable i2, IntegerValue offset, Literal l)
void AddPrecedenceWithOffset(IntegerVariable i1, IntegerVariable i2, IntegerValue offset)
~PrecedencesPropagator() override
void AddPrecedenceWithAllOptions(IntegerVariable i1, IntegerVariable i2, IntegerValue offset, IntegerVariable offset_var, absl::Span< const Literal > presence_literals)
void ComputePrecedences(const std::vector< IntegerVariable > &vars, std::vector< IntegerPrecedences > *output)
void AddPrecedence(IntegerVariable i1, IntegerVariable i2)
int AddGreaterThanAtLeastOneOfConstraints(Model *model)
PrecedencesPropagator(Model *model)
void AddPrecedenceWithVariableOffset(IntegerVariable i1, IntegerVariable i2, IntegerVariable offset_var)
void Untrail(const Trail &trail, int trail_index) final
bool PropagateOutgoingArcs(IntegerVariable var)
std::function< void(Model *)> GreaterOrEqual(IntegerVariable v, int64_t lb)
std::function< void(Model *)> ConditionalSum2LowerOrEqual(IntegerVariable a, IntegerVariable b, int64_t ub, const std::vector< Literal > &enforcement_literals)
const IntegerVariable kNoIntegerVariable(-1)
std::function< void(Model *)> Sum2LowerOrEqual(IntegerVariable a, IntegerVariable b, int64_t ub)
std::function< void(Model *)> Sum3LowerOrEqual(IntegerVariable a, IntegerVariable b, IntegerVariable c, int64_t ub)
std::function< void(Model *)> LowerOrEqual(IntegerVariable v, int64_t ub)
std::vector< IntegerVariable > NegationOf(const std::vector< IntegerVariable > &vars)
std::function< void(Model *)> Equality(IntegerVariable v, int64_t value)
std::function< void(Model *)> EqualityWithOffset(IntegerVariable a, IntegerVariable b, int64_t offset)
std::function< void(Model *)> ConditionalLowerOrEqualWithOffset(IntegerVariable a, IntegerVariable b, int64_t offset, Literal is_le)
std::function< void(Model *)> ConditionalSum3LowerOrEqual(IntegerVariable a, IntegerVariable b, IntegerVariable c, int64_t ub, const std::vector< Literal > &enforcement_literals)
std::function< void(Model *)> LowerOrEqualWithOffset(IntegerVariable a, IntegerVariable b, int64_t offset)
Collection of objects used to extend the Constraint Solver library.
std::vector< int > indices
std::vector< IntegerValue > offsets