Class Solver
java.lang.Object
com.google.ortools.constraintsolver.Solver
Solver Class
A solver represents the main computation engine. It implements the entire
range of Constraint Programming protocols:
- Reversibility
- Propagation
- Search
Usually, Constraint Programming code consists of
- the creation of the Solver,
- the creation of the decision variables of the model,
- the creation of the constraints of the model and their addition to the
solver() through the AddConstraint() method,
- the creation of the main DecisionBuilder class,
- the launch of the solve() method with the decision builder.
For the time being, Solver is neither MT_SAFE nor MT_HOT.
A solver represents the main computation engine. It implements the entire
range of Constraint Programming protocols:
- Reversibility
- Propagation
- Search
Usually, Constraint Programming code consists of
- the creation of the Solver,
- the creation of the decision variables of the model,
- the creation of the constraints of the model and their addition to the
solver() through the AddConstraint() method,
- the creation of the main DecisionBuilder class,
- the launch of the solve() method with the decision builder.
For the time being, Solver is neither MT_SAFE nor MT_HOT.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This exceptions signal that a failure has been raised in the C++ world.static class
Holds semantic information stating that the 'expression' has been
cast into 'variable' using the Var() method, and that
'maintainer' is responsible for maintaining the equality between
'variable' and 'expression'. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Selects the first possible value which is the closest to the center
of the domain of the selected variable.
The center is defined as (min + max) / 2.static final int
Selects the max value of the selected variable.static final int
Selects the min value of the selected variable.static final int
Selects randomly one of the possible values of the selected variable.static final int
After successful NextSolution and before EndSearch.static final int
STARTS_AFTER or ENDS_BEFORE, i.e. d is not in t.
t starts after d, i.e.static final int
static final int
Pairs are compared each time a variable is selected.static final int
Select the first unbound variable.
Variables are considered in the order of the vector of IntVars used
to create the selector.static final int
Among unbound variables, select the variable with the highest maximal
value.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector.static final int
Among unbound variables, select the variable with the smallest minimal
value.
In case of a tie, the first one is selected, "first" defined by the
order in the vector of IntVars used to create the selector.static final int
Among unbound variables, select the variable with the largest
gap between the first and the second values of the domain.static final int
Among unbound variables, select the variable with the highest size.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector.static final int
Among unbound variables, select the variable with the smallest size.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector.static final int
Among unbound variables, select the variable with the smallest size,
i.e., the smallest number of possible values.
In case of a tie, the selected variable is the one with the highest max
value.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector.static final int
Among unbound variables, select the variable with the smallest size,
i.e., the smallest number of possible values.
In case of a tie, the selected variable is the one with the highest min
value.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector.static final int
Among unbound variables, select the variable with the smallest size,
i.e., the smallest number of possible values.
In case of a tie, the selected variables is the one with the lowest max
value.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector.static final int
Among unbound variables, select the variable with the smallest size,
i.e., the smallest number of possible values.
In case of a tie, the selected variables is the one with the lowest min
value.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector.static final int
static final int
Selects the next unbound variable on a path, the path being defined by
the variables: var[i] corresponds to the index of the next of i.static final int
Randomly select one of the remaining unbound variables.static final int
static final int
Pairs are compared at the first call of the selector, and results are
cached.static final int
Operator which cross exchanges the starting chains of 2 paths, including
exchanging the whole paths.
First and last nodes are not moved.
Possible neighbors for the paths 1 -> 2 -> 3 -> 4 -> 5 and 6 -> 7 -> 8
(where (1, 5) and (6, 8) are first and last nodes of the paths and can
therefore not be moved):
1 -> [7] -> 3 -> 4 -> 5 6 -> [2] -> 8
1 -> [7] -> 4 -> 5 6 -> [2 -> 3] -> 8
1 -> [7] -> 5 6 -> [2 -> 3 -> 4] -> 8static final int
STARTS_BEFORE and ENDS_AFTER at the same time, i.e. d is in t.
t starts before d, i.e.static final int
Operator which defines a neighborhood to decrement values.
The behavior is the same as INCREMENT, except values are decremented
instead of incremented.static final int
DELAYED_PRIORITY is the lowest priority: Demons will be processed after
VAR_PRIORITY and NORMAL_PRIORITY demons.static final int
t ends after d, i.e.static final int
t1 ends after t2 end, i.e.static final int
t1 ends after t2 start, i.e.static final int
t ends at d, i.e.static final int
t1 ends at t2 end, i.e.static final int
t1 ends at t2 start, i.e.static final int
t ends before d, i.e.static final int
Move is accepted when the current objective value is in the interval
objective.Min .. objective.Max.static final int
Operator which exchanges the positions of two nodes.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 -> 5
(where (1, 5) are first and last nodes of the path and can therefore not
be moved):
1 -> [3] -> [2] -> 4 -> 5
1 -> [4] -> 3 -> [2] -> 5
1 -> 2 -> [4] -> [3] -> 5static final int
Operator which makes an inactive node active and an active one inactive.
It is similar to SwapActiveOperator except that it tries to insert the
inactive node in all possible positions instead of just the position of
the node made inactive.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 with 5 inactive
(where 1 and 4 are first and last nodes of the path) are:
1 -> [5] -> 3 -> 4 with 2 inactive
1 -> 3 -> [5] -> 4 with 2 inactive
1 -> [5] -> 2 -> 4 with 3 inactive
1 -> 2 -> [5] -> 4 with 3 inactivestatic final int
Operator which relaxes one entire path and all inactive nodes, thus
defining num_paths neighbors.static final int
Move is accepted when the current objective value >= objective.Min.static final int
Executing the root node.static final int
Executing the search code.static final int
Operator which defines one neighbor per variable.static final int
The default behavior is ASSIGN_MIN_VALUE.static final int
The simple selection is ASSIGN_MIN_VALUE.static final int
The default behavior is CHOOSE_FIRST_UNBOUND.static final int
The simple selection is CHOOSE_FIRST_UNBOUND.static final int
The default is INTERVAL_SET_TIMES_FORWARD.static final int
Selects the variable with the highest ending time of all variables,
and fixes the ending time to this highest values.static final int
Selects the variable with the lowest starting time of all variables,
and fixes its starting time to this lowest value.static final int
The simple is INTERVAL_SET_TIMES_FORWARD.static final int
Right branches are ignored.static final int
Left branches are ignored.static final int
Backtracks to the previous decisions, i.e. left and right branches are
not applied.static final int
Number of priorities for demons.static final int
Move is accepted when the current objective value <= objective.Max.static final int
Lin-Kernighan local search.
While the accumulated local gain is positive, perform a 2opt or a 3opt
move followed by a series of 2opt moves.static final int
Operator which inserts an inactive node into a path.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 with 5 inactive
(where 1 and 4 are first and last nodes of the path) are:
1 -> [5] -> 2 -> 3 -> 4
1 -> 2 -> [5] -> 3 -> 4
1 -> 2 -> 3 -> [5] -> 4static final int
Operator which makes a "chain" of path nodes inactive.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 (where 1 and 4 are
first and last nodes of the path) are:
1 -> 3 -> 4 with 2 inactive
1 -> 2 -> 4 with 3 inactive
1 -> 4 with 2 and 3 inactivestatic final int
Operator which makes path nodes inactive.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 (where 1 and 4 are
first and last nodes of the path) are:
1 -> 3 -> 4 with 2 inactive
1 -> 2 -> 4 with 3 inactivestatic final int
static final int
static final int
Keeps the default behavior, i.e. apply left branch first, and then right
branch in case of backtracking.static final int
After failed NextSolution and before EndSearch.static final int
NORMAL_PRIORITY is the highest priority: Demons will be processed first.static final int
Optimization directions.static final int
Relocate: OROPT and RELOCATE.
Operator which moves a sub-chain of a path to another position; the
specified chain length is the fixed length of the chains being moved.
When this length is 1, the operator simply moves a node to another
position.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 -> 5, for a chain
length of 2 (where (1, 5) are first and last nodes of the path and can
therefore not be moved):
1 -> 4 -> [2 -> 3] -> 5
1 -> [3 -> 4] -> 2 -> 5
Using Relocate with chain lengths of 1, 2 and 3 together is equivalent
to the OrOpt operator on a path.static final int
Before search, after search.static final int
Operator which relaxes two sub-chains of three consecutive arcs each.
Each sub-chain is defined by a start node and the next three arcs.static final int
After search, the model is infeasible.static final int
Relocate neighborhood with length of 1 (see OROPT comment).static final int
static final int
This enum is used internally in private methods Solver::PushState and
Solver::PopState to tag states in the search tree.static final int
Used for scheduling.static final int
static final int
static final int
Operator which defines one neighbor per variable.static final int
Split the domain in two around the center, and choose the lower
part first.static final int
Split the domain in two around the center, and choose the lower
part first.static final int
t starts after d, i.e.static final int
t1 starts after t2 end, i.e.static final int
t1 starts after t2 start, i.e.static final int
t starts at d, i.e.static final int
t1 starts at t2 end, i.e.static final int
t1 starts at t2 start, i.e.static final int
t starts before d, i.e.static final int
STARTS_AT_START and ENDS_AT_END at the same time.
t1 starts at t2 start, i.e.static final int
Operator which replaces an active node by an inactive one.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 with 5 inactive
(where 1 and 4 are first and last nodes of the path) are:
1 -> [5] -> 3 -> 4 with 2 inactive
1 -> 2 -> [5] -> 4 with 3 inactivestatic final int
Operator which replaces a chain of active nodes by an inactive one.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 with 5 inactive
(where 1 and 4 are first and last nodes of the path) are:
1 -> [5] -> 3 -> 4 with 2 inactive
1 -> 2 -> [5] -> 4 with 3 inactive
1 -> [5] -> 4 with 2 and 3 inactiveprotected boolean
static final int
Applies right branch first.static final int
TSP-base LNS.
Randomly merge consecutive nodes until n "meta"-nodes remain and solve
the corresponding TSP.
This is an "unlimited" neighborhood which must be stopped by search
limits.static final int
Sliding TSP operator.
Uses an exact dynamic programming algorithm to solve the TSP
corresponding to path sub-chains.
For a subchain 1 -> 2 -> 3 -> 4 -> 5 -> 6, solves the TSP on
nodes A, 2, 3, 4, 5, where A is a merger of nodes 1 and 6 such that
cost(A,i) = cost(1,i) and cost(i,A) = cost(i,6).static final int
Operator which reverses a sub-chain of a path.static final int
Operator which relaxes all inactive nodes and one sub-chain of six
consecutive arcs.static final int
VAR_PRIORITY is between DELAYED_PRIORITY and NORMAL_PRIORITY. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(ModelVisitor visitor) Accepts the given model visitor.long
The number of accepted neighbors.void
addCastConstraint
(CastConstraint constraint, IntVar target_var, IntExpr expr) Adds 'constraint' to the solver and marks it as a cast constraint, that
is, a constraint created calling Var() on an expression.void
Adds the constraint 'c' to the model.
After calling this method, and until there is a backtrack that undoes the
addition, any assignment of variables to values must satisfy the given
constraint in order to be considered feasible.void
addLocalSearchMonitor
(LocalSearchMonitor monitor) Adds the local search monitor to the solver.void
addPropagationMonitor
(PropagationMonitor monitor) Adds the propagation monitor to the solver.long
branches()
The number of branches explored since the creation of the solver.cache()
Returns the cache of the model.castExpression
(IntVar var) Internal.boolean
checkAssignment
(Assignment solution) Checks whether the given assignment satisfies all relevant constraints.boolean
Checks whether adding this constraint will lead to an immediate
failure.void
void
Internalvoid
Clears the local search state.void
Manipulate neighbors count; to be used for testing purposes only.
TODO(user): Find a workaround to avoid exposing this.compose
(DecisionBuilder[] dbs) compose
(DecisionBuilder db1, DecisionBuilder db2) Creates a decision builder which sequentially composes decision builders.
At each leaf of a decision builder, the next decision builder is therefore
called.compose
(DecisionBuilder db1, DecisionBuilder db2, DecisionBuilder db3) compose
(DecisionBuilder db1, DecisionBuilder db2, DecisionBuilder db3, DecisionBuilder db4) Creates a local search operator which concatenates a vector of operators.
Each operator from the vector is called sequentially.concatenateOperators
(LocalSearchOperator[] ops, boolean restart) concatenateOperators
(LocalSearchOperator[] ops, IntIntToLongFunction evaluator) int
Counts the number of constraints that have been added
to the solver before the search.context()
Gets the current context of the search.boolean
Returns true whether the current search has been
created using a Solve() call instead of a NewSearch one.static ConstraintSolverParameters
Create a ConstraintSolverParameters proto with all the default values.void
delete()
long
demon_runs
(int p) The number of demons executed during search for a given priority.void
void
exportProfilingOverview
(String filename) Exports the profiling information in a human readable overview.
The parameter profile_level used to create the solver must be
set to true.void
fail()
Abandon the current branch in the search tree.long
The fail_stamp() is incremented after each backtrack.long
failures()
The number of failures encountered since the creation of the solver.long
The number of filtered neighbors (neighbors accepted by filters).protected void
finalize()
void
Tells the solver to kill or restart the current search.static long
long
GetGuidedLocalSearchPenalty
(long i, long j, long k) Returns the local search monitor.Returns (or creates) an assignment representing the state of local search.Returns the propagation monitor.long[]
Unsafe temporary vector.boolean
hasName
(PropagationBaseObject object) Returns whether the object has been named or not.void
boolean
Returns whether we are instrumenting demons.boolean
Returns whether we are tracing variables.boolean
Returns whether we are profiling local search.boolean
Returns whether we are profiling the solver.void
void
Returns local search profiling information in a human readable format.|expr|makeAbsEquality
(IntVar var, IntVar abs_var) Creates the constraint abs(var) == abs_var.Local Search FiltersmakeAllDifferent
(IntVar[] vars) All variables are pairwise different.makeAllDifferent
(IntVar[] vars, boolean stronger_propagation) All variables are pairwise different.makeAllDifferentExcept
(IntVar[] vars, long escape_value) All variables are pairwise different, unless they are assigned to
the escape value.makeAllowedAssignment
(IntVar[] vars, IntTupleSet tuples) This method creates a constraint where the graph of the relation
between the variables is given in extension.Collect all solutions of the search.makeAllSolutionCollector
(Assignment assignment) Collect all solutions of the search.This method creates an empty assignment.This method creates an assignment which is a copy of 'a'.makeAssignVariablesValues
(IntVar[] vars, long[] values) MakeAssignVariablesValuesOrDoNothing
(IntVar[] vars, long[] values) MakeAssignVariablesValuesOrFail
(IntVar[] vars, long[] values) makeAssignVariableValue
(IntVar var, long val) Decisions.MakeAssignVariableValueOrDoNothing
(IntVar var, long value) makeAssignVariableValueOrFail
(IntVar var, long value) makeAtSolutionCallback
(Runnable callback) MakeBestLexicographicValueSolutionCollector
(Assignment assignment, SWIGTYPE_p_std__vectorT_bool_t maximize) Same as above, but supporting lexicographic objectives; 'maximize'
specifies the optimization direction for each objective in 'assignment'.Same as above, but supporting lexicographic objectives; 'maximize'
specifies the optimization direction for each objective.makeBestValueSolutionCollector
(boolean maximize) Collect the solution corresponding to the optimal value of the
objective of the internal assignment; if this assignment does not have an
objective no solution is collected.makeBestValueSolutionCollector
(Assignment assignment, boolean maximize) Collect the solution corresponding to the optimal value of the objective
of 'assignment'; if 'assignment' does not have an objective no solution is
collected.makeBetweenCt
(IntExpr expr, long l, long u) (l <= expr <= u)MakeBoolVar will create a variable with a {0, 1} domain.makeBoolVar
(String name) MakeBoolVar will create a variable with a {0, 1} domain.IntVar[]
makeBoolVarArray
(int count) IntVar[]
makeBoolVarArray
(int count, String name) makeBranchesLimit
(long branches) Creates a search limit that constrains the number of branches
explored in the search tree.makeCircuit
(IntVar[] nexts) Force the "nexts" variable to create a complete Hamiltonian path.makeClosureDemon
(Runnable closure) Creates a demon from a closure.makeConditionalExpression
(IntVar condition, IntExpr expr, long unperformed_value) Conditional Expr condition ?makeConstantRestart
(int frequency) This search monitor will restart the search periodically after 'frequency'
failures.Returns a decision builder that will add the given constraint to
the model.This method is a specialized case of the MakeConstraintDemon
method to call the InitiatePropagate of the constraint 'ct'.makeConvexPiecewiseExpr
(IntExpr expr, long early_cost, long early_date, long late_date, long late_cost) Convex piecewise function.|{i | vars[i] == value}| == max_count|{i | vars[i] == value}| == max_countmakeCover
(IntervalVar[] vars, IntervalVar target_var) This constraint states that the target_var is the convex hull of
the intervals.makeCumulative
(IntervalVar[] intervals, int[] demands, long capacity, String name) This constraint forces that, for any integer t, the sum of the demands
corresponding to an interval containing t does not exceed the given
capacity.
Intervals and demands should be vectors of equal size.
Demands should only contain non-negative values.makeCumulative
(IntervalVar[] intervals, int[] demands, IntVar capacity, String name) This constraint enforces that, for any integer t, the sum of the demands
corresponding to an interval containing t does not exceed the given
capacity.
Intervals and demands should be vectors of equal size.
Demands should only contain non-negative values.makeCumulative
(IntervalVar[] intervals, long[] demands, long capacity, String name) This constraint forces that, for any integer t, the sum of the demands
corresponding to an interval containing t does not exceed the given
capacity.
Intervals and demands should be vectors of equal size.
Demands should only contain non-negative values.makeCumulative
(IntervalVar[] intervals, long[] demands, IntVar capacity, String name) This constraint forces that, for any integer t, the sum of the demands
corresponding to an interval containing t does not exceed the given
capacity.
Intervals and demands should be vectors of equal size.
Demands should only contain non-negative values.makeCumulative
(IntervalVar[] intervals, IntVar[] demands, long capacity, String name) This constraint enforces that, for any integer t, the sum of demands
corresponding to an interval containing t does not exceed the given
capacity.
Intervals and demands should be vectors of equal size.
Demands should be positive.makeCumulative
(IntervalVar[] intervals, IntVar[] demands, IntVar capacity, String name) This constraint enforces that, for any integer t, the sum of demands
corresponding to an interval containing t does not exceed the given
capacity.
Intervals and demands should be vectors of equal size.
Demands should be positive.makeCustomLimit
(BooleanSupplier limiter) Callback-based search limit.makeDecision
(Consumer<Solver> apply, Consumer<Solver> refute) makeDecisionBuilderFromAssignment
(Assignment assignment, DecisionBuilder db, IntVar[] vars) Returns a decision builder for which the left-most leaf corresponds
to assignment, the rest of the tree being explored using 'db'.makeDefaultPhase
(IntVar[] vars) makeDefaultPhase
(IntVar[] vars, DefaultPhaseParameters parameters) Creates a regular limit proto containing default values.Solution Pool.This method is a specialized case of the MakeConstraintDemon
method to call the InitiatePropagate of the constraint 'ct' with
low priority.makeDelayedPathCumul
(IntVar[] nexts, IntVar[] active, IntVar[] cumuls, IntVar[] transits) Delayed version of the same constraint: propagation on the nexts variables
is delayed until all constraints have propagated.makeDeviation
(IntVar[] vars, IntVar deviation_var, long total_sum) Deviation constraint:
sum_i |n * vars[i] - total_sum| <= deviation_var and
sum_i vars[i] == total_sum
n = #varsmakeDifference
(long value, IntExpr expr) value - exprmakeDifference
(IntExpr left, IntExpr right) left - rightmakeDisjunctiveConstraint
(IntervalVar[] intervals, String name) This constraint forces all interval vars into an non-overlapping
sequence.makeDistribute
(IntVar[] vars, int[] card_min, int[] card_max) Aggregated version of count with bounded cardinalities:
forall j in 0 .. card_size - 1:
card_min[j] <= |{i | v[i] == j}| <= card_max[j]makeDistribute
(IntVar[] vars, int[] values, int[] card_min, int[] card_max) Aggregated version of count with bounded cardinalities:
forall j in 0 .. card_size - 1:
card_min[j] <= |{i | v[i] == values[j]}| <= card_max[j]makeDistribute
(IntVar[] vars, int[] values, IntVar[] cards) Aggregated version of count: |{i | v[i] == values[j]}| == cards[j]makeDistribute
(IntVar[] vars, long[] card_min, long[] card_max) Aggregated version of count with bounded cardinalities:
forall j in 0 .. card_size - 1:
card_min[j] <= |{i | v[i] == j}| <= card_max[j]makeDistribute
(IntVar[] vars, long[] values, long[] card_min, long[] card_max) Aggregated version of count with bounded cardinalities:
forall j in 0 .. card_size - 1:
card_min[j] <= |{i | v[i] == values[j]}| <= card_max[j]makeDistribute
(IntVar[] vars, long[] values, IntVar[] cards) Aggregated version of count: |{i | v[i] == values[j]}| == cards[j]makeDistribute
(IntVar[] vars, long card_min, long card_max, long card_size) Aggregated version of count with bounded cardinalities:
forall j in 0 .. card_size - 1: card_min <= |{i | v[i] == j}| <= card_maxmakeDistribute
(IntVar[] vars, IntVar[] cards) Aggregated version of count: |{i | v[i] == j}| == cards[j]expr / value (integer division)numerator / denominator (integer division).makeElement
(int[] values, IntVar index) values[index]makeElement
(long[] values, IntVar index) values[index]makeElement
(IntVar[] vars, IntVar index) vars[expr]makeElement
(LongBinaryOperator values, IntVar index1, IntVar index2) 2D version of function-based element expression, values(expr1, expr2).makeElement
(LongUnaryOperator values, IntVar index) Function-based element.makeElementEquality
(int[] vals, IntVar index, IntVar target) makeElementEquality
(long[] vals, IntVar index, IntVar target) makeElementEquality
(IntVar[] vars, IntVar index, long target) makeElementEquality
(IntVar[] vars, IntVar index, IntVar target) makeEnterSearchCallback
(Runnable callback) ----- Callback-based search monitors -----makeEquality
(IntervalVar var1, IntervalVar var2) This constraints states that the two interval variables are equal.makeEquality
(IntExpr expr, int value) expr == valuemakeEquality
(IntExpr expr, long value) expr == valuemakeEquality
(IntExpr left, IntExpr right) left == rightmakeExitSearchCallback
(Runnable callback) makeFailuresLimit
(long failures) Creates a search limit that constrains the number of failures
that can happen when exploring the search tree.This constraint always fails.makeFalseConstraint
(String explanation) Collect the first solution of the search.makeFirstSolutionCollector
(Assignment assignment) Collect the first solution of the search.makeFixedDurationEndSyncedOnEndIntervalVar
(IntervalVar interval_var, long duration, long offset) Creates an interval var with a fixed duration whose end is
synchronized with the end of another interval, with a given
offset.makeFixedDurationEndSyncedOnStartIntervalVar
(IntervalVar interval_var, long duration, long offset) Creates an interval var with a fixed duration whose end is
synchronized with the start of another interval, with a given
offset.makeFixedDurationIntervalVar
(long start_min, long start_max, long duration, boolean optional, String name) Creates an interval var with a fixed duration.makeFixedDurationIntervalVar
(IntVar start_variable, long duration, IntVar performed_variable, String name) Creates an interval var with a fixed duration, and performed_variable.
The duration must be greater than 0.makeFixedDurationIntervalVar
(IntVar start_variable, long duration, String name) Creates a performed interval var with a fixed duration.makeFixedDurationIntervalVarArray
(int count, long start_min, long start_max, long duration, boolean optional) makeFixedDurationIntervalVarArray
(int count, long start_min, long start_max, long duration, boolean optional, String name) makeFixedDurationStartSyncedOnEndIntervalVar
(IntervalVar interval_var, long duration, long offset) Creates an interval var with a fixed duration whose start is
synchronized with the end of another interval, with a given
offset.makeFixedDurationStartSyncedOnStartIntervalVar
(IntervalVar interval_var, long duration, long offset) Creates an interval var with a fixed duration whose start is
synchronized with the start of another interval, with a given
offset.makeFixedInterval
(long start, long duration, String name) Creates a fixed and performed interval.makeGenericTabuSearch
(boolean maximize, IntVar v, long step, IntVar[] tabu_vars, long forbid_tenure) Creates a Tabu Search based on the vars |vars|.
A solution is "tabu" if all the vars in |vars| keep their value.makeGreater
(IntExpr expr, int value) expr > valuemakeGreater
(IntExpr expr, long value) expr > valuemakeGreater
(IntExpr left, IntExpr right) left > rightmakeGreaterOrEqual
(IntExpr expr, int value) expr >= valuemakeGreaterOrEqual
(IntExpr expr, long value) expr >= valuemakeGreaterOrEqual
(IntExpr left, IntExpr right) left >= rightmakeIfThenElseCt
(IntVar condition, IntExpr then_expr, IntExpr else_expr, IntVar target_var) Special cases with arrays of size two.MakeImprovementLimit
(IntVar objective_var, boolean maximize, double objective_scaling_factor, double objective_offset, double improvement_rate_coefficient, int improvement_rate_solutions_distance) Limits the search based on the improvements of 'objective_var'.makeIndexExpression
(IntVar[] vars, long value) Returns the expression expr such that vars[expr] == value.
It assumes that vars are all different.makeIndexOfConstraint
(IntVar[] vars, IntVar index, long target) This constraint is a special case of the element constraint with
an array of integer variables, where the variables are all
different and the index variable is constrained such that
vars[index] == target.makeIndexOfFirstMaxValueConstraint
(IntVar index, IntVar[] vars) Creates a constraint that binds the index variable to the index of the
first variable with the maximum value.makeIndexOfFirstMinValueConstraint
(IntVar index, IntVar[] vars) Creates a constraint that binds the index variable to the index of the
first variable with the minimum value.makeIntConst
(long val) IntConst will create a constant expression.makeIntConst
(long val, String name) IntConst will create a constant expression.makeIntervalRelaxedMax
(IntervalVar interval_var) Creates and returns an interval variable that wraps around the given one,
relaxing the max start and end.makeIntervalRelaxedMin
(IntervalVar interval_var) Creates and returns an interval variable that wraps around the given one,
relaxing the min start and end.makeIntervalVar
(long start_min, long start_max, long duration_min, long duration_max, long end_min, long end_max, boolean optional, String name) Creates an interval var by specifying the bounds on start,
duration, and end.makeIntervalVarRelation
(IntervalVar t, int r, long d) This method creates a relation between an interval var and a
date.makeIntervalVarRelation
(IntervalVar t1, int r, IntervalVar t2) This method creates a relation between two interval vars.makeIntervalVarRelationWithDelay
(IntervalVar t1, int r, IntervalVar t2, long delay) This method creates a relation between two interval vars.
The given delay is added to the second interval.
i.e.: t1 STARTS_AFTER_END of t2 with a delay of 2
means t1 will start at least two units of time after the end of t2.makeIntVar
(int[] values) MakeIntVar will create a variable with the given sparse domain.makeIntVar
(int[] values, String name) MakeIntVar will create a variable with the given sparse domain.makeIntVar
(long[] values) MakeIntVar will create a variable with the given sparse domain.makeIntVar
(long[] values, String name) MakeIntVar will create a variable with the given sparse domain.makeIntVar
(long min, long max) MakeIntVar will create the best range based int var for the bounds given.makeIntVar
(long min, long max, String name) MakeIntVar will create the best range based int var for the bounds given.IntVar[]
makeIntVarArray
(int count, long min, long max) IntVar[]
makeIntVarArray
(int count, long min, long max, String name) makeInversePermutationConstraint
(IntVar[] left, IntVar[] right) Creates a constraint that enforces that 'left' and 'right' both
represent permutations of [0..left.size()-1], and that 'right' is
the inverse permutation of 'left', i.e. for all i in
[0..left.size()-1], right[left[i]] = i.makeIsBetweenCt
(IntExpr expr, long l, long u, IntVar b) b == (l <= expr <= u)makeIsBetweenVar
(IntExpr v, long l, long u) makeIsDifferentCstCt
(IntExpr var, long value, IntVar boolvar) boolvar == (var !makeIsDifferentCstCt
(IntExpr v1, IntExpr v2, IntVar b) b == (v1 !makeIsDifferentCstVar
(IntExpr var, long value) status var of (var !makeIsDifferentCstVar
(IntExpr v1, IntExpr v2) status var of (v1 !makeIsEqualCstCt
(IntExpr var, long value, IntVar boolvar) boolvar == (var == value)makeIsEqualCstVar
(IntExpr var, long value) status var of (var == value)makeIsEqualVar
(IntExpr v1, IntExpr v2) status var of (v1 == v2)makeIsEqualVar
(IntExpr v1, IntExpr v2, IntVar b) b == (v1 == v2)makeIsGreaterCstCt
(IntExpr v, long c, IntVar b) b == (v > c)makeIsGreaterCstVar
(IntExpr var, long value) status var of (var > value)makeIsGreaterCt
(IntExpr left, IntExpr right, IntVar b) b == (left > right)makeIsGreaterOrEqualCstCt
(IntExpr var, long value, IntVar boolvar) boolvar == (var >= value)makeIsGreaterOrEqualCstVar
(IntExpr var, long value) status var of (var >= value)makeIsGreaterOrEqualCt
(IntExpr left, IntExpr right, IntVar b) b == (left >= right)makeIsGreaterOrEqualVar
(IntExpr left, IntExpr right) status var of (left >= right)makeIsGreaterVar
(IntExpr left, IntExpr right) status var of (left > right)makeIsLessCstCt
(IntExpr v, long c, IntVar b) b == (v < c)makeIsLessCstVar
(IntExpr var, long value) status var of (var < value)makeIsLessCt
(IntExpr left, IntExpr right, IntVar b) b == (left < right)makeIsLessOrEqualCstCt
(IntExpr var, long value, IntVar boolvar) boolvar == (var <= value)makeIsLessOrEqualCstVar
(IntExpr var, long value) status var of (var <= value)makeIsLessOrEqualCt
(IntExpr left, IntExpr right, IntVar b) b == (left <= right)makeIsLessOrEqualVar
(IntExpr left, IntExpr right) status var of (left <= right)makeIsLessVar
(IntExpr left, IntExpr right) status var of (left < right)MakeIsLexicalLessOrEqualWithOffsetsCt
(IntVar[] left, IntVar[] right, long[] offsets, IntVar boolvar) makeIsMemberCt
(IntExpr expr, int[] values, IntVar boolvar) makeIsMemberCt
(IntExpr expr, long[] values, IntVar boolvar) boolvar == (expr in set)makeIsMemberVar
(IntExpr expr, int[] values) makeIsMemberVar
(IntExpr expr, long[] values) Collect the last solution of the search.makeLastSolutionCollector
(Assignment assignment) Collect the last solution of the search.expr < valueexpr < valueleft < rightmakeLessOrEqual
(IntExpr expr, int value) expr <= valuemakeLessOrEqual
(IntExpr expr, long value) expr <= valuemakeLessOrEqual
(IntExpr left, IntExpr right) left <= rightmakeLexicalLess
(IntVar[] left, IntVar[] right) Creates a constraint that enforces that left is lexicographically less
than right.makeLexicalLessOrEqual
(IntVar[] left, IntVar[] right) Creates a constraint that enforces that left is lexicographically less
than or equal to right.MakeLexicalLessOrEqualWithOffsets
(IntVar[] left, IntVar[] right, long[] offsets) Creates a constraint that enforces that left is lexicographically less
than or equal to right with an offset.MakeLexicographicImprovementLimit
(IntVar[] objective_vars, SWIGTYPE_p_std__vectorT_bool_t maximize, double[] objective_scaling_factors, double[] objective_offsets, double improvement_rate_coefficient, int improvement_rate_solutions_distance) Same as MakeImprovementLimit on a lexicographic objective based on
'objective_vars' and related arguments.MakeLexicographicOptimize
(SWIGTYPE_p_std__vectorT_bool_t maximize, IntVar[] variables, long[] steps) Creates a lexicographic objective, following the order of the variables
given.MakeLexicographicSimulatedAnnealing
(SWIGTYPE_p_std__vectorT_bool_t maximize, IntVar[] vars, long[] steps, long[] initial_temperatures) MakeLexicographicTabuSearch
(SWIGTYPE_p_std__vectorT_bool_t maximize, IntVar[] objectives, long[] steps, IntVar[] vars, long keep_tenure, long forbid_tenure, double tabu_factor) makeLimit
(long time, long branches, long failures, long solutions) makeLimit
(long time, long branches, long failures, long solutions, boolean smart_time_check) makeLimit
(long time, long branches, long failures, long solutions, boolean smart_time_check, boolean cumulative) makeLimit
(RegularLimitParameters proto) Creates a search limit from its protobuf descriptionmakeLimit
(SearchLimit limit_1, SearchLimit limit_2) Creates a search limit that is reached when either of the underlying limit
is reached.makeLimit
(SWIGTYPE_p_absl__Duration time, long branches, long failures, long solutions) Limits the search with the 'time', 'branches', 'failures' and
'solutions' limits.makeLimit
(SWIGTYPE_p_absl__Duration time, long branches, long failures, long solutions, boolean smart_time_check) Limits the search with the 'time', 'branches', 'failures' and
'solutions' limits.makeLimit
(SWIGTYPE_p_absl__Duration time, long branches, long failures, long solutions, boolean smart_time_check, boolean cumulative) Limits the search with the 'time', 'branches', 'failures' and
'solutions' limits.makeLocalSearchPhase
(Assignment assignment, LocalSearchPhaseParameters parameters) Local Search decision builders factories.
Local search is used to improve a given solution.makeLocalSearchPhase
(IntVar[] vars, DecisionBuilder first_solution, DecisionBuilder first_solution_sub_decision_builder, LocalSearchPhaseParameters parameters) Variant with a sub_decison_builder specific to the first solution.makeLocalSearchPhase
(IntVar[] vars, DecisionBuilder first_solution, LocalSearchPhaseParameters parameters) makeLocalSearchPhase
(SequenceVar[] vars, DecisionBuilder first_solution, LocalSearchPhaseParameters parameters) makeLocalSearchPhaseParameters
(IntVar objective, LocalSearchOperator ls_operator, DecisionBuilder sub_decision_builder) Local Search Phase ParametersmakeLocalSearchPhaseParameters
(IntVar objective, LocalSearchOperator ls_operator, DecisionBuilder sub_decision_builder, RegularLimit limit) makeLocalSearchPhaseParameters
(IntVar objective, LocalSearchOperator ls_operator, DecisionBuilder sub_decision_builder, RegularLimit limit, LocalSearchFilterManager filter_manager) makeLocalSearchPhaseParameters
(IntVar objective, SolutionPool pool, LocalSearchOperator ls_operator, DecisionBuilder sub_decision_builder) makeLocalSearchPhaseParameters
(IntVar objective, SolutionPool pool, LocalSearchOperator ls_operator, DecisionBuilder sub_decision_builder, RegularLimit limit) makeLocalSearchPhaseParameters
(IntVar objective, SolutionPool pool, LocalSearchOperator ls_operator, DecisionBuilder sub_decision_builder, RegularLimit limit, LocalSearchFilterManager filter_manager) makeLubyRestart
(int scale_factor) This search monitor will restart the search periodically.
At the iteration n, it will restart after scale_factor * Luby(n) failures
where Luby is the Luby Strategy (i.e. 1 1 2 1 1 2 4 1 1 2 1 1 2 4 8...).makeMapDomain
(IntVar var, IntVar[] actives) This constraint maps the domain of 'var' onto the array of
variables 'actives'.std::max(expr, value)std::max(expr, value)std::max(left, right)std::max(vars)makeMaxEquality
(IntVar[] vars, IntVar max_var) makeMaximize
(IntVar v, long step) Creates a maximization objective.makeMemberCt
(IntExpr expr, int[] values) makeMemberCt
(IntExpr expr, long[] values) expr in set.std::min(expr, value)std::min(expr, value)std::min (left, right)std::min(vars)makeMinEquality
(IntVar[] vars, IntVar min_var) makeMinimize
(IntVar v, long step) Creates a minimization objective.makeMirrorInterval
(IntervalVar interval_var) Creates an interval var that is the mirror image of the given one, that
is, the interval var obtained by reversing the axis.makeModulo
(IntExpr x, long mod) General piecewise-linear function expression, built from f(x) where f is
piecewise-linear.makeModulo
(IntExpr x, IntExpr mod) Modulo expression x % mod (with the python convention for modulo).makeMonotonicElement
(LongUnaryOperator values, boolean increasing, IntVar index) Function based element.Creates a local search operator that tries to move the assignment of some
variables toward a target.makeMoveTowardTargetOperator
(IntVar[] variables, long[] target_values) Creates a local search operator that tries to move the assignment of some
variables toward a target.MakeNBestLexicographicValueSolutionCollector
(int solution_count, SWIGTYPE_p_std__vectorT_bool_t maximize) MakeNBestLexicographicValueSolutionCollector
(Assignment assignment, int solution_count, SWIGTYPE_p_std__vectorT_bool_t maximize) Same as above but supporting lexicographic objectives; 'maximize'
specifies the optimization direction for each objective.makeNBestValueSolutionCollector
(int solution_count, boolean maximize) makeNBestValueSolutionCollector
(Assignment assignment, int solution_count, boolean maximize) Same as MakeBestValueSolutionCollector but collects the best
solution_count solutions.makeNeighborhoodLimit
(LocalSearchOperator op, long limit) Creates a local search operator that wraps another local search
operator and limits the number of neighbors explored (i.e., calls
to MakeNextNeighbor from the current solution (between two calls
to Start()).makeNestedOptimize
(DecisionBuilder db, Assignment solution, boolean maximize, long step) NestedOptimize will collapse a search tree described by a
decision builder 'db' and a set of monitors and wrap it into a
single point.makeNestedOptimize
(DecisionBuilder db, Assignment solution, boolean maximize, long step, SearchMonitor monitor1) makeNestedOptimize
(DecisionBuilder db, Assignment solution, boolean maximize, long step, SearchMonitor[] monitors) makeNestedOptimize
(DecisionBuilder db, Assignment solution, boolean maximize, long step, SearchMonitor monitor1, SearchMonitor monitor2) makeNestedOptimize
(DecisionBuilder db, Assignment solution, boolean maximize, long step, SearchMonitor monitor1, SearchMonitor monitor2, SearchMonitor monitor3) makeNestedOptimize
(DecisionBuilder db, Assignment solution, boolean maximize, long step, SearchMonitor monitor1, SearchMonitor monitor2, SearchMonitor monitor3, SearchMonitor monitor4) makeNoCycle
(IntVar[] nexts, IntVar[] active) Prevent cycles.makeNoCycle
(IntVar[] nexts, IntVar[] active, LongPredicate sink_handler) Prevent cycles.makeNoCycle
(IntVar[] nexts, IntVar[] active, LongPredicate sink_handler, boolean assume_paths) makeNonEquality
(IntExpr expr, int value) expr !makeNonEquality
(IntExpr expr, long value) expr !makeNonEquality
(IntExpr left, IntExpr right) left !makeNonOverlappingBoxesConstraint
(IntVar[] x_vars, IntVar[] y_vars, IntVar[] x_size, IntVar[] y_size) This constraint states that all the boxes must not overlap.
The coordinates of box i are:
(x_vars[i], y_vars[i]),
(x_vars[i], y_vars[i] + y_size[i]),
(x_vars[i] + x_size[i], y_vars[i]),
(x_vars[i] + x_size[i], y_vars[i] + y_size[i]).
The sizes must be non-negative.makeNonOverlappingBoxesConstraint
(IntVar[] x_vars, IntVar[] y_vars, SWIGTYPE_p_absl__SpanT_int_const_t x_size, SWIGTYPE_p_absl__SpanT_int_const_t y_size) makeNonOverlappingBoxesConstraint
(IntVar[] x_vars, IntVar[] y_vars, SWIGTYPE_p_absl__SpanT_long_const_t x_size, SWIGTYPE_p_absl__SpanT_long_const_t y_size) makeNonOverlappingNonStrictBoxesConstraint
(IntVar[] x_vars, IntVar[] y_vars, IntVar[] x_size, IntVar[] y_size) This constraint states that all the boxes must not overlap.
The coordinates of box i are:
(x_vars[i], y_vars[i]),
(x_vars[i], y_vars[i] + y_size[i]),
(x_vars[i] + x_size[i], y_vars[i]),
(x_vars[i] + x_size[i], y_vars[i] + y_size[i]).
The sizes must be positive.
Boxes with a zero dimension can be placed anywhere.makeNonOverlappingNonStrictBoxesConstraint
(IntVar[] x_vars, IntVar[] y_vars, SWIGTYPE_p_absl__SpanT_int_const_t x_size, SWIGTYPE_p_absl__SpanT_int_const_t y_size) makeNonOverlappingNonStrictBoxesConstraint
(IntVar[] x_vars, IntVar[] y_vars, SWIGTYPE_p_absl__SpanT_long_const_t x_size, SWIGTYPE_p_absl__SpanT_long_const_t y_size) makeNotBetweenCt
(IntExpr expr, long l, long u) (expr < l || expr > u)
This constraint is lazy as it will not make holes in the domain of
variables.makeNotMemberCt
(IntExpr expr, int[] values) makeNotMemberCt
(IntExpr expr, int[] starts, int[] ends) expr should not be in the list of forbidden intervals [start[i]..end[i]].makeNotMemberCt
(IntExpr expr, long[] values) expr not in set.makeNotMemberCt
(IntExpr expr, long[] starts, long[] ends) expr should not be in the list of forbidden intervals [start[i]..end[i]].makeNullIntersect
(IntVar[] first_vars, IntVar[] second_vars) Creates a constraint that states that all variables in the first
vector are different from all variables in the second
group.makeNullIntersectExcept
(IntVar[] first_vars, IntVar[] second_vars, long escape_value) Creates a constraint that states that all variables in the first
vector are different from all variables from the second group,
unless they are assigned to the escape value.makeOperator
(IntVar[] vars, int op) Local Search Operators.makeOperator
(IntVar[] vars, int op, SWIGTYPE_p_std__functionT_std__vectorT_int_t_const_Rfint_intF_t get_incoming_neighbors) Local Search Operators.makeOperator
(IntVar[] vars, int op, SWIGTYPE_p_std__functionT_std__vectorT_int_t_const_Rfint_intF_t get_incoming_neighbors, SWIGTYPE_p_std__functionT_std__vectorT_int_t_const_Rfint_intF_t get_outgoing_neighbors) Local Search Operators.makeOperator
(IntVar[] vars, IntVar[] secondary_vars, int op) makeOperator
(IntVar[] vars, IntVar[] secondary_vars, int op, SWIGTYPE_p_std__functionT_std__vectorT_int_t_const_Rfint_intF_t get_incoming_neighbors) makeOperator
(IntVar[] vars, IntVar[] secondary_vars, int op, SWIGTYPE_p_std__functionT_std__vectorT_int_t_const_Rfint_intF_t get_incoming_neighbors, SWIGTYPE_p_std__functionT_std__vectorT_int_t_const_Rfint_intF_t get_outgoing_neighbors) makeOperator
(IntVar[] vars, IntVar[] secondary_vars, LongTernaryOperator evaluator, int op) makeOperator
(IntVar[] vars, LongTernaryOperator evaluator, int op) makeOpposite
(IntExpr expr) -exprmakeOptimize
(boolean maximize, IntVar v, long step) Creates a objective with a given sense (true = maximization).This constraint packs all variables onto 'number_of_bins'
variables.makePathConnected
(IntVar[] nexts, long[] sources, long[] sinks, IntVar[] status) Constraint enforcing that status[i] is true iff there's a path defined on
next variables from sources[i] to sinks[i].
Check whether more propagation is needed.makePathCumul
(IntVar[] nexts, IntVar[] active, IntVar[] cumuls, IntVar[] transits) Creates a constraint which accumulates values along a path such that:
cumuls[next[i]] = cumuls[i] + transits[i].
Active variables indicate if the corresponding next variable is active;
this could be useful to model unperformed nodes in a routing problem.makePathCumul
(IntVar[] nexts, IntVar[] active, IntVar[] cumuls, IntVar[] slacks, LongBinaryOperator transit_evaluator) Creates a constraint which accumulates values along a path such that:
cumuls[next[i]] = cumuls[i] + transit_evaluator(i, next[i]) + slacks[i].
Active variables indicate if the corresponding next variable is active;
this could be useful to model unperformed nodes in a routing problem.
Ownership of transit_evaluator is taken and it must be a repeatable
callback.makePathCumul
(IntVar[] nexts, IntVar[] active, IntVar[] cumuls, LongBinaryOperator transit_evaluator) Creates a constraint which accumulates values along a path such that:
cumuls[next[i]] = cumuls[i] + transit_evaluator(i, next[i]).
Active variables indicate if the corresponding next variable is active;
this could be useful to model unperformed nodes in a routing problem.
Ownership of transit_evaluator is taken and it must be a repeatable
callback.makePhase
(IntervalVar[] intervals, int str) Scheduling phases.Phases on IntVar arrays.
for all other functions that have several homonyms in this .h).makePhase
(IntVar[] vars, int var_str, LongTernaryPredicate var_val1_val2_comparator) var_val1_val2_comparator(var, val1, val2) is true iff assigning value
"val1" to variable "var" is better than assigning value "val2".makePhase
(IntVar[] vars, int var_str, LongBinaryOperator value_evaluator) makePhase
(IntVar[] vars, int var_str, LongBinaryOperator value_evaluator, LongUnaryOperator tie_breaker) makePhase
(IntVar[] vars, LongBinaryOperator eval, int str) Returns a decision builder which assigns values to variables which
minimize the values returned by the evaluator.makePhase
(IntVar[] vars, LongBinaryOperator eval, LongUnaryOperator tie_breaker, int str) Returns a decision builder which assigns values to variables
which minimize the values returned by the evaluator.makePhase
(IntVar[] vars, LongUnaryOperator var_evaluator, int val_str) makePhase
(IntVar[] vars, LongUnaryOperator var_evaluator, LongBinaryOperator value_evaluator) makePhase
(IntVar[] vars, LongUnaryOperator var_evaluator, LongBinaryOperator value_evaluator, LongUnaryOperator tie_breaker) Shortcuts for small arrays.makePhase
(SequenceVar[] sequences, int str) expr ^ n (n > 0)Prints the model.expr * valueleft * rightActivates profiling on a decision builder.makeRandomLnsOperator
(IntVar[] vars, int number_of_variables) Creates a large neighborhood search operator which creates fragments (set
of relaxed variables) with up to number_of_variables random variables
(sampling with replacement is performed meaning that at most
number_of_variables variables are selected).makeRandomLnsOperator
(IntVar[] vars, int number_of_variables, int seed) makeRankFirstInterval
(SequenceVar sequence, int index) Returns a decision that tries to rank first the ith interval var
in the sequence variable.makeRankLastInterval
(SequenceVar sequence, int index) Returns a decision that tries to rank last the ith interval var
in the sequence variable.makeRestoreAssignment
(Assignment assignment) Returns a DecisionBuilder which restores an Assignment
(calls void Assignment::Restore())MakeRoundRobinCompoundObjectiveMonitor
(SWIGTYPE_p_std__vectorT_operations_research__BaseObjectiveMonitor_p_t monitors, int num_max_local_optima_before_metaheuristic_switch) Creates a Guided Local Search monitor.
Description here: http://en.wikipedia.org/wiki/Guided_Local_SearchmakeScalProd
(IntVar[] vars, int[] coefs) scalar productmakeScalProd
(IntVar[] vars, long[] coefs) scalar productmakeScalProdEquality
(IntVar[] vars, int[] coefficients, long cst) makeScalProdEquality
(IntVar[] vars, int[] coefficients, IntVar target) makeScalProdEquality
(IntVar[] vars, long[] coefficients, long cst) makeScalProdEquality
(IntVar[] vars, long[] coefficients, IntVar target) makeScalProdGreaterOrEqual
(IntVar[] vars, int[] coeffs, long cst) makeScalProdGreaterOrEqual
(IntVar[] vars, long[] coeffs, long cst) makeScalProdLessOrEqual
(IntVar[] vars, int[] coefficients, long cst) makeScalProdLessOrEqual
(IntVar[] vars, long[] coefficients, long cst) makeScheduleOrExpedite
(IntervalVar var, long est, SWIGTYPE_p_long marker) Returns a decision that tries to schedule a task at a given time.
On the Apply branch, it will set that interval var as performed and set
its end to 'est'.makeScheduleOrPostpone
(IntervalVar var, long est, SWIGTYPE_p_long marker) Returns a decision that tries to schedule a task at a given time.
On the Apply branch, it will set that interval var as performed and set
its start to 'est'.makeSearchLog
(int branch_period) The SearchMonitors below will display a periodic search log
on LOG(INFO) every branch_period branches explored.makeSearchLog
(int branch_period, IntVar var) At each solution, this monitor also display the var value.makeSearchLog
(int branch_period, IntVar[] vars, Supplier<String> display_callback) At each solution, this monitor will display the 'vars' values and the
result ofdisplay_callback
.makeSearchLog
(int branch_period, IntVar var, Supplier<String> display_callback) At each solution, this monitor will display the 'var' value and the
result ofdisplay_callback
.makeSearchLog
(int branch_period, OptimizeVar opt_var) OptimizeVar Search Logs
At each solution, this monitor will also display the 'opt_var' value.makeSearchLog
(int branch_period, OptimizeVar opt_var, Supplier<String> display_callback) Creates a search monitor that will also print the result of the
display callback.makeSearchLog
(int branch_period, Supplier<String> display_callback) At each solution, this monitor will also display result of
display_callback
.makeSearchTrace
(String prefix) Creates a search monitor that will trace precisely the behavior of the
search.makeSemiContinuousExpr
(IntExpr expr, long fixed_charge, long step) Semi continuous Expression (x <= 0 -> f(x) = 0; x > 0 -> f(x) = ax + b)
a >= 0 and b >= 0makeSimulatedAnnealing
(boolean maximize, IntVar v, long step, long initial_temperature) Creates a Simulated Annealing monitor.makeSolutionsLimit
(long solutions) Creates a search limit that constrains the number of solutions found
during the search.SolveOnce will collapse a search tree described by a decision
builder 'db' and a set of monitors and wrap it into a single point.
If there are no solutions to this nested tree, then SolveOnce will
fail.makeSolveOnce
(DecisionBuilder db, SearchMonitor monitor1) makeSolveOnce
(DecisionBuilder db, SearchMonitor[] monitors) makeSolveOnce
(DecisionBuilder db, SearchMonitor monitor1, SearchMonitor monitor2) makeSolveOnce
(DecisionBuilder db, SearchMonitor monitor1, SearchMonitor monitor2, SearchMonitor monitor3) makeSolveOnce
(DecisionBuilder db, SearchMonitor monitor1, SearchMonitor monitor2, SearchMonitor monitor3, SearchMonitor monitor4) makeSortingConstraint
(IntVar[] vars, IntVar[] sorted) Creates a constraint binding the arrays of variables "vars" and
"sorted_vars": sorted_vars[0] must be equal to the minimum of all
variables in vars, and so on: the value of sorted_vars[i] must be
equal to the i-th value of variables invars.
This constraint propagates in both directions: from "vars" to
"sorted_vars" and vice-versa.
Behind the scenes, this constraint maintains that:
- sorted is always increasing.
- whatever the values of vars, there exists a permutation that
injects its values into the sorted variables.
For more info, please have a look at:
https://mpi-inf.mpg.de/~mehlhorn/ftp/Mehlhorn-Thiel.pdfmakeSplitVariableDomain
(IntVar var, long val, boolean start_with_lower_half) makeSquare
(IntExpr expr) expr * exprDisplays some nice statistics on the model.makeStoreAssignment
(Assignment assignment) Returns a DecisionBuilder which stores an Assignment
(calls void Assignment::Store())makeStrictDisjunctiveConstraint
(IntervalVar[] intervals, String name) This constraint forces all interval vars into an non-overlapping
sequence.makeSubCircuit
(IntVar[] nexts) Force the "nexts" variable to create a complete Hamiltonian path
for those that do not loop upon themselves.expr + value.left + right.sum of all vars.makeSumEquality
(IntVar[] vars, long cst) makeSumEquality
(IntVar[] vars, IntVar var) makeSumGreaterOrEqual
(IntVar[] vars, long cst) makeSumLessOrEqual
(IntVar[] vars, long cst) Variation on arrays.makeSumObjectiveFilter
(IntVar[] vars, IntVar[] secondary_vars, LongTernaryOperator values, int filter_enum) makeSumObjectiveFilter
(IntVar[] vars, LongBinaryOperator values, int filter_enum) makeSymmetryManager
(SymmetryBreaker[] visitors) Symmetry Breaking.makeSymmetryManager
(SymmetryBreaker v1, SymmetryBreaker v2, SymmetryBreaker v3, SymmetryBreaker v4) makeTabuSearch
(boolean maximize, IntVar objective, long step, IntVar[] vars, long keep_tenure, long forbid_tenure, double tabu_factor) MetaHeuristics which try to get the search out of local optima.
Creates a Tabu Search monitor.
In the context of local search the behavior is similar to MakeOptimize(),
creating an objective in a given sense.This constraint implements a temporal disjunction between two
interval vars.makeTemporalDisjunction
(IntervalVar t1, IntervalVar t2, IntVar alt) This constraint implements a temporal disjunction between two
interval vars t1 and t2.makeTimeLimit
(long time_in_ms) Creates a search limit that constrains the running time.makeTransitionConstraint
(IntVar[] vars, IntTupleSet transition_table, long initial_state, int[] final_states) This constraint create a finite automaton that will check the
sequence of variables vars.makeTransitionConstraint
(IntVar[] vars, IntTupleSet transition_table, long initial_state, long[] final_states) This constraint create a finite automaton that will check the
sequence of variables vars.This constraint always succeeds.makeVariableGreaterOrEqualValue
(IntVar var, long value) makeVariableLessOrEqualValue
(IntVar var, long value) makeWeightedMaximize
(IntVar[] sub_objectives, int[] weights, long step) Creates a maximization weigthed objective.makeWeightedMaximize
(IntVar[] sub_objectives, long[] weights, long step) Creates a maximization weigthed objective.makeWeightedMinimize
(IntVar[] sub_objectives, int[] weights, long step) Creates a minimization weighted objective.makeWeightedMinimize
(IntVar[] sub_objectives, long[] weights, long step) Creates a minimization weighted objective.makeWeightedOptimize
(boolean maximize, IntVar[] sub_objectives, int[] weights, long step) Creates a weighted objective with a given sense (true = maximization).makeWeightedOptimize
(boolean maximize, IntVar[] sub_objectives, long[] weights, long step) Creates a weighted objective with a given sense (true = maximization).static long
Current memory usage in bytesReturns the name of the model.MultiArmedBanditConcatenateOperators
(LocalSearchOperator[] ops, double memory_coefficient, double exploration_coefficient, boolean maximize) Creates a local search operator which concatenates a vector of operators.
Uses Multi-Armed Bandit approach for choosing the next operator to use.
Sorts operators based on Upper Confidence Bound Algorithm which evaluates
each operator as sum of average improvement and exploration function.
Updates the order of operators when accepts a neighbor with objective
improvement.boolean
Returns whether all variables should be named.long
The number of neighbors created.void
void
newSearch
(DecisionBuilder db, SearchMonitor m1) void
newSearch
(DecisionBuilder db, SearchMonitor[] monitors)
Decomposed search.
The code for a top level search should look like
solver->NewSearch(db);
while (solver->NextSolution()) {
.. use the current solution
}
solver()->EndSearch();void
newSearch
(DecisionBuilder db, SearchMonitor m1, SearchMonitor m2) void
newSearch
(DecisionBuilder db, SearchMonitor m1, SearchMonitor m2, SearchMonitor m3) void
newSearch
(DecisionBuilder db, SearchMonitor m1, SearchMonitor m2, SearchMonitor m3, SearchMonitor m4) boolean
int
The direction of optimization, getter and setter.Stored Parameters.void
popState()
void
The PushState and PopState methods manipulates the states
of the reversible objects.int
rand32
(int size) Returns a random value between 0 and 'size' - 1;long
rand64
(long size) Returns a random value between 0 and 'size' - 1;Randomized version of local search concatenator; calls a random operator
at each call to MakeNextNeighbor().randomConcatenateOperators
(LocalSearchOperator[] ops, int seed) Randomized version of local search concatenator; calls a random operator
at each call to MakeNextNeighbor().registerDemon
(Demon demon) Adds a new demon and wraps it inside a DemonProfiler if necessary.Registers a new IntervalVar and wraps it inside a TraceIntervalVar
if necessary.registerIntExpr
(IntExpr expr) Registers a new IntExpr and wraps it inside a TraceIntExpr if necessary.registerIntVar
(IntVar var) Registers a new IntVar and wraps it inside a TraceIntVar if necessary.void
reSeed
(int seed) Reseed the solver random generator.void
void
RunUncheckedLocalSearch
(Assignment initial_solution, LocalSearchFilterManager filter_manager, LocalSearchOperator ls_operator, SearchMonitor[] monitors, RegularLimit limit) Experimental: runs a local search on the given initial solution, checking
the feasibility and the objective value of solutions using the filter
manager only (solutions are never restored in the CP world).RunUncheckedLocalSearch
(Assignment initial_solution, LocalSearchFilterManager filter_manager, LocalSearchOperator ls_operator, SearchMonitor[] monitors, RegularLimit limit, SWIGTYPE_p_absl__flat_hash_setT_operations_research__IntVar_p_t touched) Experimental: runs a local search on the given initial solution, checking
the feasibility and the objective value of solutions using the filter
manager only (solutions are never restored in the CP world).int
Gets the search depth of the current active search.int
Gets the search left depth of the current active search.void
set_context
(String context) Sets the current context of the search.void
set_optimization_direction
(int direction) void
SetGuidedLocalSearchPenaltyCallback
(LongTernaryOperator penalty_callback) void
setTmpVector
(long[] value) Unsafe temporary vector.void
SetUseFastLocalSearch
(boolean use_fast_local_search) enabled for metaheuristics.
Disables/enables fast local search.void
These methods are only useful for the SWIG wrappers, which need a way
to externally cause the Solver to fail.long
The number of solutions found since the start of the search.boolean
solve
(DecisionBuilder db) boolean
solve
(DecisionBuilder db, SearchMonitor m1) boolean
solve
(DecisionBuilder db, SearchMonitor[] monitors)
Solves the problem using the given DecisionBuilder and returns true if a
solution was found and accepted.
These methods are the ones most users should use to search for a solution.
Note that the definition of 'solution' is subtle.boolean
solve
(DecisionBuilder db, SearchMonitor m1, SearchMonitor m2) boolean
solve
(DecisionBuilder db, SearchMonitor m1, SearchMonitor m2, SearchMonitor m3) boolean
solve
(DecisionBuilder db, SearchMonitor m1, SearchMonitor m2, SearchMonitor m3, SearchMonitor m4) boolean
boolean
boolean
solveAndCommit
(DecisionBuilder db, SearchMonitor[] monitors)
SolveAndCommit using a decision builder and up to three
search monitors, usually one for the objective, one for the limits
and one to collect solutions.
The difference between a SolveAndCommit() and a Solve() method
call is the fact that SolveAndCommit will not backtrack all
modifications at the end of the search.boolean
solveAndCommit
(DecisionBuilder db, SearchMonitor m1, SearchMonitor m2) boolean
solveAndCommit
(DecisionBuilder db, SearchMonitor m1, SearchMonitor m2, SearchMonitor m3) int
Gets the number of nested searches.long
stamp()
The stamp indicates how many moves in the search tree we have performed.
It is useful to detect if we need to update same lazy structures.int
state()
State of the solver.static long
swigRelease
(Solver obj) void
Performs PeriodicCheck on the top-level search; for instance, can be
called from a nested solve to check top-level limits.int
Returns a percentage representing the propress of the search before
reaching the limits of the top-level search (can be called from a nested
solve).toString()
misc debug string.tryDecisions
(DecisionBuilder[] dbs) tryDecisions
(DecisionBuilder db1, DecisionBuilder db2) Creates a decision builder which will create a search tree where each
decision builder is called from the top of the search tree.tryDecisions
(DecisionBuilder db1, DecisionBuilder db2, DecisionBuilder db3) tryDecisions
(DecisionBuilder db1, DecisionBuilder db2, DecisionBuilder db3, DecisionBuilder db4) long
The number of unchecked solutions found by local search.boolean
Returns true if fast local search is enabled.long
wallTime()
DEPRECATED: Use Now() instead.
Time elapsed, in ms since the creation of the solver.
-
Field Details
-
swigCMemOwn
protected transient boolean swigCMemOwn -
kNumPriorities
public static final int kNumPrioritiesNumber of priorities for demons. -
INT_VAR_DEFAULT
public static final int INT_VAR_DEFAULTThe default behavior is CHOOSE_FIRST_UNBOUND. -
INT_VAR_SIMPLE
public static final int INT_VAR_SIMPLEThe simple selection is CHOOSE_FIRST_UNBOUND. -
CHOOSE_FIRST_UNBOUND
public static final int CHOOSE_FIRST_UNBOUNDSelect the first unbound variable.
Variables are considered in the order of the vector of IntVars used
to create the selector. -
CHOOSE_RANDOM
public static final int CHOOSE_RANDOMRandomly select one of the remaining unbound variables. -
CHOOSE_MIN_SIZE_LOWEST_MIN
public static final int CHOOSE_MIN_SIZE_LOWEST_MINAmong unbound variables, select the variable with the smallest size,
i.e., the smallest number of possible values.
In case of a tie, the selected variables is the one with the lowest min
value.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector. -
CHOOSE_MIN_SIZE_HIGHEST_MIN
public static final int CHOOSE_MIN_SIZE_HIGHEST_MINAmong unbound variables, select the variable with the smallest size,
i.e., the smallest number of possible values.
In case of a tie, the selected variable is the one with the highest min
value.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector. -
CHOOSE_MIN_SIZE_LOWEST_MAX
public static final int CHOOSE_MIN_SIZE_LOWEST_MAXAmong unbound variables, select the variable with the smallest size,
i.e., the smallest number of possible values.
In case of a tie, the selected variables is the one with the lowest max
value.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector. -
CHOOSE_MIN_SIZE_HIGHEST_MAX
public static final int CHOOSE_MIN_SIZE_HIGHEST_MAXAmong unbound variables, select the variable with the smallest size,
i.e., the smallest number of possible values.
In case of a tie, the selected variable is the one with the highest max
value.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector. -
CHOOSE_LOWEST_MIN
public static final int CHOOSE_LOWEST_MINAmong unbound variables, select the variable with the smallest minimal
value.
In case of a tie, the first one is selected, "first" defined by the
order in the vector of IntVars used to create the selector. -
CHOOSE_HIGHEST_MAX
public static final int CHOOSE_HIGHEST_MAXAmong unbound variables, select the variable with the highest maximal
value.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector. -
CHOOSE_MIN_SIZE
public static final int CHOOSE_MIN_SIZEAmong unbound variables, select the variable with the smallest size.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector. -
CHOOSE_MAX_SIZE
public static final int CHOOSE_MAX_SIZEAmong unbound variables, select the variable with the highest size.
In case of a tie, the first one is selected, first being defined by the
order in the vector of IntVars used to create the selector. -
CHOOSE_MAX_REGRET_ON_MIN
public static final int CHOOSE_MAX_REGRET_ON_MINAmong unbound variables, select the variable with the largest
gap between the first and the second values of the domain. -
CHOOSE_PATH
public static final int CHOOSE_PATHSelects the next unbound variable on a path, the path being defined by
the variables: var[i] corresponds to the index of the next of i. -
INT_VALUE_DEFAULT
public static final int INT_VALUE_DEFAULTThe default behavior is ASSIGN_MIN_VALUE. -
INT_VALUE_SIMPLE
public static final int INT_VALUE_SIMPLEThe simple selection is ASSIGN_MIN_VALUE. -
ASSIGN_MIN_VALUE
public static final int ASSIGN_MIN_VALUESelects the min value of the selected variable. -
ASSIGN_MAX_VALUE
public static final int ASSIGN_MAX_VALUESelects the max value of the selected variable. -
ASSIGN_RANDOM_VALUE
public static final int ASSIGN_RANDOM_VALUESelects randomly one of the possible values of the selected variable. -
ASSIGN_CENTER_VALUE
public static final int ASSIGN_CENTER_VALUESelects the first possible value which is the closest to the center
of the domain of the selected variable.
The center is defined as (min + max) / 2. -
SPLIT_LOWER_HALF
public static final int SPLIT_LOWER_HALFSplit the domain in two around the center, and choose the lower
part first. -
SPLIT_UPPER_HALF
public static final int SPLIT_UPPER_HALFSplit the domain in two around the center, and choose the lower
part first. -
CHOOSE_STATIC_GLOBAL_BEST
public static final int CHOOSE_STATIC_GLOBAL_BESTPairs are compared at the first call of the selector, and results are
cached. Next calls to the selector use the previous computation, and so
are not up-to-date, e.g. some <variable, value> pairs may not be
possible anymore due to propagation since the first to call. -
CHOOSE_DYNAMIC_GLOBAL_BEST
public static final int CHOOSE_DYNAMIC_GLOBAL_BESTPairs are compared each time a variable is selected. That way all pairs
are relevant and evaluation is accurate.
This strategy runs in O(number-of-pairs) at each variable selection,
versus O(1) in the static version. -
SEQUENCE_DEFAULT
public static final int SEQUENCE_DEFAULTUsed for scheduling. Not yet implemented. -
SEQUENCE_SIMPLE
public static final int SEQUENCE_SIMPLE -
CHOOSE_MIN_SLACK_RANK_FORWARD
public static final int CHOOSE_MIN_SLACK_RANK_FORWARD -
CHOOSE_RANDOM_RANK_FORWARD
public static final int CHOOSE_RANDOM_RANK_FORWARD -
INTERVAL_DEFAULT
public static final int INTERVAL_DEFAULTThe default is INTERVAL_SET_TIMES_FORWARD. -
INTERVAL_SIMPLE
public static final int INTERVAL_SIMPLEThe simple is INTERVAL_SET_TIMES_FORWARD. -
INTERVAL_SET_TIMES_FORWARD
public static final int INTERVAL_SET_TIMES_FORWARDSelects the variable with the lowest starting time of all variables,
and fixes its starting time to this lowest value. -
INTERVAL_SET_TIMES_BACKWARD
public static final int INTERVAL_SET_TIMES_BACKWARDSelects the variable with the highest ending time of all variables,
and fixes the ending time to this highest values. -
TWOOPT
public static final int TWOOPTOperator which reverses a sub-chain of a path. It is called TwoOpt
because it breaks two arcs on the path; resulting paths are called
two-optimal.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 -> 5
(where (1, 5) are first and last nodes of the path and can therefore not
be moved):
1 -> [3 -> 2] -> 4 -> 5
1 -> [4 -> 3 -> 2] -> 5
1 -> 2 -> [4 -> 3] -> 5 -
OROPT
public static final int OROPTRelocate: OROPT and RELOCATE.
Operator which moves a sub-chain of a path to another position; the
specified chain length is the fixed length of the chains being moved.
When this length is 1, the operator simply moves a node to another
position.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 -> 5, for a chain
length of 2 (where (1, 5) are first and last nodes of the path and can
therefore not be moved):
1 -> 4 -> [2 -> 3] -> 5
1 -> [3 -> 4] -> 2 -> 5
Using Relocate with chain lengths of 1, 2 and 3 together is equivalent
to the OrOpt operator on a path. The OrOpt operator is a limited
version of 3Opt (breaks 3 arcs on a path). -
RELOCATE
public static final int RELOCATERelocate neighborhood with length of 1 (see OROPT comment). -
EXCHANGE
public static final int EXCHANGEOperator which exchanges the positions of two nodes.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 -> 5
(where (1, 5) are first and last nodes of the path and can therefore not
be moved):
1 -> [3] -> [2] -> 4 -> 5
1 -> [4] -> 3 -> [2] -> 5
1 -> 2 -> [4] -> [3] -> 5 -
CROSS
public static final int CROSSOperator which cross exchanges the starting chains of 2 paths, including
exchanging the whole paths.
First and last nodes are not moved.
Possible neighbors for the paths 1 -> 2 -> 3 -> 4 -> 5 and 6 -> 7 -> 8
(where (1, 5) and (6, 8) are first and last nodes of the paths and can
therefore not be moved):
1 -> [7] -> 3 -> 4 -> 5 6 -> [2] -> 8
1 -> [7] -> 4 -> 5 6 -> [2 -> 3] -> 8
1 -> [7] -> 5 6 -> [2 -> 3 -> 4] -> 8 -
MAKEACTIVE
public static final int MAKEACTIVEOperator which inserts an inactive node into a path.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 with 5 inactive
(where 1 and 4 are first and last nodes of the path) are:
1 -> [5] -> 2 -> 3 -> 4
1 -> 2 -> [5] -> 3 -> 4
1 -> 2 -> 3 -> [5] -> 4 -
MAKEINACTIVE
public static final int MAKEINACTIVEOperator which makes path nodes inactive.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 (where 1 and 4 are
first and last nodes of the path) are:
1 -> 3 -> 4 with 2 inactive
1 -> 2 -> 4 with 3 inactive -
MAKECHAININACTIVE
public static final int MAKECHAININACTIVEOperator which makes a "chain" of path nodes inactive.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 (where 1 and 4 are
first and last nodes of the path) are:
1 -> 3 -> 4 with 2 inactive
1 -> 2 -> 4 with 3 inactive
1 -> 4 with 2 and 3 inactive -
SWAPACTIVE
public static final int SWAPACTIVEOperator which replaces an active node by an inactive one.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 with 5 inactive
(where 1 and 4 are first and last nodes of the path) are:
1 -> [5] -> 3 -> 4 with 2 inactive
1 -> 2 -> [5] -> 4 with 3 inactive -
SWAPACTIVECHAIN
public static final int SWAPACTIVECHAINOperator which replaces a chain of active nodes by an inactive one.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 with 5 inactive
(where 1 and 4 are first and last nodes of the path) are:
1 -> [5] -> 3 -> 4 with 2 inactive
1 -> 2 -> [5] -> 4 with 3 inactive
1 -> [5] -> 4 with 2 and 3 inactive -
EXTENDEDSWAPACTIVE
public static final int EXTENDEDSWAPACTIVEOperator which makes an inactive node active and an active one inactive.
It is similar to SwapActiveOperator except that it tries to insert the
inactive node in all possible positions instead of just the position of
the node made inactive.
Possible neighbors for the path 1 -> 2 -> 3 -> 4 with 5 inactive
(where 1 and 4 are first and last nodes of the path) are:
1 -> [5] -> 3 -> 4 with 2 inactive
1 -> 3 -> [5] -> 4 with 2 inactive
1 -> [5] -> 2 -> 4 with 3 inactive
1 -> 2 -> [5] -> 4 with 3 inactive -
PATHLNS
public static final int PATHLNSOperator which relaxes two sub-chains of three consecutive arcs each.
Each sub-chain is defined by a start node and the next three arcs. Those
six arcs are relaxed to build a new neighbor.
PATHLNS explores all possible pairs of starting nodes and so defines
n^2 neighbors, n being the number of nodes.
Note that the two sub-chains can be part of the same path; they even may
overlap. -
FULLPATHLNS
public static final int FULLPATHLNSOperator which relaxes one entire path and all inactive nodes, thus
defining num_paths neighbors. -
UNACTIVELNS
public static final int UNACTIVELNSOperator which relaxes all inactive nodes and one sub-chain of six
consecutive arcs. That way the path can be improved by inserting
inactive nodes or swapping arcs. -
INCREMENT
public static final int INCREMENTOperator which defines one neighbor per variable. Each neighbor tries to
increment by one the value of the corresponding variable. When a new
solution is found the neighborhood is rebuilt from scratch, i.e., tries
to increment values in the variable order.
Consider for instance variables x and y. x is incremented one by one to
its max, and when it is not possible to increment x anymore, y is
incremented once. If this is a solution, then next neighbor tries to
increment x. -
DECREMENT
public static final int DECREMENTOperator which defines a neighborhood to decrement values.
The behavior is the same as INCREMENT, except values are decremented
instead of incremented. -
SIMPLELNS
public static final int SIMPLELNSOperator which defines one neighbor per variable. Each neighbor relaxes
one variable.
When a new solution is found the neighborhood is rebuilt from scratch.
Consider for instance variables x and y. First x is relaxed and the
solver is looking for the best possible solution (with only x relaxed).
Then y is relaxed, and the solver is looking for a new solution.
If a new solution is found, then the next variable to be relaxed is x. -
LK
public static final int LKLin-Kernighan local search.
While the accumulated local gain is positive, perform a 2opt or a 3opt
move followed by a series of 2opt moves. Return a neighbor for which the
global gain is positive. -
TSPOPT
public static final int TSPOPTSliding TSP operator.
Uses an exact dynamic programming algorithm to solve the TSP
corresponding to path sub-chains.
For a subchain 1 -> 2 -> 3 -> 4 -> 5 -> 6, solves the TSP on
nodes A, 2, 3, 4, 5, where A is a merger of nodes 1 and 6 such that
cost(A,i) = cost(1,i) and cost(i,A) = cost(i,6). -
TSPLNS
public static final int TSPLNSTSP-base LNS.
Randomly merge consecutive nodes until n "meta"-nodes remain and solve
the corresponding TSP.
This is an "unlimited" neighborhood which must be stopped by search
limits. To force diversification, the operator iteratively forces each
node to serve as base of a meta-node. -
GE
public static final int GEMove is accepted when the current objective value >= objective.Min. -
LE
public static final int LEMove is accepted when the current objective value <= objective.Max. -
EQ
public static final int EQMove is accepted when the current objective value is in the interval
objective.Min .. objective.Max. -
DELAYED_PRIORITY
public static final int DELAYED_PRIORITYDELAYED_PRIORITY is the lowest priority: Demons will be processed after
VAR_PRIORITY and NORMAL_PRIORITY demons. -
VAR_PRIORITY
public static final int VAR_PRIORITYVAR_PRIORITY is between DELAYED_PRIORITY and NORMAL_PRIORITY. -
NORMAL_PRIORITY
public static final int NORMAL_PRIORITYNORMAL_PRIORITY is the highest priority: Demons will be processed first. -
ENDS_AFTER_END
public static final int ENDS_AFTER_ENDt1 ends after t2 end, i.e. End(t1) >= End(t2) + delay. -
ENDS_AFTER_START
public static final int ENDS_AFTER_STARTt1 ends after t2 start, i.e. End(t1) >= Start(t2) + delay. -
ENDS_AT_END
public static final int ENDS_AT_ENDt1 ends at t2 end, i.e. End(t1) == End(t2) + delay. -
ENDS_AT_START
public static final int ENDS_AT_STARTt1 ends at t2 start, i.e. End(t1) == Start(t2) + delay. -
STARTS_AFTER_END
public static final int STARTS_AFTER_ENDt1 starts after t2 end, i.e. Start(t1) >= End(t2) + delay. -
STARTS_AFTER_START
public static final int STARTS_AFTER_STARTt1 starts after t2 start, i.e. Start(t1) >= Start(t2) + delay. -
STARTS_AT_END
public static final int STARTS_AT_ENDt1 starts at t2 end, i.e. Start(t1) == End(t2) + delay. -
STARTS_AT_START
public static final int STARTS_AT_STARTt1 starts at t2 start, i.e. Start(t1) == Start(t2) + delay. -
STAYS_IN_SYNC
public static final int STAYS_IN_SYNCSTARTS_AT_START and ENDS_AT_END at the same time.
t1 starts at t2 start, i.e. Start(t1) == Start(t2) + delay.
t1 ends at t2 end, i.e. End(t1) == End(t2). -
ENDS_AFTER
public static final int ENDS_AFTERt ends after d, i.e. End(t) >= d. -
ENDS_AT
public static final int ENDS_ATt ends at d, i.e. End(t) == d. -
ENDS_BEFORE
public static final int ENDS_BEFOREt ends before d, i.e. End(t) <= d. -
STARTS_AFTER
public static final int STARTS_AFTERt starts after d, i.e. Start(t) >= d. -
STARTS_AT
public static final int STARTS_ATt starts at d, i.e. Start(t) == d. -
STARTS_BEFORE
public static final int STARTS_BEFOREt starts before d, i.e. Start(t) <= d. -
CROSS_DATE
public static final int CROSS_DATESTARTS_BEFORE and ENDS_AFTER at the same time, i.e. d is in t.
t starts before d, i.e. Start(t) <= d.
t ends after d, i.e. End(t) >= d. -
AVOID_DATE
public static final int AVOID_DATESTARTS_AFTER or ENDS_BEFORE, i.e. d is not in t.
t starts after d, i.e. Start(t) >= d.
t ends before d, i.e. End(t) <= d. -
NO_CHANGE
public static final int NO_CHANGEKeeps the default behavior, i.e. apply left branch first, and then right
branch in case of backtracking. -
KEEP_LEFT
public static final int KEEP_LEFTRight branches are ignored. This is used to make the code faster when
backtrack makes no sense or is not useful.
This is faster as there is no need to create one new node per decision. -
KEEP_RIGHT
public static final int KEEP_RIGHTLeft branches are ignored. This is used to make the code faster when
backtrack makes no sense or is not useful.
This is faster as there is no need to create one new node per decision. -
KILL_BOTH
public static final int KILL_BOTHBacktracks to the previous decisions, i.e. left and right branches are
not applied. -
SWITCH_BRANCHES
public static final int SWITCH_BRANCHESApplies right branch first. Left branch will be applied in case of
backtracking. -
SENTINEL
public static final int SENTINELThis enum is used internally in private methods Solver::PushState and
Solver::PopState to tag states in the search tree. -
SIMPLE_MARKER
public static final int SIMPLE_MARKER -
CHOICE_POINT
public static final int CHOICE_POINT -
REVERSIBLE_ACTION
public static final int REVERSIBLE_ACTION -
OUTSIDE_SEARCH
public static final int OUTSIDE_SEARCHBefore search, after search. -
IN_ROOT_NODE
public static final int IN_ROOT_NODEExecuting the root node. -
IN_SEARCH
public static final int IN_SEARCHExecuting the search code. -
AT_SOLUTION
public static final int AT_SOLUTIONAfter successful NextSolution and before EndSearch. -
NO_MORE_SOLUTIONS
public static final int NO_MORE_SOLUTIONSAfter failed NextSolution and before EndSearch. -
PROBLEM_INFEASIBLE
public static final int PROBLEM_INFEASIBLEAfter search, the model is infeasible. -
NOT_SET
public static final int NOT_SETOptimization directions. -
MAXIMIZATION
public static final int MAXIMIZATION -
MINIMIZATION
public static final int MINIMIZATION
-
-
Constructor Details
-
Solver
public Solver(long cPtr, boolean cMemoryOwn) -
Solver
Solver API -
Solver
-
-
Method Details
-
getCPtr
-
swigRelease
-
finalize
-
delete
public void delete() -
makeIntVarArray
-
makeIntVarArray
-
makeBoolVarArray
-
makeBoolVarArray
-
makeFixedDurationIntervalVarArray
public IntervalVar[] makeFixedDurationIntervalVarArray(int count, long start_min, long start_max, long duration, boolean optional) -
makeFixedDurationIntervalVarArray
public IntervalVar[] makeFixedDurationIntervalVarArray(int count, long start_min, long start_max, long duration, boolean optional, String name) -
keepAliveDecisionBuilder
-
keepAliveDecisionBuilder
-
parameters
Stored Parameters. -
const_parameters
-
defaultSolverParameters
Create a ConstraintSolverParameters proto with all the default values. -
addConstraint
Adds the constraint 'c' to the model.
After calling this method, and until there is a backtrack that undoes the
addition, any assignment of variables to values must satisfy the given
constraint in order to be considered feasible. There are two fairly
different use cases:
- the most common use case is modeling: the given constraint is really
part of the problem that the user is trying to solve. In this use case,
AddConstraint is called outside of search (i.e., with state() ==
OUTSIDE_SEARCH). Most users should only use AddConstraint in this
way. In this case, the constraint will belong to the model forever: it
cannot be removed by backtracking.
- a rarer use case is that 'c' is not a real constraint of the model. It
may be a constraint generated by a branching decision (a constraint whose
goal is to restrict the search space), a symmetry breaking constraint (a
constraint that does restrict the search space, but in a way that cannot
have an impact on the quality of the solutions in the subtree), or an
inferred constraint that, while having no semantic value to the model (it
does not restrict the set of solutions), is worth having because we
believe it may strengthen the propagation. In these cases, it happens
that the constraint is added during the search (i.e., with state() ==
IN_SEARCH or state() == IN_ROOT_NODE). When a constraint is
added during a search, it applies only to the subtree of the search tree
rooted at the current node, and will be automatically removed by
backtracking.
This method does not take ownership of the constraint. If the constraint
has been created by any factory method (Solver::MakeXXX), it will
automatically be deleted. However, power users who implement their own
constraints should do: solver.AddConstraint(solver.RevAlloc(new
MyConstraint(...)); -
addCastConstraint
Adds 'constraint' to the solver and marks it as a cast constraint, that
is, a constraint created calling Var() on an expression. This is used
internally. -
solve
Solves the problem using the given DecisionBuilder and returns true if a
solution was found and accepted.
These methods are the ones most users should use to search for a solution.
Note that the definition of 'solution' is subtle. A solution here is
defined as a leaf of the search tree with respect to the given decision
builder for which there is no failure. What this means is that, contrary
to intuition, a solution may not have all variables of the model bound.
It is the responsibility of the decision builder to keep returning
decisions until all variables are indeed bound. The most extreme
counterexample is calling Solve with a trivial decision builder whose
Next() method always returns nullptr. In this case, Solve immediately
returns 'true', since not assigning any variable to any value is a
solution, unless the root node propagation discovers that the model is
infeasible.
This function must be called either from outside of search,
or from within the Next() method of a decision builder.
Solve will terminate whenever any of the following event arise:
A search monitor asks the solver to terminate the search by calling
solver()->FinishCurrentSearch().
A solution is found that is accepted by all search monitors, and none of
the search monitors decides to search for another one.
Upon search termination, there will be a series of backtracks all the way
to the top level. This means that a user cannot expect to inspect the
solution by querying variables after a call to Solve(): all the
information will be lost. In order to do something with the solution, the
user must either:
Use a search monitor that can process such a leaf. See, in particular,
the SolutionCollector class.
Do not use Solve. Instead, use the more fine-grained approach using
methods NewSearch(...), NextSolution(), and EndSearch().
- Parameters:
db
- The decision builder that will generate the search tree.monitors
- A vector of search monitors that will be notified of
various events during the search. In their reaction to these events, such
monitors may influence the search.
-
solve
-
solve
-
solve
-
solve
-
solve
public boolean solve(DecisionBuilder db, SearchMonitor m1, SearchMonitor m2, SearchMonitor m3, SearchMonitor m4) -
newSearch
Decomposed search.
The code for a top level search should look like
solver->NewSearch(db);
while (solver->NextSolution()) {
.. use the current solution
}
solver()->EndSearch(); -
newSearch
-
newSearch
-
newSearch
-
newSearch
-
newSearch
public void newSearch(DecisionBuilder db, SearchMonitor m1, SearchMonitor m2, SearchMonitor m3, SearchMonitor m4) -
nextSolution
public boolean nextSolution() -
restartSearch
public void restartSearch() -
endSearch
public void endSearch() -
solveAndCommit
SolveAndCommit using a decision builder and up to three
search monitors, usually one for the objective, one for the limits
and one to collect solutions.
The difference between a SolveAndCommit() and a Solve() method
call is the fact that SolveAndCommit will not backtrack all
modifications at the end of the search. This method is only
usable during the Next() method of a decision builder. -
solveAndCommit
-
solveAndCommit
-
solveAndCommit
-
solveAndCommit
public boolean solveAndCommit(DecisionBuilder db, SearchMonitor m1, SearchMonitor m2, SearchMonitor m3) -
checkAssignment
Checks whether the given assignment satisfies all relevant constraints. -
checkConstraint
Checks whether adding this constraint will lead to an immediate
failure. It will return false if the model is already inconsistent, or if
adding the constraint makes it inconsistent. -
state
public int state()State of the solver. -
fail
public void fail()Abandon the current branch in the search tree. A backtrack will follow. -
toString
-
memoryUsage
public static long memoryUsage()Current memory usage in bytes -
wallTime
public long wallTime()DEPRECATED: Use Now() instead.
Time elapsed, in ms since the creation of the solver. -
branches
public long branches()The number of branches explored since the creation of the solver. -
solutions
public long solutions()The number of solutions found since the start of the search. -
unchecked_solutions
public long unchecked_solutions()The number of unchecked solutions found by local search. -
demon_runs
public long demon_runs(int p) The number of demons executed during search for a given priority. -
failures
public long failures()The number of failures encountered since the creation of the solver. -
neighbors
public long neighbors()The number of neighbors created. -
ClearNeighbors
public void ClearNeighbors()Manipulate neighbors count; to be used for testing purposes only.
TODO(user): Find a workaround to avoid exposing this. -
IncrementNeighbors
public void IncrementNeighbors() -
filteredNeighbors
public long filteredNeighbors()The number of filtered neighbors (neighbors accepted by filters). -
acceptedNeighbors
public long acceptedNeighbors()The number of accepted neighbors. -
stamp
public long stamp()The stamp indicates how many moves in the search tree we have performed.
It is useful to detect if we need to update same lazy structures. -
fail_stamp
public long fail_stamp()The fail_stamp() is incremented after each backtrack. -
set_context
Sets the current context of the search. -
context
Gets the current context of the search. -
optimization_direction
public int optimization_direction()The direction of optimization, getter and setter. -
set_optimization_direction
public void set_optimization_direction(int direction) -
SetGuidedLocalSearchPenaltyCallback
-
GetGuidedLocalSearchPenalty
public long GetGuidedLocalSearchPenalty(long i, long j, long k) -
makeIntVar
-
makeIntVar
-
makeIntVar
-
makeIntVar
MakeIntVar will create the best range based int var for the bounds given. -
makeIntVar
MakeIntVar will create a variable with the given sparse domain. -
makeIntVar
MakeIntVar will create a variable with the given sparse domain. -
makeBoolVar
-
makeBoolVar
MakeBoolVar will create a variable with a {0, 1} domain. -
makeIntConst
-
makeIntConst
IntConst will create a constant expression. -
makeSum
-
makeSum
-
makeSum
-
makeScalProd
-
makeScalProd
-
makeDifference
-
makeDifference
-
makeOpposite
-
makeProd
-
makeProd
-
makeDiv
-
makeDiv
-
makeAbs
-
makeSquare
-
makePower
-
makeElement
-
makeElement
-
makeElement
Function-based element. The constraint takes ownership of the
callback. The callback must be able to cope with any possible
value in the domain of 'index' (potentially negative ones too). -
makeMonotonicElement
Function based element. The constraint takes ownership of the
callback. The callback must be monotonic. It must be able to
cope with any possible value in the domain of 'index'
(potentially negative ones too). Furtermore, monotonicity is not
checked. Thus giving a non-monotonic function, or specifying an
incorrect increasing parameter will result in undefined behavior. -
makeElement
2D version of function-based element expression, values(expr1, expr2). -
makeElement
-
makeIndexExpression
-
makeIfThenElseCt
public Constraint makeIfThenElseCt(IntVar condition, IntExpr then_expr, IntExpr else_expr, IntVar target_var) Special cases with arrays of size two. -
makeMin
-
makeMin
-
makeMin
-
makeMin
-
makeMax
-
makeMax
-
makeMax
-
makeMax
-
makeConvexPiecewiseExpr
-
makeSemiContinuousExpr
-
makeModulo
-
makeModulo
-
makeConditionalExpression
-
makeTrueConstraint
This constraint always succeeds. -
makeFalseConstraint
This constraint always fails. -
makeFalseConstraint
-
makeIsEqualCstCt
boolvar == (var == value) -
makeIsEqualCstVar
-
makeIsEqualVar
b == (v1 == v2) -
makeIsEqualVar
-
makeEquality
left == right -
makeEquality
expr == value -
makeEquality
expr == value -
makeIsDifferentCstCt
boolvar == (var != value) -
makeIsDifferentCstVar
-
makeIsDifferentCstVar
-
makeIsDifferentCstCt
b == (v1 != v2) -
makeNonEquality
left != right -
makeNonEquality
expr != value -
makeNonEquality
expr != value -
makeIsLessOrEqualCstCt
boolvar == (var <= value) -
makeIsLessOrEqualCstVar
-
makeIsLessOrEqualVar
-
makeIsLessOrEqualCt
b == (left <= right) -
makeLessOrEqual
left <= right -
makeLessOrEqual
expr <= value -
makeLessOrEqual
expr <= value -
makeIsGreaterOrEqualCstCt
boolvar == (var >= value) -
makeIsGreaterOrEqualCstVar
-
makeIsGreaterOrEqualVar
-
makeIsGreaterOrEqualCt
b == (left >= right) -
makeGreaterOrEqual
left >= right -
makeGreaterOrEqual
expr >= value -
makeGreaterOrEqual
expr >= value -
makeIsGreaterCstCt
b == (v > c) -
makeIsGreaterCstVar
-
makeIsGreaterVar
-
makeIsGreaterCt
b == (left > right) -
makeGreater
left > right -
makeGreater
expr > value -
makeGreater
expr > value -
makeIsLessCstCt
b == (v < c) -
makeIsLessCstVar
-
makeIsLessVar
-
makeIsLessCt
b == (left < right) -
makeLess
left < right -
makeLess
expr < value -
makeLess
expr < value -
makeSumLessOrEqual
Variation on arrays. -
makeSumGreaterOrEqual
-
makeSumEquality
-
makeSumEquality
-
makeScalProdEquality
-
makeScalProdEquality
-
makeScalProdEquality
-
makeScalProdEquality
-
makeScalProdGreaterOrEqual
-
makeScalProdGreaterOrEqual
-
makeScalProdLessOrEqual
-
makeScalProdLessOrEqual
-
makeMinEquality
-
makeMaxEquality
-
makeElementEquality
-
makeElementEquality
-
makeElementEquality
-
makeElementEquality
-
makeAbsEquality
Creates the constraint abs(var) == abs_var. -
makeIndexOfConstraint
This constraint is a special case of the element constraint with
an array of integer variables, where the variables are all
different and the index variable is constrained such that
vars[index] == target. -
makeConstraintInitialPropagateCallback
This method is a specialized case of the MakeConstraintDemon
method to call the InitiatePropagate of the constraint 'ct'. -
makeDelayedConstraintInitialPropagateCallback
This method is a specialized case of the MakeConstraintDemon
method to call the InitiatePropagate of the constraint 'ct' with
low priority. -
makeClosureDemon
-
makeBetweenCt
(l <= expr <= u) -
makeNotBetweenCt
(expr < l || expr > u)
This constraint is lazy as it will not make holes in the domain of
variables. It will propagate only when expr->Min() >= l
or expr->Max() <= u. -
makeIsBetweenCt
b == (l <= expr <= u) -
makeIsBetweenVar
-
makeMemberCt
expr in set. Propagation is lazy, i.e. this constraint does not
creates holes in the domain of the variable. -
makeMemberCt
-
makeNotMemberCt
expr not in set. -
makeNotMemberCt
-
makeNotMemberCt
expr should not be in the list of forbidden intervals [start[i]..end[i]]. -
makeNotMemberCt
expr should not be in the list of forbidden intervals [start[i]..end[i]]. -
makeIsMemberCt
boolvar == (expr in set) -
makeIsMemberCt
-
makeIsMemberVar
-
makeIsMemberVar
-
makeCount
|{i | vars[i] == value}| == max_count -
makeCount
|{i | vars[i] == value}| == max_count -
makeDistribute
Aggregated version of count: |{i | v[i] == values[j]}| == cards[j] -
makeDistribute
Aggregated version of count: |{i | v[i] == values[j]}| == cards[j] -
makeDistribute
Aggregated version of count: |{i | v[i] == j}| == cards[j] -
makeDistribute
Aggregated version of count with bounded cardinalities:
forall j in 0 .. card_size - 1: card_min <= |{i | v[i] == j}| <= card_max -
makeDistribute
Aggregated version of count with bounded cardinalities:
forall j in 0 .. card_size - 1:
card_min[j] <= |{i | v[i] == j}| <= card_max[j] -
makeDistribute
Aggregated version of count with bounded cardinalities:
forall j in 0 .. card_size - 1:
card_min[j] <= |{i | v[i] == j}| <= card_max[j] -
makeDistribute
Aggregated version of count with bounded cardinalities:
forall j in 0 .. card_size - 1:
card_min[j] <= |{i | v[i] == values[j]}| <= card_max[j] -
makeDistribute
Aggregated version of count with bounded cardinalities:
forall j in 0 .. card_size - 1:
card_min[j] <= |{i | v[i] == values[j]}| <= card_max[j] -
makeDeviation
Deviation constraint:
sum_i |n * vars[i] - total_sum| <= deviation_var and
sum_i vars[i] == total_sum
n = #vars -
makeAllDifferent
All variables are pairwise different. This corresponds to the
stronger version of the propagation algorithm. -
makeAllDifferent
All variables are pairwise different. If 'stronger_propagation'
is true, stronger, and potentially slower propagation will
occur. This API will be deprecated in the future. -
makeAllDifferentExcept
All variables are pairwise different, unless they are assigned to
the escape value. -
makeSortingConstraint
Creates a constraint binding the arrays of variables "vars" and
"sorted_vars": sorted_vars[0] must be equal to the minimum of all
variables in vars, and so on: the value of sorted_vars[i] must be
equal to the i-th value of variables invars.
This constraint propagates in both directions: from "vars" to
"sorted_vars" and vice-versa.
Behind the scenes, this constraint maintains that:
- sorted is always increasing.
- whatever the values of vars, there exists a permutation that
injects its values into the sorted variables.
For more info, please have a look at:
https://mpi-inf.mpg.de/~mehlhorn/ftp/Mehlhorn-Thiel.pdf -
makeLexicalLess
Creates a constraint that enforces that left is lexicographically less
than right. -
makeLexicalLessOrEqual
Creates a constraint that enforces that left is lexicographically less
than or equal to right. -
MakeLexicalLessOrEqualWithOffsets
Creates a constraint that enforces that left is lexicographically less
than or equal to right with an offset. This means that for the first index
i such that left[i] is not in [right[i] - (offset[i] - 1), right[i]],
left[i] + offset[i] <= right[i]. Offset values must be > 0. -
MakeIsLexicalLessOrEqualWithOffsetsCt
public Constraint MakeIsLexicalLessOrEqualWithOffsetsCt(IntVar[] left, IntVar[] right, long[] offsets, IntVar boolvar) -
makeInversePermutationConstraint
Creates a constraint that enforces that 'left' and 'right' both
represent permutations of [0..left.size()-1], and that 'right' is
the inverse permutation of 'left', i.e. for all i in
[0..left.size()-1], right[left[i]] = i. -
makeIndexOfFirstMaxValueConstraint
Creates a constraint that binds the index variable to the index of the
first variable with the maximum value. -
makeIndexOfFirstMinValueConstraint
Creates a constraint that binds the index variable to the index of the
first variable with the minimum value. -
makeNullIntersect
Creates a constraint that states that all variables in the first
vector are different from all variables in the second
group. Thus the set of values in the first vector does not
intersect with the set of values in the second vector. -
makeNullIntersectExcept
public Constraint makeNullIntersectExcept(IntVar[] first_vars, IntVar[] second_vars, long escape_value) Creates a constraint that states that all variables in the first
vector are different from all variables from the second group,
unless they are assigned to the escape value. Thus the set of
values in the first vector minus the escape value does not
intersect with the set of values in the second vector. -
makeNoCycle
Prevent cycles. The "nexts" variables represent the next in the chain.
"active" variables indicate if the corresponding next variable is active;
this could be useful to model unperformed nodes in a routing problem.
A callback can be added to specify sink values (by default sink values
are values >= vars.size()). Ownership of the callback is passed to the
constraint.
If assume_paths is either not specified or true, the constraint assumes
the "nexts" variables represent paths (and performs a faster propagation);
otherwise the constraint assumes they represent a forest. -
makeNoCycle
Prevent cycles. The "nexts" variables represent the next in the chain.
"active" variables indicate if the corresponding next variable is active;
this could be useful to model unperformed nodes in a routing problem.
A callback can be added to specify sink values (by default sink values
are values >= vars.size()). Ownership of the callback is passed to the
constraint.
If assume_paths is either not specified or true, the constraint assumes
the "nexts" variables represent paths (and performs a faster propagation);
otherwise the constraint assumes they represent a forest. -
makeNoCycle
public Constraint makeNoCycle(IntVar[] nexts, IntVar[] active, LongPredicate sink_handler, boolean assume_paths) -
makeCircuit
Force the "nexts" variable to create a complete Hamiltonian path. -
makeSubCircuit
Force the "nexts" variable to create a complete Hamiltonian path
for those that do not loop upon themselves. -
makePathCumul
public Constraint makePathCumul(IntVar[] nexts, IntVar[] active, IntVar[] cumuls, IntVar[] transits) Creates a constraint which accumulates values along a path such that:
cumuls[next[i]] = cumuls[i] + transits[i].
Active variables indicate if the corresponding next variable is active;
this could be useful to model unperformed nodes in a routing problem. -
makeDelayedPathCumul
public Constraint makeDelayedPathCumul(IntVar[] nexts, IntVar[] active, IntVar[] cumuls, IntVar[] transits) Delayed version of the same constraint: propagation on the nexts variables
is delayed until all constraints have propagated. -
makePathCumul
public Constraint makePathCumul(IntVar[] nexts, IntVar[] active, IntVar[] cumuls, LongBinaryOperator transit_evaluator) Creates a constraint which accumulates values along a path such that:
cumuls[next[i]] = cumuls[i] + transit_evaluator(i, next[i]).
Active variables indicate if the corresponding next variable is active;
this could be useful to model unperformed nodes in a routing problem.
Ownership of transit_evaluator is taken and it must be a repeatable
callback. -
makePathCumul
public Constraint makePathCumul(IntVar[] nexts, IntVar[] active, IntVar[] cumuls, IntVar[] slacks, LongBinaryOperator transit_evaluator) Creates a constraint which accumulates values along a path such that:
cumuls[next[i]] = cumuls[i] + transit_evaluator(i, next[i]) + slacks[i].
Active variables indicate if the corresponding next variable is active;
this could be useful to model unperformed nodes in a routing problem.
Ownership of transit_evaluator is taken and it must be a repeatable
callback. -
makePathConnected
Constraint enforcing that status[i] is true iff there's a path defined on
next variables from sources[i] to sinks[i].
Check whether more propagation is needed. -
makeMapDomain
This constraint maps the domain of 'var' onto the array of
variables 'actives'. That is
for all i in [0 .. size - 1]: actives[i] == 1 <=> var->Contains(i); -
makeAllowedAssignment
This method creates a constraint where the graph of the relation
between the variables is given in extension. There are 'arity'
variables involved in the relation and the graph is given by a
integer tuple set. -
makeTransitionConstraint
public Constraint makeTransitionConstraint(IntVar[] vars, IntTupleSet transition_table, long initial_state, long[] final_states) This constraint create a finite automaton that will check the
sequence of variables vars. It uses a transition table called
'transition_table'. Each transition is a triple
(current_state, variable_value, new_state).
The initial state is given, and the set of accepted states is decribed
by 'final_states'. These states are hidden inside the constraint.
Only the transitions (i.e. the variables) are visible. -
makeTransitionConstraint
public Constraint makeTransitionConstraint(IntVar[] vars, IntTupleSet transition_table, long initial_state, int[] final_states) This constraint create a finite automaton that will check the
sequence of variables vars. It uses a transition table called
'transition_table'. Each transition is a triple
(current_state, variable_value, new_state).
The initial state is given, and the set of accepted states is decribed
by 'final_states'. These states are hidden inside the constraint.
Only the transitions (i.e. the variables) are visible. -
makeNonOverlappingBoxesConstraint
public Constraint makeNonOverlappingBoxesConstraint(IntVar[] x_vars, IntVar[] y_vars, IntVar[] x_size, IntVar[] y_size) This constraint states that all the boxes must not overlap.
The coordinates of box i are:
(x_vars[i], y_vars[i]),
(x_vars[i], y_vars[i] + y_size[i]),
(x_vars[i] + x_size[i], y_vars[i]),
(x_vars[i] + x_size[i], y_vars[i] + y_size[i]).
The sizes must be non-negative. Boxes with a zero dimension can be
pushed like any box. -
makeNonOverlappingBoxesConstraint
public Constraint makeNonOverlappingBoxesConstraint(IntVar[] x_vars, IntVar[] y_vars, SWIGTYPE_p_absl__SpanT_long_const_t x_size, SWIGTYPE_p_absl__SpanT_long_const_t y_size) -
makeNonOverlappingBoxesConstraint
public Constraint makeNonOverlappingBoxesConstraint(IntVar[] x_vars, IntVar[] y_vars, SWIGTYPE_p_absl__SpanT_int_const_t x_size, SWIGTYPE_p_absl__SpanT_int_const_t y_size) -
makeNonOverlappingNonStrictBoxesConstraint
public Constraint makeNonOverlappingNonStrictBoxesConstraint(IntVar[] x_vars, IntVar[] y_vars, IntVar[] x_size, IntVar[] y_size) This constraint states that all the boxes must not overlap.
The coordinates of box i are:
(x_vars[i], y_vars[i]),
(x_vars[i], y_vars[i] + y_size[i]),
(x_vars[i] + x_size[i], y_vars[i]),
(x_vars[i] + x_size[i], y_vars[i] + y_size[i]).
The sizes must be positive.
Boxes with a zero dimension can be placed anywhere. -
makeNonOverlappingNonStrictBoxesConstraint
public Constraint makeNonOverlappingNonStrictBoxesConstraint(IntVar[] x_vars, IntVar[] y_vars, SWIGTYPE_p_absl__SpanT_long_const_t x_size, SWIGTYPE_p_absl__SpanT_long_const_t y_size) -
makeNonOverlappingNonStrictBoxesConstraint
public Constraint makeNonOverlappingNonStrictBoxesConstraint(IntVar[] x_vars, IntVar[] y_vars, SWIGTYPE_p_absl__SpanT_int_const_t x_size, SWIGTYPE_p_absl__SpanT_int_const_t y_size) -
makePack
This constraint packs all variables onto 'number_of_bins'
variables. For any given variable, a value of 'number_of_bins'
indicates that the variable is not assigned to any bin.
Dimensions, i.e., cumulative constraints on this packing, can be
added directly from the pack class. -
makeFixedDurationIntervalVar
public IntervalVar makeFixedDurationIntervalVar(long start_min, long start_max, long duration, boolean optional, String name) Creates an interval var with a fixed duration. The duration must
be greater than 0. If optional is true, then the interval can be
performed or unperformed. If optional is false, then the interval
is always performed. -
makeFixedDurationIntervalVar
Creates a performed interval var with a fixed duration. The duration must
be greater than 0. -
makeFixedDurationIntervalVar
public IntervalVar makeFixedDurationIntervalVar(IntVar start_variable, long duration, IntVar performed_variable, String name) Creates an interval var with a fixed duration, and performed_variable.
The duration must be greater than 0. -
makeFixedInterval
Creates a fixed and performed interval. -
makeIntervalVar
public IntervalVar makeIntervalVar(long start_min, long start_max, long duration_min, long duration_max, long end_min, long end_max, boolean optional, String name) Creates an interval var by specifying the bounds on start,
duration, and end. -
makeMirrorInterval
Creates an interval var that is the mirror image of the given one, that
is, the interval var obtained by reversing the axis. -
makeFixedDurationStartSyncedOnStartIntervalVar
public IntervalVar makeFixedDurationStartSyncedOnStartIntervalVar(IntervalVar interval_var, long duration, long offset) Creates an interval var with a fixed duration whose start is
synchronized with the start of another interval, with a given
offset. The performed status is also in sync with the performed
status of the given interval variable. -
makeFixedDurationStartSyncedOnEndIntervalVar
public IntervalVar makeFixedDurationStartSyncedOnEndIntervalVar(IntervalVar interval_var, long duration, long offset) Creates an interval var with a fixed duration whose start is
synchronized with the end of another interval, with a given
offset. The performed status is also in sync with the performed
status of the given interval variable. -
makeFixedDurationEndSyncedOnStartIntervalVar
public IntervalVar makeFixedDurationEndSyncedOnStartIntervalVar(IntervalVar interval_var, long duration, long offset) Creates an interval var with a fixed duration whose end is
synchronized with the start of another interval, with a given
offset. The performed status is also in sync with the performed
status of the given interval variable. -
makeFixedDurationEndSyncedOnEndIntervalVar
public IntervalVar makeFixedDurationEndSyncedOnEndIntervalVar(IntervalVar interval_var, long duration, long offset) Creates an interval var with a fixed duration whose end is
synchronized with the end of another interval, with a given
offset. The performed status is also in sync with the performed
status of the given interval variable. -
makeIntervalRelaxedMin
Creates and returns an interval variable that wraps around the given one,
relaxing the min start and end. Relaxing means making unbounded when
optional. If the variable is non-optional, this method returns
interval_var.
More precisely, such an interval variable behaves as follows:
When the underlying must be performed, the returned interval variable
behaves exactly as the underlying;
When the underlying may or may not be performed, the returned interval
variable behaves like the underlying, except that it is unbounded on
the min side;
When the underlying cannot be performed, the returned interval variable
is of duration 0 and must be performed in an interval unbounded on
both sides.
This is very useful to implement propagators that may only modify
the start max or end max. -
makeIntervalRelaxedMax
Creates and returns an interval variable that wraps around the given one,
relaxing the max start and end. Relaxing means making unbounded when
optional. If the variable is non optional, this method returns
interval_var.
More precisely, such an interval variable behaves as follows:
When the underlying must be performed, the returned interval variable
behaves exactly as the underlying;
When the underlying may or may not be performed, the returned interval
variable behaves like the underlying, except that it is unbounded on
the max side;
When the underlying cannot be performed, the returned interval variable
is of duration 0 and must be performed in an interval unbounded on
both sides.
This is very useful for implementing propagators that may only modify
the start min or end min. -
makeIntervalVarRelation
This method creates a relation between an interval var and a
date. -
makeIntervalVarRelation
This method creates a relation between two interval vars. -
makeIntervalVarRelationWithDelay
public Constraint makeIntervalVarRelationWithDelay(IntervalVar t1, int r, IntervalVar t2, long delay) This method creates a relation between two interval vars.
The given delay is added to the second interval.
i.e.: t1 STARTS_AFTER_END of t2 with a delay of 2
means t1 will start at least two units of time after the end of t2. -
makeTemporalDisjunction
This constraint implements a temporal disjunction between two
interval vars t1 and t2. 'alt' indicates which alternative was
chosen (alt == 0 is equivalent to t1 before t2). -
makeTemporalDisjunction
This constraint implements a temporal disjunction between two
interval vars. -
makeDisjunctiveConstraint
This constraint forces all interval vars into an non-overlapping
sequence. Intervals with zero duration can be scheduled anywhere. -
makeStrictDisjunctiveConstraint
This constraint forces all interval vars into an non-overlapping
sequence. Intervals with zero durations cannot overlap with over
intervals. -
makeCumulative
public Constraint makeCumulative(IntervalVar[] intervals, long[] demands, long capacity, String name) This constraint forces that, for any integer t, the sum of the demands
corresponding to an interval containing t does not exceed the given
capacity.
Intervals and demands should be vectors of equal size.
Demands should only contain non-negative values. Zero values are
supported, and the corresponding intervals are filtered out, as they
neither impact nor are impacted by this constraint. -
makeCumulative
public Constraint makeCumulative(IntervalVar[] intervals, int[] demands, long capacity, String name) This constraint forces that, for any integer t, the sum of the demands
corresponding to an interval containing t does not exceed the given
capacity.
Intervals and demands should be vectors of equal size.
Demands should only contain non-negative values. Zero values are
supported, and the corresponding intervals are filtered out, as they
neither impact nor are impacted by this constraint. -
makeCumulative
public Constraint makeCumulative(IntervalVar[] intervals, long[] demands, IntVar capacity, String name) This constraint forces that, for any integer t, the sum of the demands
corresponding to an interval containing t does not exceed the given
capacity.
Intervals and demands should be vectors of equal size.
Demands should only contain non-negative values. Zero values are
supported, and the corresponding intervals are filtered out, as they
neither impact nor are impacted by this constraint. -
makeCumulative
public Constraint makeCumulative(IntervalVar[] intervals, int[] demands, IntVar capacity, String name) This constraint enforces that, for any integer t, the sum of the demands
corresponding to an interval containing t does not exceed the given
capacity.
Intervals and demands should be vectors of equal size.
Demands should only contain non-negative values. Zero values are
supported, and the corresponding intervals are filtered out, as they
neither impact nor are impacted by this constraint. -
makeCumulative
public Constraint makeCumulative(IntervalVar[] intervals, IntVar[] demands, long capacity, String name) This constraint enforces that, for any integer t, the sum of demands
corresponding to an interval containing t does not exceed the given
capacity.
Intervals and demands should be vectors of equal size.
Demands should be positive. -
makeCumulative
public Constraint makeCumulative(IntervalVar[] intervals, IntVar[] demands, IntVar capacity, String name) This constraint enforces that, for any integer t, the sum of demands
corresponding to an interval containing t does not exceed the given
capacity.
Intervals and demands should be vectors of equal size.
Demands should be positive. -
makeCover
This constraint states that the target_var is the convex hull of
the intervals. If none of the interval variables is performed,
then the target var is unperformed too. Also, if the target
variable is unperformed, then all the intervals variables are
unperformed too. -
makeEquality
This constraints states that the two interval variables are equal. -
makeAssignment
This method creates an empty assignment. -
makeAssignment
This method creates an assignment which is a copy of 'a'. -
makeFirstSolutionCollector
Collect the first solution of the search. -
makeFirstSolutionCollector
Collect the first solution of the search. The variables will need to
be added later. -
makeLastSolutionCollector
Collect the last solution of the search. -
makeLastSolutionCollector
Collect the last solution of the search. The variables will need to
be added later. -
makeBestValueSolutionCollector
Collect the solution corresponding to the optimal value of the objective
of 'assignment'; if 'assignment' does not have an objective no solution is
collected. This collector only collects one solution corresponding to the
best objective value (the first one found). -
MakeBestLexicographicValueSolutionCollector
public SolutionCollector MakeBestLexicographicValueSolutionCollector(Assignment assignment, SWIGTYPE_p_std__vectorT_bool_t maximize) Same as above, but supporting lexicographic objectives; 'maximize'
specifies the optimization direction for each objective in 'assignment'. -
makeBestValueSolutionCollector
Collect the solution corresponding to the optimal value of the
objective of the internal assignment; if this assignment does not have an
objective no solution is collected. This collector only collects one
solution corresponding to the best objective value (the first one found).
The variables and objective(s) will need to be added later. -
MakeBestLexicographicValueSolutionCollector
public SolutionCollector MakeBestLexicographicValueSolutionCollector(SWIGTYPE_p_std__vectorT_bool_t maximize) Same as above, but supporting lexicographic objectives; 'maximize'
specifies the optimization direction for each objective. -
makeNBestValueSolutionCollector
public SolutionCollector makeNBestValueSolutionCollector(Assignment assignment, int solution_count, boolean maximize) Same as MakeBestValueSolutionCollector but collects the best
solution_count solutions. Collected solutions are sorted in increasing
optimality order (the best solution is the last one). -
makeNBestValueSolutionCollector
-
MakeNBestLexicographicValueSolutionCollector
public SolutionCollector MakeNBestLexicographicValueSolutionCollector(Assignment assignment, int solution_count, SWIGTYPE_p_std__vectorT_bool_t maximize) Same as above but supporting lexicographic objectives; 'maximize'
specifies the optimization direction for each objective. -
MakeNBestLexicographicValueSolutionCollector
public SolutionCollector MakeNBestLexicographicValueSolutionCollector(int solution_count, SWIGTYPE_p_std__vectorT_bool_t maximize) -
makeAllSolutionCollector
Collect all solutions of the search. -
makeAllSolutionCollector
Collect all solutions of the search. The variables will need to
be added later. -
makeMinimize
Creates a minimization objective. -
makeMaximize
Creates a maximization objective. -
makeOptimize
Creates a objective with a given sense (true = maximization). -
makeWeightedMinimize
Creates a minimization weighted objective. The actual objective is
scalar_prod(sub_objectives, weights). -
makeWeightedMinimize
Creates a minimization weighted objective. The actual objective is
scalar_prod(sub_objectives, weights). -
makeWeightedMaximize
Creates a maximization weigthed objective. -
makeWeightedMaximize
Creates a maximization weigthed objective. -
makeWeightedOptimize
public OptimizeVar makeWeightedOptimize(boolean maximize, IntVar[] sub_objectives, long[] weights, long step) Creates a weighted objective with a given sense (true = maximization). -
makeWeightedOptimize
public OptimizeVar makeWeightedOptimize(boolean maximize, IntVar[] sub_objectives, int[] weights, long step) Creates a weighted objective with a given sense (true = maximization). -
MakeLexicographicOptimize
public OptimizeVar MakeLexicographicOptimize(SWIGTYPE_p_std__vectorT_bool_t maximize, IntVar[] variables, long[] steps) Creates a lexicographic objective, following the order of the variables
given. Each variable has a corresponding optimization direction and step. -
makeTabuSearch
public ObjectiveMonitor makeTabuSearch(boolean maximize, IntVar objective, long step, IntVar[] vars, long keep_tenure, long forbid_tenure, double tabu_factor) MetaHeuristics which try to get the search out of local optima.
Creates a Tabu Search monitor.
In the context of local search the behavior is similar to MakeOptimize(),
creating an objective in a given sense. The behavior differs once a local
optimum is reached: thereafter solutions which degrade the value of the
objective are allowed if they are not "tabu". A solution is "tabu" if it
doesn't respect the following rules:
- improving the best solution found so far
- variables in the "keep" list must keep their value, variables in the
"forbid" list must not take the value they have in the list.
Variables with new values enter the tabu lists after each new solution
found and leave the lists after a given number of iterations (called
tenure). Only the variables passed to the method can enter the lists.
The tabu criterion is softened by the tabu factor which gives the number
of "tabu" violations which is tolerated; a factor of 1 means no violations
allowed; a factor of 0 means all violations are allowed. -
MakeLexicographicTabuSearch
public ObjectiveMonitor MakeLexicographicTabuSearch(SWIGTYPE_p_std__vectorT_bool_t maximize, IntVar[] objectives, long[] steps, IntVar[] vars, long keep_tenure, long forbid_tenure, double tabu_factor) -
makeGenericTabuSearch
public ObjectiveMonitor makeGenericTabuSearch(boolean maximize, IntVar v, long step, IntVar[] tabu_vars, long forbid_tenure) Creates a Tabu Search based on the vars |vars|.
A solution is "tabu" if all the vars in |vars| keep their value. -
makeSimulatedAnnealing
public ObjectiveMonitor makeSimulatedAnnealing(boolean maximize, IntVar v, long step, long initial_temperature) Creates a Simulated Annealing monitor. -
MakeLexicographicSimulatedAnnealing
public ObjectiveMonitor MakeLexicographicSimulatedAnnealing(SWIGTYPE_p_std__vectorT_bool_t maximize, IntVar[] vars, long[] steps, long[] initial_temperatures) -
MakeRoundRobinCompoundObjectiveMonitor
public BaseObjectiveMonitor MakeRoundRobinCompoundObjectiveMonitor(SWIGTYPE_p_std__vectorT_operations_research__BaseObjectiveMonitor_p_t monitors, int num_max_local_optima_before_metaheuristic_switch) Creates a Guided Local Search monitor.
Description here: http://en.wikipedia.org/wiki/Guided_Local_Search -
makeLubyRestart
This search monitor will restart the search periodically.
At the iteration n, it will restart after scale_factor * Luby(n) failures
where Luby is the Luby Strategy (i.e. 1 1 2 1 1 2 4 1 1 2 1 1 2 4 8...). -
makeConstantRestart
This search monitor will restart the search periodically after 'frequency'
failures. -
makeTimeLimit
Creates a search limit that constrains the running time. -
makeTimeLimit
-
makeBranchesLimit
Creates a search limit that constrains the number of branches
explored in the search tree. -
makeFailuresLimit
Creates a search limit that constrains the number of failures
that can happen when exploring the search tree. -
makeSolutionsLimit
Creates a search limit that constrains the number of solutions found
during the search. -
makeLimit
public RegularLimit makeLimit(SWIGTYPE_p_absl__Duration time, long branches, long failures, long solutions, boolean smart_time_check, boolean cumulative) Limits the search with the 'time', 'branches', 'failures' and
'solutions' limits. 'smart_time_check' reduces the calls to the wall -
makeLimit
public RegularLimit makeLimit(SWIGTYPE_p_absl__Duration time, long branches, long failures, long solutions, boolean smart_time_check) Limits the search with the 'time', 'branches', 'failures' and
'solutions' limits. 'smart_time_check' reduces the calls to the wall -
makeLimit
public RegularLimit makeLimit(SWIGTYPE_p_absl__Duration time, long branches, long failures, long solutions) Limits the search with the 'time', 'branches', 'failures' and
'solutions' limits. 'smart_time_check' reduces the calls to the wall -
makeLimit
Creates a search limit from its protobuf description -
makeLimit
public RegularLimit makeLimit(long time, long branches, long failures, long solutions, boolean smart_time_check, boolean cumulative) -
makeLimit
public RegularLimit makeLimit(long time, long branches, long failures, long solutions, boolean smart_time_check) -
makeLimit
-
makeDefaultRegularLimitParameters
Creates a regular limit proto containing default values. -
makeLimit
Creates a search limit that is reached when either of the underlying limit
is reached. That is, the returned limit is more stringent than both
argument limits. -
MakeImprovementLimit
public ImprovementSearchLimit MakeImprovementLimit(IntVar objective_var, boolean maximize, double objective_scaling_factor, double objective_offset, double improvement_rate_coefficient, int improvement_rate_solutions_distance) Limits the search based on the improvements of 'objective_var'. Stops the
search when the improvement rate gets lower than a threshold value. This
threshold value is computed based on the improvement rate during the first
phase of the search. -
MakeLexicographicImprovementLimit
public ImprovementSearchLimit MakeLexicographicImprovementLimit(IntVar[] objective_vars, SWIGTYPE_p_std__vectorT_bool_t maximize, double[] objective_scaling_factors, double[] objective_offsets, double improvement_rate_coefficient, int improvement_rate_solutions_distance) Same as MakeImprovementLimit on a lexicographic objective based on
'objective_vars' and related arguments. -
makeCustomLimit
Callback-based search limit. Search stops when limiter returns true; if
this happens at a leaf the corresponding solution will be rejected. -
makeSearchLog
The SearchMonitors below will display a periodic search log
on LOG(INFO) every branch_period branches explored. -
makeSearchLog
At each solution, this monitor also display the var value. -
makeSearchLog
At each solution, this monitor will also display result of
display_callback
. -
makeSearchLog
public SearchMonitor makeSearchLog(int branch_period, IntVar var, Supplier<String> display_callback) At each solution, this monitor will display the 'var' value and the
result ofdisplay_callback
. -
makeSearchLog
public SearchMonitor makeSearchLog(int branch_period, IntVar[] vars, Supplier<String> display_callback) At each solution, this monitor will display the 'vars' values and the
result ofdisplay_callback
. -
makeSearchLog
OptimizeVar Search Logs
At each solution, this monitor will also display the 'opt_var' value. -
makeSearchLog
public SearchMonitor makeSearchLog(int branch_period, OptimizeVar opt_var, Supplier<String> display_callback) Creates a search monitor that will also print the result of the
display callback. -
makeSearchTrace
Creates a search monitor that will trace precisely the behavior of the
search. Use this only for low level debugging. -
makeEnterSearchCallback
----- Callback-based search monitors ----- -
makeExitSearchCallback
-
makeAtSolutionCallback
-
makePrintModelVisitor
Prints the model. -
makeStatisticsModelVisitor
Displays some nice statistics on the model. -
makeSymmetryManager
Symmetry Breaking. -
makeSymmetryManager
-
makeSymmetryManager
-
makeSymmetryManager
public SearchMonitor makeSymmetryManager(SymmetryBreaker v1, SymmetryBreaker v2, SymmetryBreaker v3) -
makeSymmetryManager
public SearchMonitor makeSymmetryManager(SymmetryBreaker v1, SymmetryBreaker v2, SymmetryBreaker v3, SymmetryBreaker v4) -
makeAssignVariableValue
-
makeVariableLessOrEqualValue
-
makeVariableGreaterOrEqualValue
-
makeSplitVariableDomain
-
makeAssignVariableValueOrFail
-
MakeAssignVariableValueOrDoNothing
-
makeAssignVariablesValues
-
MakeAssignVariablesValuesOrDoNothing
-
MakeAssignVariablesValuesOrFail
-
makeFailDecision
-
makeDecision
-
compose
Creates a decision builder which sequentially composes decision builders.
At each leaf of a decision builder, the next decision builder is therefore
called. For instance, Compose(db1, db2) will result in the following tree:
d1 tree |
| \ |
db1 leaves |
| \ |
db2 tree db2 tree db2 tree | -
compose
-
compose
public DecisionBuilder compose(DecisionBuilder db1, DecisionBuilder db2, DecisionBuilder db3, DecisionBuilder db4) -
compose
-
tryDecisions
Creates a decision builder which will create a search tree where each
decision builder is called from the top of the search tree. For instance
the decision builder Try(db1, db2) will entirely explore the search tree
of db1 then the one of db2, resulting in the following search tree:
Tree root |
\ |
db1 tree db2 tree |
This is very handy to try a decision builder which partially explores the
search space and if it fails to try another decision builder.
"Try"-builders "recursively". For instance, Try(a,b,c,d) will give a tree
unbalanced to the right, whereas Try(Try(a,b), Try(b,c)) will give a
balanced tree. Investigate if we should only provide the binary version
and/or if we should balance automatically. -
tryDecisions
-
tryDecisions
public DecisionBuilder tryDecisions(DecisionBuilder db1, DecisionBuilder db2, DecisionBuilder db3, DecisionBuilder db4) -
tryDecisions
-
makePhase
Phases on IntVar arrays.
for all other functions that have several homonyms in this .h). -
makePhase
-
makePhase
-
makePhase
public DecisionBuilder makePhase(IntVar[] vars, int var_str, LongTernaryPredicate var_val1_val2_comparator) var_val1_val2_comparator(var, val1, val2) is true iff assigning value
"val1" to variable "var" is better than assigning value "val2". -
makePhase
public DecisionBuilder makePhase(IntVar[] vars, LongUnaryOperator var_evaluator, LongBinaryOperator value_evaluator) -
makePhase
public DecisionBuilder makePhase(IntVar[] vars, int var_str, LongBinaryOperator value_evaluator, LongUnaryOperator tie_breaker) -
makePhase
public DecisionBuilder makePhase(IntVar[] vars, LongUnaryOperator var_evaluator, LongBinaryOperator value_evaluator, LongUnaryOperator tie_breaker) -
makeDefaultPhase
-
makeDefaultPhase
-
makePhase
Shortcuts for small arrays. -
makePhase
-
makePhase
-
makePhase
public DecisionBuilder makePhase(IntVar v0, IntVar v1, IntVar v2, IntVar v3, int var_str, int val_str) -
makeScheduleOrPostpone
Returns a decision that tries to schedule a task at a given time.
On the Apply branch, it will set that interval var as performed and set
its start to 'est'. On the Refute branch, it will just update the
'marker' to 'est' + 1. This decision is used in the
INTERVAL_SET_TIMES_FORWARD strategy. -
makeScheduleOrExpedite
Returns a decision that tries to schedule a task at a given time.
On the Apply branch, it will set that interval var as performed and set
its end to 'est'. On the Refute branch, it will just update the
'marker' to 'est' - 1. This decision is used in the
INTERVAL_SET_TIMES_BACKWARD strategy. -
makeRankFirstInterval
Returns a decision that tries to rank first the ith interval var
in the sequence variable. -
makeRankLastInterval
Returns a decision that tries to rank last the ith interval var
in the sequence variable. -
makePhase
Returns a decision builder which assigns values to variables which
minimize the values returned by the evaluator. The arguments passed to the
evaluator callback are the indices of the variables in vars and the values
of these variables. Ownership of the callback is passed to the decision
builder. -
makePhase
public DecisionBuilder makePhase(IntVar[] vars, LongBinaryOperator eval, LongUnaryOperator tie_breaker, int str) Returns a decision builder which assigns values to variables
which minimize the values returned by the evaluator. In case of
tie breaks, the second callback is used to choose the best index
in the array of equivalent pairs with equivalent evaluations. The
arguments passed to the evaluator callback are the indices of the
variables in vars and the values of these variables. Ownership of
the callback is passed to the decision builder. -
makePhase
Scheduling phases. -
makePhase
-
makeDecisionBuilderFromAssignment
public DecisionBuilder makeDecisionBuilderFromAssignment(Assignment assignment, DecisionBuilder db, IntVar[] vars) Returns a decision builder for which the left-most leaf corresponds
to assignment, the rest of the tree being explored using 'db'. -
makeConstraintAdder
Returns a decision builder that will add the given constraint to
the model. -
makeSolveOnce
SolveOnce will collapse a search tree described by a decision
builder 'db' and a set of monitors and wrap it into a single point.
If there are no solutions to this nested tree, then SolveOnce will
fail. If there is a solution, it will find it and returns nullptr. -
makeSolveOnce
-
makeSolveOnce
public DecisionBuilder makeSolveOnce(DecisionBuilder db, SearchMonitor monitor1, SearchMonitor monitor2) -
makeSolveOnce
public DecisionBuilder makeSolveOnce(DecisionBuilder db, SearchMonitor monitor1, SearchMonitor monitor2, SearchMonitor monitor3) -
makeSolveOnce
public DecisionBuilder makeSolveOnce(DecisionBuilder db, SearchMonitor monitor1, SearchMonitor monitor2, SearchMonitor monitor3, SearchMonitor monitor4) -
makeSolveOnce
-
makeNestedOptimize
public DecisionBuilder makeNestedOptimize(DecisionBuilder db, Assignment solution, boolean maximize, long step) NestedOptimize will collapse a search tree described by a
decision builder 'db' and a set of monitors and wrap it into a
single point. If there are no solutions to this nested tree, then
NestedOptimize will fail. If there are solutions, it will find
the best as described by the mandatory objective in the solution
as well as the optimization direction, instantiate all variables
to this solution, and return nullptr. -
makeNestedOptimize
public DecisionBuilder makeNestedOptimize(DecisionBuilder db, Assignment solution, boolean maximize, long step, SearchMonitor monitor1) -
makeNestedOptimize
public DecisionBuilder makeNestedOptimize(DecisionBuilder db, Assignment solution, boolean maximize, long step, SearchMonitor monitor1, SearchMonitor monitor2) -
makeNestedOptimize
public DecisionBuilder makeNestedOptimize(DecisionBuilder db, Assignment solution, boolean maximize, long step, SearchMonitor monitor1, SearchMonitor monitor2, SearchMonitor monitor3) -
makeNestedOptimize
public DecisionBuilder makeNestedOptimize(DecisionBuilder db, Assignment solution, boolean maximize, long step, SearchMonitor monitor1, SearchMonitor monitor2, SearchMonitor monitor3, SearchMonitor monitor4) -
makeNestedOptimize
public DecisionBuilder makeNestedOptimize(DecisionBuilder db, Assignment solution, boolean maximize, long step, SearchMonitor[] monitors) -
makeRestoreAssignment
Returns a DecisionBuilder which restores an Assignment
(calls void Assignment::Restore()) -
makeStoreAssignment
Returns a DecisionBuilder which stores an Assignment
(calls void Assignment::Store()) -
makeOperator
public LocalSearchOperator makeOperator(IntVar[] vars, int op, SWIGTYPE_p_std__functionT_std__vectorT_int_t_const_Rfint_intF_t get_incoming_neighbors, SWIGTYPE_p_std__functionT_std__vectorT_int_t_const_Rfint_intF_t get_outgoing_neighbors) Local Search Operators. -
makeOperator
public LocalSearchOperator makeOperator(IntVar[] vars, int op, SWIGTYPE_p_std__functionT_std__vectorT_int_t_const_Rfint_intF_t get_incoming_neighbors) Local Search Operators. -
makeOperator
Local Search Operators. -
makeOperator
public LocalSearchOperator makeOperator(IntVar[] vars, IntVar[] secondary_vars, int op, SWIGTYPE_p_std__functionT_std__vectorT_int_t_const_Rfint_intF_t get_incoming_neighbors, SWIGTYPE_p_std__functionT_std__vectorT_int_t_const_Rfint_intF_t get_outgoing_neighbors) -
makeOperator
public LocalSearchOperator makeOperator(IntVar[] vars, IntVar[] secondary_vars, int op, SWIGTYPE_p_std__functionT_std__vectorT_int_t_const_Rfint_intF_t get_incoming_neighbors) -
makeOperator
-
makeOperator
-
makeOperator
public LocalSearchOperator makeOperator(IntVar[] vars, IntVar[] secondary_vars, LongTernaryOperator evaluator, int op) -
makeRandomLnsOperator
Creates a large neighborhood search operator which creates fragments (set
of relaxed variables) with up to number_of_variables random variables
(sampling with replacement is performed meaning that at most
number_of_variables variables are selected). Warning: this operator will
always return neighbors; using it without a search limit will result in a
non-ending search.
Optionally a random seed can be specified. -
makeRandomLnsOperator
-
makeMoveTowardTargetOperator
Creates a local search operator that tries to move the assignment of some
variables toward a target. The target is given as an Assignment. This
operator generates neighbors in which the only difference compared to the
current state is that one variable that belongs to the target assignment
is set to its target value. -
makeMoveTowardTargetOperator
Creates a local search operator that tries to move the assignment of some
variables toward a target. The target is given either as two vectors: a
vector of variables and a vector of associated target values. The two
vectors should be of the same length. This operator generates neighbors in
which the only difference compared to the current state is that one
variable that belongs to the given vector is set to its target value. -
concatenateOperators
Creates a local search operator which concatenates a vector of operators.
Each operator from the vector is called sequentially. By default, when a
neighbor is found the neighborhood exploration restarts from the last
active operator (the one which produced the neighbor).
This can be overridden by setting restart to true to force the exploration
to start from the first operator in the vector.
The default behavior can also be overridden using an evaluation callback
to set the order in which the operators are explored (the callback is
called in LocalSearchOperator::Start()). The first argument of the
callback is the index of the operator which produced the last move, the
second argument is the index of the operator to be evaluated. Ownership of
the callback is taken by ConcatenateOperators.
Example:
const int kPriorities = {10, 100, 10, 0};
int64_t Evaluate(int active_operator, int current_operator) {
return kPriorities[current_operator];
}
LocalSearchOperator* concat =
solver.ConcatenateOperators(operators,
NewPermanentCallback(&Evaluate));
The elements of the vector operators will be sorted by increasing priority
and explored in that order (tie-breaks are handled by keeping the relative
operator order in the vector). This would result in the following order:
operators[3], operators[0], operators[2], operators[1]. -
concatenateOperators
-
concatenateOperators
public LocalSearchOperator concatenateOperators(LocalSearchOperator[] ops, IntIntToLongFunction evaluator) -
randomConcatenateOperators
Randomized version of local search concatenator; calls a random operator
at each call to MakeNextNeighbor(). -
randomConcatenateOperators
Randomized version of local search concatenator; calls a random operator
at each call to MakeNextNeighbor(). The provided seed is used to
initialize the random number generator. -
MultiArmedBanditConcatenateOperators
public LocalSearchOperator MultiArmedBanditConcatenateOperators(LocalSearchOperator[] ops, double memory_coefficient, double exploration_coefficient, boolean maximize) Creates a local search operator which concatenates a vector of operators.
Uses Multi-Armed Bandit approach for choosing the next operator to use.
Sorts operators based on Upper Confidence Bound Algorithm which evaluates
each operator as sum of average improvement and exploration function.
Updates the order of operators when accepts a neighbor with objective
improvement. -
makeNeighborhoodLimit
Creates a local search operator that wraps another local search
operator and limits the number of neighbors explored (i.e., calls
to MakeNextNeighbor from the current solution (between two calls
to Start()). When this limit is reached, MakeNextNeighbor()
returns false. The counter is cleared when Start() is called. -
makeLocalSearchPhase
public DecisionBuilder makeLocalSearchPhase(Assignment assignment, LocalSearchPhaseParameters parameters) Local Search decision builders factories.
Local search is used to improve a given solution. This initial solution
can be specified either by an Assignment or by a DecisionBulder, and the
corresponding variables, the initial solution being the first solution
found by the DecisionBuilder.
The LocalSearchPhaseParameters parameter holds the actual definition of
the local search phase:
- a local search operator used to explore the neighborhood of the current
solution,
- a decision builder to instantiate unbound variables once a neighbor has
been defined; in the case of LNS-based operators instantiates fragment
variables; search monitors can be added to this sub-search by wrapping
the decision builder with MakeSolveOnce.
- a search limit specifying how long local search looks for neighbors
before accepting one; the last neighbor is always taken and in the case
of a greedy search, this corresponds to the best local neighbor;
first-accept (which is the default behavior) can be modeled using a
solution found limit of 1,
- a vector of local search filters used to speed up the search by pruning
unfeasible neighbors.
Metaheuristics can be added by defining specialized search monitors;
currently down/up-hill climbing is available through OptimizeVar, as well
as Guided Local Search, Tabu Search and Simulated Annealing. -
makeLocalSearchPhase
public DecisionBuilder makeLocalSearchPhase(IntVar[] vars, DecisionBuilder first_solution, LocalSearchPhaseParameters parameters) -
makeLocalSearchPhase
public DecisionBuilder makeLocalSearchPhase(IntVar[] vars, DecisionBuilder first_solution, DecisionBuilder first_solution_sub_decision_builder, LocalSearchPhaseParameters parameters) Variant with a sub_decison_builder specific to the first solution. -
makeLocalSearchPhase
public DecisionBuilder makeLocalSearchPhase(SequenceVar[] vars, DecisionBuilder first_solution, LocalSearchPhaseParameters parameters) -
RunUncheckedLocalSearch
public Assignment RunUncheckedLocalSearch(Assignment initial_solution, LocalSearchFilterManager filter_manager, LocalSearchOperator ls_operator, SearchMonitor[] monitors, RegularLimit limit, SWIGTYPE_p_absl__flat_hash_setT_operations_research__IntVar_p_t touched) Experimental: runs a local search on the given initial solution, checking
the feasibility and the objective value of solutions using the filter
manager only (solutions are never restored in the CP world). Only greedy
descent is supported. -
RunUncheckedLocalSearch
public Assignment RunUncheckedLocalSearch(Assignment initial_solution, LocalSearchFilterManager filter_manager, LocalSearchOperator ls_operator, SearchMonitor[] monitors, RegularLimit limit) Experimental: runs a local search on the given initial solution, checking
the feasibility and the objective value of solutions using the filter
manager only (solutions are never restored in the CP world). Only greedy
descent is supported. -
makeDefaultSolutionPool
Solution Pool. -
makeLocalSearchPhaseParameters
public LocalSearchPhaseParameters makeLocalSearchPhaseParameters(IntVar objective, LocalSearchOperator ls_operator, DecisionBuilder sub_decision_builder) Local Search Phase Parameters -
makeLocalSearchPhaseParameters
public LocalSearchPhaseParameters makeLocalSearchPhaseParameters(IntVar objective, LocalSearchOperator ls_operator, DecisionBuilder sub_decision_builder, RegularLimit limit) -
makeLocalSearchPhaseParameters
public LocalSearchPhaseParameters makeLocalSearchPhaseParameters(IntVar objective, LocalSearchOperator ls_operator, DecisionBuilder sub_decision_builder, RegularLimit limit, LocalSearchFilterManager filter_manager) -
makeLocalSearchPhaseParameters
public LocalSearchPhaseParameters makeLocalSearchPhaseParameters(IntVar objective, SolutionPool pool, LocalSearchOperator ls_operator, DecisionBuilder sub_decision_builder) -
makeLocalSearchPhaseParameters
public LocalSearchPhaseParameters makeLocalSearchPhaseParameters(IntVar objective, SolutionPool pool, LocalSearchOperator ls_operator, DecisionBuilder sub_decision_builder, RegularLimit limit) -
makeLocalSearchPhaseParameters
public LocalSearchPhaseParameters makeLocalSearchPhaseParameters(IntVar objective, SolutionPool pool, LocalSearchOperator ls_operator, DecisionBuilder sub_decision_builder, RegularLimit limit, LocalSearchFilterManager filter_manager) -
MakeAcceptFilter
Local Search Filters -
MakeRejectFilter
-
makeVariableDomainFilter
-
makeSumObjectiveFilter
public IntVarLocalSearchFilter makeSumObjectiveFilter(IntVar[] vars, LongBinaryOperator values, int filter_enum) -
makeSumObjectiveFilter
public IntVarLocalSearchFilter makeSumObjectiveFilter(IntVar[] vars, IntVar[] secondary_vars, LongTernaryOperator values, int filter_enum) -
topPeriodicCheck
public void topPeriodicCheck()Performs PeriodicCheck on the top-level search; for instance, can be
called from a nested solve to check top-level limits. -
topProgressPercent
public int topProgressPercent()Returns a percentage representing the propress of the search before
reaching the limits of the top-level search (can be called from a nested
solve). -
pushState
public void pushState()The PushState and PopState methods manipulates the states
of the reversible objects. They are visible only because they
are useful to write unitary tests. -
popState
public void popState() -
searchDepth
public int searchDepth()Gets the search depth of the current active search. Returns -1 if
there is no active search opened. -
searchLeftDepth
public int searchLeftDepth()Gets the search left depth of the current active search. Returns -1 if
there is no active search opened. -
solveDepth
public int solveDepth()Gets the number of nested searches. It returns 0 outside search,
1 during the top level search, 2 or more in case of nested searches. -
rand64
public long rand64(long size) Returns a random value between 0 and 'size' - 1; -
rand32
public int rand32(int size) Returns a random value between 0 and 'size' - 1; -
reSeed
public void reSeed(int seed) Reseed the solver random generator. -
exportProfilingOverview
Exports the profiling information in a human readable overview.
The parameter profile_level used to create the solver must be
set to true. -
localSearchProfile
Returns local search profiling information in a human readable format. -
currentlyInSolve
public boolean currentlyInSolve()Returns true whether the current search has been
created using a Solve() call instead of a NewSearch one. It
returns false if the solver is not in search at all. -
constraints
public int constraints()Counts the number of constraints that have been added
to the solver before the search. -
accept
Accepts the given model visitor. -
balancing_decision
-
clear_fail_intercept
public void clear_fail_intercept()Internal -
SetUseFastLocalSearch
public void SetUseFastLocalSearch(boolean use_fast_local_search) enabled for metaheuristics.
Disables/enables fast local search. -
UseFastLocalSearch
public boolean UseFastLocalSearch()Returns true if fast local search is enabled. -
hasName
Returns whether the object has been named or not. -
registerDemon
-
registerIntExpr
-
registerIntVar
-
registerIntervalVar
Registers a new IntervalVar and wraps it inside a TraceIntervalVar
if necessary. -
cache
Returns the cache of the model. -
instrumentsDemons
public boolean instrumentsDemons()Returns whether we are instrumenting demons. -
isProfilingEnabled
public boolean isProfilingEnabled()Returns whether we are profiling the solver. -
isLocalSearchProfilingEnabled
public boolean isLocalSearchProfilingEnabled()Returns whether we are profiling local search. -
instrumentsVariables
public boolean instrumentsVariables()Returns whether we are tracing variables. -
nameAllVariables
public boolean nameAllVariables()Returns whether all variables should be named. -
model_name
Returns the name of the model. -
getPropagationMonitor
Returns the propagation monitor. -
addPropagationMonitor
Adds the propagation monitor to the solver. This is called internally when
a propagation monitor is passed to the Solve() or NewSearch() method. -
getLocalSearchMonitor
Returns the local search monitor. -
addLocalSearchMonitor
Adds the local search monitor to the solver. This is called internally
when a propagation monitor is passed to the Solve() or NewSearch() method. -
GetOrCreateLocalSearchState
Returns (or creates) an assignment representing the state of local search. -
ClearLocalSearchState
public void ClearLocalSearchState()Clears the local search state. -
setTmpVector
public void setTmpVector(long[] value) Unsafe temporary vector. It is used to avoid leaks in operations
that need storage and that may fail. See IntVar::SetValues() for
instance. It is not locked; do not use in a multi-threaded or reentrant
setup. -
getTmpVector
public long[] getTmpVector()Unsafe temporary vector. It is used to avoid leaks in operations
that need storage and that may fail. See IntVar::SetValues() for
instance. It is not locked; do not use in a multi-threaded or reentrant
setup. -
castExpression
-
finishCurrentSearch
public void finishCurrentSearch()Tells the solver to kill or restart the current search. -
restartCurrentSearch
public void restartCurrentSearch() -
shouldFail
public void shouldFail()These methods are only useful for the SWIG wrappers, which need a way
to externally cause the Solver to fail. -
checkFail
public void checkFail() -
MakeProfiledDecisionBuilderWrapper
Activates profiling on a decision builder.
-