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()

CpModel ( )
inline

Definition at line 25 of file CpModel.cs.

Member Function Documentation

◆ Add()

Constraint Add ( BoundedLinearExpression  lin)
inline

Adds a linear constraint to the model.

Definition at line 192 of file CpModel.cs.

◆ AddAbsEquality()

Constraint AddAbsEquality ( LinearExpr  target,
LinearExpr  expr 
)
inline

Adds target == abs(expr).

Definition at line 729 of file CpModel.cs.

◆ AddAllDifferent()

Constraint AddAllDifferent ( IEnumerable< LinearExpr exprs)
inline

Adds the constraint AllDifferent(exprs).

Definition at line 220 of file CpModel.cs.

◆ AddAllowedAssignments()

TableConstraint AddAllowedAssignments ( IEnumerable< IntVar vars)
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
varsa 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()

void AddAssumption ( ILiteral  lit)
inline

Adds a literal to the model as assumption.

Definition at line 1051 of file CpModel.cs.

◆ AddAssumptions()

void AddAssumptions ( IEnumerable< ILiteral literals)
inline

Adds multiple literals to the model as assumptions.

Definition at line 1057 of file CpModel.cs.

◆ AddAtLeastOne()

Constraint AddAtLeastOne ( IEnumerable< ILiteral literals)
inline

Same as AddBoolOr: ∑(literals) ≥ 1.

Definition at line 585 of file CpModel.cs.

◆ AddAtMostOne()

Constraint AddAtMostOne ( IEnumerable< ILiteral literals)
inline

Adds AtMostOne(literals): ∑(literals) ≤ 1.

Definition at line 595 of file CpModel.cs.

◆ AddAutomaton()

AutomatonConstraint AddAutomaton ( IEnumerable< IntVar vars,
long  starting_state,
IEnumerable< long >  final_states 
)
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
varsa non empty list of variables whose values correspond to the labels of the arcs traversed by the automaton
starting_statethe initial state of the automaton
final_statesa non empty list of admissible final states
Returns
an instance of the AutomatonConstraint class

Definition at line 415 of file CpModel.cs.

◆ AddBoolAnd()

Constraint AddBoolAnd ( IEnumerable< ILiteral literals)
inline

Adds And(literals) == true.

Definition at line 633 of file CpModel.cs.

◆ AddBoolOr()

Constraint AddBoolOr ( IEnumerable< ILiteral literals)
inline

Adds Or(literals) == true.

Definition at line 566 of file CpModel.cs.

◆ AddBoolXor()

Constraint AddBoolXor ( IEnumerable< ILiteral literals)
inline

Adds XOr(literals) == true.

Definition at line 652 of file CpModel.cs.

◆ AddCircuit()

CircuitConstraint 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 >()

CumulativeConstraint AddCumulative< C > ( capacity)
inline

Adds Cumulative(capacity).

This constraint enforces that:

forall t:
∑( demands[i] if (start(intervals[t]) ≤ t < end(intervals[t])) and
(t is present) ) ≤ capacity
Parameters
capacitythe 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()

void AddDecisionStrategy ( IEnumerable< IntVar vars,
DecisionStrategyProto.Types.VariableSelectionStrategy  var_str,
DecisionStrategyProto.Types.DomainReductionStrategy  dom_str 
)
inline

Adds DecisionStrategy(variables, var_str, dom_str).

.

Definition at line 1021 of file CpModel.cs.

◆ AddDivisionEquality< T, N, D >()

Constraint AddDivisionEquality< T, N, D > ( target,
num,
denom 
)
inline

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

Definition at line 711 of file CpModel.cs.

◆ AddElement() [1/3]

Constraint AddElement ( IntVar  index,
IEnumerable< int >  values,
IntVar  target 
)
inline

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

Definition at line 281 of file CpModel.cs.

◆ AddElement() [2/3]

Constraint AddElement ( IntVar  index,
IEnumerable< IntVar vars,
IntVar  target 
)
inline

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

Definition at line 239 of file CpModel.cs.

◆ AddElement() [3/3]

