Package org.optaplanner.core.impl.partitionedsearch

## Class PartitionSolver<Solution_>

- java.lang.Object
- - org.optaplanner.core.impl.solver.AbstractSolver<Solution_>
  - - org.optaplanner.core.impl.partitionedsearch.PartitionSolver<Solution_>

- Type Parameters:
    `Solution_` - the solution type, the class with the `PlanningSolution` annotation
  All Implemented Interfaces:
    `Solver<Solution_>`

      public class PartitionSolver<Solution_>
      extends AbstractSolver<Solution_>

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected SolverScope<Solution_>` | `solverScope` |

    - ### Fields inherited from class org.optaplanner.core.impl.solver.AbstractSolver

      `bestSolutionRecaller, logger, phaseLifecycleSupport, phaseList, solverEventSupport, termination`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `PartitionSolver​(BestSolutionRecaller<Solution_> bestSolutionRecaller, Termination<Solution_> termination, List<Phase<Solution_>> phaseList, SolverScope<Solution_> solverScope)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `addProblemFactChange​(ProblemFactChange<Solution_> problemFactChange)` | Schedules a `ProblemFactChange` to be processed.
    `boolean` | `addProblemFactChanges​(List<ProblemFactChange<Solution_>> problemFactChanges)` | Schedules multiple `ProblemFactChange`s to be processed.
    `long` | `getScoreCalculationCount()` |
    `boolean` | `isEveryProblemFactChangeProcessed()` | Checks if all scheduled `ProblemFactChange`s have been processed.
    `boolean` | `isSolving()` | This method is thread-safe.
    `boolean` | `isTerminateEarly()` | This method is thread-safe.
    `Solution_` | `solve​(Solution_ problem)` | Solves the planning problem and returns the best solution encountered (which might or might not be optimal, feasible or even initialized).
    `void` | `solvingEnded​(SolverScope<Solution_> solverScope)` |
    `void` | `solvingStarted​(SolverScope<Solution_> solverScope)` |
    `boolean` | `terminateEarly()` | Notifies the solver that it should stop at its earliest convenience.

    - ### Methods inherited from class org.optaplanner.core.impl.solver.AbstractSolver

      `addEventListener, addPhaseLifecycleListener, removeEventListener, removePhaseLifecycleListener, runPhases`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### solverScope

          protected final SolverScope<Solution_> solverScope

  - ### Constructor Detail

    - #### PartitionSolver

          public PartitionSolver​(BestSolutionRecaller<Solution_> bestSolutionRecaller,
                                 Termination<Solution_> termination,
                                 List<Phase<Solution_>> phaseList,
                                 SolverScope<Solution_> solverScope)

  - ### Method Detail

    - #### isSolving

          public boolean isSolving()

      Description copied from interface: `Solver`
      This method is thread-safe.
      Returns:
        true if the `Solver.solve(Solution_)` method is still running.

    - #### terminateEarly

          public boolean terminateEarly()

      Description copied from interface: `Solver`
      Notifies the solver that it should stop at its earliest convenience. This method returns immediately, but it takes an undetermined time for the `Solver.solve(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 `Solver.solve(Object)`.

      Returns:
        true if successful, false if was already terminating or terminated
      See Also:
        `Solver.isTerminateEarly()`, `Future.cancel(boolean)`

    - #### isTerminateEarly

          public boolean isTerminateEarly()

      Description copied from interface: `Solver`
      This method is thread-safe.
      Returns:
        true if terminateEarly has been called since the `Solver` started.
      See Also:
        `Future.isCancelled()`

    - #### addProblemFactChange

          public boolean addProblemFactChange​(ProblemFactChange<Solution_> problemFactChange)

      Description copied from interface: `Solver`
      Schedules a `ProblemFactChange` to be processed.

      As a side-effect, this restarts the `Solver`, effectively resetting all `Termination`s, but not `Solver.terminateEarly()`.

      This method is thread-safe. Follows specifications of `BlockingQueue.add(Object)` with by default a capacity of `Integer.MAX_VALUE`.

      Parameters:
        `problemFactChange` - never null
      Returns:
        true (as specified by `Collection.add(E)`)
      See Also:
        `Solver.addProblemFactChanges(List)`

    - #### addProblemFactChanges

          public boolean addProblemFactChanges​(List<ProblemFactChange<Solution_>> problemFactChanges)

      Description copied from interface: `Solver`
      Schedules multiple `ProblemFactChange`s to be processed.

      As a side-effect, this restarts the `Solver`, effectively resetting all `Termination`s, but not `Solver.terminateEarly()`.

      This method is thread-safe. Follows specifications of `Collection.addAll(Collection)` with by default a capacity of `Integer.MAX_VALUE`.

      Parameters:
        `problemFactChanges` - never null
      Returns:
        true (as specified by `Collection.add(E)`)
      See Also:
        `Solver.addProblemFactChange(ProblemFactChange)`

    - #### isEveryProblemFactChangeProcessed

          public boolean isEveryProblemFactChangeProcessed()

      Description copied from interface: `Solver`
      Checks if all scheduled `ProblemFactChange`s have been processed.

      This method is thread-safe.

      Returns:
        true if there are no `ProblemFactChange`s left to do

    - #### solve

          public Solution_ solve​(Solution_ problem)

      Description copied from interface: `Solver`
      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, call `Solver.terminateEarly()`.

      Parameters:
        `problem` - never null, a `PlanningSolution`, usually its planning variables are uninitialized
      Returns:
        never null, but it can return the original, uninitialized `PlanningSolution` with a null `Score`.
      See Also:
        `Solver.terminateEarly()`

    - #### solvingStarted

          public void solvingStarted​(SolverScope<Solution_> solverScope)

      Overrides:
        `solvingStarted` in class `AbstractSolver<Solution_>`

    - #### solvingEnded

          public void solvingEnded​(SolverScope<Solution_> solverScope)

      Overrides:
        `solvingEnded` in class `AbstractSolver<Solution_>`

    - #### getScoreCalculationCount

          public long getScoreCalculationCount()