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 aSolverFactory
with it, useSolverFactory.create(SolverConfig)
.
-
-
Field Summary
Fields Modifier and Type Field Description protected Boolean
daemon
protected List<Class<?>>
entityClassList
protected EnvironmentMode
environmentMode
static String
MOVE_THREAD_COUNT_AUTO
static String
MOVE_THREAD_COUNT_NONE
protected Integer
moveThreadBufferSize
protected String
moveThreadCount
protected List<PhaseConfig>
phaseConfigList
protected Class<? extends RandomFactory>
randomFactoryClass
protected Long
randomSeed
protected RandomType
randomType
protected ScoreDirectorFactoryConfig
scoreDirectorFactoryConfig
protected Class<?>
solutionClass
protected Class<? extends ThreadFactory>
threadFactoryClass
static String
XML_ELEMENT_NAME
static String
XML_NAMESPACE
static String
XML_TYPE_NAME
-
Constructor Summary
Constructors Constructor Description SolverConfig()
Create an empty solver config.SolverConfig(ClassLoader classLoader)
SolverConfig(SolverConfig inheritedConfig)
Allows you to programmatically change theSolverConfig
per concurrent request, based on a template solver config, by building a separateSolverFactory
withSolverFactory.create(SolverConfig)
and a separateSolver
per request to avoid race conditions.
-
Method Summary
-
Methods inherited from class org.optaplanner.core.config.AbstractConfig
toString
-
-
-
-
Field Detail
-
XML_ELEMENT_NAME
public static final String XML_ELEMENT_NAME
- See Also:
- Constant Field Values
-
XML_NAMESPACE
public static final String XML_NAMESPACE
- See Also:
- Constant Field Values
-
XML_TYPE_NAME
public static final String XML_TYPE_NAME
- See Also:
- Constant Field Values
-
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
-
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
-
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 theSolverConfig
per concurrent request, based on a template solver config, by building a separateSolverFactory
withSolverFactory.create(SolverConfig)
and a separateSolver
per 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, theClassLoader
to use for loading all resources andClass
es, 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, theClassLoader
to use for loading all resources andClass
es, 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, theClassLoader
to use for loading all resources andClass
es, 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, theClassLoader
to use for loading all resources andClass
es, 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)
-
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)
-
inherit
public SolverConfig inherit(SolverConfig inheritedConfig)
Do not use this method, it is an internal method. UseSolverConfig(SolverConfig)
instead.- Specified by:
inherit
in classAbstractConfig<SolverConfig>
- Parameters:
inheritedConfig
- never null- Returns:
- this
-
copyConfig
public SolverConfig copyConfig()
Description copied from class:AbstractConfig
Typically implemented by constructing a new instance and callingAbstractConfig.inherit(AbstractConfig)
on it- Specified by:
copyConfig
in classAbstractConfig<SolverConfig>
- Returns:
- new instance
-
-