java.lang.Object
org.maxicp.search.blackbox.BlackBoxSearch
- All Implemented Interfaces:
SearchMethod
Commercial-solver-style black-box search orchestrator for modeling-level CP and scheduling problems.
Implements SearchMethod so it can be used as a drop-in replacement for DFSearch
inside model.runCP(cp -> ...) via cp.blackBoxSearch(), or directly on a
ModelDispatcher via model.blackBoxSearch(), model.solve(...), and
model.optimize(...).
Automatically discovers both integer/boolean variables (IntExpression) and scheduling
interval variables (IntervalVar) from the model when not explicitly provided.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordConfiguration for exhaustive DFS/FDS phase.static enumStrategy used to choose which decision variables are frozen in each LNS restart.static final recordSnapshot of anIntervalVarin an incumbent solution.static final recordConfiguration for LNS improvement phase.static final recordConfiguration for restart-based feasibility phase.static enumLogging granularity for phase execution. -
Constructor Summary
ConstructorsConstructorDescriptionBlackBoxSearch(ModelDispatcher model) Creates a black-box search with automatic decision-variable and interval-variable inference.BlackBoxSearch(ModelDispatcher model, List<IntExpression> vars, Objective objective) Creates a black-box search on explicit integer decision variables with an objective.BlackBoxSearch(ModelDispatcher model, IntExpression[] vars) Creates a black-box search on an array of integer decision variables without objective (feasibility).BlackBoxSearch(ModelDispatcher model, IntExpression[] vars, Objective objective) Creates a black-box search on an array of integer decision variables with an objective.BlackBoxSearch(ModelDispatcher model, IntervalVar... intervals) Creates a black-box search on an array of scheduling interval variables.BlackBoxSearch(ModelDispatcher model, IntervalVar[][] intervals) Creates a black-box search on a 2D matrix of scheduling interval variables.BlackBoxSearch(ModelDispatcher model, Objective objective) Creates a black-box search with automatic decision-variable and interval-variable inference. -
Method Summary
Modifier and TypeMethodDescriptionaddPhase(String name, RunnableSearch search, double timeShare, boolean requiresFeasible) Registers one executable phase in the black-box plan.Returns the best incumbent interval snapshots found so far, if any.Returns the incumbent objective value, if any.Returns the best incumbent solution found so far, if any.bestValue(IntExpression var) Returns the value ofvarin the best incumbent solution found so far, if available.bestValues(IntExpression... targetVars) Returns the values of the given expressions in the best incumbent solution found so far.Returns an unmodifiable view of the recorded variable values in the best solution.Returns phase names that were actually executed (in execution order).voidonFailure(Consumer<SearchStatistics> listener) Adds a listener that is called whenever a failure occurs and the search backtracks.onIncumbent(BiConsumer<List<Integer>, Integer> listener) Registers a callback invoked whenever a new feasible or improving incumbent is recorded.voidonSolution(Consumer<SearchStatistics> listener) Adds a listener that is called on each solution.Optimizes the given objective under a wall-clock timeout in seconds.optimize(Objective obj, Predicate<SearchStatistics> limit) Start the solving process with a given objective.Optimizes the given low-level objective within the specified time limit (in seconds).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.solve()Start the solving processsolve(int timeLimitInSeconds) Solves the feasibility model under a wall-clock timeout in seconds.solve(Predicate<SearchStatistics> limit) Start the solving process with a given predicate called at each node to stop the search when it becomes true.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.start(int timeLimitInSeconds) Executes the configured phase plan under a global timeout.status()Returns the overall status of the most recent search run.voidupdateObjective(Integer objectiveValue) voidupdateSolution(List<Integer> solution) Builds the built-in default plan.withFeasibilityPlan(BlackBoxSearch.RestartPhaseOptions restart, BlackBoxSearch.ExhaustivePhaseOptions exhaustive, double initialExhaustiveShare, double restartShare, double exhaustiveShare) Configures the feasibility phase plan explicitly.withOptimizationPlan(BlackBoxSearch.RestartPhaseOptions restart, BlackBoxSearch.LnsPhaseOptions lns, BlackBoxSearch.ExhaustivePhaseOptions exhaustive, double initialExhaustiveShare, double restartShare, double lnsShare, double exhaustiveShare) Configures the optimization phase plan explicitly.withVerbosity(BlackBoxSearch.Verbosity verbosity) Sets logging verbosity for this search.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
-
Constructor Details
-
BlackBoxSearch
Creates a black-box search on explicit integer decision variables with an objective. -
BlackBoxSearch
Creates a black-box search with automatic decision-variable and interval-variable inference. -
BlackBoxSearch
Creates a black-box search on an array of integer decision variables with an objective. -
BlackBoxSearch
Creates a black-box search on an array of integer decision variables without objective (feasibility). -
BlackBoxSearch
Creates a black-box search on an array of scheduling interval variables. -
BlackBoxSearch
Creates a black-box search on a 2D matrix of scheduling interval variables. -
BlackBoxSearch
Creates a black-box search with automatic decision-variable and interval-variable inference.
-
-
Method Details
-
withVerbosity
Sets logging verbosity for this search. -
onIncumbent
Registers a callback invoked whenever a new feasible or improving incumbent is recorded. -
onSolution
Description copied from interface:SearchMethodAdds 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
Description copied from interface:SearchMethodAdds 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
-
addPhase
public BlackBoxSearch addPhase(String name, RunnableSearch search, double timeShare, boolean requiresFeasible) Registers one executable phase in the black-box plan. -
withDefaultPhasePlan
Builds the built-in default plan. -
withOptimizationPlan
public BlackBoxSearch withOptimizationPlan(BlackBoxSearch.RestartPhaseOptions restart, BlackBoxSearch.LnsPhaseOptions lns, BlackBoxSearch.ExhaustivePhaseOptions exhaustive, double initialExhaustiveShare, double restartShare, double lnsShare, double exhaustiveShare) Configures the optimization phase plan explicitly. -
withFeasibilityPlan
public BlackBoxSearch withFeasibilityPlan(BlackBoxSearch.RestartPhaseOptions restart, BlackBoxSearch.ExhaustivePhaseOptions exhaustive, double initialExhaustiveShare, double restartShare, double exhaustiveShare) Configures the feasibility phase plan explicitly. -
start
Executes the configured phase plan under a global timeout.- Parameters:
timeLimitInSeconds- global timeout in seconds- Returns:
- merged global status across executed phases
-
solve
Description copied from interface:SearchMethodStart the solving process- Specified by:
solvein interfaceSearchMethod- Returns:
- an object with the statistics on the search
-
solve
Solves the feasibility model under a wall-clock timeout in seconds.- Parameters:
timeLimitInSeconds- timeout in seconds- Returns:
- aggregated search statistics
-
solve
Description copied from interface:SearchMethodStart 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
Description copied from interface:SearchMethodStart 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
-
optimize
- Specified by:
optimizein interfaceSearchMethod
-
optimize
Optimizes the given objective under a wall-clock timeout in seconds.- Parameters:
obj- symbolic objective to minimize or maximizetimeLimitInSeconds- timeout in seconds- Returns:
- aggregated search statistics
-
optimize
- Specified by:
optimizein interfaceSearchMethod
-
optimizeSubjectTo
public SearchStatistics optimizeSubjectTo(Objective objToTighten, Predicate<SearchStatistics> limit, Runnable subjectTo) - Specified by:
optimizeSubjectToin interfaceSearchMethod
-
optimize
Description copied from interface:SearchMethodStart 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
Optimizes the given low-level objective within the specified time limit (in seconds). -
optimize
Description copied from interface:SearchMethodStart 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) Description copied from interface:SearchMethodExecutes 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
-
status
Returns the overall status of the most recent search run. -
bestSolution
Returns the best incumbent solution found so far, if any. -
bestIntervalSolution
Returns the best incumbent interval snapshots found so far, if any. -
bestValue
Returns the value ofvarin the best incumbent solution found so far, if available. -
bestValues
Returns the values of the given expressions in the best incumbent solution found so far. -
bestVarValuesMap
Returns an unmodifiable view of the recorded variable values in the best solution. -
bestObjectiveValue
Returns the incumbent objective value, if any. -
executedPhases
Returns phase names that were actually executed (in execution order). -
updateObjective
-
updateSolution
-
getRunnableSearches
-