C++ Reference

C++ Reference: CP-SAT

cp_model.h
Go to the documentation of this file.
1 // Copyright 2010-2018 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 
38 #ifndef OR_TOOLS_SAT_CP_MODEL_H_
39 #define OR_TOOLS_SAT_CP_MODEL_H_
40 
41 #include <string>
42 
43 #include "absl/container/flat_hash_map.h"
44 #include "absl/types/span.h"
47 #include "ortools/sat/cp_model_utils.h"
48 #include "ortools/sat/model.h"
49 #include "ortools/sat/sat_parameters.pb.h"
51 
53 namespace sat {
54 
55 class CpModelBuilder;
56 class LinearExpr;
57 
66 class BoolVar {
67  public:
68  BoolVar();
69 
71  BoolVar WithName(const std::string& name);
72 
74  const std::string& Name() const { return Proto().name(); }
75 
77  BoolVar Not() const { return BoolVar(NegatedRef(index_), cp_model_); }
78 
80  bool operator==(const BoolVar& other) const {
81  return other.cp_model_ == cp_model_ && other.index_ == index_;
82  }
83 
85  bool operator!=(const BoolVar& other) const {
86  return other.cp_model_ != cp_model_ || other.index_ != index_;
87  }
88 
90  std::string DebugString() const;
91 
93  const IntegerVariableProto& Proto() const {
94  return cp_model_->variables(index_);
95  }
96 
99  return cp_model_->mutable_variables(index_);
100  }
101 
108  int index() const { return index_; }
109 
110  private:
111  friend class CircuitConstraint;
112  friend class Constraint;
113  friend class CpModelBuilder;
114  friend class IntVar;
115  friend class IntervalVar;
116  friend class LinearExpr;
117  friend class ReservoirConstraint;
118  friend bool SolutionBooleanValue(const CpSolverResponse& r, BoolVar x);
119 
120  BoolVar(int index, CpModelProto* cp_model);
121 
122  CpModelProto* cp_model_ = nullptr;
123  int index_ = kint32min;
124 };
125 
126 std::ostream& operator<<(std::ostream& os, const BoolVar& var);
127 
132 BoolVar Not(BoolVar x);
133 
144 class IntVar {
145  public:
146  IntVar();
147 
149  IntVar(const BoolVar& var); // NOLINT(runtime/explicit)
150 
152  IntVar WithName(const std::string& name);
153 
155  const std::string& Name() const { return Proto().name(); }
156 
158  bool operator==(const IntVar& other) const {
159  return other.cp_model_ == cp_model_ && other.index_ == index_;
160  }
161 
163  bool operator!=(const IntVar& other) const {
164  return other.cp_model_ != cp_model_ || other.index_ != index_;
165  }
166 
168  std::string DebugString() const;
169 
171  const IntegerVariableProto& Proto() const {
172  return cp_model_->variables(index_);
173  }
174 
177  return cp_model_->mutable_variables(index_);
178  }
179 
181  int index() const { return index_; }
182 
183  private:
184  friend class CpModelBuilder;
185  friend class CumulativeConstraint;
186  friend class LinearExpr;
187  friend class IntervalVar;
188  friend class ReservoirConstraint;
189  friend int64 SolutionIntegerValue(const CpSolverResponse& r,
190  const LinearExpr& expr);
191  friend int64 SolutionIntegerMin(const CpSolverResponse& r, IntVar x);
192  friend int64 SolutionIntegerMax(const CpSolverResponse& r, IntVar x);
193 
194  IntVar(int index, CpModelProto* cp_model);
195 
196  CpModelProto* cp_model_ = nullptr;
197  int index_ = kint32min;
198 };
199 
200 std::ostream& operator<<(std::ostream& os, const IntVar& var);
201 
237 class LinearExpr {
238  public:
239  LinearExpr();
240 
246  LinearExpr(BoolVar var); // NOLINT(runtime/explicit)
247 
249  LinearExpr(IntVar var); // NOLINT(runtime/explicit)
250 
252  LinearExpr(int64 constant); // NOLINT(runtime/explicit)
253 
255  LinearExpr& AddConstant(int64 value);
256 
258  void AddVar(IntVar var);
259 
261  void AddTerm(IntVar var, int64 coeff);
262 
264  static LinearExpr Sum(absl::Span<const IntVar> vars);
265 
267  static LinearExpr ScalProd(absl::Span<const IntVar> vars,
268  absl::Span<const int64> coeffs);
269 
271  static LinearExpr BooleanSum(absl::Span<const BoolVar> vars);
272 
274  static LinearExpr BooleanScalProd(absl::Span<const BoolVar> vars,
275  absl::Span<const int64> coeffs);
277  static LinearExpr Term(IntVar var, int64 coefficient);
278 
280  const std::vector<IntVar>& variables() const { return variables_; }
281 
283  const std::vector<int64>& coefficients() const { return coefficients_; }
284 
286  int64 constant() const { return constant_; }
287 
288  // TODO(user): LinearExpr.DebugString() and operator<<.
289 
290  private:
291  std::vector<IntVar> variables_;
292  std::vector<int64> coefficients_;
293  int64 constant_ = 0;
294 };
295 
315 class IntervalVar {
316  public:
318  IntervalVar();
319 
321  IntervalVar WithName(const std::string& name);
322 
324  std::string Name() const;
325 
327  IntVar StartVar() const;
328 
330  IntVar SizeVar() const;
331 
333  IntVar EndVar() const;
334 
340  BoolVar PresenceBoolVar() const;
341 
343  bool operator==(const IntervalVar& other) const {
344  return other.cp_model_ == cp_model_ && other.index_ == index_;
345  }
346 
348  bool operator!=(const IntervalVar& other) const {
349  return other.cp_model_ != cp_model_ || other.index_ != index_;
350  }
351 
353  std::string DebugString() const;
354 
357  return cp_model_->constraints(index_).interval();
358  }
359 
362  return cp_model_->mutable_constraints(index_)->mutable_interval();
363  }
364 
366  int index() const { return index_; }
367 
368  private:
369  friend class CpModelBuilder;
370  friend class CumulativeConstraint;
371  friend class NoOverlap2DConstraint;
372  friend std::ostream& operator<<(std::ostream& os, const IntervalVar& var);
373 
374  IntervalVar(int index, CpModelProto* cp_model);
375 
376  CpModelProto* cp_model_ = nullptr;
377  int index_ = kint32min;
378 };
379 
380 std::ostream& operator<<(std::ostream& os, const IntervalVar& var);
381 
391 class Constraint {
392  public:
410  Constraint OnlyEnforceIf(absl::Span<const BoolVar> literals);
411 
414 
416  Constraint WithName(const std::string& name);
417 
419  const std::string& Name() const;
420 
422  const ConstraintProto& Proto() const { return *proto_; }
423 
425  ConstraintProto* MutableProto() const { return proto_; }
426 
427  protected:
428  friend class CpModelBuilder;
429 
430  explicit Constraint(ConstraintProto* proto);
431 
433 };
434 
441  public:
449  void AddArc(int tail, int head, BoolVar literal);
450 
451  private:
452  friend class CpModelBuilder;
453 
455 };
456 
463 class TableConstraint : public Constraint {
464  public:
466  void AddTuple(absl::Span<const int64> tuple);
467 
468  private:
469  friend class CpModelBuilder;
470 
472 };
473 
481  public:
487  void AddEvent(IntVar time, int64 demand);
488 
495  void AddOptionalEvent(IntVar time, int64 demand, BoolVar is_active);
496 
497  private:
498  friend class CpModelBuilder;
499 
501 
502  CpModelBuilder* builder_;
503 };
504 
512  public:
514  void AddTransition(int tail, int head, int64 transition_label);
515 
516  private:
517  friend class CpModelBuilder;
518 
520 };
521 
529  public:
531  void AddRectangle(IntervalVar x_coordinate, IntervalVar y_coordinate);
532 
533  private:
534  friend class CpModelBuilder;
535 
537 };
538 
546  public:
548  void AddDemand(IntervalVar interval, IntVar demand);
549 
550  private:
551  friend class CpModelBuilder;
552 
554 
555  CpModelBuilder* builder_;
556 };
557 
566  public:
568  IntVar NewIntVar(const Domain& domain);
569 
572 
574  IntVar NewConstant(int64 value);
575 
577  BoolVar TrueVar();
578 
580  BoolVar FalseVar();
581 
583  IntervalVar NewIntervalVar(IntVar start, IntVar size, IntVar end);
584 
587  BoolVar presence);
588 
590  Constraint AddBoolOr(absl::Span<const BoolVar> literals);
591 
593  Constraint AddBoolAnd(absl::Span<const BoolVar> literals);
594 
596  Constraint AddBoolXor(absl::Span<const BoolVar> literals);
597 
600  return AddBoolOr({a.Not(), b});
601  }
602 
604  Constraint AddEquality(const LinearExpr& left, const LinearExpr& right);
605 
607  Constraint AddGreaterOrEqual(const LinearExpr& left, const LinearExpr& right);
608 
610  Constraint AddGreaterThan(const LinearExpr& left, const LinearExpr& right);
611 
613  Constraint AddLessOrEqual(const LinearExpr& left, const LinearExpr& right);
614 
616  Constraint AddLessThan(const LinearExpr& left, const LinearExpr& right);
617 
619  Constraint AddLinearConstraint(const LinearExpr& expr, const Domain& domain);
620 
622  Constraint AddNotEqual(const LinearExpr& left, const LinearExpr& right);
623 
625  Constraint AddAllDifferent(absl::Span<const IntVar> vars);
626 
629  absl::Span<const IntVar> variables,
630  IntVar target);
631 
633  Constraint AddElement(IntVar index, absl::Span<const int64> values,
634  IntVar target);
635 
652 
664  TableConstraint AddAllowedAssignments(absl::Span<const IntVar> vars);
665 
676  TableConstraint AddForbiddenAssignments(absl::Span<const IntVar> vars);
677 
683  Constraint AddInverseConstraint(absl::Span<const IntVar> variables,
684  absl::Span<const IntVar> inverse_variables);
685 
704  ReservoirConstraint AddReservoirConstraint(int64 min_level, int64 max_level);
705 
734  absl::Span<const IntVar> transition_variables, int starting_state,
735  absl::Span<const int> final_states);
736 
738  Constraint AddMinEquality(IntVar target, absl::Span<const IntVar> vars);
739 
741  Constraint AddMaxEquality(IntVar target, absl::Span<const IntVar> vars);
742 
744  Constraint AddDivisionEquality(IntVar target, IntVar numerator,
745  IntVar denominator);
746 
748  Constraint AddAbsEquality(IntVar target, IntVar var);
749 
751  Constraint AddModuloEquality(IntVar target, IntVar var, IntVar mod);
752 
754  Constraint AddProductEquality(IntVar target, absl::Span<const IntVar> vars);
755 
760  Constraint AddNoOverlap(absl::Span<const IntervalVar> vars);
761 
766 
773 
775  void Minimize(const LinearExpr& expr);
776 
778  void Maximize(const LinearExpr& expr);
779 
787  void ScaleObjectiveBy(double scaling);
788 
790  void AddDecisionStrategy(
791  absl::Span<const IntVar> variables,
794 
796  void AddDecisionStrategy(
797  absl::Span<const BoolVar> variables,
800 
801  // TODO(user) : add MapDomain?
802 
803  const CpModelProto& Build() const { return Proto(); }
804 
805  const CpModelProto& Proto() const { return cp_model_; }
806  CpModelProto* MutableProto() { return &cp_model_; }
807 
808  private:
809  friend class CumulativeConstraint;
810  friend class ReservoirConstraint;
811 
812  // Returns a (cached) integer variable index with a constant value.
813  int IndexFromConstant(int64 value);
814 
815  // Returns a valid integer index from a BoolVar index.
816  // If the input index is a positive, it returns this index.
817  // If the input index is negative, it creates a cached IntVar equal to
818  // 1 - BoolVar(PositiveRef(index)), and returns the index of this new
819  // variable.
820  int GetOrCreateIntegerIndex(int index);
821 
822  void FillLinearTerms(const LinearExpr& left, const LinearExpr& right,
823  LinearConstraintProto* proto);
824 
825  CpModelProto cp_model_;
826  absl::flat_hash_map<int64, int> constant_to_index_map_;
827  absl::flat_hash_map<int, int> bool_to_integer_index_map_;
828 };
829 
831 int64 SolutionIntegerValue(const CpSolverResponse& r, const LinearExpr& expr);
832 
834 int64 SolutionIntegerMin(const CpSolverResponse& r, IntVar x);
835 
837 int64 SolutionIntegerMax(const CpSolverResponse& r, IntVar x);
838 
841 
842 } // namespace sat
843 } // namespace operations_research
844 
845 #endif // OR_TOOLS_SAT_CP_MODEL_H_
Constraint AddAllDifferent(absl::Span< const IntVar > vars)
this constraint forces all variables to have different values.
std::string DebugString() const
Returns a debug std::string.
Constraint AddAbsEquality(IntVar target, IntVar var)
Adds target == abs(var).
const CpModelProto & Build() const
Definition: cp_model.h:803
const std::vector< int64 > & coefficients() const
Returns the vector of coefficients.
Definition: cp_model.h:283
ConstraintProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:425
NoOverlap2DConstraint AddNoOverlap2D()
The no_overlap_2d constraint prevents a set of boxes from overlapping.
IntVar EndVar() const
Returns the end variable.
std::ostream & operator<<(std::ostream &os, const BoolVar &var)
const std::vector< IntVar > & variables() const
Returns the vector of variables.
Definition: cp_model.h:280
TableConstraint AddForbiddenAssignments(absl::Span< const IntVar > vars)
Adds an forbidden assignments constraint.
IntVar NewConstant(int64 value)
Creates a constant variable.
AutomatonConstraint AddAutomaton(absl::Span< const IntVar > transition_variables, int starting_state, absl::Span< const int > final_states)
An automaton constraint/.
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.
void AddTerm(IntVar var, int64 coeff)
Adds a term (var * coeff) to the linear expression.
IntervalVar NewOptionalIntervalVar(IntVar start, IntVar size, IntVar end, BoolVar presence)
Creates an optional interval variable.
IntVar NewIntVar(const Domain &domain)
Creates an integer variable with the given domain.
int64 constant() const
Returns the constant term.
Definition: cp_model.h:286
Constraint AddModuloEquality(IntVar target, IntVar var, IntVar mod)
Adds target = var % mod.
IntervalVar NewIntervalVar(IntVar start, IntVar size, IntVar end)
Creates an interval variable.
int64 SolutionIntegerMin(const CpSolverResponse &r, IntVar x)
Returns the min of an integer variable in a solution.
Wrapper class around the cp_model proto.
Definition: cp_model.h:565
ReservoirConstraint AddReservoirConstraint(int64 min_level, int64 max_level)
Adds a reservoir constraint with optional refill/emptying events.
bool operator!=(const BoolVar &other) const
Dis-Equality test.
Definition: cp_model.h:85
void AddOptionalEvent(IntVar time, int64 demand, BoolVar is_active)
Adds a optional event.
IntVar WithName(const std::string &name)
Sets the name of the variable.
Specialized reservoir constraint.
Definition: cp_model.h:480
BoolVar TrueVar()
Creates an always true Boolean variable.
Constraint AddDivisionEquality(IntVar target, IntVar numerator, IntVar denominator)
Adds target = num / denom (integer division rounded towards 0).
void AddRectangle(IntervalVar x_coordinate, IntervalVar y_coordinate)
Adds a rectangle (parallel to the axis) to the constraint.
const std::string & Name() const
Returns the name of the variable.
Definition: cp_model.h:74
Constraint(ConstraintProto *proto)
void AddDemand(IntervalVar interval, IntVar demand)
Adds a pair (interval, demand) to the constraint.
Constraint AddLessOrEqual(const LinearExpr &left, const LinearExpr &right)
Adds left <= right.
A dedicated container for linear expressions.
Definition: cp_model.h:237
const ConstraintProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:422
int64 SolutionIntegerMax(const CpSolverResponse &r, IntVar x)
Returns the max of an integer variable in a solution.
const IntegerVariableProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:171
BoolVar PresenceBoolVar() const
Returns a BoolVar indicating the presence of this interval.
friend bool SolutionBooleanValue(const CpSolverResponse &r, BoolVar x)
Evaluates the value of a Boolean literal in a solver response.
BoolVar FalseVar()
Creates an always false Boolean variable.
static LinearExpr BooleanSum(absl::Span< const BoolVar > vars)
Constructs the sum of a list of Booleans.
Represents a Interval variable.
Definition: cp_model.h:315
bool operator!=(const IntervalVar &other) const
Difference test with another interval variable.
Definition: cp_model.h:348
BoolVar WithName(const std::string &name)
Sets the name of the variable.
const std::string & Name() const
Returns the name of the variable (or the empty std::string if not set).
Definition: cp_model.h:155
Specialized cumulative constraint.
Definition: cp_model.h:545
static LinearExpr Term(IntVar var, int64 coefficient)
Construncts var * coefficient.
IntVar SizeVar() const
Returns the size variable.
void AddEvent(IntVar time, int64 demand)
Adds a mandatory event.
A Boolean variable.
Definition: cp_model.h:66
Specialized assignment constraint.
Definition: cp_model.h:463
BoolVar Not(BoolVar x)
A convenient wrapper so we can write Not(x) instead of x.Not() which is sometimes clearer.
Constraint AddElement(IntVar index, absl::Span< const int64 > values, IntVar target)
Adds the element constraint: values[index] == target.
const IntervalConstraintProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:356
Constraint AddLessThan(const LinearExpr &left, const LinearExpr &right)
Adds left < right.
Constraint AddBoolXor(absl::Span< const BoolVar > literals)
Adds the constraint that a odd number of literal is true.
int index() const
Returns the index of the variable in the model.
Definition: cp_model.h:108
::operations_research::sat::IntegerVariableProto * mutable_variables(int index)
Definition: cp_model.pb.h:7298
IntVar StartVar() const
Returns the start variable.
void Maximize(const LinearExpr &expr)
Adds a linear maximization objective.
void AddTuple(absl::Span< const int64 > tuple)
Adds a tuple of possible values to the constraint.
Constraint AddGreaterOrEqual(const LinearExpr &left, const LinearExpr &right)
Adds left >= right.
friend int64 SolutionIntegerMax(const CpSolverResponse &r, IntVar x)
Returns the max of an integer variable in a solution.
TableConstraint AddAllowedAssignments(absl::Span< const IntVar > vars)
Adds an allowed assignments constraint.
Constraint AddInverseConstraint(absl::Span< const IntVar > variables, absl::Span< const IntVar > inverse_variables)
An inverse constraint.
void ScaleObjectiveBy(double scaling)
Sets scaling of the objective.
const CpModelProto & Proto() const
Definition: cp_model.h:805
IntegerVariableProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:176
Specialized no_overlap2D constraint.
Definition: cp_model.h:528
Constraint OnlyEnforceIf(absl::Span< const BoolVar > literals)
The constraint will be enforced iff all literals listed here are true.
Constraint AddBoolAnd(absl::Span< const BoolVar > literals)
Adds the constraint that all literals must be true.
Constraint AddNotEqual(const LinearExpr &left, const LinearExpr &right)
Adds left != right.
bool operator==(const BoolVar &other) const
Equality test with another boolvar.
Definition: cp_model.h:80
friend int64 SolutionIntegerMin(const CpSolverResponse &r, IntVar x)
Returns the min of an integer variable in a solution.
Constraint WithName(const std::string &name)
Sets the name of the constraint.
::operations_research::sat::IntervalConstraintProto * mutable_interval()
Definition: cp_model.pb.h:6769
static LinearExpr Sum(absl::Span< const IntVar > vars)
Constructs the sum of a list of variables.
std::string DebugString() const
Debug std::string.
bool SolutionBooleanValue(const CpSolverResponse &r, BoolVar x)
Evaluates the value of a Boolean literal in a solver response.
const IntegerVariableProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:93
Constraint AddGreaterThan(const LinearExpr &left, const LinearExpr &right)
Adds left > right.
BoolVar Not() const
Returns the logical negation of the current Boolean variable.
Definition: cp_model.h:77
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
Returns the name of the constraint (or the empty std::string if not set).
static LinearExpr ScalProd(absl::Span< const IntVar > vars, absl::Span< const int64 > coeffs)
Constructs the scalar product of variables and coefficients.
Constraint AddLinearConstraint(const LinearExpr &expr, const Domain &domain)
Adds expr in domain.
int64 SolutionIntegerValue(const CpSolverResponse &r, const LinearExpr &expr)
Evaluates the value of an linear expression in a solver response.
void AddTransition(int tail, int head, int64 transition_label)
Adds a transitions to the automaton.
bool operator==(const IntervalVar &other) const
Equality test with another interval variable.
Definition: cp_model.h:343
We call "domain" any subset of Int64 = [kint64min, kint64max].
friend std::ostream & operator<<(std::ostream &os, const IntervalVar &var)
int index() const
Returns the index of the interval constraint in the model.
Definition: cp_model.h:366
const ::operations_research::sat::IntegerVariableProto & variables(int index) const
Definition: cp_model.pb.h:7307
Constraint AddBoolOr(absl::Span< const BoolVar > literals)
Adds the constraint that at least one of the literals must be true.
int index() const
Returns the index of the variable in the model.
Definition: cp_model.h:181
Constraint AddMaxEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == max(vars).
void Minimize(const LinearExpr &expr)
Adds a linear minimization objective.
CircuitConstraint AddCircuitConstraint()
Adds a circuit constraint.
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.
IntegerVariableProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:98
std::string Name() const
Returns the name of the interval (or the empty std::string if not set).
Specialized circuit constraint.
Definition: cp_model.h:440
void AddVar(IntVar var)
Adds a single integer variable to the linear expression.
Constraint AddNoOverlap(absl::Span< const IntervalVar > vars)
Adds a no-overlap constraint that ensures that all present intervals do not overlap in time.
bool operator!=(const IntVar &other) const
Difference test with anpther IntVar.
Definition: cp_model.h:163
An integer variable.
Definition: cp_model.h:144
::operations_research::sat::ConstraintProto * mutable_constraints(int index)
Definition: cp_model.pb.h:7328
Constraint AddMinEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == min(vars).
const ::operations_research::sat::ConstraintProto & constraints(int index) const
Definition: cp_model.pb.h:7337
LinearExpr & AddConstant(int64 value)
Adds a constant value to the linear expression.
IntervalConstraintProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:361
const ::operations_research::sat::IntervalConstraintProto & interval() const
Definition: cp_model.pb.h:6763
CumulativeConstraint AddCumulative(IntVar capacity)
The cumulative constraint.
bool operator==(const IntVar &other) const
Equality test with another IntVar.
Definition: cp_model.h:158
std::string DebugString() const
Returns a debug std::string.
void AddArc(int tail, int head, BoolVar literal)
Add an arc to the circuit.
Constraint AddProductEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == prod(vars).
Specialized automaton constraint.
Definition: cp_model.h:511
Constraint AddImplication(BoolVar a, BoolVar b)
Adds a => b.
Definition: cp_model.h:599
static LinearExpr BooleanScalProd(absl::Span< const BoolVar > vars, absl::Span< const int64 > coeffs)
Constructs the scalar product of Booleans and coefficients.
BoolVar NewBoolVar()
Creates a Boolean variable.
IntervalVar WithName(const std::string &name)
Sets the name of the variable.