14#ifndef OR_TOOLS_SAT_ALL_DIFFERENT_H_
15#define OR_TOOLS_SAT_ALL_DIFFERENT_H_
22#include "absl/container/flat_hash_map.h"
23#include "absl/log/check.h"
24#include "absl/types/span.h"
39 const std::vector<IntegerVariable>& vars);
50 const std::vector<IntegerVariable>& vars);
52 const std::vector<AffineExpression>& expressions);
65 const std::vector<IntegerVariable>& variables);
86 bool MakeAugmentingPath(
int start);
89 inline LiteralIndex VariableLiteralIndexOf(
int x, int64_t
value);
90 inline bool VariableHasPossibleValue(
int x, int64_t
value);
96 const int num_variables_;
97 const std::vector<IntegerVariable> variables_;
98 int64_t min_all_values_;
99 int64_t num_all_values_;
100 std::vector<int64_t> variable_min_value_;
101 std::vector<int64_t> variable_max_value_;
102 std::vector<std::vector<LiteralIndex>> variable_literal_index_;
108 std::vector<std::vector<int>> successor_;
109 std::vector<bool> value_visited_;
110 std::vector<bool> variable_visited_;
111 std::vector<int> value_to_variable_;
112 std::vector<int> variable_to_value_;
113 std::vector<int> prev_matching_;
114 std::vector<int> visiting_;
115 std::vector<int> variable_visited_from_;
133 std::vector<std::vector<int>> residual_graph_successors_;
134 std::vector<int> component_number_;
169 struct CachedBounds {
176 void FillHallReason(IntegerValue hall_lb, IntegerValue hall_ub);
181 bool PropagateLowerBounds();
182 bool PropagateLowerBoundsInternal(IntegerValue min_lb,
183 absl::Span<CachedBounds> bounds);
200 int FindStartIndexAndCompressPath(
int index);
202 int GetIndex(IntegerValue
value)
const {
203 DCHECK_GE(
value, base_);
204 DCHECK_LT(
value - base_, index_to_start_index_.size());
205 return (
value - base_).value();
208 IntegerValue GetValue(
int index)
const {
return base_ + IntegerValue(
index); }
210 IntegerTrail* integer_trail_;
213 std::vector<CachedBounds> bounds_;
214 std::vector<CachedBounds> negated_bounds_;
217 std::vector<IntegerValue> hall_starts_;
218 std::vector<IntegerValue> hall_ends_;
222 std::vector<int> indices_to_clear_;
223 std::vector<int> index_to_start_index_;
224 std::vector<int> index_to_end_index_;
225 std::vector<bool> index_is_present_;
226 std::vector<AffineExpression> index_to_expr_;
229 std::vector<IntegerLiteral> integer_reason_;
void RegisterWith(GenericLiteralWatcher *watcher)
AllDifferentBoundsPropagator(const AllDifferentBoundsPropagator &)=delete
This type is neither copyable nor movable.
AllDifferentBoundsPropagator & operator=(const AllDifferentBoundsPropagator &)=delete
AllDifferentBoundsPropagator(const std::vector< AffineExpression > &expressions, IntegerTrail *integer_trail)
Implementation of AllDifferentAC().
AllDifferentConstraint(std::vector< IntegerVariable > variables, IntegerEncoder *encoder, Trail *trail, IntegerTrail *integer_trail)
void RegisterWith(GenericLiteralWatcher *watcher)
Base class for CP like propagators.
std::function< void(Model *)> AllDifferentAC(const std::vector< IntegerVariable > &variables)
std::function< void(Model *)> AllDifferentBinary(const std::vector< IntegerVariable > &vars)
std::function< void(Model *)> AllDifferentOnBounds(const std::vector< AffineExpression > &expressions)
In SWIG mode, we don't want anything besides these top-level includes.