C++ Reference
C++ Reference: CP-SAT
cp_model.h
Go to the documentation of this file.
void AddArc(int tail, int head, BoolVar literal)
Add an arc to the circuit.
friend int64_t SolutionIntegerValue(const CpSolverResponse &r, const LinearExpr &expr)
Evaluates the value of an linear expression in a solver response.
BoolVar FalseVar()
Creates an always false Boolean variable.
IntervalVar NewOptionalFixedSizeIntervalVar(const LinearExpr &start, int64_t size, BoolVar presence)
Creates an optional interval variable with a fixed size.
Constraint AddModuloEquality(IntVar target, IntVar var, IntVar mod)
Adds target = var % mod.
const std::string & name() const
Definition: cp_model.pb.h:6722
Specialized reservoir constraint.
Definition: cp_model.h:532
std::ostream & operator<<(std::ostream &os, const BoolVar &var)
LinearExpr EndExpr() const
Returns the end linear expression.
BoolVar TrueVar()
Creates an always true Boolean variable.
Constraint AddLinMaxEquality(const LinearExpr &target, absl::Span< const LinearExpr > exprs)
Adds target == max(exprs).
const CpModelProto & Proto() const
Definition: cp_model.h:911
void AddAssumption(BoolVar lit)
Adds a literal to the model as assumptions.
Constraint AddAbsEquality(IntVar target, IntVar var)
Adds target == abs(var).
CircuitConstraint AddCircuitConstraint()
Adds a circuit constraint.
Constraint AddGreaterThan(const LinearExpr &left, const LinearExpr &right)
Adds left > right.
Specialized no_overlap2D constraint.
Definition: cp_model.h:580
BoolVar Not() const
Returns the logical negation of the current Boolean variable.
Definition: cp_model.h:80
int64_t SolutionIntegerMin(const CpSolverResponse &r, IntVar x)
Returns the min 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.
LinearExpr AddConstant(int64_t value) const
Adds a constant value to an integer variable and returns a linear expression.
Constraint AddAllDifferent(absl::Span< const IntVar > vars)
this constraint forces all variables to have different values.
Constraint AddEquality(const LinearExpr &left, const LinearExpr &right)
Adds left == right.
DecisionStrategyProto_DomainReductionStrategy
Definition: cp_model.pb.h:210
ConstraintProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:454
bool operator==(const BoolVar &other) const
Equality test with another boolvar.
Definition: cp_model.h:83
TableConstraint AddAllowedAssignments(absl::Span< const IntVar > vars)
Adds an allowed assignments constraint.
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:395
ReservoirConstraint AddReservoirConstraint(int64_t min_level, int64_t max_level)
Adds a reservoir constraint with optional refill/emptying events.
friend bool SolutionBooleanValue(const CpSolverResponse &r, BoolVar x)
Evaluates the value of a Boolean literal in a solver response.
friend int64_t SolutionIntegerMin(const CpSolverResponse &r, IntVar x)
Returns the min of an integer variable in a solution.
void AddTuple(absl::Span< const int64_t > tuple)
Adds a tuple of possible values to the constraint.
IntervalVar WithName(const std::string &name)
Sets the name of the variable.
friend int64_t SolutionIntegerMax(const CpSolverResponse &r, IntVar x)
Returns the max of an integer variable in a solution.
bool operator==(const IntervalVar &other) const
Equality test with another interval variable.
Definition: cp_model.h:372
Constraint AddBoolOr(absl::Span< const BoolVar > literals)
Adds the constraint that at least one of the literals must be true.
LinearExpr & AddExpression(const LinearExpr &expr)
Adds another linear expression to the linear expression.
Constraint AddProductEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == prod(vars).
IntervalVar NewFixedSizeIntervalVar(const LinearExpr &start, int64_t size)
Creates an interval variable with a fixed size.
DecisionStrategyProto_VariableSelectionStrategy
Definition: cp_model.pb.h:182
BoolVar GetBoolVarFromProtoIndex(int index)
Returns the Boolean variable from its index in the proto.
LinearExpr & AddConstant(int64_t value)
Adds a constant value to the linear expression.
AutomatonConstraint AddAutomaton(absl::Span< const IntVar > transition_variables, int starting_state, absl::Span< const int > final_states)
An automaton constraint/.
Specialized circuit constraint.
Definition: cp_model.h:469
Constraint AddBoolXor(absl::Span< const BoolVar > literals)
Adds the constraint that a odd number of literal is true.
Specialized cumulative constraint.
Definition: cp_model.h:597
bool operator!=(const IntVar &other) const
Difference test with anpther IntVar.
Definition: cp_model.h:175
Specialized assignment constraint.
Definition: cp_model.h:515
void AddDemand(IntervalVar interval, IntVar demand)
Adds a pair (interval, demand) to the constraint.
void Minimize(const LinearExpr &expr)
Adds a linear minimization objective.
const IntegerVariableProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:96
const std::vector< int64_t > & coefficients() const
Returns the vector of coefficients.
Definition: cp_model.h:299
IntegerVariableProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:188
bool operator!=(const IntervalVar &other) const
Difference test with another interval variable.
Definition: cp_model.h:377
static LinearExpr Term(IntVar var, int64_t coefficient)
Constructs var * coefficient.
int64_t SolutionIntegerMax(const CpSolverResponse &r, IntVar x)
Returns the max of an integer variable in a solution.
IntVar NewConstant(int64_t value)
Creates a constant variable.
void Maximize(const LinearExpr &expr)
Adds a linear maximization objective.
CpModelProto * MutableProto()
Definition: cp_model.h:912
IntVar GetIntVarFromProtoIndex(int index)
Returns the integer variable from its index in the proto.
IntervalVar NewIntervalVar(const LinearExpr &start, const LinearExpr &size, const LinearExpr &end)
Creates an interval variable from 3 affine expressions.
Constraint AddNotEqual(const LinearExpr &left, const LinearExpr &right)
Adds left != right.
void ClearAssumptions()
Remove all assumptions from the model.
Constraint AddMaxEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == max(vars).
IntVar Var() const
Checks that the expression is 1 * var + 0, and returns var.
const ConstraintProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:451
const ::operations_research::sat::IntegerVariableProto & variables(int index) const
Definition: cp_model.pb.h:12054
Constraint AddInverseConstraint(absl::Span< const IntVar > variables, absl::Span< const IntVar > inverse_variables)
An inverse constraint.
MultipleCircuitConstraint AddMultipleCircuitConstraint()
Adds a multiple circuit constraint, aka the "VRP" (Vehicle Routing Problem) constraint.
BoolVar PresenceBoolVar() const
Returns a BoolVar indicating the presence of this interval.
BoolVar Not(BoolVar x)
A convenient wrapper so we can write Not(x) instead of x.Not() which is sometimes clearer.
int64_t SolutionIntegerValue(const CpSolverResponse &r, const LinearExpr &expr)
Evaluates the value of an linear expression in a solver response.
const ::operations_research::sat::ConstraintProto & constraints(int index) const
Definition: cp_model.pb.h:12094
Constraint AddElement(IntVar index, absl::Span< const int64_t > values, IntVar target)
Adds the element constraint: values[index] == target.
IntervalVar GetIntervalVarFromProtoIndex(int index)
Returns the interval variable from its index in the proto.
std::string DebugString() const
Returns a debug string.
LinearExpr & AddTerm(IntVar var, int64_t coeff)
Adds a term (var * coeff) to the linear expression.
void AddEvent(IntVar time, int64_t demand)
Adds a mandatory event.
IntVar NewIntVar(const Domain &domain)
Creates an integer variable with the given domain.
const CpModelProto & Build() const
Definition: cp_model.h:909
::operations_research::sat::IntervalConstraintProto * mutable_interval()
Definition: cp_model.pb.h:10920
const std::string & Name() const
Returns the name of the constraint (or the empty string if not set).
Constraint AddMinEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == min(vars).
A dedicated container for linear expressions.
Definition: cp_model.h:250
Constraint OnlyEnforceIf(absl::Span< const BoolVar > literals)
The constraint will be enforced iff all literals listed here are true.
void AddAssumptions(absl::Span< const BoolVar > literals)
Adds multiple literals to the model as assumptions.
Constraint(ConstraintProto *proto)
Constraint AddBoolAnd(absl::Span< const BoolVar > literals)
Adds the constraint that all literals must be true.
::operations_research::sat::ConstraintProto * mutable_constraints(int index)
Definition: cp_model.pb.h:12082
static LinearExpr Sum(absl::Span< const IntVar > vars)
Constructs the sum of a list of variables.
bool SolutionBooleanValue(const CpSolverResponse &r, BoolVar x)
Evaluates the value of a Boolean literal in a solver response.
void AddOptionalEvent(IntVar time, int64_t demand, BoolVar is_active)
Adds a optional event.
void AddArc(int tail, int head, BoolVar literal)
Add an arc to the circuit.
void ScaleObjectiveBy(double scaling)
Sets scaling of the objective.
const std::string & Name() const
Returns the name of the variable (or the empty string if not set).
Definition: cp_model.h:163
We call domain any subset of Int64 = [kint64min, kint64max].
Definition: sorted_interval_list.h:81
Constraint AddLinMinEquality(const LinearExpr &target, absl::Span< const LinearExpr > exprs)
Adds target == min(exprs).
Specialized automaton constraint.
Definition: cp_model.h:563
Constraint AddGreaterOrEqual(const LinearExpr &left, const LinearExpr &right)
Adds left >= right.
Constraint AddVariableElement(IntVar index, absl::Span< const IntVar > variables, IntVar target)
Adds the element constraint: variables[index] == target.
LinearExpr & AddVar(IntVar var)
Adds a single integer variable to the linear expression.
BoolVar WithName(const std::string &name)
Sets the name of the variable.
Constraint AddLessThan(const LinearExpr &left, const LinearExpr &right)
Adds left < right.
IntVar WithName(const std::string &name)
Sets the name of the variable.
static LinearExpr ScalProd(absl::Span< const IntVar > vars, absl::Span< const int64_t > coeffs)
Constructs the scalar product of variables and coefficients.
Constraint AddNoOverlap(absl::Span< const IntervalVar > vars)
Adds a no-overlap constraint that ensures that all present intervals do not overlap in time.
Constraint WithName(const std::string &name)
Sets the name of the constraint.
Specialized circuit constraint.
Definition: cp_model.h:492
void AddRectangle(IntervalVar x_coordinate, IntervalVar y_coordinate)
Adds a rectangle (parallel to the axis) to the constraint.
NoOverlap2DConstraint AddNoOverlap2D()
The no_overlap_2d constraint prevents a set of boxes from overlapping.
int64_t Value() const
Checks that the expression is constant and returns its value.
Definition: cp_model.h:54
void AddTransition(int tail, int head, int64_t transition_label)
Adds a transitions to the automaton.
TableConstraint AddForbiddenAssignments(absl::Span< const IntVar > vars)
Adds an forbidden assignments constraint.
const ::operations_research::sat::IntervalConstraintProto & interval() const
Definition: cp_model.pb.h:10889
void AddHint(IntVar var, int64_t value)
Adds hinting to a variable.
IntervalVar NewOptionalIntervalVar(const LinearExpr &start, const LinearExpr &size, const LinearExpr &end, BoolVar presence)
Creates an optional interval variable from 3 affine expressions and a Boolean variable.
LinearExpr StartExpr() const
Returns the start linear expression.
LinearExpr SizeExpr() const
Returns the size linear expression.
Constraint AddLessOrEqual(const LinearExpr &left, const LinearExpr &right)
Adds left <= right.
IntervalConstraintProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:390
CumulativeConstraint AddCumulative(IntVar capacity)
The cumulative constraint.
IntegerVariableProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:101
bool operator==(const IntVar &other) const
Equality test with another IntVar.
Definition: cp_model.h:170
std::string Name() const
Returns the name of the interval (or the empty string if not set).
Constraint AddLinearConstraint(const LinearExpr &expr, const Domain &domain)
Adds expr in domain.
const IntervalConstraintProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:385
Wrapper class around the cp_model proto.
Definition: cp_model.h:617
const std::vector< IntVar > & variables() const
Returns the vector of variables.
Definition: cp_model.h:296
static LinearExpr BooleanSum(absl::Span< const BoolVar > vars)
Constructs the sum of a list of Booleans.
::operations_research::sat::IntegerVariableProto * mutable_variables(int index)
Definition: cp_model.pb.h:12042
Constraint AddDivisionEquality(IntVar target, IntVar numerator, IntVar denominator)
Adds target = num / denom (integer division rounded towards 0).
static LinearExpr BooleanScalProd(absl::Span< const BoolVar > vars, absl::Span< const int64_t > coeffs)
Constructs the scalar product of Booleans and coefficients.
void CopyFrom(const CpModelProto &model_proto)
Replace the current model with the one from the given proto.
const IntegerVariableProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:183
LinearExpr()