Class SolverFactory<Solution_>
- java.lang.Object
-
- org.optaplanner.core.api.solver.SolverFactory<Solution_>
-
- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation
- Direct Known Subclasses:
DefaultSolverFactory
public abstract class SolverFactory<Solution_> extends Object
CreatesSolver
instances. Most applications only need one SolverFactory.To create a SolverFactory, use
createFromXmlResource(String)
. To change the configuration programmatically, create aSolverConfig
first 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 newSolver
instance.abstract SolverFactory<Solution_>
cloneSolverFactory()
Deprecated.in favor ofSolverConfig(SolverConfig)
andcreate(SolverConfig)
.static <Solution_>
SolverFactory<Solution_>create(SolverConfig solverConfig)
Uses aSolverConfig
to 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 thatSolverConfig
to 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 thatSolverConfig
to build aSolverFactory
.static <Solution_>
SolverFactory<Solution_>createFromXmlResource(String solverConfigResource, ClassLoader classLoader)
As defined bycreateFromXmlResource(String)
.abstract ScoreDirectorFactory<Solution_>
getScoreDirectorFactory()
Useful to reuse theScore
calculation (for example in a UI) and to explain theScore
to the user with theConstraintMatchTotal
andIndictment
API.abstract SolverConfig
getSolverConfig()
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 thatSolverConfig
to build aSolverFactory
. The XML root element must be<solver>
.- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation- 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 thePlanningSolution
annotation- 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 <Solution_> SolverFactory<Solution_> createFromXmlFile(File solverConfigFile)
Reads an XML solver configuration from the file system and uses thatSolverConfig
to 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 thePlanningSolution
annotation- 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 thePlanningSolution
annotation- Parameters:
solverConfigFile
- never nullclassLoader
- sometimes null, theClassLoader
to use for loading all resources andClass
es, 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 thePlanningSolution
annotation- 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 thePlanningSolution
annotation- 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
@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 thePlanningSolution
annotation- 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 thePlanningSolution
annotation- 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
-
create
public static <Solution_> SolverFactory<Solution_> create(SolverConfig solverConfig)
Uses aSolverConfig
to build aSolverFactory
. If you don't need to manipulate theSolverConfig
programmatically, usecreateFromXmlResource(String)
instead.- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation- 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 thePlanningSolution
annotation- 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 thePlanningSolution
annotation- Parameters:
classLoader
- sometimes null, theClassLoader
to use for loading all resources andClass
es, 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 thePlanningSolution
annotation- Parameters:
solverConfigResource
- never null, a classpath resource in theKieContainer
as 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 thePlanningSolution
annotation- Parameters:
releaseId
- never nullsolverConfigResource
- never null, a classpath resource in theKieContainer
as 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 thePlanningSolution
annotation- Parameters:
kieContainer
- never nullsolverConfigResource
- never null, a classpath resource in theKieContainer
as 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 thePlanningSolution
annotation- 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 thePlanningSolution
annotation- 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 thePlanningSolution
annotation- Parameters:
kieContainer
- never null- Returns:
- never null
-
buildSolver
public abstract Solver<Solution_> buildSolver()
Creates a newSolver
instance.- Returns:
- never null
-
getScoreDirectorFactory
public abstract ScoreDirectorFactory<Solution_> getScoreDirectorFactory()
Useful to reuse theScore
calculation (for example in a UI) and to explain theScore
to the user with theConstraintMatchTotal
andIndictment
API.- 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 aSolverFactory
dynamically (without parsing XML each time), usecreate(SolverConfig)
instead.This method is not thread-safe. To configure a
SolverConfig
differently for parallel requests, build a templateSolverFactory
from 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 aSolverFactory
dynamically (without parsing XML each time), useSolverConfig(SolverConfig)
andcreate(SolverConfig)
instead.Build a
SolverFactory
quickly (without parsing XML) that builds the exact sameSolver
withbuildSolver()
, but can also be modified withgetSolverConfig()
to build a differentSolver
without affecting the originalSolverFactory
.- Returns:
- never null, often a different
SolverFactory
subclass implementation than this instance
-
-