DotNet Reference
.Net Reference
Detailed Description
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) |
Creates an integer variable with domain [lb, ub]. More... | |
IntVar | NewIntVarFromDomain (Domain domain, string name) |
Creates an integer variable with given domain. More... | |
IntVar | NewConstant (long value) |
Creates a constant variable. More... | |
BoolVar | NewBoolVar (string name) |
Creates an Boolean variable with given domain. More... | |
ILiteral | TrueLiteral () |
Returns a constant true literal. More... | |
ILiteral | FalseLiteral () |
Returns a constant false literal. More... | |
Constraint | AddLinearConstraint (LinearExpr expr, long lb, long ub) |
Adds lb ≤ expr ≤ ub . More... | |
Constraint | AddLinearExpressionInDomain (LinearExpr expr, Domain domain) |
Adds expr ∈ domain . More... | |
Constraint | Add (BoundedLinearExpression lin) |
Adds a linear constraint to the model. More... | |
Constraint | AddAllDifferent (IEnumerable< LinearExpr > exprs) |
Adds the constraint AllDifferent(exprs) . More... | |
Constraint | AddElement (IntVar index, IEnumerable< IntVar > vars, IntVar target) |
Adds the element constraint: variables[index] == target . More... | |
Constraint | AddElement (IntVar index, IEnumerable< long > values, IntVar target) |
Adds the element constraint: values[index] == target . More... | |
Constraint | AddElement (IntVar index, IEnumerable< int > values, IntVar target) |
Adds the element constraint: values[index] == target . More... | |
CircuitConstraint | AddCircuit () |
Adds and returns an empty circuit constraint. More... | |
MultipleCircuitConstraint | AddMultipleCircuit () |
Adds and returns an empty multiple circuit constraint. More... | |
TableConstraint | AddAllowedAssignments (IEnumerable< IntVar > vars) |
Adds AllowedAssignments(variables) . More... | |
TableConstraint | AddForbiddenAssignments (IEnumerable< IntVar > vars) |
Adds ForbiddenAssignments(variables) . More... | |
AutomatonConstraint | AddAutomaton (IEnumerable< IntVar > vars, long starting_state, IEnumerable< long > final_states) |
Adds an automaton constraint. More... | |
Constraint | AddInverse (IEnumerable< IntVar > direct, IEnumerable< IntVar > reverse) |
Adds Inverse(variables, inverseVariables) . More... | |
ReservoirConstraint | AddReservoirConstraint (long minLevel, long maxLevel) |
Adds a reservoir constraint with optional refill/emptying events. More... | |
void | AddMapDomain (IntVar var, IEnumerable< IntVar > bool_vars, long offset=0) |
Constraint | AddImplication (ILiteral a, ILiteral b) |
Adds a ⇒ b . More... | |
Constraint | AddBoolOr (IEnumerable< ILiteral > literals) |
Adds Or(literals) == true . More... | |
Constraint | AddAtLeastOne (IEnumerable< ILiteral > literals) |
Same as AddBoolOr: ∑(literals) ≥ 1 . More... | |
Constraint | AddAtMostOne (IEnumerable< ILiteral > literals) |
Adds AtMostOne(literals): ∑(literals) ≤ 1 . More... | |
Constraint | AddExactlyOne (IEnumerable< ILiteral > literals) |
Adds ExactlyOne(literals): ∑(literals) == 1 . More... | |
Constraint | AddBoolAnd (IEnumerable< ILiteral > literals) |
Adds And(literals) == true . More... | |
Constraint | AddBoolXor (IEnumerable< ILiteral > literals) |
Adds XOr(literals) == true . More... | |
Constraint | AddMinEquality (LinearExpr target, IEnumerable< LinearExpr > exprs) |
Adds target == Min(exprs) . More... | |
Constraint | AddMaxEquality (LinearExpr target, IEnumerable< LinearExpr > exprs) |
Adds target == Max(exprs) . More... | |
Constraint | AddDivisionEquality< T, N, D > (T target, N num, D denom) |
Adds target == num / denom (integer division rounded towards 0). More... | |
Constraint | AddAbsEquality (LinearExpr target, LinearExpr expr) |
Adds target == abs(expr) . More... | |
Constraint | AddModuloEquality< T, V, M > (T target, V v, M m) |
Adds target == v % m . More... | |
Constraint | AddMultiplicationEquality (LinearExpr target, IEnumerable< LinearExpr > exprs) |
Adds target == ∏(exprs) . More... | |
Constraint | AddMultiplicationEquality (LinearExpr target, LinearExpr left, LinearExpr right) |
Adds target == left * right . More... | |
IntervalVar | NewIntervalVar< S, D, E > (S start, D size, E end, string name) |
Creates an interval variable from three affine expressions start, size, and end. More... | |
IntervalVar | NewFixedSizeIntervalVar< S > (S start, long size, string name) |
Creates an interval variable from an affine expression start, and a fixed size. More... | |
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. More... | |
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. More... | |
Constraint | AddNoOverlap (IEnumerable< IntervalVar > intervals) |
Adds NoOverlap(intervalVars) . More... | |
NoOverlap2dConstraint | AddNoOverlap2D () |
Adds NoOverlap2D() . More... | |
CumulativeConstraint | AddCumulative< C > (C capacity) |
Adds Cumulative(capacity) . More... | |
void | Minimize (LinearExpr obj) |
Adds a minimization objective of a linear expression. More... | |
void | Maximize (LinearExpr obj) |
Adds a maximization objective of a linear expression. More... | |
void | AddDecisionStrategy (IEnumerable< IntVar > vars, DecisionStrategyProto.Types.VariableSelectionStrategy var_str, DecisionStrategyProto.Types.DomainReductionStrategy dom_str) |
Adds DecisionStrategy(variables, var_str, dom_str) . More... | |
void | AddHint (IntVar var, long value) |
Adds variable hinting to the model. More... | |
void | ClearHints () |
Clears all hinting from the model. More... | |
void | AddAssumption (ILiteral lit) |
Adds a literal to the model as assumption. More... | |
void | AddAssumptions (IEnumerable< ILiteral > literals) |
Adds multiple literals to the model as assumptions. More... | |
void | ClearAssumptions () |
Clears all assumptions from the model. More... | |
String | ModelStats () |
Returns some statistics on model as a string. More... | |
Boolean | ExportToFile (String file) |
Write the model as a protocol buffer to file . More... | |
String | Validate () |
Returns a non empty string explaining the issue if the model is invalid. More... | |
Properties | |
CpModelProto | Model [get] |
The underlying CpModelProto. More... | |
Constructor & Destructor Documentation
◆ CpModel()
|
inline |
Definition at line 25 of file CpModel.cs.
Member Function Documentation
◆ Add()
|
inline |
Adds a linear constraint to the model.
Definition at line 192 of file CpModel.cs.
◆ AddAbsEquality()
|
inline |
Adds target == abs(expr)
.
Definition at line 729 of file CpModel.cs.
◆ AddAllDifferent()
|
inline |
Adds the constraint AllDifferent(exprs)
.
Definition at line 220 of file CpModel.cs.
◆ AddAllowedAssignments()
|
inline |
Adds AllowedAssignments(variables)
.
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 tuples of the tupleList.
- Parameters
-
vars a list of variables
- Returns
- an instance of the TableConstraint class without any tuples. Tuples can be added directly to the table constraint
Definition at line 347 of file CpModel.cs.
◆ AddAssumption()
|
inline |
Adds a literal to the model as assumption.
Definition at line 1051 of file CpModel.cs.
◆ AddAssumptions()
|
inline |
Adds multiple literals to the model as assumptions.
Definition at line 1057 of file CpModel.cs.
◆ AddAtLeastOne()
|
inline |
Same as AddBoolOr: ∑(literals) ≥ 1
.
Definition at line 585 of file CpModel.cs.
◆ AddAtMostOne()
|
inline |
Adds AtMostOne(literals): ∑(literals) ≤ 1
.
Definition at line 595 of file CpModel.cs.
◆ AddAutomaton()
|
inline |
Adds 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 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 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
, 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 variables variables[i]
. That is, this arc can only be selected variables[i]
a 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.
- Parameters
-
vars a non empty list of variables 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
- Returns
- an instance of the AutomatonConstraint class
Definition at line 415 of file CpModel.cs.
◆ AddBoolAnd()
|
inline |
Adds And(literals) == true
.
Definition at line 633 of file CpModel.cs.
◆ AddBoolOr()
|
inline |
Adds Or(literals) == true
.
Definition at line 566 of file CpModel.cs.
◆ AddBoolXor()
|
inline |
Adds XOr(literals) == true
.
Definition at line 652 of file CpModel.cs.
◆ AddCircuit()
|
inline |
Adds and returns an empty circuit constraint.
A circuit is a unique Hamiltonian path in a subgraph of the total graph. In case a node i
is not in the path, 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.
◆ AddCumulative< C >()
|
inline |
Adds Cumulative(capacity)
.
This constraint enforces that:
- Parameters
-
capacity the maximum capacity of the cumulative constraint. It must be a positive affine expression
- Returns
- an instance of the CumulativeConstraint class. this class allows adding (interval, demand) pairs incrementally
Definition at line 981 of file CpModel.cs.
◆ AddDecisionStrategy()
|
inline |
◆ AddDivisionEquality< T, N, D >()
|
inline |
Adds target == num / denom
(integer division rounded towards 0).
Definition at line 711 of file CpModel.cs.
◆ AddElement() [1/3]
|
inline |
Adds the element constraint: values[index] == target
.
Definition at line 281 of file CpModel.cs.
◆ AddElement() [2/3]
|
inline |
Adds the element constraint: variables[index] == target
.
Definition at line 239 of file CpModel.cs.
◆ AddElement() [3/3]
|
inline |
Adds the element constraint: values[index] == target
.
Definition at line 260 of file CpModel.cs.
◆ AddExactlyOne()
|
inline |
Adds ExactlyOne(literals): ∑(literals) == 1
.
Definition at line 614 of file CpModel.cs.
◆ AddForbiddenAssignments()
|
inline |
Adds ForbiddenAssignments(variables)
.
A ForbiddenAssignments constraint is a constraint on an array of variables where the list of impossible combinations is provided in the tuples list.
- Parameters
-
vars a list of variables
- Returns
- an instance of the TableConstraint class without any tuples. Tuples can be added directly to the table constraint
Definition at line 375 of file CpModel.cs.
◆ AddHint()
|
inline |
Adds variable hinting to the model.
Definition at line 1037 of file CpModel.cs.
◆ AddImplication()
|
inline |
Adds a ⇒ b
.
Definition at line 549 of file CpModel.cs.
◆ AddInverse()
|
inline |
Adds Inverse(variables, inverseVariables)
.
An inverse constraint enforces that if direct[i] == j
, then reverse[j] == i
, and vice versa.
- Parameters
-
direct an array of integer variables reverse an array of integer variables
- Returns
- an instance of the Constraint class
Definition at line 446 of file CpModel.cs.
◆ AddLinearConstraint()
|
inline |
Adds lb ≤ expr ≤ ub
.
Definition at line 141 of file CpModel.cs.
◆ AddLinearExpressionInDomain()
|
inline |
Adds expr ∈ domain
.
Definition at line 158 of file CpModel.cs.
◆ AddMapDomain()
Definition at line 504 of file CpModel.cs.
◆ AddMaxEquality()
|
inline |
Adds target == Max(exprs)
.
Definition at line 691 of file CpModel.cs.
◆ AddMinEquality()
|
inline |
Adds target == Min(exprs)
.
Definition at line 671 of file CpModel.cs.
◆ AddModuloEquality< T, V, M >()
|
inline |
Adds target == v % m
.
Definition at line 747 of file CpModel.cs.
◆ AddMultipleCircuit()
|
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.
◆ AddMultiplicationEquality() [1/2]
|
inline |
Adds target == ∏(exprs)
.
Definition at line 765 of file CpModel.cs.
◆ AddMultiplicationEquality() [2/2]
|
inline |
Adds target == left * right
.
Definition at line 785 of file CpModel.cs.
◆ AddNoOverlap()
|
inline |
Adds NoOverlap(intervalVars)
.
A NoOverlap constraint ensures that all present intervals do not overlap in time.
- Parameters
-
intervals the list of interval variables to constrain
- Returns
- an instance of the Constraint class
Definition at line 925 of file CpModel.cs.
◆ AddNoOverlap2D()
|
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.
- Returns
- an instance of the NoOverlap2dConstraint class. This class allows adding rectangles incrementally
Definition at line 955 of file CpModel.cs.
◆ AddReservoirConstraint()
|
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.
- Parameters
-
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
- Returns
- an instance of the ReservoirConstraint class
Definition at line 492 of file CpModel.cs.
◆ ClearAssumptions()
|
inline |
Clears all assumptions from the model.
Definition at line 1066 of file CpModel.cs.
◆ ClearHints()
|
inline |
Clears all hinting from the model.
Definition at line 1045 of file CpModel.cs.
◆ ExportToFile()
|
inline |
Write the model as a protocol buffer to file
.
- Parameters
-
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.
- Returns
- true if the model was correctly written
Definition at line 1143 of file CpModel.cs.
◆ FalseLiteral()
|
inline |
Returns a constant false literal.
Definition at line 118 of file CpModel.cs.
◆ Maximize()
|
inline |
Adds a maximization objective of a linear expression.
Definition at line 1001 of file CpModel.cs.
◆ Minimize()
|
inline |
Adds a minimization objective of a linear expression.
Definition at line 995 of file CpModel.cs.
◆ ModelStats()
|
inline |
Returns some statistics on model as a string.
Definition at line 1128 of file CpModel.cs.
◆ NewBoolVar()
|
inline |
Creates an Boolean variable with given domain.
Definition at line 98 of file CpModel.cs.
◆ NewConstant()
|
inline |
Creates a constant variable.
Definition at line 88 of file CpModel.cs.
◆ NewFixedSizeIntervalVar< S >()
|
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.
- Parameters
-
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
- Returns
- An IntervalVar object
Definition at line 843 of file CpModel.cs.
◆ NewIntervalVar< S, D, E >()
|
inline |
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
.
- Parameters
-
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
- Returns
- An IntervalVar object
Definition at line 815 of file CpModel.cs.
◆ NewIntVar()
|
inline |
Creates an integer variable with domain [lb, ub].
- Parameters
-
lb the lower bound of the domain ub the upper bound of the domain name the name of the variable
- Returns
- a variable with the given domain
Definition at line 64 of file CpModel.cs.
◆ NewIntVarFromDomain()
|
inline |
Creates an integer variable with given domain.
- Parameters
-
domain an instance of the Domain class name the name of the variable
- Returns
- a variable with the given domain
Definition at line 78 of file CpModel.cs.
◆ NewOptionalFixedSizeIntervalVar< S >()
|
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.
- Parameters
-
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
- Returns
- An IntervalVar object
Definition at line 904 of file CpModel.cs.
◆ NewOptionalIntervalVar< S, D, E >()
|
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
.
- Parameters
-
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
- Returns
- An IntervalVar object
Definition at line 873 of file CpModel.cs.
◆ TrueLiteral()
|
inline |
Returns a constant true literal.
Definition at line 108 of file CpModel.cs.
◆ Validate()
|
inline |
Returns a non empty string explaining the issue if the model is invalid.
Definition at line 1153 of file CpModel.cs.
Property Documentation
◆ Model
|
get |
The underlying CpModelProto.
Definition at line 40 of file CpModel.cs.
The documentation for this class was generated from the following file: