Class SolverConfig
- java.lang.Object
-
- org.optaplanner.core.config.AbstractConfig<SolverConfig>
-
- org.optaplanner.core.config.solver.SolverConfig
-
public class SolverConfig extends AbstractConfig<SolverConfig>
To read it from XML, usecreateFromXmlResource(String). To build aSolverFactorywith it, useSolverFactory.create(SolverConfig).
-
-
Field Summary
Fields Modifier and Type Field Description protected Booleandaemonprotected static longDEFAULT_RANDOM_SEEDprotected List<Class<?>>entityClassListprotected EnvironmentModeenvironmentModestatic StringMOVE_THREAD_COUNT_AUTOstatic StringMOVE_THREAD_COUNT_NONEprotected IntegermoveThreadBufferSizeprotected StringmoveThreadCountprotected List<PhaseConfig>phaseConfigListprotected Class<? extends RandomFactory>randomFactoryClassprotected LongrandomSeedprotected RandomTyperandomTypeprotected ScanAnnotatedClassesConfigscanAnnotatedClassesConfigDeprecated.in favor of the Quarkus integration in OptaPlanner 8 or Spring Boot starter.protected ScoreDirectorFactoryConfigscoreDirectorFactoryConfigprotected Class<?>solutionClassprotected Class<? extends ThreadFactory>threadFactoryClass
-
Constructor Summary
Constructors Constructor Description SolverConfig()Create an empty solver config.SolverConfig(ClassLoader classLoader)SolverConfig(SolverConfig inheritedConfig)Allows you to programmatically change theSolverConfigper concurrent request, based on a template solver config, by building a separateSolverFactorywithSolverFactory.create(SolverConfig)and a separateSolverper request to avoid race conditions.
-
Method Summary
-
Methods inherited from class org.optaplanner.core.config.AbstractConfig
deduceEntityDescriptor, deduceVariableDescriptor, deduceVariableDescriptorList, toString
-
-
-
-
Field Detail
-
MOVE_THREAD_COUNT_NONE
public static final String MOVE_THREAD_COUNT_NONE
- See Also:
- Constant Field Values
-
MOVE_THREAD_COUNT_AUTO
public static final String MOVE_THREAD_COUNT_AUTO
- See Also:
- Constant Field Values
-
DEFAULT_RANDOM_SEED
protected static final long DEFAULT_RANDOM_SEED
- See Also:
- Constant Field Values
-
environmentMode
protected EnvironmentMode environmentMode
-
daemon
protected Boolean daemon
-
randomType
protected RandomType randomType
-
randomSeed
protected Long randomSeed
-
randomFactoryClass
protected Class<? extends RandomFactory> randomFactoryClass
-
moveThreadCount
protected String moveThreadCount
-
moveThreadBufferSize
protected Integer moveThreadBufferSize
-
threadFactoryClass
protected Class<? extends ThreadFactory> threadFactoryClass
-
scanAnnotatedClassesConfig
@Deprecated protected ScanAnnotatedClassesConfig scanAnnotatedClassesConfig
Deprecated.in favor of the Quarkus integration in OptaPlanner 8 or Spring Boot starter.
-
solutionClass
protected Class<?> solutionClass
-
scoreDirectorFactoryConfig
protected ScoreDirectorFactoryConfig scoreDirectorFactoryConfig
-
phaseConfigList
protected List<PhaseConfig> phaseConfigList
-
-
Constructor Detail
-
SolverConfig
public SolverConfig()
Create an empty solver config.
-
SolverConfig
public SolverConfig(ClassLoader classLoader)
- Parameters:
classLoader- sometimes null
-
SolverConfig
public SolverConfig(SolverConfig inheritedConfig)
Allows you to programmatically change theSolverConfigper concurrent request, based on a template solver config, by building a separateSolverFactorywithSolverFactory.create(SolverConfig)and a separateSolverper request to avoid race conditions.- Parameters:
inheritedConfig- never null
-
-
Method Detail
-
createFromXmlResource
public static SolverConfig createFromXmlResource(String solverConfigResource)
Reads an XML solver configuration from the classpath.- Parameters:
solverConfigResource- never null, a classpath resource as defined byClassLoader.getResource(String)- Returns:
- never null
-
createFromXmlResource
public static SolverConfig createFromXmlResource(String solverConfigResource, ClassLoader classLoader)
As defined bycreateFromXmlResource(String).- Parameters:
solverConfigResource- never null, a classpath resource as defined byClassLoader.getResource(String)classLoader- sometimes null, theClassLoaderto use for loading all resources andClasses, null to use the defaultClassLoader- Returns:
- never null
-
createFromXmlFile
public static SolverConfig createFromXmlFile(File solverConfigFile)
Reads an XML solver configuration from the file system.Warning: this leads to platform dependent code, it's recommend to use
createFromXmlResource(String)instead.- Parameters:
solverConfigFile- never null- Returns:
- never null
-
createFromXmlFile
public static SolverConfig createFromXmlFile(File solverConfigFile, ClassLoader classLoader)
As defined bycreateFromXmlFile(File).- Parameters:
solverConfigFile- never nullclassLoader- sometimes null, theClassLoaderto use for loading all resources andClasses, null to use the defaultClassLoader- Returns:
- never null
-
createFromXmlInputStream
public static SolverConfig createFromXmlInputStream(InputStream in)
- Parameters:
in- never null, gets closed- Returns:
- never null
-
createFromXmlInputStream
public static SolverConfig createFromXmlInputStream(InputStream in, ClassLoader classLoader)
As defined bycreateFromXmlInputStream(InputStream).- Parameters:
in- never null, gets closedclassLoader- sometimes null, theClassLoaderto use for loading all resources andClasses, null to use the defaultClassLoader- Returns:
- never null
-
createFromXmlReader
public static SolverConfig createFromXmlReader(Reader reader)
- Parameters:
reader- never null, gets closed- Returns:
- never null
-
createFromXmlReader
public static SolverConfig createFromXmlReader(Reader reader, ClassLoader classLoader)
As defined bycreateFromXmlReader(Reader).- Parameters:
reader- never null, gets closedclassLoader- sometimes null, theClassLoaderto use for loading all resources andClasses, null to use the defaultClassLoader- Returns:
- never null
-
getClassLoader
public ClassLoader getClassLoader()
-
setClassLoader
public void setClassLoader(ClassLoader classLoader)
-
getEnvironmentMode
public EnvironmentMode getEnvironmentMode()
-
setEnvironmentMode
public void setEnvironmentMode(EnvironmentMode environmentMode)
-
getDaemon
public Boolean getDaemon()
-
setDaemon
public void setDaemon(Boolean daemon)
-
getRandomType
public RandomType getRandomType()
-
setRandomType
public void setRandomType(RandomType randomType)
-
getRandomSeed
public Long getRandomSeed()
-
setRandomSeed
public void setRandomSeed(Long randomSeed)
-
getRandomFactoryClass
public Class<? extends RandomFactory> getRandomFactoryClass()
-
setRandomFactoryClass
public void setRandomFactoryClass(Class<? extends RandomFactory> randomFactoryClass)
-
getMoveThreadCount
public String getMoveThreadCount()
-
setMoveThreadCount
public void setMoveThreadCount(String moveThreadCount)
-
getMoveThreadBufferSize
public Integer getMoveThreadBufferSize()
-
setMoveThreadBufferSize
public void setMoveThreadBufferSize(Integer moveThreadBufferSize)
-
getThreadFactoryClass
public Class<? extends ThreadFactory> getThreadFactoryClass()
-
setThreadFactoryClass
public void setThreadFactoryClass(Class<? extends ThreadFactory> threadFactoryClass)
-
getScanAnnotatedClassesConfig
@Deprecated public ScanAnnotatedClassesConfig getScanAnnotatedClassesConfig()
Deprecated.in favor of the Quarkus integration in OptaPlanner 8 or Spring Boot starter..
-
setScanAnnotatedClassesConfig
@Deprecated public void setScanAnnotatedClassesConfig(ScanAnnotatedClassesConfig scanAnnotatedClassesConfig)
Deprecated.in favor of the Quarkus integration in OptaPlanner 8 or Spring Boot starter..
-
getSolutionClass
public Class<?> getSolutionClass()
-
setSolutionClass
public void setSolutionClass(Class<?> solutionClass)
-
getScoreDirectorFactoryConfig
public ScoreDirectorFactoryConfig getScoreDirectorFactoryConfig()
-
setScoreDirectorFactoryConfig
public void setScoreDirectorFactoryConfig(ScoreDirectorFactoryConfig scoreDirectorFactoryConfig)
-
getTerminationConfig
public TerminationConfig getTerminationConfig()
-
setTerminationConfig
public void setTerminationConfig(TerminationConfig terminationConfig)
-
getPhaseConfigList
public List<PhaseConfig> getPhaseConfigList()
-
setPhaseConfigList
public void setPhaseConfigList(List<PhaseConfig> phaseConfigList)
-
withEnvironmentMode
public SolverConfig withEnvironmentMode(EnvironmentMode environmentMode)
-
withDaemon
public SolverConfig withDaemon(Boolean daemon)
-
withRandomType
public SolverConfig withRandomType(RandomType randomType)
-
withRandomSeed
public SolverConfig withRandomSeed(Long randomSeed)
-
withRandomFactoryClass
public SolverConfig withRandomFactoryClass(Class<? extends RandomFactory> randomFactoryClass)
-
withMoveThreadCount
public SolverConfig withMoveThreadCount(String moveThreadCount)
-
withMoveThreadBufferSize
public SolverConfig withMoveThreadBufferSize(Integer moveThreadBufferSize)
-
withThreadFactoryClass
public SolverConfig withThreadFactoryClass(Class<? extends ThreadFactory> threadFactoryClass)
-
withSolutionClass
public SolverConfig withSolutionClass(Class<?> solutionClass)
-
withEntityClassList
public SolverConfig withEntityClassList(List<Class<?>> entityClassList)
-
withEntityClasses
public SolverConfig withEntityClasses(Class<?>... entityClasses)
-
withScoreDirectorFactory
public SolverConfig withScoreDirectorFactory(ScoreDirectorFactoryConfig scoreDirectorFactoryConfig)
-
withTerminationConfig
public SolverConfig withTerminationConfig(TerminationConfig terminationConfig)
-
withPhaseList
public SolverConfig withPhaseList(List<PhaseConfig> phaseConfigList)
-
withPhases
public SolverConfig withPhases(PhaseConfig... phaseConfigs)
-
determineEnvironmentMode
public EnvironmentMode determineEnvironmentMode()
-
offerRandomSeedFromSubSingleIndex
public void offerRandomSeedFromSubSingleIndex(long subSingleIndex)
-
buildSolver
public <Solution_> Solver<Solution_> buildSolver(SolverConfigContext configContext)
Do not use this method, it is an internal method. UseSolverFactory.buildSolver()instead.Will be removed in 8.0 (by putting it in an InnerSolverConfig).
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
configContext- never null- Returns:
- never null
-
buildRandomFactory
protected RandomFactory buildRandomFactory(EnvironmentMode environmentMode_)
-
getAvailableProcessors
protected int getAvailableProcessors()
-
resolveMoveThreadCount
protected Integer resolveMoveThreadCount()
-
buildScoreDirectorFactory
public <Solution_> InnerScoreDirectorFactory<Solution_> buildScoreDirectorFactory(SolverConfigContext configContext, EnvironmentMode environmentMode)
Do not use this method, it is an internal method. UseSolverFactory.getScoreDirectorFactory()instead.Will be removed in 8.0 (by putting it in an InnerSolverConfig).
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
configContext- never nullenvironmentMode- never null- Returns:
- never null
-
buildSolutionDescriptor
public <Solution_> SolutionDescriptor<Solution_> buildSolutionDescriptor(SolverConfigContext configContext)
Do not use this method, it is an internal method.Will be removed in 8.0 (by putting it in an InnerSolverConfig).
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Returns:
- never null
-
buildPhaseList
protected <Solution_> List<Phase<Solution_>> buildPhaseList(HeuristicConfigPolicy configPolicy, BestSolutionRecaller bestSolutionRecaller, Termination termination)
-
inherit
public SolverConfig inherit(SolverConfig inheritedConfig)
Do not use this method, it is an internal method. UseSolverConfig(SolverConfig)instead.- Specified by:
inheritin classAbstractConfig<SolverConfig>- Parameters:
inheritedConfig- never null- Returns:
- this
-
copyConfig
public SolverConfig copyConfig()
Description copied from class:AbstractConfigTypically implemented by constructing a new instance and callingAbstractConfig.inherit(AbstractConfig)on it- Specified by:
copyConfigin classAbstractConfig<SolverConfig>- Returns:
- new instance
-
-