public final class BranchingScheme extends Object
A typical custom search on an array of variable q
is illustrated next
DFSearch search = Factory.makeDfs(cp, () -> {
int idx = -1; // index of the first variable that is not bound
for (int k = 0; k < q.length; k++)
if(q[k].size() > 1) {
idx=k;
break;
}
if(idx == -1)
return new Procedure[0];
else {
IntVar qi = q[idx];
int v = qi.min();
Procedure left = () -> Factory.equal(qi, v);
Procedure right = () -> Factory.notEqual(qi, v);
return branch(left,right);
}
});
Factory.makeDfs(Solver, Supplier)
Modifier and Type | Field and Description |
---|---|
static Procedure[] |
EMPTY
Constant that should be returned
to notify the solver that there are no branches
to create any more and that the current state should
be considered as a solution.
|
Modifier and Type | Method and Description |
---|---|
static Supplier<Procedure[]> |
and(Supplier<Procedure[]>... choices)
Sequential Search combinator that linearly
considers a list of branching generator.
|
static Procedure[] |
branch(Procedure... branches) |
static Supplier<Procedure[]> |
firstFail(IntVar... x)
First-Fail strategy.
|
static Supplier<Procedure[]> |
limitedDiscrepancy(Supplier<Procedure[]> branching,
int maxDiscrepancy)
Limited Discrepancy Search combinator
that limits the number of right decisions
|
static <T,N extends Comparable<N>> |
selectMin(T[] x,
Predicate<T> p,
Function<T,N> f)
Minimum selector.
|
public static final Procedure[] EMPTY
Factory.makeDfs(Solver, Supplier)
public static Procedure[] branch(Procedure... branches)
branches
- the ordered closures for the child branches
ordered from left to right in the depth first search.DFSearch
public static <T,N extends Comparable<N>> T selectMin(T[] x, Predicate<T> p, Function<T,N> f)
Example of usage.
IntVar xs = selectMin(x,xi -> xi.size() > 1,xi -> xi.size());
T
- the type of the elements in x, for instance IntVar
N
- the type on which the minimum is computed, for instance Integer
x
- the array on which the minimum value is searchedp
- the predicate that filters the element eligible for selectionf
- the evaluation function that returns a comparable when applied on an element of xpublic static Supplier<Procedure[]> firstFail(IntVar... x)
x
- the variable on which the first fail strategy is applied.Factory.makeDfs(Solver, Supplier)
public static Supplier<Procedure[]> and(Supplier<Procedure[]>... choices)
choices
- the branching schemes considered sequentially in the sequential by
path in the search treeSequencer
public static Supplier<Procedure[]> limitedDiscrepancy(Supplier<Procedure[]> branching, int maxDiscrepancy)
branching
- a branching schememaxDiscrepancy
- a discrepancy limit (non negative number)LimitedDiscrepancyBranching
Copyright © 2018 Laurent Michel, Pierre Schaus, Pascal Van Hentenryck. All rights reserved.