Java Reference
Java Reference
Detailed Description
Main modeling class.
Proposes a factory to create all modeling objects understood by the SAT solver.
Definition at line 40 of file CpModel.java.
Classes | |
| class | CpModelException |
| class | MismatchedArrayLengths |
| Exception thrown when parallel arrays have mismatched lengths. More... | |
| class | WrongLength |
| Exception thrown when an array has a wrong length. More... | |
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 | newBoolVar (String name) |
| Creates a Boolean variable with the given name. More... | |
| IntVar | newConstant (long value) |
| Creates a constant variable. More... | |
| Constraint | addBoolOr (Literal[] literals) |
| Adds. More... | |
| Constraint | addBoolAnd (Literal[] literals) |
| Adds. More... | |
| Constraint | addBoolXor (Literal[] literals) |
| Adds. More... | |
| Constraint | addImplication (Literal a, Literal b) |
| Adds. More... | |
| Constraint | addLinearExpressionInDomain (LinearExpr expr, Domain domain) |
| Adds. More... | |
| Constraint | addLinearConstraint (LinearExpr expr, long lb, long ub) |
| Adds. More... | |
| Constraint | addEquality (LinearExpr expr, long value) |
| Adds. More... | |
| Constraint | addEquality (LinearExpr left, LinearExpr right) |
| Adds. More... | |
| Constraint | addEqualityWithOffset (LinearExpr left, LinearExpr right, long offset) |
| Adds. More... | |
| Constraint | addLessOrEqual (LinearExpr expr, long value) |
| Adds. More... | |
| Constraint | addLessOrEqual (LinearExpr left, LinearExpr right) |
| Adds. More... | |
| Constraint | addLessThan (LinearExpr expr, long value) |
| Adds. More... | |
| Constraint | addLessThan (LinearExpr left, LinearExpr right) |
| Adds. More... | |
| Constraint | addLessOrEqualWithOffset (LinearExpr left, LinearExpr right, long offset) |
| Adds. More... | |
| Constraint | addGreaterOrEqual (LinearExpr expr, long value) |
| Adds. More... | |
| Constraint | addGreaterOrEqual (LinearExpr left, LinearExpr right) |
| Adds. More... | |
| Constraint | addGreaterThan (LinearExpr expr, long value) |
| Adds. More... | |
| Constraint | addGreaterThan (LinearExpr left, LinearExpr right) |
| Adds. More... | |
| Constraint | addGreaterOrEqualWithOffset (LinearExpr left, LinearExpr right, long offset) |
| Adds. More... | |
| Constraint | addDifferent (LinearExpr expr, long value) |
| Adds. More... | |
| Constraint | addDifferent (IntVar left, IntVar right) |
| Adds. More... | |
| Constraint | addDifferentWithOffset (IntVar left, IntVar right, long offset) |
| Adds. More... | |
| Constraint | addAllDifferent (IntVar[] variables) |
| Adds. More... | |
| Constraint | addElement (IntVar index, IntVar[] variables, IntVar target) |
| Adds the element constraint: More... | |
| Constraint | addElement (IntVar index, long[] values, IntVar target) |
| Adds the element constraint: More... | |
| Constraint | addElement (IntVar index, int[] values, IntVar target) |
| Adds the element constraint: More... | |
| Constraint | addCircuit (int[] tails, int[] heads, Literal[] literals) throws MismatchedArrayLengths |
| Adds. More... | |
| Constraint | addAllowedAssignments (IntVar[] variables, long[][] tuplesList) throws WrongLength |
| Adds. More... | |
| Constraint | addAllowedAssignments (IntVar[] variables, int[][] tuplesList) throws WrongLength |
| Adds. More... | |
| Constraint | addForbiddenAssignments (IntVar[] variables, long[][] tuplesList) throws WrongLength |
| Adds. More... | |
| Constraint | addForbiddenAssignments (IntVar[] variables, int[][] tuplesList) throws WrongLength |
| Adds. More... | |
| Constraint | addAutomaton (IntVar[] transitionVariables, long startingState, long[] finalStates, long[][] transitions) throws WrongLength |
| Adds an automaton constraint. More... | |
| Constraint | addInverse (IntVar[] variables, IntVar[] inverseVariables) throws MismatchedArrayLengths |
| Adds. More... | |
| Constraint | addReservoirConstraint (IntVar[] times, long[] demands, long minLevel, long maxLevel) throws MismatchedArrayLengths |
| Adds. More... | |
| Constraint | addReservoirConstraint (IntVar[] times, int[] demands, long minLevel, long maxLevel) throws MismatchedArrayLengths |
| Adds. More... | |
| Constraint | addReservoirConstraintWithActive (IntVar[] times, long[] demands, IntVar[] actives, long minLevel, long maxLevel) throws MismatchedArrayLengths |
| Adds. More... | |
| Constraint | addReservoirConstraintWithActive (IntVar[] times, int[] demands, IntVar[] actives, long minLevel, long maxLevel) throws MismatchedArrayLengths |
| Adds. More... | |
| void | addMapDomain (IntVar var, Literal[] booleans, long offset) |
| Adds. More... | |
| Constraint | addMinEquality (IntVar target, IntVar[] vars) |
| Adds. More... | |
| Constraint | addMaxEquality (IntVar target, IntVar[] vars) |
| Adds. More... | |
| Constraint | addDivisionEquality (IntVar target, IntVar num, IntVar denom) |
| Adds. More... | |
| Constraint | addAbsEquality (IntVar target, IntVar var) |
| Adds. More... | |
| Constraint | addModuloEquality (IntVar target, IntVar var, IntVar mod) |
| Adds. More... | |
| Constraint | addModuloEquality (IntVar target, IntVar var, long mod) |
| Adds. More... | |
| Constraint | addProductEquality (IntVar target, IntVar[] vars) |
| Adds. More... | |
| IntervalVar | newIntervalVar (IntVar start, IntVar size, IntVar end, String name) |
| Creates an interval variable from start, size, and end. More... | |
| IntervalVar | newIntervalVar (IntVar start, IntVar size, long end, String name) |
| Creates an interval variable with a fixed end. More... | |
| IntervalVar | newIntervalVar (IntVar start, long size, IntVar end, String name) |
| Creates an interval variable with a fixed size. More... | |
| IntervalVar | newIntervalVar (long start, IntVar size, IntVar end, String name) |
| Creates an interval variable with a fixed start. More... | |
| IntervalVar | newFixedInterval (long start, long size, String name) |
| Creates a fixed interval from its start and its size. More... | |
| IntervalVar | newOptionalIntervalVar (IntVar start, IntVar size, IntVar end, Literal isPresent, String name) |
| Creates an optional interval variable from start, size, end, and isPresent. More... | |
| IntervalVar | newOptionalIntervalVar (IntVar start, IntVar size, long end, Literal isPresent, String name) |
| Creates an optional interval with a fixed end. More... | |
| IntervalVar | newOptionalIntervalVar (IntVar start, long size, IntVar end, Literal isPresent, String name) |
| Creates an optional interval with a fixed size. More... | |
| IntervalVar | newOptionalIntervalVar (long start, IntVar size, IntVar end, Literal isPresent, String name) |
| Creates an optional interval with a fixed start. More... | |
| IntervalVar | newOptionalFixedInterval (long start, long size, Literal isPresent, String name) |
| Creates an optional fixed interval from start and size. More... | |
| Constraint | addNoOverlap (IntervalVar[] intervalVars) |
| Adds. More... | |
| Constraint | addNoOverlap2D (IntervalVar[] xIntervals, IntervalVar[] yIntervals) |
| Adds. More... | |
| Constraint | addCumulative (IntervalVar[] intervals, IntVar[] demands, IntVar capacity) |
| Adds. More... | |
| Constraint | addCumulative (IntervalVar[] intervals, long[] demands, IntVar capacity) |
| Adds. More... | |
| Constraint | addCumulative (IntervalVar[] intervals, int[] demands, IntVar capacity) |
| Adds. More... | |
| Constraint | addCumulative (IntervalVar[] intervals, IntVar[] demands, long capacity) |
| Adds. More... | |
| Constraint | addCumulative (IntervalVar[] intervals, long[] demands, long capacity) |
| Adds. More... | |
| Constraint | addCumulative (IntervalVar[] intervals, int[] demands, long capacity) |
| Adds. More... | |
| void | addHint (IntVar var, long value) |
| Adds hinting to a variable. More... | |
| void | minimize (LinearExpr expr) |
| Adds a minimization objective of a linear expression. More... | |
| void | maximize (LinearExpr expr) |
| Adds a maximization objective of a linear expression. More... | |
| void | addDecisionStrategy (IntVar[] variables, DecisionStrategyProto.VariableSelectionStrategy varStr, DecisionStrategyProto.DomainReductionStrategy domStr) |
| Adds. More... | |
| String | modelStats () |
| Returns some statistics on model as a string. More... | |
| String | validate () |
| Returns a non empty string explaining the issue if the model is invalid. More... | |
| CpModelProto | model () |
| int | negated (int index) |
| CpModelProto.Builder | getBuilder () |
| Returns the model builder. More... | |
Constructor & Destructor Documentation
◆ CpModel()
|
inline |
Definition at line 62 of file CpModel.java.
Member Function Documentation
◆ addAbsEquality()
|
inline |
◆ addAllDifferent()
|
inline |
Adds.
.
This constraint forces all variables to have different values.
- Parameters
-
variables a list of integer variables
- Returns
- an instance of the Constraint class
Definition at line 249 of file CpModel.java.
◆ addAllowedAssignments() [1/2]
|
inline |
◆ addAllowedAssignments() [2/2]
|
inline |
Adds.
.
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
-
variables a list of variables tuplesList a list of admissible tuples. Each tuple must have the same length as the variables, and the ith value of a tuple corresponds to the ith variable.
- Returns
- an instance of the Constraint class
- Exceptions
-
WrongLength if one tuple does not have the same length as the variables
Definition at line 345 of file CpModel.java.
◆ 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. 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 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.
- Parameters
-
transitionVariables a non empty list of variables whose values correspond to the labels of the arcs traversed by the automaton startingState the initial state of the automaton finalStates a non empty list of admissible final states transitions a list of transition for the automaton, in the following format (currentState, variableValue, nextState)
- Returns
- an instance of the Constraint class
- Exceptions
-
WrongLength if one transition does not have a length of 3
Definition at line 454 of file CpModel.java.
◆ addBoolAnd()
|
inline |
◆ addBoolOr()
|
inline |
◆ addBoolXor()
|
inline |
◆ addCircuit()
|
inline |
Adds.
.
Adds a circuit constraint from a sparse list of arcs that encode the graph.
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
associated with a true literal. Otherwise this constraint will fail.
- Parameters
-
tails the tails of all arcs heads the heads of all arcs literals the literals that control whether an arc is selected or not
- Returns
- an instance of the Constraint class
- Exceptions
-
MismatchedArrayLengths if the arrays have different sizes
Definition at line 309 of file CpModel.java.
◆ addCumulative() [1/6]
|
inline |
Adds.
with fixed demands.
- See also
- addCumulative(IntervalVar[], IntVar[], IntVar) AddCumulative
Definition at line 906 of file CpModel.java.
◆ addCumulative() [2/6]
|
inline |
Adds.
with fixed demands and fixed capacity.
- See also
- addCumulative(IntervalVar[], IntVar[], IntVar) AddCumulative
Definition at line 951 of file CpModel.java.
◆ addCumulative() [3/6]
|
inline |
Adds.
.
This constraint enforces that:
.
- Parameters
-
intervals the list of intervals demands the list of demands for each interval. Each demand must be a positive integer variable. capacity the maximum capacity of the cumulative constraint. It must be a positive integer variable.
- Returns
- an instance of the Constraint class
Definition at line 870 of file CpModel.java.
◆ addCumulative() [4/6]
|
inline |
Adds.
with fixed capacity.
- See also
- addCumulative(IntervalVar[], IntVar[], IntVar) AddCumulative
Definition at line 915 of file CpModel.java.
◆ addCumulative() [5/6]
|
inline |
Adds.
with fixed demands.
- See also
- addCumulative(IntervalVar[], IntVar[], IntVar) AddCumulative
Definition at line 888 of file CpModel.java.
◆ addCumulative() [6/6]
|
inline |
Adds.
with fixed demands and fixed capacity.
- See also
- addCumulative(IntervalVar[], IntVar[], IntVar) AddCumulative
Definition at line 933 of file CpModel.java.
◆ addDecisionStrategy()
|
inline |
◆ addDifferent() [1/2]
|
inline |
◆ addDifferent() [2/2]
|
inline |
◆ addDifferentWithOffset()
|
inline |
◆ addDivisionEquality()
|
inline |
◆ addElement() [1/3]
|
inline |
◆ addElement() [2/3]
|
inline |
Adds the element constraint:
.
Definition at line 259 of file CpModel.java.
◆ addElement() [3/3]
|
inline |
◆ addEquality() [1/2]
|
inline |
◆ addEquality() [2/2]
|
inline |
◆ addEqualityWithOffset()
|
inline |
◆ addForbiddenAssignments() [1/2]
|
inline |
◆ addForbiddenAssignments() [2/2]
|
inline |
Adds.
.
A ForbiddenAssignments constraint is a constraint on an array of variables where the list of impossible combinations is provided in the tuples list.
- Parameters
-
variables a list of variables tuplesList a list of forbidden tuples. Each tuple must have the same length as the variables, and the ith value of a tuple corresponds to the ith variable.
- Returns
- an instance of the Constraint class
- Exceptions
-
WrongLength if one tuple does not have the same length as the variables
Definition at line 402 of file CpModel.java.
◆ addGreaterOrEqual() [1/2]
|
inline |
◆ addGreaterOrEqual() [2/2]
|
inline |
◆ addGreaterOrEqualWithOffset()
|
inline |
◆ addGreaterThan() [1/2]
|
inline |
◆ addGreaterThan() [2/2]
|
inline |
◆ addHint()
|
inline |
Adds hinting to a variable.
Definition at line 956 of file CpModel.java.
◆ addImplication()
|
inline |
◆ addInverse()
|
inline |
Adds.
.
An inverse constraint enforces that if 'variables[i]' is assigned a value 'j', then inverseVariables[j] is assigned a value 'i'. And vice versa.
- Parameters
-
variables an array of integer variables inverseVariables an array of integer variables
- Returns
- an instance of the Constraint class
- Exceptions
-
MismatchedArrayLengths if variables and inverseVariables have different length
Definition at line 487 of file CpModel.java.
◆ addLessOrEqual() [1/2]
|
inline |
◆ addLessOrEqual() [2/2]
|
inline |
◆ addLessOrEqualWithOffset()
|
inline |
◆ addLessThan() [1/2]
|
inline |
◆ addLessThan() [2/2]
|
inline |
◆ addLinearConstraint()
|
inline |
◆ addLinearExpressionInDomain()
|
inline |
◆ addMapDomain()
Adds.
.
Definition at line 616 of file CpModel.java.
◆ addMaxEquality()
|
inline |
◆ addMinEquality()
|
inline |
◆ addModuloEquality() [1/2]
|
inline |
◆ addModuloEquality() [2/2]
|
inline |
◆ addNoOverlap()
|
inline |
Adds.
.
A NoOverlap constraint ensures that all present intervals do not overlap in time.
- Parameters
-
intervalVars the list of interval variables to constrain
- Returns
- an instance of the Constraint class
Definition at line 823 of file CpModel.java.
◆ addNoOverlap2D()
|
inline |
Adds.
.
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.
- Parameters
-
xIntervals the X coordinates of the rectangles yIntervals the Y coordinates of the rectangles
- Returns
- an instance of the Constraint class
Definition at line 843 of file CpModel.java.
◆ addProductEquality()
|
inline |
◆ addReservoirConstraint() [1/2]
|
inline |
Adds.
.
- See also
- addReservoirConstraint(IntVar[], long[], long, long) Reservoir
Definition at line 549 of file CpModel.java.
◆ addReservoirConstraint() [2/2]
|
inline |
Adds.
.
Maintains a reservoir level within bounds. The water level starts at 0, and at any non negative time , it must be between minLevel and maxLevel. Furthermore, this constraints expect all times variables to be non negative. If the variable times[i] is assigned a value t, then the current level changes by demands[i] (which is constant) at the time t.
Note that
can be greater than 0, or
can be less than 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,
.
- Parameters
-
times a list of positive integer variables which specify the time of the filling or emptying the reservoir demands a list of integer values that specifies the amount of the emptying or feeling minLevel at any non negative time, the level of the reservoir must be greater of equal than the min level maxLevel at any non negative time, the level of the reservoir must be less or equal than the max level
- Returns
- an instance of the Constraint class
- Exceptions
-
MismatchedArrayLengths if times and demands have different length
Definition at line 526 of file CpModel.java.
◆ addReservoirConstraintWithActive() [1/2]
|
inline |
Adds.
.
- See also
- addReservoirConstraintWithActive(IntVar[], long[], IntVar[], long, long) Reservoir
Definition at line 609 of file CpModel.java.
◆ addReservoirConstraintWithActive() [2/2]
|
inline |
Adds.
.
Maintains a reservoir level within bounds. The water level starts at 0, and at any non negative time , it must be between minLevel and maxLevel. Furthermore, this constraints expect all times variables to be non negative. If actives[i] is true, and if times[i] is assigned a value t, then the current level changes by demands[i] (which is constant) at the time t.
Note that
can be greater than 0, or
can be less than 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,
.
- Parameters
-
times a list of positive integer variables which specify the time of the filling or emptying the reservoir demands a list of integer values that specifies the amount of the emptying or feeling actives a list of integer variables that specifies if the operation actually takes place. minLevel at any non negative time, the level of the reservoir must be greater of equal than the min level maxLevel at any non negative time, the level of the reservoir must be less or equal than the max level
- Returns
- an instance of the Constraint class
- Exceptions
-
MismatchedArrayLengths if times, demands, or actives have different length
Definition at line 579 of file CpModel.java.
◆ getBuilder()
|
inline |
Returns the model builder.
Definition at line 1035 of file CpModel.java.
◆ maximize()
|
inline |
Adds a maximization objective of a linear expression.
Definition at line 973 of file CpModel.java.
◆ minimize()
|
inline |
Adds a minimization objective of a linear expression.
Definition at line 964 of file CpModel.java.
◆ model()
|
inline |
Definition at line 1026 of file CpModel.java.
◆ modelStats()
|
inline |
Returns some statistics on model as a string.
Definition at line 997 of file CpModel.java.
◆ negated()
|
inline |
Definition at line 1030 of file CpModel.java.
◆ newBoolVar()
|
inline |
Creates a Boolean variable with the given name.
Definition at line 85 of file CpModel.java.
◆ newConstant()
|
inline |
Creates a constant variable.
Definition at line 90 of file CpModel.java.
◆ newFixedInterval()
|
inline |
Creates a fixed interval from its start and its size.
Definition at line 747 of file CpModel.java.
◆ newIntervalVar() [1/4]
|
inline |
Creates an interval variable from start, size, and end.
An interval variable is a constraint, that is itself used in other constraints like NoOverlap.
Internally, it ensures that
.
- Parameters
-
start the start of the interval size the size of the interval end the end of the interval name the name of the interval variable
- Returns
- An IntervalVar object
Definition at line 712 of file CpModel.java.
◆ newIntervalVar() [2/4]
|
inline |
Creates an interval variable with a fixed end.
Definition at line 721 of file CpModel.java.
◆ newIntervalVar() [3/4]
|
inline |
Creates an interval variable with a fixed size.
Definition at line 731 of file CpModel.java.
◆ newIntervalVar() [4/4]
|
inline |
Creates an interval variable with a fixed start.
Definition at line 741 of file CpModel.java.
◆ newIntVar()
|
inline |
Creates an integer variable with domain [lb, ub].
Definition at line 69 of file CpModel.java.
◆ newIntVarFromDomain()
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 80 of file CpModel.java.
◆ newOptionalFixedInterval()
|
inline |
Creates an optional fixed interval from start and size.
Definition at line 809 of file CpModel.java.
◆ newOptionalIntervalVar() [1/4]
|
inline |
Creates an optional interval variable from start, size, end, and isPresent.
An optional interval variable is a constraint, that is itself used in other constraints like NoOverlap. This constraint is protected by an
literal that indicates if it is active or not.
Internally, it ensures that
.
- Parameters
-
start the start of the interval. It can be an integer value, or an integer variable. size the size of the interval. It can be an integer value, or an integer variable. end the end of the interval. It can be an integer value, or an integer variable. isPresent 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 769 of file CpModel.java.
◆ newOptionalIntervalVar() [2/4]
|
inline |
Creates an optional interval with a fixed end.
Definition at line 780 of file CpModel.java.
◆ newOptionalIntervalVar() [3/4]
|
inline |
Creates an optional interval with a fixed size.
Definition at line 791 of file CpModel.java.
◆ newOptionalIntervalVar() [4/4]
|
inline |
Creates an optional interval with a fixed start.
Definition at line 798 of file CpModel.java.
◆ validate()
|
inline |
Returns a non empty string explaining the issue if the model is invalid.
Definition at line 1002 of file CpModel.java.
The documentation for this class was generated from the following file: