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 io.micrometer.core.instrument.Tags
monitoringTags
protected Semaphore
runnableThreadSemaphore
Used for capping CPU power usage in multithreaded scenarios.protected InnerScoreDirector<Solution_,?>
scoreDirector
protected Set<SolverMetric>
solverMetricSet
protected Score
startingInitializedScore
protected int
startingSolverCount
protected Long
startingSystemTimeMillis
protected Map<io.micrometer.core.instrument.Tags,List<AtomicReference<Number>>>
stepScoreMap
Used for tracking step scoreprotected Random
workingRandom
-
Constructor Summary
Constructors Constructor Description SolverScope()
-
Method Summary
-
-
-
Field Detail
-
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
-
-
Method Detail
-
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)
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)
-
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 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()
-
-