Class SolverScope<Solution_>

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

    public class SolverScope<Solution_>
    extends Object
    • Field Detail

      • logger

        protected final transient org.slf4j.Logger logger
      • startingSolverCount

        protected int startingSolverCount
      • workingRandom

        protected Random workingRandom
      • 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

      • SolverScope

        public SolverScope()
    • Method Detail

      • getStartingSolverCount

        public int getStartingSolverCount()
      • setStartingSolverCount

        public void setStartingSolverCount​(int startingSolverCount)
      • getWorkingRandom

        public Random getWorkingRandom()
      • setWorkingRandom

        public void setWorkingRandom​(Random workingRandom)
      • setRunnableThreadSemaphore

        public void setRunnableThreadSemaphore​(Semaphore runnableThreadSemaphore)
      • getStartingSystemTimeMillis

        public Long getStartingSystemTimeMillis()
      • getEndingSystemTimeMillis

        public Long getEndingSystemTimeMillis()
      • 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()
      • 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()