34 #ifndef OR_TOOLS_SAT_CP_MODEL_H_ 35 #define OR_TOOLS_SAT_CP_MODEL_H_ 39 #include "absl/container/flat_hash_map.h" 40 #include "absl/types/span.h" 43 #include "ortools/sat/cp_model_utils.h" 72 return other.cp_model_ == cp_model_ && other.index_ == index_;
76 return other.cp_model_ != cp_model_ || other.index_ != index_;
93 int index()
const {
return index_; }
108 int index_ = kint32min;
137 return other.cp_model_ == cp_model_ && other.index_ == index_;
141 return other.cp_model_ != cp_model_ || other.index_ != index_;
157 int index()
const {
return index_; }
173 int index_ = kint32min;
236 absl::Span<const int64> coeffs);
243 absl::Span<const int64> coeffs);
246 const std::vector<IntVar>&
variables()
const {
return variables_; }
247 const std::vector<int64>&
coefficients()
const {
return coefficients_; }
253 std::vector<IntVar> variables_;
254 std::vector<int64> coefficients_;
283 std::string
Name()
const;
299 return other.cp_model_ == cp_model_ && other.index_ == index_;
303 return other.cp_model_ != cp_model_ || other.index_ != index_;
319 int index()
const {
return index_; }
330 int index_ = kint32min;
364 const std::string&
Name()
const;
399 void AddTuple(absl::Span<const int64> tuple);
430 void AddTransition(
int tail,
int head, int64 transition_label);
537 absl::Span<const IntVar> variables,
583 absl::Span<const IntVar> inverse_variables);
626 absl::Span<const IntVar> transition_variables,
int starting_state,
627 absl::Span<const int> final_states);
672 absl::Span<const IntVar> variables,
678 absl::Span<const BoolVar> variables,
694 int IndexFromConstant(int64 value);
701 int GetOrCreateIntegerIndex(
int index);
707 absl::flat_hash_map<int64, int> constant_to_index_map_;
708 absl::flat_hash_map<int, int> bool_to_integer_index_map_;
727 #endif // OR_TOOLS_SAT_CP_MODEL_H_ ReservoirConstraint AddReservoirConstraint(int64 min_level, int64 max_level)
Adds a reservoir constraint with optional refill/emptying events.
Constraint AddGreaterThan(const LinearExpr &left, const LinearExpr &right)
Adds left > right.
IntVar NewIntVar(const Domain &domain)
Creates an integer variable with the given domain.
Constraint AddBoolOr(absl::Span< const BoolVar > literals)
Adds the constraint that at least one of the literals must be true.
void Maximize(const LinearExpr &expr)
Adds a linear maximization objective.
void AddTransition(int tail, int head, int64 transition_label)
bool operator==(const BoolVar &other) const
std::ostream & operator<<(std::ostream &os, const BoolVar &var)
Constraint WithName(const std::string &name)
Sets the name of the constraint.
const std::vector< IntVar > & variables() const
Useful for testing.
const ConstraintProto & Proto() const
Useful for testing.
const std::string & name() const
void AddDemand(IntervalVar interval, IntVar demand)
void AddOptionalEvent(IntVar time, int64 demand, BoolVar is_active)
Constraint AddImplication(BoolVar a, BoolVar b)
Adds a => b.
ConstraintProto * MutableProto() const
Useful for model edition.
void AddRectangle(IntervalVar x_coordinate, IntervalVar y_coordinate)
Constraint AddLinearConstraint(const LinearExpr &expr, const Domain &domain)
Adds expr in domain.
IntervalVar()
Default ctor.
Constraint(ConstraintProto *proto)
Constraint AddMinEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == min(vars).
IntVar StartVar() const
Returns the start variable.
int64 SolutionIntegerMin(const CpSolverResponse &r, IntVar x)
Returns the min of an integer variable in a solution.
Constraint AddModuloEquality(IntVar target, IntVar var, IntVar mod)
Adds target = var % mod.
Wrapper class around the cp_model proto.
IntVar EndVar() const
Returns the end variable.
IntervalConstraintProto * MutableProto() const
Useful for model edition.
Constraint AddInverseConstraint(absl::Span< const IntVar > variables, absl::Span< const IntVar > inverse_variables)
An inverse constraint enforces that if 'variables[i]' is assigned a value 'j', then inverse_variables...
Specialized reservoir constraint.
const CpModelProto & Proto() const
A dedicated container for linear expressions.
int64 SolutionIntegerMax(const CpSolverResponse &r, IntVar x)
Returns the max of an integer variable in a solution.
void AddDecisionStrategy(absl::Span< const IntVar > variables, DecisionStrategyProto::VariableSelectionStrategy var_strategy, DecisionStrategyProto::DomainReductionStrategy domain_strategy)
Adds a decision strategy on a list of integer variables.
static LinearExpr Sum(absl::Span< const IntVar > vars)
Constructs the sum of a list of variables.
CircuitConstraint AddCircuitConstraint()
Adds a circuit constraint.
Constraint AddBoolAnd(absl::Span< const BoolVar > literals)
Adds the constraint that all literals must be true.
BoolVar NewBoolVar()
Creates a Boolean variable.
BoolVar FalseVar()
Creates an always false Boolean variable.
friend bool SolutionBooleanValue(const CpSolverResponse &r, BoolVar x)
Returns the value of a Boolean literal (a Boolean variable or its negation) in a solver response.
Constraint AddMaxEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == max(vars).
CumulativeConstraint AddCumulative(IntVar capacity)
The cumulative constraint ensures that for any integer point, the sum of the demands of the intervals...
Constraint AddDivisionEquality(IntVar target, IntVar numerator, IntVar denominator)
Adds target = num / denom (integer division rounded towards 0).
Represents a Interval variable.
const IntervalConstraintProto & Proto() const
Useful for testing.
IntVar WithName(const std::string &name)
Sets the name of the variable.
BoolVar WithName(const std::string &name)
Sets the name of the variable.
void AddEvent(IntVar time, int64 demand)
Constraint AddGreaterOrEqual(const LinearExpr &left, const LinearExpr &right)
Adds left >= right.
BoolVar PresenceBoolVar() const
Returns a BoolVar indicating the presence of this interval.
DecisionStrategyProto_DomainReductionStrategy
IntervalVar NewIntervalVar(IntVar start, IntVar size, IntVar end)
Creates an interval variable.
IntervalVar NewOptionalIntervalVar(IntVar start, IntVar size, IntVar end, BoolVar presence)
Creates an optional interval variable.
int index() const
Returns the index of the interval constraint in the model.
Specialized cumulative constraint.
static LinearExpr BooleanScalProd(absl::Span< const BoolVar > vars, absl::Span< const int64 > coeffs)
Constructs the scalar product of Booleans and coefficients.
Constraint AddElement(IntVar index, absl::Span< const int64 > values, IntVar target)
Adds the element constraint: values[index] == target.
DecisionStrategyProto_VariableSelectionStrategy
const ::operations_research::sat::ConstraintProto & constraints(int index) const
Constraint AddAbsEquality(IntVar target, IntVar var)
Adds target == abs(var).
Constraint AddAllDifferent(absl::Span< const IntVar > vars)
this constraint forces all variables to have different values.
TableConstraint AddForbiddenAssignments(absl::Span< const IntVar > vars)
Adds an forbidden assignments constraint.
Specialized assignment constraint.
BoolVar Not(BoolVar x)
A convenient wrapper so we can write Not(x) instead of x.Not() which is sometimes clearer.
bool operator!=(const BoolVar &other) const
bool operator!=(const IntervalVar &other) const
void ScaleObjectiveBy(double scaling)
Sets scaling of the objective.
const CpModelProto & Build() const
friend int64 SolutionIntegerMax(const CpSolverResponse &r, IntVar x)
Returns the max of an integer variable in a solution.
Constraint AddLessThan(const LinearExpr &left, const LinearExpr &right)
Adds left < right.
std::string DebugString() const
const std::string & Name() const
::operations_research::sat::IntegerVariableProto * mutable_variables(int index)
bool operator!=(const IntVar &other) const
Specialized no_overlap2D constraint.
bool operator==(const IntervalVar &other) const
const std::string & Name() const
IntVar NewConstant(int64 value)
Creates a constant variable.
friend int64 SolutionIntegerMin(const CpSolverResponse &r, IntVar x)
Returns the min of an integer variable in a solution.
bool SolutionBooleanValue(const CpSolverResponse &r, BoolVar x)
Returns the value of a Boolean literal (a Boolean variable or its negation) in a solver response.
Constraint AddBoolXor(absl::Span< const BoolVar > literals)
Adds the constraint that a odd number of literal is true.
friend int64 SolutionIntegerValue(const CpSolverResponse &r, const LinearExpr &expr)
Evaluates the value of an linear expression in a solver response.
const std::string & Name() const
std::string DebugString() const
Constraint AddProductEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == prod(vars).
TableConstraint AddAllowedAssignments(absl::Span< const IntVar > vars)
Adds an allowed assignments constraint.
static LinearExpr ScalProd(absl::Span< const IntVar > vars, absl::Span< const int64 > coeffs)
Constructs the scalar product of variables and coefficients.
int64 SolutionIntegerValue(const CpSolverResponse &r, const LinearExpr &expr)
Evaluates the value of an linear expression in a solver response.
const IntegerVariableProto & Proto() const
Useful for testing.
void Minimize(const LinearExpr &expr)
Adds a linear minimization objective.
void AddTerm(IntVar var, int64 coeff)
Adds a term (var * coeff) to the linear expression.
We call "domain" any subset of Int64 = [kint64min, kint64max].
friend std::ostream & operator<<(std::ostream &os, const IntervalVar &var)
::operations_research::sat::ConstraintProto * mutable_constraints(int index)
IntVar SizeVar() const
Returns the size variable.
CpModelProto * MutableProto()
LinearExpr & AddConstant(int64 value)
Adds a constant value to the linear expression.
void AddTuple(absl::Span< const int64 > tuple)
IntegerVariableProto * MutableProto() const
Useful for model edition.
AutomatonConstraint AddAutomaton(absl::Span< const IntVar > transition_variables, int starting_state, absl::Span< const int > final_states)
An automaton constraint takes a list of variables (of size n), an initial state, a set of final state...
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
NoOverlap2DConstraint AddNoOverlap2D()
The no_overlap_2d constraint prevents a set of boxes from overlapping.
Specialized circuit constraint.
IntervalVar WithName(const std::string &name)
Sets the name of the variable.
::operations_research::sat::IntervalConstraintProto * mutable_interval()
int index() const
Returns the index of the variable in the model.
std::string DebugString() const
const IntegerVariableProto & Proto() const
Useful for testing.
const ::operations_research::sat::IntegerVariableProto & variables(int index) const
Constraint AddNoOverlap(absl::Span< const IntervalVar > vars)
Adds a constraint than ensures that all present intervals do not overlap in time.
IntegerVariableProto * MutableProto() const
Useful for model edition.
Constraint AddVariableElement(IntVar index, absl::Span< const IntVar > variables, IntVar target)
Adds the element constraint: variables[index] == target.
Constraint AddEquality(const LinearExpr &left, const LinearExpr &right)
Adds left == right.
Constraint AddLessOrEqual(const LinearExpr &left, const LinearExpr &right)
Adds left <= right.
bool operator==(const IntVar &other) const
static LinearExpr BooleanSum(absl::Span< const BoolVar > vars)
Constructs the sum of a list of Booleans.
void AddArc(int tail, int head, BoolVar literal)
Specialized automaton constraint.
Constraint AddNotEqual(const LinearExpr &left, const LinearExpr &right)
Adds left != right.
void AddVar(IntVar var)
Adds a single integer variable to the linear expression.
const std::vector< int64 > & coefficients() const
const ::operations_research::sat::IntervalConstraintProto & interval() const
BoolVar TrueVar()
Creates an always true Boolean variable.
Constraint OnlyEnforceIf(absl::Span< const BoolVar > literals)
The constraint will be enforced iff all literals listed here are true.
int index() const
Returns the index of the variable in the model.
BoolVar Not() const
Returns the logical negation of the current Boolean variable.