C++ Reference: class CpModelBuilder

Note: This documentation is automatically generated.

Method
AddAbsEquality

Return type: Constraint

Arguments: const LinearExpr& target, const LinearExpr& expr

Adds target == abs(expr).

AddAllDifferent

Return type: Constraint

Arguments: absl::Span<const IntVar> vars

This constraint forces all variables to have different values.

AddAllDifferent

Return type: Constraint

Arguments: absl::Span<const LinearExpr> exprs

This constraint forces all expressions to have different values.

AddAllDifferent

Return type: Constraint

Arguments: std::initializer_list<LinearExpr> exprs

This constraint forces all expressions to have different values.

AddAllowedAssignments

Return type: TableConstraint

Arguments: absl::Span<const IntVar> vars

AddAssumption

Return type: void

Arguments: BoolVar lit

Adds a literal to the model as assumptions.

AddAssumptions

Return type: void

Arguments: absl::Span<const BoolVar> literals

Adds multiple literals to the model as assumptions.

AddAtLeastOne

Return type: Constraint

Arguments: absl::Span<const BoolVar> literals

Same as AddBoolOr(). Sum literals >= 1.

AddAtMostOne

Return type: Constraint

Arguments: absl::Span<const BoolVar> literals

At most one literal is true. Sum literals <= 1.

AddAutomaton

Return type: AutomatonConstraint

Arguments: absl::Span<const IntVar> transition_variables, int starting_state, absl::Span<const int> final_states

AddBoolAnd

Return type: Constraint

Arguments: absl::Span<const BoolVar> literals

Adds the constraint that all literals must be true.

AddBoolOr

Return type: Constraint

Arguments: absl::Span<const BoolVar> literals

Adds the constraint that at least one of the literals must be true.

AddBoolXor

Return type: Constraint

Arguments: absl::Span<const BoolVar> literals

Adds the constraint that an odd number of literals is true.

AddCircuitConstraint

Return type: CircuitConstraint

AddCumulative

Return type: CumulativeConstraint

Arguments: LinearExpr capacity

AddDecisionStrategy

Return type: void

Arguments: absl::Span<const IntVar> variables, DecisionStrategyProto::VariableSelectionStrategy var_strategy, DecisionStrategyProto::DomainReductionStrategy domain_strategy

Adds a decision strategy on a list of integer variables.

AddDecisionStrategy

Return type: void

Arguments: absl::Span<const BoolVar> variables, DecisionStrategyProto::VariableSelectionStrategy var_strategy, DecisionStrategyProto::DomainReductionStrategy domain_strategy

Adds a decision strategy on a list of boolean variables.

AddDivisionEquality

Return type: Constraint

Arguments: const LinearExpr& target, const LinearExpr& numerator, const LinearExpr& denominator

Adds target = num / denom (integer division rounded towards 0).

AddElement

Return type: Constraint

Arguments: IntVar index, absl::Span<const int64_t> values, IntVar target

Adds the element constraint: values[index] == target

AddEquality

Return type: Constraint

Arguments: const LinearExpr& left, const LinearExpr& right

Adds left == right.

AddExactlyOne

Return type: Constraint

Arguments: absl::Span<const BoolVar> literals

Exactly one literal is true. Sum literals == 1.

AddForbiddenAssignments

Return type: TableConstraint

Arguments: absl::Span<const IntVar> vars

AddGreaterOrEqual

Return type: Constraint

Arguments: const LinearExpr& left, const LinearExpr& right

Adds left >= right.

AddGreaterThan

Return type: Constraint

Arguments: const LinearExpr& left, const LinearExpr& right

Adds left > right.

AddHint

Return type: void

Arguments: IntVar var, int64_t value

Adds hinting to a variable.

AddHint

Return type: void

Arguments: BoolVar var, bool value

Adds hinting to a Boolean variable.

AddImplication

Return type: Constraint

Arguments: BoolVar a, BoolVar b

Adds a => b.

AddImplication

Return type: Constraint

Arguments: absl::Span<const BoolVar> lhs, absl::Span<const BoolVar> rhs

Adds implication: if all lhs vars are true then all rhs vars must be true.

AddInverseConstraint

Return type: Constraint

Arguments: absl::Span<const IntVar> variables, absl::Span<const IntVar> inverse_variables

AddLessOrEqual

Return type: Constraint

Arguments: const LinearExpr& left, const LinearExpr& right

Adds left <= right.

AddLessThan

Return type: Constraint

Arguments: const LinearExpr& left, const LinearExpr& right

Adds left < right.

AddLinearConstraint

Return type: Constraint

Arguments: const LinearExpr& expr, const Domain& domain

Adds expr in domain.

AddMaxEquality

Return type: Constraint

Arguments: const LinearExpr& target, absl::Span<const IntVar> vars

Adds target == max(vars).

AddMaxEquality

Return type: Constraint

Arguments: const LinearExpr& target, absl::Span<const LinearExpr> exprs

Adds target == max(exprs).

AddMaxEquality

Return type: Constraint

Arguments: const LinearExpr& target, std::initializer_list<LinearExpr> exprs

Adds target == max(exprs).

AddMinEquality

Return type: Constraint

Arguments: const LinearExpr& target, absl::Span<const IntVar> vars

