Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
all_different.cc
Go to the documentation of this file.
1// Copyright 2010-2025 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
15
16#include <algorithm>
17#include <cstdint>
18#include <functional>
19#include <limits>
20#include <utility>
21#include <vector>
22
23#include "absl/algorithm/container.h"
24#include "absl/container/btree_map.h"
25#include "absl/container/flat_hash_map.h"
26#include "absl/log/check.h"
27#include "absl/types/span.h"
30#include "ortools/sat/integer.h"
32#include "ortools/sat/model.h"
35#include "ortools/util/sort.h"
37
38namespace operations_research {
39namespace sat {
40
41std::function<void(Model*)> AllDifferentBinary(
42 absl::Span<const IntegerVariable> vars) {
43 return [=, vars = std::vector<IntegerVariable>(vars.begin(), vars.end())](
44 Model* model) {
45 // Fully encode all the given variables and construct a mapping value ->
46 // List of literal each indicating that a given variable takes this value.
47 //
48 // Note that we use a map to always add the constraints in the same order.
49 absl::btree_map<IntegerValue, std::vector<Literal>> value_to_literals;
50 IntegerEncoder* encoder = model->GetOrCreate<IntegerEncoder>();
51 for (const IntegerVariable var : vars) {
52 model->Add(FullyEncodeVariable(var));
53 for (const auto& entry : encoder->FullDomainEncoding(var)) {
54 value_to_literals[entry.value].push_back(entry.literal);
55 }
56 }
57
58 // Add an at most one constraint for each value.
59 for (const auto& entry : value_to_literals) {
60 if (entry.second.size() > 1) {
61 model->Add(AtMostOneConstraint(entry.second));
62 }
63 }
64
65 // If the number of values is equal to the number of variables, we have
66 // a permutation. We can add a bool_or for each literals attached to a
67 // value.
68 if (value_to_literals.size() == vars.size()) {
69 for (const auto& entry : value_to_literals) {
70 model->Add(ClauseConstraint(entry.second));
71 }
72 }
73 };
74}
75
76std::function<void(Model*)> AllDifferentOnBounds(
77 absl::Span<const AffineExpression> expressions) {
78 return [=, expressions = std::vector<AffineExpression>(
79 expressions.begin(), expressions.end())](Model* model) {
80 if (expressions.empty()) return;
81 auto* constraint = new AllDifferentBoundsPropagator(
82 expressions, model->GetOrCreate<IntegerTrail>());
83 constraint->RegisterWith(model->GetOrCreate<GenericLiteralWatcher>());
84 model->TakeOwnership(constraint);
85 };
86}
87
88std::function<void(Model*)> AllDifferentOnBounds(
89 absl::Span<const IntegerVariable> vars) {
90 return [=, vars = std::vector<IntegerVariable>(vars.begin(), vars.end())](
91 Model* model) {
92 if (vars.empty()) return;
93 std::vector<AffineExpression> expressions;
94 expressions.reserve(vars.size());
95 for (const IntegerVariable var : vars) {
96 expressions.push_back(AffineExpression(var));
97 }
98 auto* constraint = new AllDifferentBoundsPropagator(
99 expressions, model->GetOrCreate<IntegerTrail>());
100 constraint->RegisterWith(model->GetOrCreate<GenericLiteralWatcher>());
101 model->TakeOwnership(constraint);
102 };
103}
104
105std::function<void(Model*)> AllDifferentAC(
106 absl::Span<const IntegerVariable> variables) {
107 return [variables](Model* model) {
108 if (variables.size() < 3) return;
109
110 AllDifferentConstraint* constraint =
111 new AllDifferentConstraint(variables, model);
112 constraint->RegisterWith(model->GetOrCreate<GenericLiteralWatcher>());
113 model->TakeOwnership(constraint);
114 };
115}
116
118 absl::Span<const IntegerVariable> variables, Model* model)
119 : num_variables_(variables.size()),
120 trail_(model->GetOrCreate<Trail>()),
121 integer_trail_(model->GetOrCreate<IntegerTrail>()) {
122 // Initialize literals cache.
123 // Note that remap all values appearing here with a dense_index.
124 num_values_ = 0;
125 absl::flat_hash_map<IntegerValue, int> dense_indexing;
126 variable_to_possible_values_.resize(num_variables_);
127 auto* encoder = model->GetOrCreate<IntegerEncoder>();
128 for (int x = 0; x < num_variables_; x++) {
129 const IntegerValue lb = integer_trail_->LowerBound(variables[x]);
130 const IntegerValue ub = integer_trail_->UpperBound(variables[x]);
131
132 // FullyEncode does not like 1-value domains, handle this case first.
133 // TODO(user): Prune now, ignore these variables during solving.
134 if (lb == ub) {
135 const auto [it, inserted] = dense_indexing.insert({lb, num_values_});
136 if (inserted) ++num_values_;
137
138 variable_to_possible_values_[x].push_back(
139 {it->second, encoder->GetTrueLiteral()});
140 continue;
141 }
142
143 // Force full encoding if not already done.
144 if (!encoder->VariableIsFullyEncoded(variables[x])) {
145 encoder->FullyEncodeVariable(variables[x]);
146 }
147
148 // Fill cache with literals, default value is kFalseLiteralIndex.
149 for (const auto [value, lit] : encoder->FullDomainEncoding(variables[x])) {
150 const auto [it, inserted] = dense_indexing.insert({value, num_values_});
151 if (inserted) ++num_values_;
152
153 variable_to_possible_values_[x].push_back({it->second, lit});
154 }
155
156 // Not sure it is needed, but lets sort.
157 absl::c_sort(
158 variable_to_possible_values_[x],
159 [](const std::pair<int, Literal>& a, const std::pair<int, Literal>& b) {
160 return a.first < b.first;
161 });
162 }
163
164 variable_to_value_.assign(num_variables_, -1);
165 visiting_.resize(num_variables_);
166 variable_visited_from_.resize(num_variables_);
167 component_number_.resize(num_variables_ + num_values_ + 1);
168}
169
171 int num_nodes, absl::Span<const int> tails, absl::Span<const int> heads,
172 absl::Span<const Literal> literals, Model* model)
173 : num_variables_(num_nodes),
174 trail_(model->GetOrCreate<Trail>()),
175 integer_trail_(model->GetOrCreate<IntegerTrail>()) {
176 num_values_ = num_nodes;
177
178 // We assume everything is already dense.
179 const int num_arcs = tails.size();
180 variable_to_possible_values_.resize(num_variables_);
181 for (int a = 0; a < num_arcs; ++a) {
182 variable_to_possible_values_[tails[a]].push_back({heads[a], literals[a]});
183 }
184
185 variable_to_value_.assign(num_variables_, -1);
186 visiting_.resize(num_variables_);
187 variable_visited_from_.resize(num_variables_);
188 component_number_.resize(num_variables_ + num_values_ + 1);
189}
190
192 const int id = watcher->Register(this);
193 watcher->SetPropagatorPriority(id, 2);
194 for (int x = 0; x < num_variables_; x++) {
195 for (const auto [_, lit] : variable_to_possible_values_[x]) {
196 // Watch only unbound literals.
197 if (!trail_->Assignment().LiteralIsAssigned(lit)) {
198 watcher->WatchLiteral(lit, id);
199 watcher->WatchLiteral(lit.Negated(), id);
200 }
201 }
202 }
203}
204
205bool AllDifferentConstraint::MakeAugmentingPath(int start) {
206 // Do a BFS and use visiting_ as a queue, with num_visited pointing
207 // at its begin() and num_to_visit its end().
208 // To switch to the augmenting path once a nonmatched value was found,
209 // we remember the BFS tree in variable_visited_from_.
210 int num_to_visit = 0;
211 int num_visited = 0;
212 // Enqueue start.
213 visiting_[num_to_visit++] = start;
214 variable_visited_[start] = true;
215 variable_visited_from_[start] = -1;
216
217 while (num_visited < num_to_visit) {
218 // Dequeue node to visit.
219 const int node = visiting_[num_visited++];
220
221 for (const int value : successor_[node]) {
222 if (value_visited_[value]) continue;
223 value_visited_[value] = true;
224 if (value_to_variable_[value] == -1) {
225 // value is not matched: change path from node to start, and return.
226 int path_node = node;
227 int path_value = value;
228 while (path_node != -1) {
229 int old_value = variable_to_value_[path_node];
230 variable_to_value_[path_node] = path_value;
231 value_to_variable_[path_value] = path_node;
232 path_node = variable_visited_from_[path_node];
233 path_value = old_value;
234 }
235 return true;
236 } else {
237 // Enqueue node matched to value.
238 const int next_node = value_to_variable_[value];
239 variable_visited_[next_node] = true;
240 visiting_[num_to_visit++] = next_node;
241 variable_visited_from_[next_node] = node;
242 }
243 }
244 }
245 return false;
246}
247
248// The algorithm copies the solver state to successor_, which is used to compute
249// a matching. If all variables can be matched, it generates the residual graph
250// in separate vectors, computes its SCCs, and filters variable -> value if
251// variable is not in the same SCC as value.
252// Explanations for failure and filtering are fine-grained:
253// failure is explained by a Hall set, i.e. dom(variables) \subseteq {values},
254// with |variables| < |values|; filtering is explained by the Hall set that
255// would happen if the variable was assigned to the value.
256//
257// TODO(user): If needed, there are several ways performance could be
258// improved.
259// If copying the variable state is too costly, it could be maintained instead.
260// If the propagator has too many fruitless calls (without failing/pruning),
261// we can remember the O(n) arcs used in the matching and the SCC decomposition,
262// and guard calls to Propagate() if these arcs are still valid.
264 // Copy variable state to graph state.
265 prev_matching_ = variable_to_value_;
266 value_to_variable_.assign(num_values_, -1);
267 variable_to_value_.assign(num_variables_, -1);
268 successor_.clear();
269 const auto assignment = AssignmentView(trail_->Assignment());
270 for (int x = 0; x < num_variables_; x++) {
271 successor_.Add({});
272 for (const auto [value, lit] : variable_to_possible_values_[x]) {
273 if (assignment.LiteralIsFalse(lit)) continue;
274
275 // Forward-checking should propagate x != value.
276 successor_.AppendToLastVector(value);
277
278 // Seed with previous matching.
279 if (prev_matching_[x] == value && value_to_variable_[value] == -1) {
280 variable_to_value_[x] = prev_matching_[x];
281 value_to_variable_[prev_matching_[x]] = x;
282 }
283 }
284 if (successor_[x].size() == 1) {
285 const int value = successor_[x][0];
286 if (value_to_variable_[value] == -1) {
287 value_to_variable_[value] = x;
288 variable_to_value_[x] = value;
289 }
290 }
291 }
292
293 // Compute max matching.
294 int x = 0;
295 for (; x < num_variables_; x++) {
296 if (variable_to_value_[x] == -1) {
297 value_visited_.assign(num_values_, false);
298 variable_visited_.assign(num_variables_, false);
299 MakeAugmentingPath(x);
300 }
301 if (variable_to_value_[x] == -1) break; // No augmenting path exists.
302 }
303
304 // Fail if covering variables impossible.
305 // Explain with the forbidden parts of the graph that prevent
306 // MakeAugmentingPath from increasing the matching size.
307 if (x < num_variables_) {
308 // For now explain all forbidden arcs.
309 std::vector<Literal>* conflict = trail_->MutableConflict();
310 conflict->clear();
311 for (int y = 0; y < num_variables_; y++) {
312 if (!variable_visited_[y]) continue;
313 for (const auto [value, lit] : variable_to_possible_values_[y]) {
314 if (!value_visited_[value]) {
315 DCHECK(assignment.LiteralIsFalse(lit));
316 conflict->push_back(lit);
317 }
318 }
319 }
320 return false;
321 }
322
323 // The current matching is a valid solution, now try to filter values.
324 // Build residual graph, compute its SCCs.
325 residual_graph_successors_.clear();
326 for (int x = 0; x < num_variables_; x++) {
327 residual_graph_successors_.Add({});
328 for (const int succ : successor_[x]) {
329 if (succ != variable_to_value_[x]) {
330 residual_graph_successors_.AppendToLastVector(num_variables_ + succ);
331 }
332 }
333 }
334
335 const int dummy_node = num_variables_ + num_values_;
336 const bool need_dummy = num_variables_ < num_values_;
337 for (int value = 0; value < num_values_; value++) {
338 residual_graph_successors_.Add({});
339 if (value_to_variable_[value] != -1) {
340 residual_graph_successors_.AppendToLastVector(value_to_variable_[value]);
341 } else if (need_dummy) {
342 residual_graph_successors_.AppendToLastVector(dummy_node);
343 }
344 }
345 if (need_dummy) {
346 DCHECK_EQ(residual_graph_successors_.size(), dummy_node);
347 residual_graph_successors_.Add({});
348 for (int x = 0; x < num_variables_; x++) {
349 residual_graph_successors_.AppendToLastVector(x);
350 }
351 }
352
353 // Compute SCCs, make node -> component map.
354 struct SccOutput {
355 explicit SccOutput(std::vector<int>* c) : components(c) {}
356 void emplace_back(int const* b, int const* e) {
357 for (int const* it = b; it < e; ++it) {
358 (*components)[*it] = num_components;
359 }
360 ++num_components;
361 }
362 int num_components = 0;
363 std::vector<int>* components;
364 };
365 SccOutput scc_output(&component_number_);
367 static_cast<int>(residual_graph_successors_.size()),
368 residual_graph_successors_, &scc_output);
369
370 // Remove arcs var -> val where SCC(var) -/->* SCC(val).
371 for (int x = 0; x < num_variables_; x++) {
372 if (successor_[x].size() == 1) continue;
373 for (const auto [value, x_lit] : variable_to_possible_values_[x]) {
374 if (assignment.LiteralIsFalse(x_lit)) continue;
375
376 const int value_node = value + num_variables_;
377 DCHECK_LT(value_node, component_number_.size());
378 if (variable_to_value_[x] != value &&
379 component_number_[x] != component_number_[value_node]) {
380 // We can deduce that x != value. To explain, force x == value,
381 // then find another assignment for the variable matched to
382 // value. It will fail: explaining why is the same as
383 // explaining failure as above, and it is an explanation of x != value.
384 value_visited_.assign(num_values_, false);
385 variable_visited_.assign(num_variables_, false);
386 // Undo x -> old_value and old_variable -> value.
387 const int old_variable = value_to_variable_[value];
388 DCHECK_GE(old_variable, 0);
389 DCHECK_LT(old_variable, num_variables_);
390 variable_to_value_[old_variable] = -1;
391 const int old_value = variable_to_value_[x];
392 value_to_variable_[old_value] = -1;
393 variable_to_value_[x] = value;
394 value_to_variable_[value] = x;
395
396 value_visited_[value] = true;
397 MakeAugmentingPath(old_variable);
398 DCHECK_EQ(variable_to_value_[old_variable], -1); // No reassignment.
399
400 std::vector<Literal>* reason = trail_->GetEmptyVectorToStoreReason();
401 for (int y = 0; y < num_variables_; y++) {
402 if (!variable_visited_[y]) continue;
403 for (const auto [value, y_lit] : variable_to_possible_values_[y]) {
404 if (!value_visited_[value]) {
405 DCHECK(assignment.LiteralIsFalse(y_lit));
406 reason->push_back(y_lit);
407 }
408 }
409 }
410
411 return trail_->EnqueueWithStoredReason(x_lit.Negated());
412 }
413 }
414 }
415
416 return true;
417}
418
420 absl::Span<const AffineExpression> expressions, IntegerTrail* integer_trail)
421 : integer_trail_(integer_trail) {
422 CHECK(!expressions.empty());
423
424 // We need +2 for sentinels.
425 const int capacity = expressions.size() + 2;
426 index_to_start_index_.resize(capacity);
427 index_to_end_index_.resize(capacity);
428 index_is_present_.Resize(capacity);
429 index_to_expr_.resize(capacity, kNoIntegerVariable);
430
431 for (int i = 0; i < expressions.size(); ++i) {
432 bounds_.push_back({expressions[i]});
433 negated_bounds_.push_back({expressions[i].Negated()});
434 }
435}
436
438 if (!PropagateLowerBounds()) return false;
439
440 // Note that it is not required to swap back bounds_ and negated_bounds_.
441 // TODO(user): investigate the impact.
442 std::swap(bounds_, negated_bounds_);
443 const bool result = PropagateLowerBounds();
444 std::swap(bounds_, negated_bounds_);
445 return result;
446}
447
448void AllDifferentBoundsPropagator::FillHallReason(IntegerValue hall_lb,
449 IntegerValue hall_ub) {
450 integer_reason_.clear();
451 const int limit = GetIndex(hall_ub);
452 for (int i = GetIndex(hall_lb); i <= limit; ++i) {
453 const AffineExpression expr = index_to_expr_[i];
454 integer_reason_.push_back(expr.GreaterOrEqual(hall_lb));
455 integer_reason_.push_back(expr.LowerOrEqual(hall_ub));
456 }
457}
458
459int AllDifferentBoundsPropagator::FindStartIndexAndCompressPath(int index) {
460 // First, walk the pointer until we find one pointing to itself.
461 int start_index = index;
462 while (true) {
463 const int next = index_to_start_index_[start_index];
464 if (start_index == next) break;
465 start_index = next;
466 }
467
468 // Second, redo the same thing and make everyone point to the representative.
469 while (true) {
470 const int next = index_to_start_index_[index];
471 if (start_index == next) break;
472 index_to_start_index_[index] = start_index;
473 index = next;
474 }
475 return start_index;
476}
477
478bool AllDifferentBoundsPropagator::PropagateLowerBounds() {
479 // Start by filling the cached bounds and sorting by increasing lb.
480 for (CachedBounds& entry : bounds_) {
481 entry.lb = integer_trail_->LowerBound(entry.expr);
482 entry.ub = integer_trail_->UpperBound(entry.expr);
483 }
484 IncrementalSort(bounds_.begin(), bounds_.end(),
485 [](CachedBounds a, CachedBounds b) { return a.lb < b.lb; });
486
487 // We will split the affine epressions in vars sorted by lb in contiguous
488 // subset with index of the form [start, start + num_in_window).
489 int start = 0;
490 int num_in_window = 1;
491
492 // Minimum lower bound in the current window.
493 IntegerValue min_lb = bounds_.front().lb;
494
495 const int size = bounds_.size();
496 for (int i = 1; i < size; ++i) {
497 const IntegerValue lb = bounds_[i].lb;
498
499 // If the lower bounds of all the other variables is greater, then it can
500 // never fall into a potential hall interval formed by the variable in the
501 // current window, so we can split the problem into independent parts.
502 if (lb <= min_lb + IntegerValue(num_in_window - 1)) {
503 ++num_in_window;
504 continue;
505 }
506
507 // Process the current window.
508 if (num_in_window > 1) {
509 absl::Span<CachedBounds> window(&bounds_[start], num_in_window);
510 if (!PropagateLowerBoundsInternal(min_lb, window)) {
511 return false;
512 }
513 }
514
515 // Start of the next window.
516 start = i;
517 num_in_window = 1;
518 min_lb = lb;
519 }
520
521 // Take care of the last window.
522 if (num_in_window > 1) {
523 absl::Span<CachedBounds> window(&bounds_[start], num_in_window);
524 return PropagateLowerBoundsInternal(min_lb, window);
525 }
526
527 return true;
528}
529
530bool AllDifferentBoundsPropagator::PropagateLowerBoundsInternal(
531 IntegerValue min_lb, absl::Span<CachedBounds> bounds) {
532 hall_starts_.clear();
533 hall_ends_.clear();
534
535 // All cached lb in bounds will be in [min_lb, min_lb + bounds_.size()).
536 // Make sure we change our base_ so that GetIndex() fit in our buffers.
537 base_ = min_lb - IntegerValue(1);
538
539 index_is_present_.ResetAllToFalse();
540
541 // Sort bounds by increasing ub.
542 std::sort(bounds.begin(), bounds.end(),
543 [](CachedBounds a, CachedBounds b) { return a.ub < b.ub; });
544 for (const CachedBounds entry : bounds) {
545 const AffineExpression expr = entry.expr;
546
547 // Note that it is important to use the cache to make sure GetIndex() is
548 // not out of bound in case integer_trail_->LowerBound() changed when we
549 // pushed something.
550 const IntegerValue lb = entry.lb;
551 const int lb_index = GetIndex(lb);
552 const bool value_is_covered = index_is_present_[lb_index];
553
554 // Check if lb is in an Hall interval, and push it if this is the case.
555 if (value_is_covered) {
556 const int hall_index =
557 std::lower_bound(hall_ends_.begin(), hall_ends_.end(), lb) -
558 hall_ends_.begin();
559 if (hall_index < hall_ends_.size() && hall_starts_[hall_index] <= lb) {
560 const IntegerValue hs = hall_starts_[hall_index];
561 const IntegerValue he = hall_ends_[hall_index];
562 FillHallReason(hs, he);
563 integer_reason_.push_back(expr.GreaterOrEqual(hs));
564 if (!integer_trail_->SafeEnqueue(expr.GreaterOrEqual(he + 1),
565 integer_reason_)) {
566 return false;
567 }
568 }
569 }
570
571 // Update our internal representation of the non-consecutive intervals.
572 //
573 // If lb is not used, we add a node there, otherwise we add it to the
574 // right of the interval that contains lb. In both cases, if there is an
575 // interval to the left (resp. right) we merge them.
576 int new_index = lb_index;
577 int start_index = lb_index;
578 int end_index = lb_index;
579 if (value_is_covered) {
580 start_index = FindStartIndexAndCompressPath(new_index);
581 new_index = index_to_end_index_[start_index] + 1;
582 end_index = new_index;
583 } else {
584 if (index_is_present_[new_index - 1]) {
585 start_index = FindStartIndexAndCompressPath(new_index - 1);
586 }
587 }
588 if (index_is_present_[new_index + 1]) {
589 end_index = index_to_end_index_[new_index + 1];
590 index_to_start_index_[new_index + 1] = start_index;
591 }
592
593 // Update the end of the representative.
594 index_to_end_index_[start_index] = end_index;
595
596 // This is the only place where we "add" a new node.
597 {
598 index_to_start_index_[new_index] = start_index;
599 index_to_expr_[new_index] = expr;
600 index_is_present_.Set(new_index);
601 }
602
603 // In most situation, we cannot have a conflict now, because it should have
604 // been detected before by pushing an interval lower bound past its upper
605 // bound. However, it is possible that when we push one bound, other bounds
606 // change. So if the upper bound is smaller than the current interval end,
607 // we abort so that the conflict reason will be better on the next call to
608 // the propagator.
609 const IntegerValue end = GetValue(end_index);
610 if (end > integer_trail_->UpperBound(expr)) return true;
611
612 // If we have a new Hall interval, add it to the set. Note that it will
613 // always be last, and if it overlaps some previous Hall intervals, it
614 // always overlaps them fully.
615 //
616 // Note: It is okay to not use entry.ub here if we want to fetch the last
617 // value, but in practice it shouldn't really change when we push a
618 // lower_bound and it is faster to use the cached entry.
619 if (end == entry.ub) {
620 const IntegerValue start = GetValue(start_index);
621 while (!hall_starts_.empty() && start <= hall_starts_.back()) {
622 hall_starts_.pop_back();
623 hall_ends_.pop_back();
624 }
625 DCHECK(hall_ends_.empty() || hall_ends_.back() < start);
626 hall_starts_.push_back(start);
627 hall_ends_.push_back(end);
628 }
629 }
630 return true;
631}
632
634 GenericLiteralWatcher* watcher) {
635 const int id = watcher->Register(this);
636 for (const CachedBounds& entry : bounds_) {
637 watcher->WatchAffineExpression(entry.expr, id);
638 }
640}
641
642} // namespace sat
643} // namespace operations_research
void RegisterWith(GenericLiteralWatcher *watcher)
AllDifferentBoundsPropagator(absl::Span< const AffineExpression > expressions, IntegerTrail *integer_trail)
Implementation of AllDifferentAC().
AllDifferentConstraint(absl::Span< const IntegerVariable > variables, Model *model)
void RegisterWith(GenericLiteralWatcher *watcher)
void WatchAffineExpression(AffineExpression e, int id)
Definition integer.h:1162
void WatchLiteral(Literal l, int id, int watch_index=-1)
Definition integer.h:1470
void SetPropagatorPriority(int id, int priority)
Definition integer.cc:2352
int Register(PropagatorInterface *propagator)
Registers a propagator and returns its unique ids.
Definition integer.cc:2326
const std::vector< ValueLiteralPair > & FullDomainEncoding(IntegerVariable var) const
Definition integer.cc:146
std::function< std::vector< ValueLiteralPair >(Model *)> FullyEncodeVariable(IntegerVariable var)
Definition integer.h:1701
std::function< void(Model *)> ClauseConstraint(absl::Span< const Literal > literals)
Definition sat_solver.h:944
const IntegerVariable kNoIntegerVariable(-1)
std::function< void(Model *)> AllDifferentBinary(absl::Span< const IntegerVariable > vars)
std::function< void(Model *)> AllDifferentOnBounds(absl::Span< const AffineExpression > expressions)
std::function< void(Model *)> AtMostOneConstraint(absl::Span< const Literal > literals)
Definition sat_solver.h:929
std::function< void(Model *)> AllDifferentAC(absl::Span< const IntegerVariable > variables)
In SWIG mode, we don't want anything besides these top-level includes.
ClosedInterval::Iterator end(ClosedInterval interval)
void IncrementalSort(int max_comparisons, Iterator begin, Iterator end, Compare comp=Compare{}, bool is_stable=false)
Definition sort.h:46
void FindStronglyConnectedComponents(NodeIndex num_nodes, const Graph &graph, SccOutput *components)
Simple wrapper function for most usage.
IntegerLiteral GreaterOrEqual(IntegerValue bound) const
var * coeff + constant >= bound.
IntegerLiteral LowerOrEqual(IntegerValue bound) const
var * coeff + constant <= bound.