Class SolverFactory<Solution_>
- java.lang.Object
-
- org.optaplanner.core.api.solver.SolverFactory<Solution_>
-
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation
- Direct Known Subclasses:
DefaultSolverFactory
public abstract class SolverFactory<Solution_> extends Object
CreatesSolverinstances. Most applications only need one SolverFactory.To create a SolverFactory, use
createFromXmlResource(String). To change the configuration programmatically, create aSolverConfigfirst and then usecreate(SolverConfig).These methods are thread-safe unless explicitly stated otherwise.
-
-
Constructor Summary
Constructors Constructor Description SolverFactory()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract Solver<Solution_>buildSolver()Creates a newSolverinstance.abstract SolverFactory<Solution_>cloneSolverFactory()Deprecated.in favor ofSolverConfig(SolverConfig)andcreate(SolverConfig).static <Solution_>
SolverFactory<Solution_>create(SolverConfig solverConfig)Uses aSolverConfigto build aSolverFactory.static <Solution_>
SolverFactory<Solution_>createEmpty()Deprecated.in favor ofSolverConfig()andcreate(SolverConfig).static <Solution_>
SolverFactory<Solution_>createEmpty(ClassLoader classLoader)Deprecated.in favor ofSolverConfig(ClassLoader)andcreate(SolverConfig).static <Solution_>
SolverFactory<Solution_>createEmptyFromKieContainer(org.kie.api.builder.ReleaseId releaseId)static <Solution_>
SolverFactory<Solution_>createEmptyFromKieContainer(org.kie.api.runtime.KieContainer kieContainer)static <Solution_>
SolverFactory<Solution_>createFromKieContainer(org.kie.api.runtime.KieContainer kieContainer, SolverConfig solverConfig)static <Solution_>
SolverFactory<Solution_>createFromKieContainerXmlResource(String solverConfigResource)UsesKieServices.getKieClasspathContainer().static <Solution_>
SolverFactory<Solution_>createFromKieContainerXmlResource(org.kie.api.builder.ReleaseId releaseId, String solverConfigResource)static <Solution_>
SolverFactory<Solution_>createFromKieContainerXmlResource(org.kie.api.runtime.KieContainer kieContainer, String solverConfigResource)static <Solution_>
SolverFactory<Solution_>createFromXmlFile(File solverConfigFile)Reads an XML solver configuration from the file system and uses thatSolverConfigto build aSolverFactory.static <Solution_>
SolverFactory<Solution_>createFromXmlFile(File solverConfigFile, ClassLoader classLoader)As defined bycreateFromXmlFile(File).static <Solution_>
SolverFactory<Solution_>createFromXmlInputStream(InputStream in)Deprecated.in favor ofSolverConfig.createFromXmlInputStream(InputStream)andcreate(SolverConfig).static <Solution_>
SolverFactory<Solution_>createFromXmlInputStream(InputStream in, ClassLoader classLoader)Deprecated.static <Solution_>
SolverFactory<Solution_>createFromXmlReader(Reader reader)Deprecated.in favor ofSolverConfig.createFromXmlReader(Reader)andcreate(SolverConfig).static <Solution_>
SolverFactory<Solution_>createFromXmlReader(Reader reader, ClassLoader classLoader)Deprecated.static <Solution_>
SolverFactory<Solution_>createFromXmlResource(String solverConfigResource)Reads an XML solver configuration from the classpath and uses thatSolverConfigto build aSolverFactory.static <Solution_>
SolverFactory<Solution_>createFromXmlResource(String solverConfigResource, ClassLoader classLoader)As defined bycreateFromXmlResource(String).abstract ScoreDirectorFactory<Solution_>getScoreDirectorFactory()Useful to reuse theScorecalculation (for example in a UI) and to explain theScoreto the user with theConstraintMatchTotalandIndictmentAPI.abstract SolverConfiggetSolverConfig()Deprecated.in favor ofSolverConfig(SolverConfig)andcreate(SolverConfig).
-
-
-
Method Detail
-
createFromXmlResource
public static <Solution_> SolverFactory<Solution_> createFromXmlResource(String solverConfigResource)
Reads an XML solver configuration from the classpath and uses thatSolverConfigto build aSolverFactory. The XML root element must be<solver>.- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
solverConfigResource- never null, a classpath resource as defined byClassLoader.getResource(String)- Returns:
- never null
-
createFromXmlResource
public static <Solution_> SolverFactory<Solution_> createFromXmlResource(String solverConfigResource, ClassLoader classLoader)
As defined bycreateFromXmlResource(String).- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- 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 <Solution_> SolverFactory<Solution_> createFromXmlFile(File solverConfigFile)
Reads an XML solver configuration from the file system and uses thatSolverConfigto build aSolverFactory.Warning: this leads to platform dependent code, it's recommend to use
createFromXmlResource(String)instead.- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
solverConfigFile- never null- Returns:
- never null
-
createFromXmlFile
public static <Solution_> SolverFactory<Solution_> createFromXmlFile(File solverConfigFile, ClassLoader classLoader)
As defined bycreateFromXmlFile(File).- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
solverConfigFile- never nullclassLoader- sometimes null, theClassLoaderto use for loading all resources andClasses, null to use the defaultClassLoader- Returns:
- never null
-
createFromXmlInputStream
@Deprecated public static <Solution_> SolverFactory<Solution_> createFromXmlInputStream(InputStream in)
Deprecated.in favor ofSolverConfig.createFromXmlInputStream(InputStream)andcreate(SolverConfig). Will be removed in 8.0.- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
in- never null, gets closed- Returns:
- never null
-
createFromXmlInputStream
@Deprecated public static <Solution_> SolverFactory<Solution_> createFromXmlInputStream(InputStream in, ClassLoader classLoader)
Deprecated.in favor ofSolverConfig.createFromXmlInputStream(InputStream, ClassLoader)andcreate(SolverConfig). Will be removed in 8.0.- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
in- never null, gets closedclassLoader- sometimes null, theClassLoaderto use for loading all resources andClasses, null to use the defaultClassLoader- Returns:
- never null
-
createFromXmlReader
@Deprecated public static <Solution_> SolverFactory<Solution_> createFromXmlReader(Reader reader)
Deprecated.in favor ofSolverConfig.createFromXmlReader(Reader)andcreate(SolverConfig). Will be removed in 8.0.- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
reader- never null, gets closed- Returns:
- never null
-
createFromXmlReader
@Deprecated public static <Solution_> SolverFactory<Solution_> createFromXmlReader(Reader reader, ClassLoader classLoader)
Deprecated.in favor ofSolverConfig.createFromXmlReader(Reader, ClassLoader)andcreate(SolverConfig). Will be removed in 8.0.- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
reader- never null, gets closedclassLoader- sometimes null, theClassLoaderto use for loading all resources andClasses, null to use the defaultClassLoader- Returns:
- never null
-
create
public static <Solution_> SolverFactory<Solution_> create(SolverConfig solverConfig)
Uses aSolverConfigto build aSolverFactory. If you don't need to manipulate theSolverConfigprogrammatically, usecreateFromXmlResource(String)instead.- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
solverConfig- never null- Returns:
- never null
-
createEmpty
@Deprecated public static <Solution_> SolverFactory<Solution_> createEmpty()
Deprecated.in favor ofSolverConfig()andcreate(SolverConfig). Will be removed in 8.0.To build configuration programmatically, useSolverConfig()instead, although it's often recommended to instead load a partial configuration withSolverConfig.createFromXmlResource(String).- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Returns:
- never null
-
createEmpty
@Deprecated public static <Solution_> SolverFactory<Solution_> createEmpty(ClassLoader classLoader)
Deprecated.in favor ofSolverConfig(ClassLoader)andcreate(SolverConfig). Will be removed in 8.0.As defined bycreateEmpty().- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
classLoader- sometimes null, theClassLoaderto use for loading all resources andClasses, null to use the defaultClassLoader- Returns:
- never null
-
createFromKieContainerXmlResource
public static <Solution_> SolverFactory<Solution_> createFromKieContainerXmlResource(String solverConfigResource)
UsesKieServices.getKieClasspathContainer().- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
solverConfigResource- never null, a classpath resource in theKieContaineras defined byClassLoader.getResource(String)- Returns:
- never null
-
createFromKieContainerXmlResource
public static <Solution_> SolverFactory<Solution_> createFromKieContainerXmlResource(org.kie.api.builder.ReleaseId releaseId, String solverConfigResource)
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
releaseId- never nullsolverConfigResource- never null, a classpath resource in theKieContaineras defined byClassLoader.getResource(String)- Returns:
- never null
-
createFromKieContainerXmlResource
public static <Solution_> SolverFactory<Solution_> createFromKieContainerXmlResource(org.kie.api.runtime.KieContainer kieContainer, String solverConfigResource)
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
kieContainer- never nullsolverConfigResource- never null, a classpath resource in theKieContaineras defined byClassLoader.getResource(String)- Returns:
- never null
-
createEmptyFromKieContainer
public static <Solution_> SolverFactory<Solution_> createEmptyFromKieContainer(org.kie.api.builder.ReleaseId releaseId)
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
releaseId- never null- Returns:
- never null
-
createFromKieContainer
public static <Solution_> SolverFactory<Solution_> createFromKieContainer(org.kie.api.runtime.KieContainer kieContainer, SolverConfig solverConfig)
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
kieContainer- never nullsolverConfig- never null- Returns:
- never null
-
createEmptyFromKieContainer
public static <Solution_> SolverFactory<Solution_> createEmptyFromKieContainer(org.kie.api.runtime.KieContainer kieContainer)
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation- Parameters:
kieContainer- never null- Returns:
- never null
-
buildSolver
public abstract Solver<Solution_> buildSolver()
Creates a newSolverinstance.- Returns:
- never null
-
getScoreDirectorFactory
public abstract ScoreDirectorFactory<Solution_> getScoreDirectorFactory()
Useful to reuse theScorecalculation (for example in a UI) and to explain theScoreto the user with theConstraintMatchTotalandIndictmentAPI.- Returns:
- never null
-
getSolverConfig
@Deprecated public abstract SolverConfig getSolverConfig()
Deprecated.in favor ofSolverConfig(SolverConfig)andcreate(SolverConfig). Will be removed in 8.0.Deprecated. To configure aSolverFactorydynamically (without parsing XML each time), usecreate(SolverConfig)instead.This method is not thread-safe. To configure a
SolverConfigdifferently for parallel requests, build a templateSolverFactoryfrom XML and clone itcloneSolverFactory()for each request, before before calling this method.- Returns:
- never null
-
cloneSolverFactory
@Deprecated public abstract SolverFactory<Solution_> cloneSolverFactory()
Deprecated.in favor ofSolverConfig(SolverConfig)andcreate(SolverConfig). Will be removed in 8.0.Deprecated. To configure aSolverFactorydynamically (without parsing XML each time), useSolverConfig(SolverConfig)andcreate(SolverConfig)instead.Build a
SolverFactoryquickly (without parsing XML) that builds the exact sameSolverwithbuildSolver(), but can also be modified withgetSolverConfig()to build a differentSolverwithout affecting the originalSolverFactory.- Returns:
- never null, often a different
SolverFactorysubclass implementation than this instance
-
-