C++ Reference: class CpModelBuilder

This documentation is automatically generated.



Wrapper class around the cp_model proto.

This class provides two types of methods:
   - NewXXX to create integer, boolean, or interval variables.
   - AddXXX to create new constraints and add them to the model.
Method
AddAbsEquality

Return type: Constraint

Arguments: IntVar target, IntVar var

Adds target == abs(var).

AddAllDifferent

Return type: Constraint

Arguments: absl::Span<const IntVar> vars

this constraint forces all variables to have different values.

AddAllowedAssignments

Return type: TableConstraint

Arguments: absl::Span<const IntVar> vars

Adds an allowed assignments constraint. An AllowedAssignments constraint is a constraint on an array of variables that forces, when all variables are fixed to a single value, that the corresponding list of values is equal to one of the tuple added to the constraint. It returns a table constraint that allows adding tuples incrementally after construction,

AddAutomaton

Return type: AutomatonConstraint

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

An automaton constraint/ An automaton constraint takes a list of variables (of size n), an initial state, a set of final states, and a set of transitions. A transition is a triplet ('tail', 'head', 'label'), where 'tail' and 'head' are states, and 'label' is the label of an arc from 'head' to 'tail', corresponding to the value of one variable in the list of variables. This automaton will be unrolled into a flow with n + 1 phases. Each phase contains the possible states of the automaton. The first state contains the initial state. The last phase contains the final states. Between two consecutive phases i and i + 1, the automaton creates a set of arcs. For each transition (tail, head, label), it will add an arc from the state 'tail' of phase i and the state 'head' of phase i + 1. This arc labeled by the value 'label' of the variables 'variables[i]'. That is, this arc can only be selected if 'variables[i]' is assigned the value 'label'. A feasible solution of this constraint is an assignment of variables such that, starting from the initial state in phase 0, there is a path labeled by the values of the variables that ends in one of the final states in the final phase. It returns an AutomatonConstraint that allows adding transition incrementally after construction.

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 a odd number of literal is true.

AddCircuitConstraint

Return type: CircuitConstraint

Adds a circuit constraint. The circuit constraint is defined on a graph where the arc presence is controlled by literals. That is the arc is part of the circuit of its corresponding literal is assigned to true. For now, we ignore node indices with no incident arc. All the other nodes must have exactly one incoming and one outgoing selected arc (i.e. literal at true). All the selected arcs that are not self-loops must form a single circuit. It returns a circuit constraint that allows adding arcs incrementally after construction.

AddCumulative

Return type: CumulativeConstraint

Arguments: IntVar capacity

The cumulative constraint It ensures that for any integer point, the sum of the demands of the intervals containing that point does not exceed the 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: IntVar target, IntVar numerator, IntVar denominator

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

AddElement

Return type: Constraint

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

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

AddEquality

Return type: Constraint

Arguments: const LinearExpr& left, const LinearExpr& right

Adds left == right.

AddForbiddenAssignments

Return type: TableConstraint

Arguments: absl::Span<const IntVar> vars

Adds an forbidden assignments constraint. A ForbiddenAssignments constraint is a constraint on an array of variables where the list of impossible combinations is provided in the tuples added to the constraint. It returns a table constraint that allows adding tuples incrementally after construction,

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 value

Adds hinting to a variable.

AddImplication

Return type: Constraint

Arguments: BoolVar a, BoolVar b

Adds a => b.

AddInverseConstraint

Return type: Constraint

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

An inverse constraint It enforces that if 'variables[i]' is assigned a value 'j', then inverse_variables[j] is assigned a value 'i'. And vice versa.

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: IntVar target, absl::Span<const IntVar> vars

Adds target == max(vars).

AddMinEquality

Return type: Constraint

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

Adds target == min(vars).

AddModuloEquality

Return type: Constraint

Arguments: IntVar target, IntVar var, IntVar mod

Adds target = var % mod.

AddNoOverlap

Return type: Constraint

Arguments: absl::Span<const IntervalVar> vars

Adds a no-overlap constraint that ensures that all present intervals do not overlap in time.

AddNoOverlap2D

Return type: NoOverlap2DConstraint

The no_overlap_2d constraint prevents a set of boxes from overlapping.

AddNotEqual

Return type: Constraint

Arguments: const LinearExpr& left, const LinearExpr& right

Adds left != right.

AddProductEquality

Return type: Constraint

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

Adds target == prod(vars).

AddReservoirConstraint

Return type: ReservoirConstraint

Arguments: int64 min_level, int64 max_level

Adds a reservoir constraint with optional refill/emptying events. Maintain a reservoir level within bounds. The water level starts at 0, and at any time >= 0, it must be within min_level, and max_level. Furthermore, this constraints expect all times variables to be >= 0. Given an event (time, demand, active), if active is true, and if time is assigned a value t, then the level of the reservoir changes by demand (which is constant) at time t. Note that level_min can be > 0, or level_max can be < 0. It just forces some demands to be executed at time 0 to make sure that we are within those bounds with the executed demands. Therefore, at any time t >= 0: sum(demands[i] * actives[i] if times[i] <= t) in [min_level, max_level] It returns a ReservoirConstraint that allows adding optional and non optional events incrementally after construction.

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&

FalseVar

Return type: BoolVar

Creates an always false Boolean variable.

Maximize

Return type: void

Arguments: const LinearExpr& expr

Adds a linear maximization objective.

Minimize

Return type: void

Arguments: const LinearExpr& expr

Adds a linear minimization objective.

MutableProto

Return type: CpModelProto*

NewBoolVar

Return type: BoolVar

Creates a Boolean variable.

NewConstant

Return type: IntVar

Arguments: int64 value

Creates a constant variable.

NewIntervalVar

Return type: IntervalVar

Arguments: IntVar start, IntVar size, IntVar end

Creates an interval variable.

NewIntVar

Return type: IntVar

Arguments: const Domain& domain

Creates an integer variable with the given domain.

NewOptionalIntervalVar

Return type: IntervalVar

Arguments: IntVar start, IntVar size, IntVar end, BoolVar presence

Creates an optional interval variable.

Proto

Return type: const CpModelProto&

ScaleObjectiveBy

Return type: void

Arguments: double scaling

Sets scaling of the objective. It must be called after \c Minimize() or \c Maximize()). \c scaling must be > 0.0.

TrueVar

Return type: BoolVar

Creates an always true Boolean variable.