C++ Reference
C++ Reference: CP-SAT
cp_model.h
const IntegerVariableProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:93
const ::operations_research::sat::IntegerVariableProto & variables(int index) const
Definition: cp_model.pb.h:9774
bool operator!=(const IntVar &other) const
Difference test with anpther IntVar.
Definition: cp_model.h:168
const std::string & Name() const
Returns the name of the variable (or the empty string if not set).
Definition: cp_model.h:156
bool SolutionBooleanValue(const CpSolverResponse &r, BoolVar x)
Evaluates the value of a Boolean literal in a solver response.
Constraint AddLessOrEqual(const LinearExpr &left, const LinearExpr &right)
Adds left <= right.
ConstraintProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:430
LinearExpr()
BoolVar WithName(const std::string &name)
Sets the name of the variable.
friend int64 SolutionIntegerMax(const CpSolverResponse &r, IntVar x)
Returns the max of an integer variable in a solution.
void AddDemand(IntervalVar interval, IntVar demand)
Adds a pair (interval, demand) to the constraint.
std::ostream & operator<<(std::ostream &os, const BoolVar &var)
Constraint AddLessThan(const LinearExpr &left, const LinearExpr &right)
Adds left < right.
IntegerVariableProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:181
bool operator!=(const IntervalVar &other) const
Difference test with another interval variable.
Definition: cp_model.h:353
Constraint AddLinMinEquality(const LinearExpr &target, absl::Span< const LinearExpr > exprs)
Adds target == min(exprs).
static LinearExpr ScalProd(absl::Span< const IntVar > vars, absl::Span< const int64 > coeffs)
Constructs the scalar product of variables and coefficients.
BoolVar PresenceBoolVar() const
Returns a BoolVar indicating the presence of this interval.
DecisionStrategyProto_DomainReductionStrategy
Definition: cp_model.pb.h:199
void AddRectangle(IntervalVar x_coordinate, IntervalVar y_coordinate)
Adds a rectangle (parallel to the axis) to the constraint.
BoolVar Not(BoolVar x)
A convenient wrapper so we can write Not(x) instead of x.Not() which is sometimes clearer.
friend std::ostream & operator<<(std::ostream &os, const IntervalVar &var)
Constraint(ConstraintProto *proto)
CircuitConstraint AddCircuitConstraint()
Adds a circuit constraint.
Specialized circuit constraint.
Definition: cp_model.h:445
void AddEvent(IntVar time, int64 demand)
Adds a mandatory event.
Constraint OnlyEnforceIf(absl::Span< const BoolVar > literals)
The constraint will be enforced iff all literals listed here are true.
Constraint AddProductEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == prod(vars).
const ConstraintProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:427
Specialized circuit constraint.
Definition: cp_model.h:468
Constraint AddGreaterOrEqual(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.
Constraint AddBoolAnd(absl::Span< const BoolVar > literals)
Adds the constraint that all literals must be true.
friend int64 SolutionIntegerValue(const CpSolverResponse &r, const LinearExpr &expr)
Evaluates the value of an linear expression in a solver response.
Definition: cp_model.h:52
LinearExpr & AddConstant(int64 value)
Adds a constant value to the linear expression.
void AddOptionalEvent(IntVar time, int64 demand, BoolVar is_active)
Adds a optional event.
LinearExpr AddConstant(int64 value) const
Adds a constant value to an integer variable and returns a linear expression.
const std::vector< int64 > & coefficients() const
Returns the vector of coefficients.
Definition: cp_model.h:288
We call domain any subset of Int64 = [kint64min, kint64max].
Definition: sorted_interval_list.h:74
const std::vector< IntVar > & variables() const
Returns the vector of variables.
Definition: cp_model.h:285
static LinearExpr Term(IntVar var, int64 coefficient)
Construncts var * coefficient.
Constraint AddAbsEquality(IntVar target, IntVar var)
Adds target == abs(var).
::operations_research::sat::IntegerVariableProto * mutable_variables(int index)
Definition: cp_model.pb.h:9762
const CpModelProto & Build() const
Definition: cp_model.h:858
int64 SolutionIntegerValue(const CpSolverResponse &r, const LinearExpr &expr)
Evaluates the value of an linear expression in a solver response.
int index() const
Returns the index of the interval constraint in the model.
Definition: cp_model.h:371
Specialized reservoir constraint.
Definition: cp_model.h:508
static LinearExpr BooleanScalProd(absl::Span< const BoolVar > vars, absl::Span< const int64 > coeffs)
Constructs the scalar product of Booleans and coefficients.
AutomatonConstraint AddAutomaton(absl::Span< const IntVar > transition_variables, int starting_state, absl::Span< const int > final_states)
An automaton constraint/.
CpModelProto * MutableProto()
Definition: cp_model.h:861
const ::operations_research::sat::ConstraintProto & constraints(int index) const
Definition: cp_model.pb.h:9813
DecisionStrategyProto_VariableSelectionStrategy
Definition: cp_model.pb.h:171
Constraint AddBoolOr(absl::Span< const BoolVar > literals)
Adds the constraint that at least one of the literals must be true.
void AddHint(IntVar var, int64 value)
Adds hinting to a variable.
const std::string & Name() const
Returns the name of the constraint (or the empty string if not set).
Constraint AddModuloEquality(IntVar target, IntVar var, IntVar mod)
Adds target = var % mod.
void AddTransition(int tail, int head, int64 transition_label)
Adds a transitions to the automaton.
const ::operations_research::sat::IntervalConstraintProto & interval() const
Definition: cp_model.pb.h:9034
Constraint AddMinEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == min(vars).
void Minimize(const LinearExpr &expr)
Adds a linear minimization objective.
int64 SolutionIntegerMin(const CpSolverResponse &r, IntVar x)
Returns the min of an integer variable in a solution.
Specialized automaton constraint.
Definition: cp_model.h:539
Constraint AddElement(IntVar index, absl::Span< const int64 > values, IntVar target)
Adds the element constraint: values[index] == target.
void Maximize(const LinearExpr &expr)
Adds a linear maximization objective.
void AddArc(int tail, int head, BoolVar literal)
Add an arc to the circuit.
CumulativeConstraint AddCumulative(IntVar capacity)
The cumulative constraint.
BoolVar Not() const
Returns the logical negation of the current Boolean variable.
Definition: cp_model.h:77
::operations_research::sat::ConstraintProto * mutable_constraints(int index)
Definition: cp_model.pb.h:9801
bool operator==(const BoolVar &other) const
Equality test with another boolvar.
Definition: cp_model.h:80
Constraint AddInverseConstraint(absl::Span< const IntVar > variables, absl::Span< const IntVar > inverse_variables)
An inverse constraint.
Specialized cumulative constraint.
Definition: cp_model.h:573
void AddArc(int tail, int head, BoolVar literal)
Add an arc to the circuit.
std::string Name() const
Returns the name of the interval (or the empty string if not set).
Constraint AddLinMaxEquality(const LinearExpr &target, absl::Span< const LinearExpr > exprs)
Adds target == max(exprs).
const std::string & name() const
Definition: cp_model.pb.h:5642
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.
BoolVar FalseVar()
Creates an always false Boolean variable.
Wrapper class around the cp_model proto.
Definition: cp_model.h:593
TableConstraint AddForbiddenAssignments(absl::Span< const IntVar > vars)
Adds an forbidden assignments constraint.
Constraint AddDivisionEquality(IntVar target, IntVar numerator, IntVar denominator)
Adds target = num / denom (integer division rounded towards 0).
friend bool SolutionBooleanValue(const CpSolverResponse &r, BoolVar x)
Evaluates the value of a Boolean literal in a solver response.
Constraint AddNoOverlap(absl::Span< const IntervalVar > vars)
Adds a no-overlap constraint that ensures that all present intervals do not overlap in time.
Constraint AddGreaterThan(const LinearExpr &left, const LinearExpr &right)
Adds left > right.
const CpModelProto & Proto() const
Definition: cp_model.h:860
MultipleCircuitConstraint AddMultipleCircuitConstraint()
Adds a multiple circuit constraint, aka the "VRP" (Vehicle Routing Problem) constraint.
const IntervalConstraintProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:361
Constraint WithName(const std::string &name)
Sets the name of the constraint.
const IntegerVariableProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Definition: cp_model.h:176
IntVar WithName(const std::string &name)
Sets the name of the variable.
Constraint AddAllDifferent(absl::Span< const IntVar > vars)
this constraint forces all variables to have different values.
NoOverlap2DConstraint AddNoOverlap2D()
The no_overlap_2d constraint prevents a set of boxes from overlapping.
::operations_research::sat::IntervalConstraintProto * mutable_interval()
Definition: cp_model.pb.h:9047
IntervalVar WithName(const std::string &name)
Sets the name of the variable.
IntVar NewConstant(int64 value)
Creates a constant variable.
IntegerVariableProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:98
TableConstraint AddAllowedAssignments(absl::Span< const IntVar > vars)
Adds an allowed assignments constraint.
void AddTuple(absl::Span< const int64 > tuple)
Adds a tuple of possible values to the constraint.
A dedicated container for linear expressions.
Definition: cp_model.h:242
void ScaleObjectiveBy(double scaling)
Sets scaling of the objective.
void AddVar(IntVar var)
Adds a single integer variable to the linear expression.
Constraint AddNotEqual(const LinearExpr &left, const LinearExpr &right)
Adds left != right.
BoolVar TrueVar()
Creates an always true Boolean variable.
void AddTerm(IntVar var, int64 coeff)
Adds a term (var * coeff) to the linear expression.
bool operator==(const IntervalVar &other) const
Equality test with another interval variable.
Definition: cp_model.h:348
std::string DebugString() const
Returns a debug string.
Specialized no_overlap2D constraint.
Definition: cp_model.h:556
bool operator==(const IntVar &other) const
Equality test with another IntVar.
Definition: cp_model.h:163
Constraint AddVariableElement(IntVar index, absl::Span< const IntVar > variables, IntVar target)
Adds the element constraint: variables[index] == target.
IntVar NewIntVar(const Domain &domain)
Creates an integer variable with the given domain.
Constraint AddMaxEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == max(vars).
IntervalVar NewOptionalIntervalVar(IntVar start, IntVar size, IntVar end, BoolVar presence)
Creates an optional interval variable.
Specialized assignment constraint.
Definition: cp_model.h:491
ReservoirConstraint AddReservoirConstraint(int64 min_level, int64 max_level)
Adds a reservoir constraint with optional refill/emptying events.
IntervalConstraintProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Definition: cp_model.h:366
static LinearExpr Sum(absl::Span< const IntVar > vars)
Constructs the sum of a list of variables.
Constraint AddEquality(const LinearExpr &left, const LinearExpr &right)
Adds left == right.
IntervalVar NewIntervalVar(IntVar start, IntVar size, IntVar end)
Creates an interval variable.
static LinearExpr BooleanSum(absl::Span< const BoolVar > vars)
Constructs the sum of a list of Booleans.
int64 SolutionIntegerMax(const CpSolverResponse &r, IntVar x)
Returns the max of an integer variable in a solution.
friend int64 SolutionIntegerMin(const CpSolverResponse &r, IntVar x)
Returns the min of an integer variable in a solution.
Constraint AddLinearConstraint(const LinearExpr &expr, const Domain &domain)
Adds expr in domain.