![]() |
Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
|
Wrapper class around the cp_model proto. More...
Wrapper class around the cp_model proto.
Definition at line 23 of file CpModel.cs.
Public Member Functions | |
| CpModel () | |
| IntVar | NewIntVar (long lb, long ub, string name) |
| Integer variables and constraints. | |
| IntVar | NewIntVarFromDomain (Domain domain, string name) |
| Creates an integer variable with given domain. | |
| IntVar | NewConstant (long value) |
| Creates a constant variable. | |
| BoolVar | NewBoolVar (string name) |
| Creates a Boolean variable with given domain. | |
| ILiteral | TrueLiteral () |
| Returns a constant true literal. | |
| ILiteral | FalseLiteral () |
| Returns a constant false literal. | |
| Constraint | AddLinearConstraint (LinearExpr expr, long lb, long ub) |
Adds lb ≤ expr ≤ ub. | |
| Constraint | AddLinearExpressionInDomain (LinearExpr expr, Domain domain) |
Adds expr ∈ domain. | |
| Constraint | Add (BoundedLinearExpression lin) |
| Adds a linear constraint to the model. | |
| Constraint | AddAllDifferent (IEnumerable< LinearExpr > exprs) |
Adds the constraint AllDifferent(exprs). | |
| Constraint | AddElement (LinearExpr index, IEnumerable< LinearExpr > exprs, LinearExpr target) |
Adds the element constraint: exprs[index] == target. | |
| Constraint | AddElement (LinearExpr index, IEnumerable< long > values, LinearExpr target) |
Adds the element constraint: values[index] == target. | |
| Constraint | AddElement (LinearExpr index, IEnumerable< int > values, LinearExpr target) |
Adds the element constraint: values[index] == target. | |
| CircuitConstraint | AddCircuit () |
| Adds and returns an empty circuit constraint. | |
| MultipleCircuitConstraint | AddMultipleCircuit () |
| Adds and returns an empty multiple circuit constraint. | |
| TableConstraint | AddAllowedAssignments (IEnumerable< LinearExpr > exprs) |
Adds AllowedAssignments(expressions). | |
| TableConstraint | AddForbiddenAssignments (IEnumerable< LinearExpr > exprs) |
Adds ForbiddenAssignments(variables). | |
| AutomatonConstraint | AddAutomaton (IEnumerable< LinearExpr > expressions, long starting_state, IEnumerable< long > final_states) |
| Adds an automaton constraint. | |
| Constraint | AddInverse (IEnumerable< IntVar > direct, IEnumerable< IntVar > reverse) |
Adds Inverse(variables, inverseVariables). | |
| ReservoirConstraint | AddReservoirConstraint (long minLevel, long maxLevel) |
| Adds a reservoir constraint with optional refill/emptying events. | |
| void | AddMapDomain (IntVar var, IEnumerable< IntVar > bool_vars, long offset=0) |
Adds var == i + offset ⇔ bool_vars[i] == true for all i. | |
| Constraint | AddImplication (ILiteral a, ILiteral b) |
Adds a ⇒ b. | |
| Constraint | AddBoolOr (IEnumerable< ILiteral > literals) |
Adds Or(literals) == true. | |
| Constraint | AddAtLeastOne (IEnumerable< ILiteral > literals) |
Same as AddBoolOr: ∑(literals) ≥ 1. | |
| Constraint | AddAtMostOne (IEnumerable< ILiteral > literals) |
Adds AtMostOne(literals): ∑(literals) ≤ 1. | |
| Constraint | AddExactlyOne (IEnumerable< ILiteral > literals) |
Adds ExactlyOne(literals): ∑(literals) == 1. | |
| Constraint | AddBoolAnd (IEnumerable< ILiteral > literals) |
Adds And(literals) == true. | |
| Constraint | AddBoolXor (IEnumerable< ILiteral > literals) |
Adds XOr(literals) == true. | |
| Constraint | AddMinEquality (LinearExpr target, IEnumerable< LinearExpr > exprs) |
Adds target == Min(exprs). | |
| Constraint | AddMaxEquality (LinearExpr target, IEnumerable< LinearExpr > exprs) |
Adds target == Max(exprs). | |
| Constraint | AddDivisionEquality< T, N, D > (T target, N num, D denom) |
Adds target == num / denom (integer division rounded towards 0). | |
| Constraint | AddAbsEquality (LinearExpr target, LinearExpr expr) |
Adds target == abs(expr). | |
| Constraint | AddModuloEquality< T, V, M > (T target, V v, M m) |
Adds target == v % m. | |
| Constraint | AddMultiplicationEquality (LinearExpr target, IEnumerable< LinearExpr > exprs) |
Adds target == ∏(exprs). | |
| Constraint | AddMultiplicationEquality (LinearExpr target, LinearExpr left, LinearExpr right) |
Adds target == left * right. | |
| IntervalVar | NewIntervalVar< S, D, E > (S start, D size, E end, string name) |
| Scheduling support. | |
| IntervalVar | NewFixedSizeIntervalVar< S > (S start, long size, string name) |
| Creates an interval variable from an affine expression start, and a fixed size. | |
| IntervalVar | NewOptionalIntervalVar< S, D, E > (S start, D size, E end, ILiteral is_present, string name) |
| Creates an optional interval variable from three affine expressions start, size, and end, and a literal is_present. | |
| IntervalVar | NewOptionalFixedSizeIntervalVar< S > (S start, long size, ILiteral is_present, string name) |
| Creates an optional interval variable from an affine expression start, a fixed size, and a literal is_present. | |
| Constraint | AddNoOverlap (IEnumerable< IntervalVar > intervals) |
| NoOverlap2dConstraint | AddNoOverlap2D () |
Adds NoOverlap2D(). | |
| CumulativeConstraint | AddCumulative< C > (C capacity) |
Adds Cumulative(capacity). | |
| void | Minimize (LinearExpr obj) |
| Objective. | |
| void | Maximize (LinearExpr obj) |
| Adds a maximization objective of a linear expression. | |
| void | AddDecisionStrategy (IEnumerable< IntVar > vars, DecisionStrategyProto.Types.VariableSelectionStrategy var_str, DecisionStrategyProto.Types.DomainReductionStrategy dom_str) |
| Search Decision. | |
| void | AddHint (IntVar var, long value) |
| Adds variable hinting to the model. | |
| void | AddHint (ILiteral lit, bool value) |
| Adds variable hinting to the model. | |
| void | ClearHints () |
| Clears all hinting from the model. | |
| void | AddAssumption (ILiteral lit) |
| Adds a literal to the model as assumption. | |
| void | AddAssumptions (IEnumerable< ILiteral > literals) |
| Adds multiple literals to the model as assumptions. | |
| void | ClearAssumptions () |
| Clears all assumptions from the model. | |
| String | ModelStats () |
| Returns some statistics on model as a string. | |
| Boolean | ExportToFile (String file) |
Write the model as a protocol buffer to file. | |
| String | Validate () |
| Returns a non empty string explaining the issue if the model is invalid. | |
Properties | |
| CpModelProto | Model [get] |
| Getters. | |
|
inline |
Definition at line 25 of file CpModel.cs.
|
inline |
Adds a linear constraint to the model.
Definition at line 192 of file CpModel.cs.
|
inline |
Adds target == abs(expr).
Definition at line 737 of file CpModel.cs.
|
inline |
Adds the constraint AllDifferent(exprs).
Definition at line 220 of file CpModel.cs.
|
inline |
Adds AllowedAssignments(expressions).
An AllowedAssignments constraint is a constraint on an array of affine expressions (a * var + b) that forces, when all expressions are fixed to a single value, that the corresponding list of values is equal to one of the tuples of the tupleList.
| exprs | a list of affine expressions (a * var + b) |
Definition at line 348 of file CpModel.cs.
|
inline |
Adds a literal to the model as assumption.
Definition at line 1077 of file CpModel.cs.
|
inline |
Adds multiple literals to the model as assumptions.
Definition at line 1083 of file CpModel.cs.
|
inline |
Same as AddBoolOr: ∑(literals) ≥ 1.
Definition at line 593 of file CpModel.cs.
|
inline |
Adds AtMostOne(literals): ∑(literals) ≤ 1.
Definition at line 603 of file CpModel.cs.
|
inline |
Adds an automaton constraint.
An automaton constraint takes a list of affine expressions (of size n), an initial state, a set of final states, and a set of transitions that will be added incrementally directly on the returned AutomatonConstraint instance. A transition is a triplet (tail, transition, head), where tail and head are states, and transition is the label of an arc from head to tail, corresponding to the value of one expression in the list of expressions.
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, label, head), 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 expression expressions[i]. That is, this arc can only be selected expressions[i]a is assigned the value label.
A feasible solution of this constraint is an assignment of expression such that, starting from the initial state in phase 0, there is a path labeled by the values of the expressions that ends in one of the final states in the final phase.
| expressions | a non empty list of affine expressions (a * var + b) whose values correspond to the labels of the arcs traversed by the automaton |
| starting_state | the initial state of the automaton |
| final_states | a non empty list of admissible final states |
Definition at line 418 of file CpModel.cs.
|
inline |
Adds And(literals) == true.
Definition at line 641 of file CpModel.cs.
|
inline |
Adds Or(literals) == true.
Definition at line 574 of file CpModel.cs.
|
inline |
Adds XOr(literals) == true.
Definition at line 660 of file CpModel.cs.
|
inline |
Adds and returns an empty circuit constraint.
A circuit is a unique Hamiltonian cycle in a subgraph of the total graph. In case a node i is not in the cycle, then there must be a loop arc i -> i associated with a true literal. Otherwise this constraint will fail.
Definition at line 307 of file CpModel.cs.
|
inline |
Adds Cumulative(capacity).
This constraint enforces that:
| capacity | the maximum capacity of the cumulative constraint. It must be a positive affine expression |
Definition at line 987 of file CpModel.cs.
|
inline |
Search Decision.
Adds DecisionStrategy(variables, var_str, dom_str)..
Definition at line 1027 of file CpModel.cs.
|
inline |
Adds target == num / denom (integer division rounded towards 0).
Definition at line 719 of file CpModel.cs.
|
inline |
Adds the element constraint: values[index] == target.
Definition at line 281 of file CpModel.cs.
|
inline |
Adds the element constraint: exprs[index] == target.
Definition at line 239 of file CpModel.cs.
|
inline |
Adds the element constraint: values[index] == target.
Definition at line 260 of file CpModel.cs.
|
inline |
Adds ExactlyOne(literals): ∑(literals) == 1.
Definition at line 622 of file CpModel.cs.
|
inline |
Adds ForbiddenAssignments(variables).
A ForbiddenAssignments constraint is a constraint on an array of affine expressions (a * var + b) where the list of impossible combinations is provided in the tuples list.
| exprs | a list of affine expressions (a * var + b) |
Definition at line 377 of file CpModel.cs.
|
inline |
Adds variable hinting to the model.
Definition at line 1054 of file CpModel.cs.
|
inline |
Adds variable hinting to the model.
Definition at line 1046 of file CpModel.cs.
|
inline |
Adds a ⇒ b.
Definition at line 557 of file CpModel.cs.
|
inline |
Adds Inverse(variables, inverseVariables).
An inverse constraint enforces that if direct[i] == j, then reverse[j] == i, and vice versa.
| direct | an array of integer variables |
| reverse | an array of integer variables |
Definition at line 449 of file CpModel.cs.
|
inline |
Adds lb ≤ expr ≤ ub.
Definition at line 141 of file CpModel.cs.
|
inline |
Adds expr ∈ domain.
Definition at line 158 of file CpModel.cs.
|
inline |
Adds var == i + offset ⇔ bool_vars[i] == true for all i.
Definition at line 512 of file CpModel.cs.
|
inline |
Adds target == Max(exprs).
Definition at line 699 of file CpModel.cs.
|
inline |
Adds target == Min(exprs).
Definition at line 679 of file CpModel.cs.
|
inline |
Adds target == v % m.
Definition at line 755 of file CpModel.cs.
|
inline |
Adds and returns an empty multiple circuit constraint.
A multiple circuit is set of cycles in a subgraph of the total graph. The node index by 0 must be part of all cycles of length > 1. Each node with index > 0 belongs to exactly one cycle. If such node does not belong in any cycle of length > 1, then there must be a looping arc on this node attached to a literal that will be true. Otherwise, the constraint will fail.
Definition at line 325 of file CpModel.cs.
|
inline |
Adds target == ∏(exprs).
Definition at line 773 of file CpModel.cs.
|
inline |
Adds target == left * right.
Definition at line 793 of file CpModel.cs.
|
inline |
Adds NoOverlap(intervalVars).
A NoOverlap constraint ensures that all present intervals do not overlap in time.
| intervals | the list of interval variables to constrain |
Definition at line 931 of file CpModel.cs.
|
inline |
Adds NoOverlap2D().
A NoOverlap2D constraint ensures that all present rectangles do not overlap on a plan. Each rectangle is aligned with the X and Y axis, and is defined by two intervals which represent its projection onto the X and Y axis.
Furthermore, one box is optional if at least one of the x or y interval is optional.
Definition at line 961 of file CpModel.cs.
|
inline |
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, it must be within [min_level, max_level].
Given an event (time, levelChange, active), if active is true, and if time is assigned a value t, then the level of the reservoir changes by levelChange (which is constant) at time t. Therefore, at any time t:
Note that min level must be ≤ 0, and the max level must be ≥ 0. Please use fixed level_changes to simulate an initial state.
| minLevel | at any time, the level of the reservoir must be greater of equal than the min level. minLevel must me ≤ 0 |
| maxLevel | at any time, the level of the reservoir must be less or equal than the max level. maxLevel must be ≥ 0 |
Definition at line 495 of file CpModel.cs.
|
inline |
Clears all assumptions from the model.
Definition at line 1092 of file CpModel.cs.
|
inline |
Clears all hinting from the model.
Definition at line 1071 of file CpModel.cs.
|
inline |
Write the model as a protocol buffer to file.
| file | file to write the model to. If the filename ends with txt, the model will be written as a text file, otherwise, the binary format will be used. |
Definition at line 1169 of file CpModel.cs.
|
inline |
Returns a constant false literal.
Definition at line 118 of file CpModel.cs.
|
inline |
Adds a maximization objective of a linear expression.
Definition at line 1007 of file CpModel.cs.
|
inline |
Objective.
Adds a minimization objective of a linear expression.
Definition at line 1001 of file CpModel.cs.
|
inline |
Returns some statistics on model as a string.
Definition at line 1154 of file CpModel.cs.
|
inline |
Creates a Boolean variable with given domain.
Definition at line 98 of file CpModel.cs.
|
inline |
Creates a constant variable.
Definition at line 88 of file CpModel.cs.
|
inline |
Creates an interval variable from an affine expression start, and a fixed size.
An interval variable is a constraint, that is itself used in other constraints like NoOverlap.
| start | the start of the interval. It needs to be an affine or constant expression. * |
| size | the fixed size of the interval |
| name | the name of the interval variable |
Definition at line 850 of file CpModel.cs.
|
inline |
Scheduling support.
Creates an interval variable from three affine expressions start, size, and end.
An interval variable is a constraint, that is itself used in other constraints like NoOverlap. Internally, it ensures that start + size == end.
| start | the start of the interval. It needs to be an affine or constant expression. |
| size | the size of the interval. It needs to be an affine or constant expression. |
| end | the end of the interval. It needs to be an affine or constant expression. |
| name | the name of the interval variable |
Definition at line 823 of file CpModel.cs.
|
inline |
Integer variables and constraints.
Creates an integer variable with domain [lb, ub].
| lb | the lower bound of the domain |
| ub | the upper bound of the domain |
| name | the name of the variable |
Definition at line 64 of file CpModel.cs.
Creates an integer variable with given domain.
| domain | an instance of the Domain class |
| name | the name of the variable |
Definition at line 78 of file CpModel.cs.
|
inline |
Creates an optional interval variable from an affine expression start, a fixed size, and a literal is_present.
An interval variable is a constraint, that is itself used in other constraints like NoOverlap.
| start | the start of the interval. It needs to be an affine or constant expression. * |
| size | the fixed size of the interval |
| is_present | a literal that indicates if the interval is active or not. A inactive interval is simply ignored by all constraints. |
| name | the name of the interval variable |
Definition at line 910 of file CpModel.cs.
|
inline |
Creates an optional interval variable from three affine expressions start, size, and end, and a literal is_present.
An interval variable is a constraint, that is itself used in other constraints like NoOverlap. Internally, it ensures that is_present ⇒ start + size == end.
| start | the start of the interval. It needs to be an affine or constant expression. |
| size | the size of the interval. It needs to be an affine or constant expression. |
| end | the end of the interval. It needs to be an affine or constant expression. |
| is_present | a literal that indicates if the interval is active or not. A inactive interval is simply ignored by all constraints. |
| name | the name of the interval variable |
Definition at line 880 of file CpModel.cs.
|
inline |
Returns a constant true literal.
Definition at line 108 of file CpModel.cs.
|
inline |
Returns a non empty string explaining the issue if the model is invalid.
Definition at line 1179 of file CpModel.cs.
|
get |