Package org.optaplanner.core.api.solver.event

## Class BestSolutionChangedEvent<Solution_>

- java.lang.Object
- - java.util.EventObject
  - - org.optaplanner.core.api.solver.event.BestSolutionChangedEvent<Solution_>

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

      public class BestSolutionChangedEvent<Solution_>
      extends EventObject

  Delivered when the `best solution` changes during solving. Delivered in the solver thread (which is the thread that calls `Solver.solve(Solution_)`).
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class java.util.EventObject

      `source`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `BestSolutionChangedEvent​(Solver<Solution_> solver, long timeMillisSpent, Solution_ newBestSolution, Score newBestScore)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Score` | `getNewBestScore()` | Returns the `Score` of the `getNewBestSolution()`.
    `Solution_` | `getNewBestSolution()` | Note that: In real-time planning, not all `ProblemFactChange`s might be processed: check `isEveryProblemFactChangeProcessed()`. this `PlanningSolution` might be uninitialized: check `Score.isSolutionInitialized()`. this `PlanningSolution` might be infeasible: check `Score.isFeasible()`.
    `long` | `getTimeMillisSpent()` |
    `boolean` | `isEveryProblemFactChangeProcessed()` |

    - ### Methods inherited from class java.util.EventObject

      `getSource, toString`

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

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

- - ### Constructor Detail

    - #### BestSolutionChangedEvent

          public BestSolutionChangedEvent​(Solver<Solution_> solver,
                                          long timeMillisSpent,
                                          Solution_ newBestSolution,
                                          Score newBestScore)

      Parameters:
        `solver` - never null
        `timeMillisSpent` - `>= 0L`
        `newBestSolution` - never null

  - ### Method Detail

    - #### getTimeMillisSpent

          public long getTimeMillisSpent()

      Returns:
        `>= 0`, the amount of millis spent since the `Solver` started until `getNewBestSolution()` was found

    - #### getNewBestSolution

          public Solution_ getNewBestSolution()

      Note that:
      - In real-time planning, not all `ProblemFactChange`s might be processed: check `isEveryProblemFactChangeProcessed()`.
      - this `PlanningSolution` might be uninitialized: check `Score.isSolutionInitialized()`.
      - this `PlanningSolution` might be infeasible: check `Score.isFeasible()`.
      Returns:
        never null

    - #### getNewBestScore

          public Score getNewBestScore()

      Returns the `Score` of the `getNewBestSolution()`.

      This is useful for generic code, which doesn't know the type of the `PlanningSolution` to retrieve the `Score` from the `getNewBestSolution()` easily.

      Returns:
        never null, because at this point it's always already calculated

    - #### isEveryProblemFactChangeProcessed

          public boolean isEveryProblemFactChangeProcessed()

      Returns:
        As defined by `Solver.isEveryProblemFactChangeProcessed()`
      See Also:
        `Solver.isEveryProblemFactChangeProcessed()`