Constraint AddElement ( IntVar  index,
IEnumerable< long >  values,
IntVar  target 
)
inline

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

Definition at line 260 of file CpModel.cs.

◆ AddExactlyOne()

Constraint AddExactlyOne ( IEnumerable< ILiteral literals)
inline

Adds ExactlyOne(literals): ∑(literals) == 1.

Definition at line 614 of file CpModel.cs.

◆ AddForbiddenAssignments()

TableConstraint AddForbiddenAssignments ( IEnumerable< IntVar vars)
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
varsa 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()

void AddHint ( IntVar  var,
long  value 
)
inline

Adds variable hinting to the model.

Definition at line 1037 of file CpModel.cs.

◆ AddImplication()

Constraint AddImplication ( ILiteral  a,
ILiteral  b 
)
inline

Adds a ⇒ b.

Definition at line 549 of file CpModel.cs.

◆ AddInverse()

Constraint AddInverse ( IEnumerable< IntVar direct,
IEnumerable< IntVar reverse 
)
inline

Adds Inverse(variables, inverseVariables).

An inverse constraint enforces that if direct[i] == j, then reverse[j] == i, and vice versa.

Parameters
directan array of integer variables
reversean array of integer variables
Returns
an instance of the Constraint class

Definition at line 446 of file CpModel.cs.

◆ AddLinearConstraint()

Constraint AddLinearConstraint ( LinearExpr  expr,
long  lb,
long  ub 
)
inline

Adds lb ≤ expr ≤ ub.

Definition at line 141 of file CpModel.cs.

◆ AddLinearExpressionInDomain()

Constraint AddLinearExpressionInDomain ( LinearExpr  expr,
Domain  domain 
)
inline

Adds expr ∈ domain.

Definition at line 158 of file CpModel.cs.

◆ AddMapDomain()

void AddMapDomain ( IntVar  var,
IEnumerable< IntVar bool_vars,
long  offset = 0 
)
inline

Definition at line 504 of file CpModel.cs.

◆ AddMaxEquality()

Constraint AddMaxEquality ( LinearExpr  target,
IEnumerable< LinearExpr exprs 
)
inline

Adds target == Max(exprs).

Definition at line 691 of file CpModel.cs.

◆ AddMinEquality()

Constraint AddMinEquality ( LinearExpr  target,
IEnumerable< LinearExpr exprs 
)
inline

Adds target == Min(exprs).

Definition at line 671 of file CpModel.cs.

◆ AddModuloEquality< T, V, M >()

Constraint AddModuloEquality< T, V, M > ( target,
v,
m 
)
inline

Adds target == v % m.

Definition at line 747 of file CpModel.cs.

◆ AddMultipleCircuit()

MultipleCircuitConstraint 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]

Constraint AddMultiplicationEquality ( LinearExpr  target,
IEnumerable< LinearExpr exprs 
)
inline

Adds target == ∏(exprs).

Definition at line 765 of file CpModel.cs.

◆ AddMultiplicationEquality() [2/2]

Constraint AddMultiplicationEquality ( LinearExpr  target,
LinearExpr  left,
LinearExpr  right 
)
inline

Adds target == left * right.

Definition at line 785 of file CpModel.cs.

◆ AddNoOverlap()

Constraint AddNoOverlap ( IEnumerable< IntervalVar intervals)
inline

Adds NoOverlap(intervalVars).

A NoOverlap constraint ensures that all present intervals do not overlap in time.

Parameters
intervalsthe list of interval variables to constrain
Returns
an instance of the Constraint class

Definition at line 925 of file CpModel.cs.

◆ AddNoOverlap2D()

NoOverlap2dConstraint 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()

ReservoirConstraint AddReservoirConstraint ( long  minLevel,
long  maxLevel 
)
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:

∑(levelChanges[i] * actives[i] if times[i] ≤ t) in [min_level, max_level]

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
minLevelat any time, the level of the reservoir must be greater of equal than the min level. minLevel must me ≤ 0
maxLevelat 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()

void ClearAssumptions ( )
inline

Clears all assumptions from the model.

Definition at line 1066 of file CpModel.cs.

◆ ClearHints()

