Limits
Built-in search limits
Search can be limited in various ways using the Solver (from model.getSolver()).
-
limitTimestops the search when the given time limit has been reached. This is the most common limit, as many applications have a limited available runtime. -
limitSolutionstops the search when the given solution limit has been reached. -
limitNodestops the search when the given search node limit has been reached. -
limitFailstops the search when the given fail limit has been reached. -
limitBacktrackstops the search when the given backtrack limit has been reached.
Info
The potential search interruption occurs at the end of a propagation, i.e. it will not interrupt a propagation algorithm, so the overall runtime of the solver might exceed the time limit.For instance, to interrupt search after 10 seconds:
Solver s = model.getSolver();
s.limitTime("10s");
model.getSolver().solve();
Custom search limits
You can design you own search limit by implementing a Criterion and using resolver.limitSearch(Criterion c):
Solver s = model.getSolver();
s.limitSearch(new Criterion() {
@Override
public boolean isMet() {
// todo return true if you want to stop search
}
});
In Java 8, this can be shortened using lambda expressions:
Solver s = model.getSolver();
s.limitSearch(() -> { /*todo return true if you want to stop search*/ });
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.