Class SolverScope<Solution_>
- java.lang.Object
-
- org.optaplanner.core.impl.solver.scope.SolverScope<Solution_>
-
- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation
public class SolverScope<Solution_> extends Object
-
-
Field Summary
Fields Modifier and Type Field 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 Description SolverScope()
-
Method Summary
-
-
-
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
-
-
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()
-
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)
Thebest solution
must never be the same instance as theworking 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 SolverScope<Solution_> createChildThreadSolverScope(ChildThreadType childThreadType)
-
initializeYielding
public void initializeYielding()
-
checkYielding
public void checkYielding()
Similar toThread.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 (soSolver.terminateEarly()
reacts immediately).
-
destroyYielding
public void destroyYielding()
-
-