Adds target == min(vars).

AddMinEquality

Return type: Constraint

Arguments: const LinearExpr& target, absl::Span<const LinearExpr> exprs

Adds target == min(exprs).

AddMinEquality

Return type: Constraint

Arguments: const LinearExpr& target, std::initializer_list<LinearExpr> exprs

Adds target == min(exprs).

AddModuloEquality

Return type: Constraint

Arguments: const LinearExpr& target, const LinearExpr& var, const LinearExpr& mod

Adds target = var % mod.

AddMultipleCircuitConstraint

Return type: MultipleCircuitConstraint

AddMultiplicationEquality

Return type: Constraint

Arguments: const LinearExpr& target, absl::Span<const LinearExpr> exprs

Adds target == prod(exprs).

AddMultiplicationEquality

Return type: Constraint

Arguments: const LinearExpr& target, absl::Span<const IntVar> vars

Adds target == prod(vars).

AddMultiplicationEquality

Return type: Constraint

Arguments: const LinearExpr& target, std::initializer_list<LinearExpr> exprs

Adds target == prod(vars).

AddMultiplicationEquality

Return type: Constraint

Arguments: const LinearExpr& target, const LinearExpr& left, const LinearExpr& right

Adds target == left * right.

AddNoOverlap

Return type: Constraint

Arguments: absl::Span<const IntervalVar> vars

AddNoOverlap2D

Return type: NoOverlap2DConstraint

AddNotEqual

Return type: Constraint

Arguments: const LinearExpr& left, const LinearExpr& right

Adds left != right.

AddReservoirConstraint

Return type: ReservoirConstraint

Arguments: int64_t min_level, int64_t max_level

AddVariableElement

Return type: Constraint

Arguments: IntVar index, absl::Span<const IntVar> variables, IntVar target

Adds the element constraint: variables[index] == target

Build

Return type: const CpModelProto&

ClearAssumptions

Return type: void

Remove all assumptions from the model.

ClearHints

Return type: void

Removes all hints.

ClearObjective

Return type: void

Removes the objective from the model.

CopyFrom

Return type: void

Arguments: const CpModelProto& model_proto

Replaces the current model with the one from the given proto.

FalseVar

Return type: BoolVar

Creates an always false Boolean variable. If this is called multiple times, the same variable will always be returned.

FixVariable

Return type: void

Arguments: IntVar var, int64_t value

It is sometime convenient when building a model to create a bunch of variables that will later be fixed. Instead of doing AddEquality(var, value) which add a constraint, these functions modify directly the underlying variable domain. Note that this ignore completely the original variable domain and just fix the given variable to the given value, even if it was outside the given variable domain. You can still use AddEquality() if this is not what you want.

FixVariable

Return type: void

Arguments: BoolVar var, bool value

GetBoolVarFromProtoIndex

Return type: BoolVar

Arguments: int index

Returns the Boolean variable from its index in the proto.

GetIntervalVarFromProtoIndex

Return type: IntervalVar

Arguments: int index

Returns the interval variable from its index in the proto.

GetIntVarFromProtoIndex

Return type: IntVar

Arguments: int index

Returns the integer variable from its index in the proto.

HasObjective

Return type: bool

Checks whether the model contains an objective.

Maximize

Return type: void

Arguments: const LinearExpr& expr

Adds a linear maximization objective.

Maximize

Return type: void

Arguments: const DoubleLinearExpr& expr

Adds a linear floating point maximization objective. Note that the coefficients will be internally scaled to integer.

Minimize

Return type: void

Arguments: const LinearExpr& expr

Adds a linear minimization objective.

Minimize

Return type: void

Arguments: const DoubleLinearExpr& expr

Adds a linear floating point minimization objective. Note that the coefficients will be internally scaled to integer.

MutableProto

Return type: CpModelProto*

NewBoolVar

Return type: BoolVar

Creates a Boolean variable.

NewConstant

Return type: IntVar

Arguments: int64_t value

Creates a constant variable. This is a shortcut for NewVariable(Domain(value)).but it will return the same variable if used twice with the same constant.

NewFixedSizeIntervalVar

Return type: IntervalVar

Arguments: const LinearExpr& start, int64_t size

Creates an interval variable with a fixed size.

NewIntervalVar

Return type: IntervalVar

Arguments: const LinearExpr& start, const LinearExpr& size, const LinearExpr& end

Creates an interval variable from 3 affine expressions.

NewIntVar

Return type: IntVar

Arguments: const Domain& domain

Creates an integer variable with the given domain.

NewOptionalFixedSizeIntervalVar

Return type: IntervalVar

Arguments: const LinearExpr& start, int64_t size, BoolVar presence

Creates an optional interval variable with a fixed size.

NewOptionalIntervalVar

Return type: IntervalVar

Arguments: const LinearExpr& start, const LinearExpr& size, const LinearExpr& end, BoolVar presence

Creates an optional interval variable from 3 affine expressions and a Boolean variable.

Proto

Return type: const CpModelProto&

SetName

Return type: void

Arguments: const std::string& name

Sets the name of the model.

TrueVar

Return type: BoolVar

Creates an always true Boolean variable. If this is called multiple times, the same variable will always be returned.