org.optaplanner.core.impl.solver.scope

## Class DefaultSolverScope<Solution_>

- java.lang.Object
- - org.optaplanner.core.impl.solver.scope.DefaultSolverScope<Solution_>

- Type Parameters:
    `Solution_` - the solution type, the class with the `PlanningSolution` annotation

      public class DefaultSolverScope<Solution_>
      extends Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Score` | `bestScore`
    `protected Solution_` | `bestSolution`
    `protected Long` | `bestSolutionTimeMillis`
    `protected long` | `childThreadsScoreCalculationCount`
    `protected Long` | `endingSystemTimeMillis`
    `protected org.slf4j.Logger` | `logger`
    `protected Semaphore` | `runnableThreadSemaphore` Used for capping CPU power usage in multithreaded scenarios.
    `protected InnerScoreDirector<Solution_>` | `scoreDirector`
    `protected Score` | `startingInitializedScore`
    `protected int` | `startingSolverCount`
    `protected Long` | `startingSystemTimeMillis`
    `protected Random` | `workingRandom`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultSolverScope()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addChildThreadsScoreCalculationCount(long addition)`
    `void` | `assertScoreFromScratch(Solution_ solution)`
    `Score` | `calculateScore()`
    `long` | `calculateTimeMillisSpentUpToNow()`
    `void` | `checkYielding()` Similar to `Thread.yield()`, but allows capping the number of active solver threads at less than the CPU processor count, so other threads (for example servlet threads that handle REST calls) and other processes (such as SSH) have access to uncontested CPUs and don't suffer any latency.
    `DefaultSolverScope<Solution_>` | `createChildThreadSolverScope(ChildThreadType childThreadType)`
    `void` | `destroyYielding()`
    `void` | `endingNow()`
    `Score` | `getBestScore()`
    `Solution_` | `getBestSolution()`
    `Long` | `getBestSolutionTimeMillis()`
    `Long` | `getBestSolutionTimeMillisSpent()`
    `Long` | `getEndingSystemTimeMillis()`
    `long` | `getScoreCalculationCount()`
    `long` | `getScoreCalculationSpeed()`
    `ScoreDefinition` | `getScoreDefinition()`
    `InnerScoreDirector<Solution_>` | `getScoreDirector()`
    `SolutionDescriptor<Solution_>` | `getSolutionDescriptor()`
    `Score` | `getStartingInitializedScore()`
    `int` | `getStartingSolverCount()`
    `Long` | `getStartingSystemTimeMillis()`
    `long` | `getTimeMillisSpent()`
    `int` | `getWorkingEntityCount()`
    `List<Object>` | `getWorkingEntityList()`
    `Random` | `getWorkingRandom()`
    `Solution_` | `getWorkingSolution()`
    `int` | `getWorkingValueCount()`
    `void` | `initializeYielding()`
    `boolean` | `isBestSolutionInitialized()`
    `void` | `setBestScore(Score bestScore)`
    `void` | `setBestSolution(Solution_ bestSolution)` The `best solution` must never be the same instance as the `working solution`, it should be a (un)changed clone.
    `void` | `setBestSolutionTimeMillis(Long bestSolutionTimeMillis)`
    `void` | `setRunnableThreadSemaphore(Semaphore runnableThreadSemaphore)`
    `void` | `setScoreDirector(InnerScoreDirector<Solution_> scoreDirector)`
    `void` | `setStartingInitializedScore(Score startingInitializedScore)`
    `void` | `setStartingSolverCount(int startingSolverCount)`
    `void` | `setWorkingRandom(Random workingRandom)`
    `void` | `setWorkingSolutionFromBestSolution()`
    `void` | `startingNow()`

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

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

