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
-
Field Summary
Modifier and TypeFieldDescriptionprotected Score
protected Solution_
protected Long
protected long
protected Long
protected io.micrometer.core.instrument.Tags
protected Semaphore
Used for capping CPU power usage in multithreaded scenarios.protected InnerScoreDirector<Solution_,
?> protected Set<SolverMetric>
protected Score
protected int
protected Long
protected final Map<io.micrometer.core.instrument.Tags,
List<AtomicReference<Number>>> Used for tracking step scoreprotected Random
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addChildThreadsScoreCalculationCount
(long addition) void
assertScoreFromScratch
(Solution_ solution) long
void
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.createChildThreadSolverScope
(ChildThreadType childThreadType) void
void
io.micrometer.core.instrument.Tags
long
long
<Score_ extends Score<Score_>>
InnerScoreDirector<Solution_,Score_> int
Map<io.micrometer.core.instrument.Tags,
List<AtomicReference<Number>>> long
int
int
void
boolean
boolean
isMetricEnabled
(SolverMetric solverMetric) void
setBestScore
(Score bestScore) void
setBestSolution
(Solution_ bestSolution) Thebest solution
must never be the same instance as theworking solution
, it should be a (un)changed clone.void
setBestSolutionTimeMillis
(Long bestSolutionTimeMillis) void
setMonitoringTags
(io.micrometer.core.instrument.Tags monitoringTags) void
setProblemChangeDirector
(DefaultProblemChangeDirector<Solution_> problemChangeDirector) void
setRunnableThreadSemaphore
(Semaphore runnableThreadSemaphore) void
setScoreDirector
(InnerScoreDirector<Solution_, ?> scoreDirector) void
setSolverMetricSet
(EnumSet<SolverMetric> solverMetricSet) void
setStartingInitializedScore
(Score startingInitializedScore) void
setStartingSolverCount
(int startingSolverCount) void
setWorkingRandom
(Random workingRandom) void
void
-
Field Details
-
solverMetricSet
-
monitoringTags
protected io.micrometer.core.instrument.Tags monitoringTags -
startingSolverCount
protected int startingSolverCount -
workingRandom
-
scoreDirector
-
runnableThreadSemaphore
Used for capping CPU power usage in multithreaded scenarios. -
startingSystemTimeMillis
-
endingSystemTimeMillis
-
childThreadsScoreCalculationCount
protected long childThreadsScoreCalculationCount -
startingInitializedScore
-
bestSolution
-
bestScore
-
bestSolutionTimeMillis
-
stepScoreMap
Used for tracking step score
-
-
Constructor Details
-
SolverScope
public SolverScope()
-
-
Method Details
-
getProblemChangeDirector
-
setProblemChangeDirector
-
getMonitoringTags
public io.micrometer.core.instrument.Tags getMonitoringTags() -
setMonitoringTags
public void setMonitoringTags(io.micrometer.core.instrument.Tags monitoringTags) -
getStepScoreMap
-
getSolverMetricSet
-
setSolverMetricSet
-
getStartingSolverCount
public int getStartingSolverCount() -
setStartingSolverCount
public void setStartingSolverCount(int startingSolverCount) -
getWorkingRandom
-
setWorkingRandom
-
getScoreDirector
-
setScoreDirector
-
setRunnableThreadSemaphore
-
getStartingSystemTimeMillis
-
getEndingSystemTimeMillis
-
getSolutionDescriptor
-
getScoreDefinition
-
getWorkingSolution
-
getWorkingEntityCount
public int getWorkingEntityCount() -
getWorkingValueCount
public int getWorkingValueCount() -
calculateScore
-
assertScoreFromScratch
-
getStartingInitializedScore
-
setStartingInitializedScore
-
addChildThreadsScoreCalculationCount
public void addChildThreadsScoreCalculationCount(long addition) -
getScoreCalculationCount
public long getScoreCalculationCount() -
getBestSolution
-
setBestSolution
Thebest solution
must never be the same instance as theworking solution
, it should be a (un)changed clone.- Parameters:
bestSolution
- never null
-
getBestScore
-
setBestScore
-
getBestSolutionTimeMillis
-
setBestSolutionTimeMillis
-
isMetricEnabled
-
startingNow
public void startingNow() -
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
-
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()
-