java.lang.Object
org.maxicp.search.AbstractSearchMethod<T>
- Type Parameters:
T- the type of the branching
- All Implemented Interfaces:
SearchMethod
- Direct Known Subclasses:
AbstractConcurrentSearchMethod,RunnableSearchMethod,SymbolicSearchMethod
An abstract search method, implementing all the parts needed, but the search method itself.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<Consumer<SearchStatistics>> protected StateManagerprotected List<Consumer<SearchStatistics>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanprotected voidnotifyFailure(SearchStatistics stats) protected voidnotifySolution(SearchStatistics stats) voidonFailure(Consumer<SearchStatistics> listener) Adds a listener that is called whenever a failure occurs and the search backtracks.voidonSolution(Consumer<SearchStatistics> listener) Adds a listener that is called on each solution.optimize(Objective obj, Predicate<SearchStatistics> limit) Start the solving process with a given objective.optimize(Objective toTighten, Predicate<SearchStatistics> limit) Start the solving process with a given objective and with a given predicate called at each node to stop the search when it becomes true.optimizeSubjectTo(Objective objToTighten, Predicate<SearchStatistics> limit, Runnable subjectTo) optimizeSubjectTo(Objective objToTighten, Predicate<SearchStatistics> limit, Runnable subjectTo) Executes a closure prior to effectively starting a branch and bound depth-first-search with a given objective to optimize and a given predicate called at each node to stop the search when it becomes true.replay(DFSLinearizer linearizer, CPVar[] variables) replaySubjectTo(DFSLinearizer linearizer, CPVar[] variables, Runnable subjectTo) replaySubjectTo(DFSLinearizer linearizer, CPVar[] variables, Runnable subjectTo, Runnable onNodeVisit) replaySubjectTo(DFSLinearizer linearizer, CPVar[] variables, Runnable subjectTo, Objective obj) solve()Start the solving processsolve(Predicate<SearchStatistics> limit) Start the solving process with a given predicate called at each node to stop the search when it becomes true.solve(DFSListener listener) Start the solving process with a given listener of the search process.protected SearchStatisticssolve(SearchStatistics statistics, Predicate<SearchStatistics> limit, Runnable onNodeVisit) solveSubjectTo(Predicate<SearchStatistics> limit, Runnable subjectTo) Start the solving process with a given predicate called at each node to stop the search when it becomes true.protected abstract voidstartSolve(SearchStatistics statistics, Predicate<SearchStatistics> limit, Runnable onNodeVisit) Start the solving process.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.maxicp.search.SearchMethod
onFailure, onSolution
-
Field Details
-
branching
-
sm
-
solutionListeners
-
failureListeners
-
-
Constructor Details
-
AbstractSearchMethod
-
-
Method Details
-
onSolution
Adds a listener that is called on each solution.- Specified by:
onSolutionin interfaceSearchMethod- Parameters:
listener- the closure to be called whenever a solution is found
-
onFailure
Adds a listener that is called whenever a failure occurs and the search backtracks. This happens when aInconsistencyExceptionis thrown when executing the closure generated by the branching.- Specified by:
onFailurein interfaceSearchMethod- Parameters:
listener- the closure to be called whenever a failure occurs and the search need to backtrack
-
notifySolution
-
notifyFailure
-
solve
protected SearchStatistics solve(SearchStatistics statistics, Predicate<SearchStatistics> limit, Runnable onNodeVisit) -
solve
Start the solving process- Specified by:
solvein interfaceSearchMethod- Returns:
- an object with the statistics on the search
-
solve
Start the solving process with a given listener of the search process.- Parameters:
listener- a listener of the search process- Returns:
- an object with the statistics on the search
-
solve
Start the solving process with a given predicate called at each node to stop the search when it becomes true.- Specified by:
solvein interfaceSearchMethod- Parameters:
limit- a predicate called at each node that stops the search when it becomes true- Returns:
- an object with the statistics on the search
-
solveSubjectTo
Start the solving process with a given predicate called at each node to stop the search when it becomes true. The state manager saves the state before executing the closure and restores it after the search. AnyInconsistencyExceptionthat may be throw when executing the closure is also catched.- Specified by:
solveSubjectToin interfaceSearchMethod- Parameters:
limit- a predicate called at each node that stops the search when it becomes truesubjectTo- the closure to execute prior to the search starts- Returns:
- an object with the statistics on the search
-
allFixed
-
replaySubjectTo
public SearchStatistics replaySubjectTo(DFSLinearizer linearizer, CPVar[] variables, Runnable subjectTo, Objective obj) -
replay
-
replaySubjectTo
public SearchStatistics replaySubjectTo(DFSLinearizer linearizer, CPVar[] variables, Runnable subjectTo) -
replaySubjectTo
public SearchStatistics replaySubjectTo(DFSLinearizer linearizer, CPVar[] variables, Runnable subjectTo, Runnable onNodeVisit) -
optimize
Start the solving process with a given objective.- Specified by:
optimizein interfaceSearchMethod- Parameters:
obj- the objective to optimize that is tightened each time a new solution is found- Returns:
- an object with the statistics on the search
-
optimize
- Specified by:
optimizein interfaceSearchMethod
-
optimize
- Specified by:
optimizein interfaceSearchMethod
-
optimize
Start the solving process with a given objective and with a given predicate called at each node to stop the search when it becomes true.- Specified by:
optimizein interfaceSearchMethod- Parameters:
toTighten- the objective to optimize that is tightened each time a new solution is foundlimit- a predicate called at each node that stops the search when it becomes true- Returns:
- an object with the statistics on the search
-
optimizeSubjectTo
public SearchStatistics optimizeSubjectTo(Objective objToTighten, Predicate<SearchStatistics> limit, Runnable subjectTo) Executes a closure prior to effectively starting a branch and bound depth-first-search with a given objective to optimize and a given predicate called at each node to stop the search when it becomes true. The state manager saves the state before executing the closure and restores it after the search. AnyInconsistencyExceptionthat may be thrown when executing the closure is also catched.- Specified by:
optimizeSubjectToin interfaceSearchMethod- Parameters:
objToTighten- the objective to optimize that is tightened each time a new solution is foundlimit- a predicate called at each node that stops the search when it becomes truesubjectTo- the closure to execute prior to the search starts- Returns:
- an object with the statistics on the search
-
optimizeSubjectTo
public SearchStatistics optimizeSubjectTo(Objective objToTighten, Predicate<SearchStatistics> limit, Runnable subjectTo) - Specified by:
optimizeSubjectToin interfaceSearchMethod
-
startSolve
protected abstract void startSolve(SearchStatistics statistics, Predicate<SearchStatistics> limit, Runnable onNodeVisit) Start the solving process.This method must be implemented by subclasses and do the heavy work. It must call notifySolution/notifyFailure when a solution is found or a failure occurs.
- Parameters:
statistics-limit-onNodeVisit- a closure to execute at each node visit
-