- - ### Field Detail

    - #### logger

          protected final transient org.slf4j.Logger logger

    - #### startingSolverCount

          protected int startingSolverCount

    - #### workingRandom

          protected Random workingRandom

    - #### scoreDirector

          protected InnerScoreDirector<Solution_> scoreDirector

    - #### runnableThreadSemaphore

          protected Semaphore runnableThreadSemaphore

      Used for capping CPU power usage in multithreaded scenarios.

    - #### startingSystemTimeMillis

          protected volatile Long startingSystemTimeMillis

    - #### endingSystemTimeMillis

          protected volatile Long endingSystemTimeMillis

    - #### childThreadsScoreCalculationCount

          protected long childThreadsScoreCalculationCount

    - #### startingInitializedScore

          protected Score startingInitializedScore

    - #### bestSolution

          protected volatile Solution_ bestSolution

    - #### bestScore

          protected volatile Score bestScore

    - #### bestSolutionTimeMillis

          protected Long bestSolutionTimeMillis

  - ### Constructor Detail

    - #### DefaultSolverScope

          public DefaultSolverScope()

  - ### Method Detail

    - #### getStartingSolverCount

          public int getStartingSolverCount()

    - #### setStartingSolverCount

          public void setStartingSolverCount(int startingSolverCount)

    - #### getWorkingRandom

          public Random getWorkingRandom()

    - #### setWorkingRandom

          public void setWorkingRandom(Random workingRandom)

    - #### getScoreDirector

          public InnerScoreDirector<Solution_> getScoreDirector()

    - #### setScoreDirector

          public void setScoreDirector(InnerScoreDirector<Solution_> scoreDirector)

    - #### setRunnableThreadSemaphore

          public void setRunnableThreadSemaphore(Semaphore runnableThreadSemaphore)

    - #### getStartingSystemTimeMillis

          public Long getStartingSystemTimeMillis()

    - #### getEndingSystemTimeMillis

          public Long getEndingSystemTimeMillis()

    - #### getSolutionDescriptor

          public SolutionDescriptor<Solution_> getSolutionDescriptor()

    - #### getScoreDefinition

          public ScoreDefinition getScoreDefinition()

    - #### getWorkingSolution

          public Solution_ getWorkingSolution()

    - #### getWorkingEntityCount

          public int getWorkingEntityCount()

    - #### getWorkingEntityList

          public List<Object> getWorkingEntityList()

    - #### getWorkingValueCount

          public int getWorkingValueCount()

    - #### calculateScore

          public Score calculateScore()

    - #### assertScoreFromScratch

          public void assertScoreFromScratch(Solution_ solution)

    - #### getStartingInitializedScore

          public Score getStartingInitializedScore()

    - #### setStartingInitializedScore

          public void setStartingInitializedScore(Score startingInitializedScore)

    - #### addChildThreadsScoreCalculationCount

          public void addChildThreadsScoreCalculationCount(long addition)

    - #### getScoreCalculationCount

          public long getScoreCalculationCount()

    - #### getBestSolution

          public Solution_ getBestSolution()

    - #### setBestSolution

          public void setBestSolution(Solution_ bestSolution)

      The `best solution` must never be the same instance as the `working solution`, it should be a (un)changed clone.
      Parameters:
        `bestSolution` - never null

    - #### getBestScore

          public Score getBestScore()

    - #### setBestScore

          public void setBestScore(Score bestScore)

    - #### getBestSolutionTimeMillis

          public Long getBestSolutionTimeMillis()

    - #### setBestSolutionTimeMillis

          public void setBestSolutionTimeMillis(Long bestSolutionTimeMillis)

    - #### startingNow

          public void startingNow()

    - #### getBestSolutionTimeMillisSpent

          public Long getBestSolutionTimeMillisSpent()

    - #### endingNow

          public void endingNow()

    - #### isBestSolutionInitialized

          public boolean isBestSolutionInitialized()

    - #### calculateTimeMillisSpentUpToNow

          public long calculateTimeMillisSpentUpToNow()

    - #### getTimeMillisSpent

          public long getTimeMillisSpent()

    - #### getScoreCalculationSpeed

          public long getScoreCalculationSpeed()

      Returns:
        at least 0, per second

    - #### setWorkingSolutionFromBestSolution

          public void setWorkingSolutionFromBestSolution()

    - #### createChildThreadSolverScope

          public DefaultSolverScope<Solution_> createChildThreadSolverScope(ChildThreadType childThreadType)

    - #### initializeYielding

          public void initializeYielding()

    - #### checkYielding

          public void checkYielding()

      Similar to `Thread.yield()`, but allows capping the number of active solver threads at less than the CPU processor count, so other threads (for example servlet threads that handle REST calls) and other processes (such as SSH) have access to uncontested CPUs and don't suffer any latency.

      Needs to be called before `Termination.isPhaseTerminated(AbstractPhaseScope)`, so the decision to start a new iteration is after any yield waiting time has been consumed (so `Solver.terminateEarly()` reacts immediately).

    - #### destroyYielding

          public void destroyYielding()

Copyright © 2006–2019 JBoss by Red Hat. All rights reserved.