void ClearHints ( )
inline

Clears all hinting from the model.

Definition at line 1045 of file CpModel.cs.

◆ ExportToFile()

Boolean ExportToFile ( String  file)
inline

Write the model as a protocol buffer to file.

Parameters
filefile 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()

ILiteral FalseLiteral ( )
inline

Returns a constant false literal.

Definition at line 118 of file CpModel.cs.

◆ Maximize()

void Maximize ( LinearExpr  obj)
inline

Adds a maximization objective of a linear expression.

Definition at line 1001 of file CpModel.cs.

◆ Minimize()

void Minimize ( LinearExpr  obj)
inline

Adds a minimization objective of a linear expression.

Definition at line 995 of file CpModel.cs.

◆ ModelStats()

String ModelStats ( )
inline

Returns some statistics on model as a string.

Definition at line 1128 of file CpModel.cs.

◆ NewBoolVar()

BoolVar NewBoolVar ( string  name)
inline

Creates an Boolean variable with given domain.

Definition at line 98 of file CpModel.cs.

◆ NewConstant()

IntVar NewConstant ( long  value)
inline

Creates a constant variable.

Definition at line 88 of file CpModel.cs.

◆ NewFixedSizeIntervalVar< S >()

IntervalVar NewFixedSizeIntervalVar< S > ( start,
long  size,
string  name 
)
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
startthe start of the interval. It needs to be an affine or constant expression. *
sizethe fixed size of the interval
namethe name of the interval variable
Returns
An IntervalVar object

Definition at line 843 of file CpModel.cs.

◆ NewIntervalVar< S, D, E >()

IntervalVar NewIntervalVar< S, D, E > ( start,
size,
end,
string  name 
)
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
startthe start of the interval. It needs to be an affine or constant expression.
sizethe size of the interval. It needs to be an affine or constant expression.
endthe end of the interval. It needs to be an affine or constant expression.
namethe name of the interval variable
Returns
An IntervalVar object

Definition at line 815 of file CpModel.cs.

◆ NewIntVar()

IntVar NewIntVar ( long  lb,
long  ub,
string  name 
)
inline

Creates an integer variable with domain [lb, ub].

Parameters
lbthe lower bound of the domain
ubthe upper bound of the domain
namethe name of the variable
Returns
a variable with the given domain

Definition at line 64 of file CpModel.cs.

◆ NewIntVarFromDomain()

IntVar NewIntVarFromDomain ( Domain  domain,
string  name 
)
inline

Creates an integer variable with given domain.

Parameters
domainan instance of the Domain class
namethe name of the variable
Returns
a variable with the given domain

Definition at line 78 of file CpModel.cs.

◆ NewOptionalFixedSizeIntervalVar< S >()

IntervalVar NewOptionalFixedSizeIntervalVar< S > ( start,
long  size,
ILiteral  is_present,
string  name 
)
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
startthe start of the interval. It needs to be an affine or constant expression. *
sizethe fixed size of the interval
is_presenta literal that indicates if the interval is active or not. A inactive interval is simply ignored by all constraints.
namethe name of the interval variable
Returns
An IntervalVar object

Definition at line 904 of file CpModel.cs.

◆ NewOptionalIntervalVar< S, D, E >()

IntervalVar NewOptionalIntervalVar< S, D, E > ( start,
size,
end,
ILiteral  is_present,
string  name 
)
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
startthe start of the interval. It needs to be an affine or constant expression.
sizethe size of the interval. It needs to be an affine or constant expression.
endthe end of the interval. It needs to be an affine or constant expression.
is_presenta literal that indicates if the interval is active or not. A inactive interval is simply ignored by all constraints.
namethe name of the interval variable
Returns
An IntervalVar object

Definition at line 873 of file CpModel.cs.

◆ TrueLiteral()

ILiteral TrueLiteral ( )
inline

Returns a constant true literal.

Definition at line 108 of file CpModel.cs.

◆ Validate()

String 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

CpModelProto Model
get

The underlying CpModelProto.

Definition at line 40 of file CpModel.cs.


The documentation for this class was generated from the following file: