Class SolverScope<Solution_>

java.lang.Object
org.optaplanner.core.impl.solver.scope.SolverScope<Solution_>
Type Parameters:
Solution_ - the solution type, the class with the PlanningSolution annotation

public class SolverScope<Solution_> extends Object
  • Field Details

    • solverMetricSet

      protected Set<SolverMetric> solverMetricSet
    • monitoringTags

      protected io.micrometer.core.instrument.Tags monitoringTags
    • 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
    • stepScoreMap

      protected final Map<io.micrometer.core.instrument.Tags,List<AtomicReference<Number>>> stepScoreMap
      Used for tracking step score
  • Constructor Details

    • SolverScope

      public SolverScope()
  • Method Details

    • getProblemChangeDirector

      public DefaultProblemChangeDirector<Solution_> getProblemChangeDirector()
    • setProblemChangeDirector

      public void setProblemChangeDirector(DefaultProblemChangeDirector<Solution_> problemChangeDirector)
    • getMonitoringTags

      public io.micrometer.core.instrument.Tags getMonitoringTags()
    • setMonitoringTags

      public void setMonitoringTags(io.micrometer.core.instrument.Tags monitoringTags)
    • getStepScoreMap

      public Map<io.micrometer.core.instrument.Tags,List<AtomicReference<Number>>> getStepScoreMap()
    • getSolverMetricSet

      public Set<SolverMetric> getSolverMetricSet()
    • setSolverMetricSet

      public void setSolverMetricSet(EnumSet<SolverMetric> solverMetricSet)
    • getStartingSolverCount

      public int getStartingSolverCount()
    • setStartingSolverCount

      public void setStartingSolverCount(int startingSolverCount)
    • getWorkingRandom

      public Random getWorkingRandom()
    • setWorkingRandom

      public void setWorkingRandom(Random workingRandom)
    • getScoreDirector

      public <Score_ extends Score<Score_>> InnerScoreDirector<Solution_,Score_> 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()
    • 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)
    • isMetricEnabled

      public boolean isMetricEnabled(SolverMetric solverMetric)
    • 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 SolverScope<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()