OR-Tools  8.2
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"
45 #include "ortools/sat/cp_model.pb.h"
48 #include "ortools/sat/model.h"
49 #include "ortools/sat/sat_parameters.pb.h"
51 
52 namespace operations_research {
53 namespace sat {
54 
55 class CpModelBuilder;
56 class LinearExpr;
57 class IntVar;
58 
67 class BoolVar {
68  public:
69  BoolVar();
70 
72  BoolVar WithName(const std::string& name);
73 
75  const std::string& Name() const { return Proto().name(); }
76 
78  BoolVar Not() const { return BoolVar(NegatedRef(index_), cp_model_); }
79 
81  bool operator==(const BoolVar& other) const {
82  return other.cp_model_ == cp_model_ && other.index_ == index_;
83  }
84 
86  bool operator!=(const BoolVar& other) const {
87  return other.cp_model_ != cp_model_ || other.index_ != index_;
88  }
89 
91  std::string DebugString() const;
92 
94  const IntegerVariableProto& Proto() const {
95  return cp_model_->variables(index_);
96  }
97 
99  IntegerVariableProto* MutableProto() const {
100  return cp_model_->mutable_variables(index_);
101  }
102 
109  int index() const { return index_; }
110 
111  private:
112  friend class CircuitConstraint;
113  friend class Constraint;
114  friend class CpModelBuilder;
115  friend class IntVar;
116  friend class IntervalVar;
118  friend class LinearExpr;
119  friend class ReservoirConstraint;
120  friend bool SolutionBooleanValue(const CpSolverResponse& r, BoolVar x);
121 
122  BoolVar(int index, CpModelProto* cp_model);
123 
124  CpModelProto* cp_model_ = nullptr;
125  int index_ = kint32min;
126 };
127 
128 std::ostream& operator<<(std::ostream& os, const BoolVar& var);
129 
134 BoolVar Not(BoolVar x);
135 
146 class IntVar {
147  public:
148  IntVar();
149 
151  IntVar(const BoolVar& var); // NOLINT(runtime/explicit)
152 
155  BoolVar ToBoolVar() const;
156 
158  IntVar WithName(const std::string& name);
159 
161  const std::string& Name() const { return Proto().name(); }
162 
166 
168  bool operator==(const IntVar& other) const {
169  return other.cp_model_ == cp_model_ && other.index_ == index_;
170  }
171 
173  bool operator!=(const IntVar& other) const {
174  return other.cp_model_ != cp_model_ || other.index_ != index_;
175  }
176 
178  std::string DebugString() const;
179 
181  const IntegerVariableProto& Proto() const {
182  return cp_model_->variables(index_);
183  }
184 
186  IntegerVariableProto* MutableProto() const {
187  return cp_model_->mutable_variables(index_);
188  }
189 
191  int index() const { return index_; }
192 
193  private:
194  friend class BoolVar;
195  friend class CpModelBuilder;
196  friend class CumulativeConstraint;
197  friend class LinearExpr;
198  friend class IntervalVar;
199  friend class ReservoirConstraint;
200  friend int64 SolutionIntegerValue(const CpSolverResponse& r,
201  const LinearExpr& expr);
202  friend int64 SolutionIntegerMin(const CpSolverResponse& r, IntVar x);
203  friend int64 SolutionIntegerMax(const CpSolverResponse& r, IntVar x);
204 
205  IntVar(int index, CpModelProto* cp_model);
206 
207  CpModelProto* cp_model_ = nullptr;
208  int index_ = kint32min;
209 };
210 
211 std::ostream& operator<<(std::ostream& os, const IntVar& var);
212 
248 class LinearExpr {
249  public:
250  LinearExpr();
251 
257  LinearExpr(BoolVar var); // NOLINT(runtime/explicit)
258 
260  LinearExpr(IntVar var); // NOLINT(runtime/explicit)
261 
263  LinearExpr(int64 constant); // NOLINT(runtime/explicit)
264 
267 
269  void AddVar(IntVar var);
270 
272  void AddTerm(IntVar var, int64 coeff);
273 
275  static LinearExpr Sum(absl::Span<const IntVar> vars);
276 
278  static LinearExpr ScalProd(absl::Span<const IntVar> vars,
279  absl::Span<const int64> coeffs);
280 
282  static LinearExpr BooleanSum(absl::Span<const BoolVar> vars);
283 
285  static LinearExpr BooleanScalProd(absl::Span<const BoolVar> vars,
286  absl::Span<const int64> coeffs);
289 
291  const std::vector<IntVar>& variables() const { return variables_; }
292 
294  const std::vector<int64>& coefficients() const { return coefficients_; }
295 
297  int64 constant() const { return constant_; }
298 
299  // TODO(user): LinearExpr.DebugString() and operator<<.
300 
301  private:
302  std::vector<IntVar> variables_;
303  std::vector<int64> coefficients_;
304  int64 constant_ = 0;
305 };
306 
326 class IntervalVar {
327  public:
329  IntervalVar();
330 
332  IntervalVar WithName(const std::string& name);
333 
335  std::string Name() const;
336 
338  IntVar StartVar() const;
339 
341  IntVar SizeVar() const;
342 
344  IntVar EndVar() const;
345 
351  BoolVar PresenceBoolVar() const;
352 
354  bool operator==(const IntervalVar& other) const {
355  return other.cp_model_ == cp_model_ && other.index_ == index_;
356  }
357 
359  bool operator!=(const IntervalVar& other) const {
360  return other.cp_model_ != cp_model_ || other.index_ != index_;
361  }
362 
364  std::string DebugString() const;
365 
367  const IntervalConstraintProto& Proto() const {
368  return cp_model_->constraints(index_).interval();
369  }
370 
372  IntervalConstraintProto* MutableProto() const {
373  return cp_model_->mutable_constraints(index_)->mutable_interval();
374  }
375 
377  int index() const { return index_; }
378 
379  private:
380  friend class CpModelBuilder;
381  friend class CumulativeConstraint;
382  friend class NoOverlap2DConstraint;
383  friend std::ostream& operator<<(std::ostream& os, const IntervalVar& var);
384 
385  IntervalVar(int index, CpModelProto* cp_model);
386 
387  CpModelProto* cp_model_ = nullptr;
388  int index_ = kint32min;
389 };
390 
391 std::ostream& operator<<(std::ostream& os, const IntervalVar& var);
392 
402 class Constraint {
403  public:
421  Constraint OnlyEnforceIf(absl::Span<const BoolVar> literals);
422 
425 
427  Constraint WithName(const std::string& name);
428 
430  const std::string& Name() const;
431 
433  const ConstraintProto& Proto() const { return *proto_; }
434 
436  ConstraintProto* MutableProto() const { return proto_; }
437 
438  protected:
439  friend class CpModelBuilder;
440 
441  explicit Constraint(ConstraintProto* proto);
442 
443  ConstraintProto* proto_ = nullptr;
444 };
445 
452  public:
460  void AddArc(int tail, int head, BoolVar literal);
461 
462  private:
463  friend class CpModelBuilder;
464 
466 };
467 
475  public:
483  void AddArc(int tail, int head, BoolVar literal);
484 
485  private:
486  friend class CpModelBuilder;
487 
489 };
490 
497 class TableConstraint : public Constraint {
498  public:
500  void AddTuple(absl::Span<const int64> tuple);
501 
502  private:
503  friend class CpModelBuilder;
504 
506 };
507 
515  public:
522 
529  void AddOptionalEvent(IntVar time, int64 demand, BoolVar is_active);
530 
531  private:
532  friend class CpModelBuilder;
533 
534  ReservoirConstraint(ConstraintProto* proto, CpModelBuilder* builder);
535 
536  CpModelBuilder* builder_;
537 };
538 
546  public:
548  void AddTransition(int tail, int head, int64 transition_label);
549 
550  private:
551  friend class CpModelBuilder;
552 
554 };
555 
563  public:
565  void AddRectangle(IntervalVar x_coordinate, IntervalVar y_coordinate);
566 
567  private:
568  friend class CpModelBuilder;
569 
571 };
572 
580  public:
583 
584  private:
585  friend class CpModelBuilder;
586 
587  CumulativeConstraint(ConstraintProto* proto, CpModelBuilder* builder);
588 
589  CpModelBuilder* builder_;
590 };
591 
600  public:
602  IntVar NewIntVar(const Domain& domain);
603 
606 
609 
611  BoolVar TrueVar();
612 
614  BoolVar FalseVar();
615 
617  IntervalVar NewIntervalVar(IntVar start, IntVar size, IntVar end);
618 
621  BoolVar presence);
622 
624  Constraint AddBoolOr(absl::Span<const BoolVar> literals);
625 
627  Constraint AddBoolAnd(absl::Span<const BoolVar> literals);
628 
630  Constraint AddBoolXor(absl::Span<const BoolVar> literals);
631 
634  return AddBoolOr({a.Not(), b});
635  }
636 
638  Constraint AddEquality(const LinearExpr& left, const LinearExpr& right);
639 
641  Constraint AddGreaterOrEqual(const LinearExpr& left, const LinearExpr& right);
642 
644  Constraint AddGreaterThan(const LinearExpr& left, const LinearExpr& right);
645 
647  Constraint AddLessOrEqual(const LinearExpr& left, const LinearExpr& right);
648 
650  Constraint AddLessThan(const LinearExpr& left, const LinearExpr& right);
651 
653  Constraint AddLinearConstraint(const LinearExpr& expr, const Domain& domain);
654 
656  Constraint AddNotEqual(const LinearExpr& left, const LinearExpr& right);
657 
659  Constraint AddAllDifferent(absl::Span<const IntVar> vars);
660 
663  absl::Span<const IntVar> variables,
664  IntVar target);
665 
667  Constraint AddElement(IntVar index, absl::Span<const int64> values,
668  IntVar target);
669 
687 
702 
714  TableConstraint AddAllowedAssignments(absl::Span<const IntVar> vars);
715 
726  TableConstraint AddForbiddenAssignments(absl::Span<const IntVar> vars);
727 
733  Constraint AddInverseConstraint(absl::Span<const IntVar> variables,
734  absl::Span<const IntVar> inverse_variables);
735 
755 
784  absl::Span<const IntVar> transition_variables, int starting_state,
785  absl::Span<const int> final_states);
786 
788  Constraint AddMinEquality(IntVar target, absl::Span<const IntVar> vars);
789 
792  absl::Span<const LinearExpr> exprs);
793 
795  Constraint AddMaxEquality(IntVar target, absl::Span<const IntVar> vars);
796 
799  absl::Span<const LinearExpr> exprs);
800 
802  Constraint AddDivisionEquality(IntVar target, IntVar numerator,
803  IntVar denominator);
804 
807 
810 
812  Constraint AddProductEquality(IntVar target, absl::Span<const IntVar> vars);
813 
818  Constraint AddNoOverlap(absl::Span<const IntervalVar> vars);
819 
824 
831 
833  void Minimize(const LinearExpr& expr);
834 
836  void Maximize(const LinearExpr& expr);
837 
845  void ScaleObjectiveBy(double scaling);
846 
848  void AddDecisionStrategy(
849  absl::Span<const IntVar> variables,
850  DecisionStrategyProto::VariableSelectionStrategy var_strategy,
851  DecisionStrategyProto::DomainReductionStrategy domain_strategy);
852 
854  void AddDecisionStrategy(
855  absl::Span<const BoolVar> variables,
856  DecisionStrategyProto::VariableSelectionStrategy var_strategy,
857  DecisionStrategyProto::DomainReductionStrategy domain_strategy);
858 
860  void AddHint(IntVar var, int64 value);
861 
863  void ClearHints();
864 
866  void AddAssumption(BoolVar lit);
867 
869  void AddAssumptions(absl::Span<const BoolVar> literals);
870 
872  void ClearAssumptions();
873 
874  // TODO(user) : add MapDomain?
875 
876  const CpModelProto& Build() const { return Proto(); }
877 
878  const CpModelProto& Proto() const { return cp_model_; }
879  CpModelProto* MutableProto() { return &cp_model_; }
880 
882  void CopyFrom(const CpModelProto& model_proto);
883 
886 
889 
892 
893  private:
894  friend class CumulativeConstraint;
895  friend class ReservoirConstraint;
896 
897  // Fills the 'expr_proto' with the linear expression represented by 'expr'.
898  void LinearExprToProto(const LinearExpr& expr,
899  LinearExpressionProto* expr_proto);
900 
901  // Returns a (cached) integer variable index with a constant value.
902  int IndexFromConstant(int64 value);
903 
904  // Returns a valid integer index from a BoolVar index.
905  // If the input index is a positive, it returns this index.
906  // If the input index is negative, it creates a cached IntVar equal to
907  // 1 - BoolVar(PositiveRef(index)), and returns the index of this new
908  // variable.
909  int GetOrCreateIntegerIndex(int index);
910 
911  void FillLinearTerms(const LinearExpr& left, const LinearExpr& right,
912  LinearConstraintProto* proto);
913 
914  CpModelProto cp_model_;
915  absl::flat_hash_map<int64, int> constant_to_index_map_;
916  absl::flat_hash_map<int, int> bool_to_integer_index_map_;
917 };
918 
920 int64 SolutionIntegerValue(const CpSolverResponse& r, const LinearExpr& expr);
921 
923 int64 SolutionIntegerMin(const CpSolverResponse& r, IntVar x);
924 
926 int64 SolutionIntegerMax(const CpSolverResponse& r, IntVar x);
927 
929 bool SolutionBooleanValue(const CpSolverResponse& r, BoolVar x);
930 
931 } // namespace sat
932 } // namespace operations_research
933 
934 #endif // OR_TOOLS_SAT_CP_MODEL_H_
We call domain any subset of Int64 = [kint64min, kint64max].
Specialized automaton constraint.
Definition: cp_model.h:545
void AddTransition(int tail, int head, int64 transition_label)
Adds a transitions to the automaton.
Definition: cp_model.cc:263
A Boolean variable.
Definition: cp_model.h:67
IntegerVariableProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:99
const std::string & Name() const
Returns the name of the variable.
Definition: cp_model.h:75
BoolVar WithName(const std::string &name)
Sets the name of the variable.
Definition: cp_model.cc:31
std::string DebugString() const
Debug string.
Definition: cp_model.cc:36
friend bool SolutionBooleanValue(const CpSolverResponse &r, BoolVar x)
Evaluates the value of a Boolean literal in a solver response.
Definition: cp_model.cc:887
bool operator!=(const BoolVar &other) const
Dis-Equality test.
Definition: cp_model.h:86
bool operator==(const BoolVar &other) const
Equality test with another boolvar.
Definition: cp_model.h:81
int index() const
Returns the index of the variable in the model.
Definition: cp_model.h:109
BoolVar Not() const
Returns the logical negation of the current Boolean variable.
Definition: cp_model.h:78
const IntegerVariableProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:94
Specialized circuit constraint.
Definition: cp_model.h:451
void AddArc(int tail, int head, BoolVar literal)
Add an arc to the circuit.
Definition: cp_model.cc:225
Constraint OnlyEnforceIf(absl::Span< const BoolVar > literals)
The constraint will be enforced iff all literals listed here are true.
Definition: cp_model.cc:213
Constraint WithName(const std::string &name)
Sets the name of the constraint.
Definition: cp_model.cc:206
const ConstraintProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:433
const std::string & Name() const
Returns the name of the constraint (or the empty string if not set).
Definition: cp_model.cc:211
ConstraintProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:436
Constraint(ConstraintProto *proto)
Definition: cp_model.cc:204
Wrapper class around the cp_model proto.
Definition: cp_model.h:599
IntVar NewConstant(int64 value)
Creates a constant variable.
Definition: cp_model.cc:385
TableConstraint AddForbiddenAssignments(absl::Span< const IntVar > vars)
Adds an forbidden assignments constraint.
Definition: cp_model.cc:583
Constraint AddLinearConstraint(const LinearExpr &expr, const Domain &domain)
Adds expr in domain.
Definition: cp_model.cc:506
void ClearAssumptions()
Remove all assumptions from the model.
Definition: cp_model.cc:813
Constraint AddAbsEquality(IntVar target, IntVar var)
Adds target == abs(var).
Definition: cp_model.cc:692
void AddAssumptions(absl::Span< const BoolVar > literals)
Adds multiple literals to the model as assumptions.
Definition: cp_model.cc:807
ReservoirConstraint AddReservoirConstraint(int64 min_level, int64 max_level)
Adds a reservoir constraint with optional refill/emptying events.
Definition: cp_model.cc:607
MultipleCircuitConstraint AddMultipleCircuitConstraint()
Adds a multiple circuit constraint, aka the "VRP" (Vehicle Routing Problem) constraint.
Definition: cp_model.cc:570
Constraint AddMinEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == min(vars).
Definition: cp_model.cc:629
BoolVar TrueVar()
Creates an always true Boolean variable.
Definition: cp_model.cc:389
IntVar NewIntVar(const Domain &domain)
Creates an integer variable with the given domain.
Definition: cp_model.cc:367
Constraint AddMaxEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == max(vars).
Definition: cp_model.cc:661
Constraint AddDivisionEquality(IntVar target, IntVar numerator, IntVar denominator)
Adds target = num / denom (integer division rounded towards 0).
Definition: cp_model.cc:682
void ClearHints()
Remove all hints.
Definition: cp_model.cc:799
void Maximize(const LinearExpr &expr)
Adds a linear maximization objective.
Definition: cp_model.cc:751
IntervalVar NewOptionalIntervalVar(IntVar start, IntVar size, IntVar end, BoolVar presence)
Creates an optional interval variable.
Definition: cp_model.cc:402
BoolVar NewBoolVar()
Creates a Boolean variable.
Definition: cp_model.cc:377
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.
Definition: cp_model.cc:769
void ScaleObjectiveBy(double scaling)
Sets scaling of the objective.
Definition: cp_model.cc:763
CircuitConstraint AddCircuitConstraint()
Adds a circuit constraint.
Definition: cp_model.cc:566
Constraint AddVariableElement(IntVar index, absl::Span< const IntVar > variables, IntVar target)
Adds the element constraint: variables[index] == target.
Definition: cp_model.cc:543
const CpModelProto & Proto() const
Definition: cp_model.h:878
CumulativeConstraint AddCumulative(IntVar capacity)
The cumulative constraint.
Definition: cp_model.cc:733
const CpModelProto & Build() const
Definition: cp_model.h:876
Constraint AddGreaterThan(const LinearExpr &left, const LinearExpr &right)
Adds left > right.
Definition: cp_model.cc:486
void CopyFrom(const CpModelProto &model_proto)
Replace the current model with the one from the given proto.
Definition: cp_model.cc:817
Constraint AddLessThan(const LinearExpr &left, const LinearExpr &right)
Adds left < right.
Definition: cp_model.cc:496
Constraint AddBoolXor(absl::Span< const BoolVar > literals)
Adds the constraint that a odd number of literal is true.
Definition: cp_model.cc:431
void AddAssumption(BoolVar lit)
Adds a literal to the model as assumptions.
Definition: cp_model.cc:803
void Minimize(const LinearExpr &expr)
Adds a linear minimization objective.
Definition: cp_model.cc:740
BoolVar FalseVar()
Creates an always false Boolean variable.
Definition: cp_model.cc:393
Constraint AddImplication(BoolVar a, BoolVar b)
Adds a => b.
Definition: cp_model.h:633
Constraint AddBoolAnd(absl::Span< const BoolVar > literals)
Adds the constraint that all literals must be true.
Definition: cp_model.cc:423
IntervalVar GetIntervalVarFromProtoIndex(int index)
Returns the interval variable from its index in the proto.
Definition: cp_model.cc:853
Constraint AddLessOrEqual(const LinearExpr &left, const LinearExpr &right)
Adds left <= right.
Definition: cp_model.cc:476
Constraint AddModuloEquality(IntVar target, IntVar var, IntVar mod)
Adds target = var % mod.
Definition: cp_model.cc:701
Constraint AddEquality(const LinearExpr &left, const LinearExpr &right)
Adds left == right.
Definition: cp_model.cc:456
NoOverlap2DConstraint AddNoOverlap2D()
The no_overlap_2d constraint prevents a set of boxes from overlapping.
Definition: cp_model.cc:729
Constraint AddElement(IntVar index, absl::Span< const int64 > values, IntVar target)
Adds the element constraint: values[index] == target.
Definition: cp_model.cc:554
Constraint AddGreaterOrEqual(const LinearExpr &left, const LinearExpr &right)
Adds left >= right.
Definition: cp_model.cc:466
Constraint AddBoolOr(absl::Span< const BoolVar > literals)
Adds the constraint that at least one of the literals must be true.
Definition: cp_model.cc:415
IntVar GetIntVarFromProtoIndex(int index)
Returns the integer variable from its index in the proto.
Definition: cp_model.cc:847
AutomatonConstraint AddAutomaton(absl::Span< const IntVar > transition_variables, int starting_state, absl::Span< const int > final_states)
An automaton constraint/.
Definition: cp_model.cc:615
void AddHint(IntVar var, int64 value)
Adds hinting to a variable.
Definition: cp_model.cc:793
Constraint AddLinMinEquality(const LinearExpr &target, absl::Span< const LinearExpr > exprs)
Adds target == min(exprs).
Definition: cp_model.cc:650
Constraint AddProductEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == prod(vars).
Definition: cp_model.cc:710
Constraint AddLinMaxEquality(const LinearExpr &target, absl::Span< const LinearExpr > exprs)
Adds target == max(exprs).
Definition: cp_model.cc:671
BoolVar GetBoolVarFromProtoIndex(int index)
Returns the Boolean variable from its index in the proto.
Definition: cp_model.cc:831
Constraint AddNotEqual(const LinearExpr &left, const LinearExpr &right)
Adds left != right.
Definition: cp_model.cc:523
Constraint AddAllDifferent(absl::Span< const IntVar > vars)
this constraint forces all variables to have different values.
Definition: cp_model.cc:535
TableConstraint AddAllowedAssignments(absl::Span< const IntVar > vars)
Adds an allowed assignments constraint.
Definition: cp_model.cc:574
Constraint AddInverseConstraint(absl::Span< const IntVar > variables, absl::Span< const IntVar > inverse_variables)
An inverse constraint.
Definition: cp_model.cc:593
IntervalVar NewIntervalVar(IntVar start, IntVar size, IntVar end)
Creates an interval variable.
Definition: cp_model.cc:397
Constraint AddNoOverlap(absl::Span< const IntervalVar > vars)
Adds a no-overlap constraint that ensures that all present intervals do not overlap in time.
Definition: cp_model.cc:720
Specialized cumulative constraint.
Definition: cp_model.h:579
void AddDemand(IntervalVar interval, IntVar demand)
Adds a pair (interval, demand) to the constraint.
Definition: cp_model.cc:280
An integer variable.
Definition: cp_model.h:146
IntegerVariableProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:186
const std::string & Name() const
Returns the name of the variable (or the empty string if not set).
Definition: cp_model.h:161
BoolVar ToBoolVar() const
Cast IntVar -> BoolVar.
Definition: cp_model.cc:87
LinearExpr AddConstant(int64 value) const
Adds a constant value to an integer variable and returns a linear expression.
Definition: cp_model.cc:97
bool operator==(const IntVar &other) const
Equality test with another IntVar.
Definition: cp_model.h:168
friend int64 SolutionIntegerValue(const CpSolverResponse &r, const LinearExpr &expr)
Evaluates the value of an linear expression in a solver response.
Definition: cp_model.cc:863
std::string DebugString() const
Returns a debug string.
Definition: cp_model.cc:101
friend int64 SolutionIntegerMax(const CpSolverResponse &r, IntVar x)
Returns the max of an integer variable in a solution.
Definition: cp_model.cc:879
bool operator!=(const IntVar &other) const
Difference test with anpther IntVar.
Definition: cp_model.h:173
IntVar WithName(const std::string &name)
Sets the name of the variable.
Definition: cp_model.cc:77
friend int64 SolutionIntegerMin(const CpSolverResponse &r, IntVar x)
Returns the min of an integer variable in a solution.
Definition: cp_model.cc:871
int index() const
Returns the index of the variable in the model.
Definition: cp_model.h:191
const IntegerVariableProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:181
Represents a Interval variable.
Definition: cp_model.h:326
BoolVar PresenceBoolVar() const
Returns a BoolVar indicating the presence of this interval.
Definition: cp_model.cc:306
std::string Name() const
Returns the name of the interval (or the empty string if not set).
Definition: cp_model.cc:311
IntVar SizeVar() const
Returns the size variable.
Definition: cp_model.cc:300
std::string DebugString() const
Returns a debug string.
Definition: cp_model.cc:315
bool operator!=(const IntervalVar &other) const
Difference test with another interval variable.
Definition: cp_model.h:359
bool operator==(const IntervalVar &other) const
Equality test with another interval variable.
Definition: cp_model.h:354
IntervalVar WithName(const std::string &name)
Sets the name of the variable.
Definition: cp_model.cc:291
IntVar EndVar() const
Returns the end variable.
Definition: cp_model.cc:304
const IntervalConstraintProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:367
IntervalConstraintProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:372
int index() const
Returns the index of the interval constraint in the model.
Definition: cp_model.h:377
friend std::ostream & operator<<(std::ostream &os, const IntervalVar &var)
Definition: cp_model.cc:330
IntVar StartVar() const
Returns the start variable.
Definition: cp_model.cc:296
A dedicated container for linear expressions.
Definition: cp_model.h:248
static LinearExpr Term(IntVar var, int64 coefficient)
Construncts var * coefficient.
Definition: cp_model.cc:161
static LinearExpr ScalProd(absl::Span< const IntVar > vars, absl::Span< const int64 > coeffs)
Constructs the scalar product of variables and coefficients.
Definition: cp_model.cc:151
LinearExpr & AddConstant(int64 value)
Adds a constant value to the linear expression.
Definition: cp_model.cc:185
static LinearExpr BooleanScalProd(absl::Span< const BoolVar > vars, absl::Span< const int64 > coeffs)
Constructs the scalar product of Booleans and coefficients.
Definition: cp_model.cc:175
static LinearExpr Sum(absl::Span< const IntVar > vars)
Constructs the sum of a list of variables.
Definition: cp_model.cc:143
static LinearExpr BooleanSum(absl::Span< const BoolVar > vars)
Constructs the sum of a list of Booleans.
Definition: cp_model.cc:167
const std::vector< IntVar > & variables() const
Returns the vector of variables.
Definition: cp_model.h:291
void AddTerm(IntVar var, int64 coeff)
Adds a term (var * coeff) to the linear expression.
Definition: cp_model.cc:192
void AddVar(IntVar var)
Adds a single integer variable to the linear expression.
Definition: cp_model.cc:190
const std::vector< int64 > & coefficients() const
Returns the vector of coefficients.
Definition: cp_model.h:294
int64 constant() const
Returns the constant term.
Definition: cp_model.h:297
void AddArc(int tail, int head, BoolVar literal)
Add an arc to the circuit.
Definition: cp_model.cc:231
Specialized no_overlap2D constraint.
Definition: cp_model.h:562
void AddRectangle(IntervalVar x_coordinate, IntervalVar y_coordinate)
Adds a rectangle (parallel to the axis) to the constraint.
Definition: cp_model.cc:270
Specialized reservoir constraint.
Definition: cp_model.h:514
void AddEvent(IntVar time, int64 demand)
Adds a mandatory event.
Definition: cp_model.cc:248
void AddOptionalEvent(IntVar time, int64 demand, BoolVar is_active)
Adds a optional event.
Definition: cp_model.cc:255
Specialized assignment constraint.
Definition: cp_model.h:497
void AddTuple(absl::Span< const int64 > tuple)
Adds a tuple of possible values to the constraint.
Definition: cp_model.cc:237
CpModelProto proto
CpModelProto const * model_proto
const std::string name
int64 value
IntVar * var
Definition: expr_array.cc:1858
int64_t int64
static const int32 kint32min
std::ostream & operator<<(std::ostream &os, const BoolVar &var)
Definition: cp_model.cc:65
int64 SolutionIntegerValue(const CpSolverResponse &r, const LinearExpr &expr)
Evaluates the value of an linear expression in a solver response.
Definition: cp_model.cc:863
int64 SolutionIntegerMax(const CpSolverResponse &r, IntVar x)
Returns the max of an integer variable in a solution.
Definition: cp_model.cc:879
BoolVar Not(BoolVar x)
A convenient wrapper so we can write Not(x) instead of x.Not() which is sometimes clearer.
Definition: cp_model.cc:63
bool SolutionBooleanValue(const CpSolverResponse &r, BoolVar x)
Evaluates the value of a Boolean literal in a solver response.
Definition: cp_model.cc:887
int64 SolutionIntegerMin(const CpSolverResponse &r, IntVar x)
Returns the min of an integer variable in a solution.
Definition: cp_model.cc:871
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Literal literal
Definition: optimization.cc:84
int index
Definition: pack.cc:508
int64 time
Definition: resource.cc:1683
int64 demand
Definition: resource.cc:123
IntervalVar * interval
Definition: resource.cc:98
int64 tail
int64 head
int64 capacity
int64 coefficient