Interface Solver<Solution_>
- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation
- All Known Implementing Classes:
AbstractSolver
,DefaultSolver
,PartitionSolver
To create a Solver, use SolverFactory.buildSolver()
.
To solve a planning problem, call solve(Object)
.
To solve a planning problem without blocking the current thread, use SolverManager
instead.
These methods are not thread-safe and should be called from the same thread,
except for the methods that are explicitly marked as thread-safe.
Note that despite that solve(Solution_)
is not thread-safe for clients of this class,
that method is free to do multithreading inside itself.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addEventListener
(SolverEventListener<Solution_> eventListener) void
addProblemChange
(ProblemChange<Solution_> problemChange) Schedules aProblemChange
to be processed.void
addProblemChanges
(List<ProblemChange<Solution_>> problemChangeList) Schedules multipleProblemChange
s to be processed.boolean
addProblemFactChange
(ProblemFactChange<Solution_> problemFactChange) Deprecated, for removal: This API element is subject to removal in a future version.boolean
addProblemFactChanges
(List<ProblemFactChange<Solution_>> problemFactChangeList) Deprecated, for removal: This API element is subject to removal in a future version.PreferaddProblemChanges(List)
.boolean
Checks if all scheduledProblemChange
s have been processed.boolean
Deprecated, for removal: This API element is subject to removal in a future version.PreferisEveryProblemChangeProcessed()
.boolean
This method is thread-safe.boolean
This method is thread-safe.void
removeEventListener
(SolverEventListener<Solution_> eventListener) Solves the planning problem and returns the best solution encountered (which might or might not be optimal, feasible or even initialized).boolean
Notifies the solver that it should stop at its earliest convenience.
-
Method Details
-
solve
Solves the planning problem and returns the best solution encountered (which might or might not be optimal, feasible or even initialized).It can take seconds, minutes, even hours or days before this method returns, depending on the termination configuration. To terminate a
Solver
early, callterminateEarly()
.- Parameters:
problem
- never null, aPlanningSolution
, usually its planning variables are uninitialized- Returns:
- never null, but it can return the original, uninitialized
PlanningSolution
with a nullScore
. - See Also:
-
terminateEarly
boolean terminateEarly()Notifies the solver that it should stop at its earliest convenience. This method returns immediately, but it takes an undetermined time for thesolve(Solution_)
to actually return.If the solver is running in daemon mode, this is the only way to terminate it normally.
This method is thread-safe. It can only be called from a different thread because the original thread is still calling
solve(Object)
.- Returns:
- true if successful, false if was already terminating or terminated
- See Also:
-
isSolving
boolean isSolving()This method is thread-safe.- Returns:
- true if the
solve(Solution_)
method is still running.
-
isTerminateEarly
boolean isTerminateEarly()This method is thread-safe.- Returns:
- true if terminateEarly has been called since the
Solver
started. - See Also:
-
addProblemChange
Schedules aProblemChange
to be processed.As a side effect, this restarts the
Solver
, effectively resetting allTermination
s, but notterminateEarly()
.This method is thread-safe. Follows specifications of
BlockingQueue.add(Object)
with by default a capacity ofInteger.MAX_VALUE
.To learn more about problem change semantics, please refer to the
ProblemChange
Javadoc.- Parameters:
problemChange
- never null- See Also:
-
addProblemChanges
Schedules multipleProblemChange
s to be processed.As a side effect, this restarts the
Solver
, effectively resetting allTermination
s, but notterminateEarly()
.This method is thread-safe. Follows specifications of
BlockingQueue.add(Object)
with by default a capacity ofInteger.MAX_VALUE
.To learn more about problem change semantics, please refer to the
ProblemChange
Javadoc.- Parameters:
problemChangeList
- never null- See Also:
-
isEveryProblemChangeProcessed
boolean isEveryProblemChangeProcessed()Checks if all scheduledProblemChange
s have been processed.This method is thread-safe.
- Returns:
- true if there are no
ProblemChange
s left to do
-
addProblemFactChange
@Deprecated(forRemoval=true) boolean addProblemFactChange(ProblemFactChange<Solution_> problemFactChange) Deprecated, for removal: This API element is subject to removal in a future version.PreferaddProblemChange(ProblemChange)
.This method is deprecated. Schedules aProblemFactChange
to be processed.As a side-effect, this restarts the
Solver
, effectively resetting all terminations, but notterminateEarly()
.This method is thread-safe. Follows specifications of
BlockingQueue.add(Object)
with by default a capacity ofInteger.MAX_VALUE
.- Parameters:
problemFactChange
- never null- Returns:
- true (as specified by
Collection.add(E)
) - See Also:
-
addProblemFactChanges
@Deprecated(forRemoval=true) boolean addProblemFactChanges(List<ProblemFactChange<Solution_>> problemFactChangeList) Deprecated, for removal: This API element is subject to removal in a future version.PreferaddProblemChanges(List)
.This method is deprecated. Schedules multipleProblemFactChange
s to be processed.As a side-effect, this restarts the
Solver
, effectively resetting all terminations, but notterminateEarly()
.This method is thread-safe. Follows specifications of
Collection.addAll(Collection)
with by default a capacity ofInteger.MAX_VALUE
.- Parameters:
problemFactChangeList
- never null- Returns:
- true (as specified by
Collection.add(E)
) - See Also:
-
isEveryProblemFactChangeProcessed
Deprecated, for removal: This API element is subject to removal in a future version.PreferisEveryProblemChangeProcessed()
.This method is deprecated. Checks if all scheduledProblemFactChange
s have been processed.This method is thread-safe.
- Returns:
- true if there are no
ProblemFactChange
s left to do
-
addEventListener
- Parameters:
eventListener
- never null
-
removeEventListener
- Parameters:
eventListener
- never null
-
addProblemChange(ProblemChange)
.