Package org.optaplanner.benchmark.api
Class PlannerBenchmarkFactory
- java.lang.Object
-
- org.optaplanner.benchmark.api.PlannerBenchmarkFactory
-
- Direct Known Subclasses:
DefaultPlannerBenchmarkFactory
public abstract class PlannerBenchmarkFactory extends Object
BuildsPlannerBenchmark
instances.Supports tweaking the configuration programmatically before a
PlannerBenchmark
instance is build.
-
-
Constructor Summary
Constructors Constructor Description PlannerBenchmarkFactory()
-
Method Summary
-
-
-
Method Detail
-
createFromSolverConfigXmlResource
public static PlannerBenchmarkFactory createFromSolverConfigXmlResource(String solverConfigResource)
Reads an XML solver configuration from the classpath and uses thatSolverConfig
to build aPlannerBenchmarkConfig
that in turn is used to build aPlannerBenchmarkFactory
. The XML root element must be<solver>
.To read an XML benchmark configuration instead, use
createFromXmlResource(String)
.- Parameters:
solverConfigResource
- never null, a classpath resource as defined byClassLoader.getResource(String)
-
createFromSolverConfigXmlResource
public static PlannerBenchmarkFactory createFromSolverConfigXmlResource(String solverConfigResource, ClassLoader classLoader)
As defined bycreateFromSolverConfigXmlResource(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
-
createFromSolverConfigXmlResource
public static PlannerBenchmarkFactory createFromSolverConfigXmlResource(String solverConfigResource, File benchmarkDirectory)
As defined bycreateFromSolverConfigXmlResource(String)
.- Parameters:
solverConfigResource
- never null, a classpath resource as defined byClassLoader.getResource(String)
benchmarkDirectory
- never null
-
createFromSolverConfigXmlResource
public static PlannerBenchmarkFactory createFromSolverConfigXmlResource(String solverConfigResource, File benchmarkDirectory, ClassLoader classLoader)
As defined bycreateFromSolverConfigXmlResource(String)
.- Parameters:
solverConfigResource
- never null, a classpath resource as defined byClassLoader.getResource(String)
benchmarkDirectory
- never nullclassLoader
- sometimes null, theClassLoader
to use for loading all resources andClass
es, null to use the defaultClassLoader
-
createFromSolverFactory
@Deprecated public static <Solution_> PlannerBenchmarkFactory createFromSolverFactory(SolverFactory<Solution_> solverFactory)
Deprecated.in favor ofcreateFromSolverConfigXmlResource(String)
or in complex casesPlannerBenchmarkConfig.createFromSolverConfig(SolverConfig)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation- Parameters:
solverFactory
- never null, also itsClassLoader
is reused if any was configured during creation
-
createFromSolverFactory
@Deprecated public static <Solution_> PlannerBenchmarkFactory createFromSolverFactory(SolverFactory<Solution_> solverFactory, File benchmarkDirectory)
Deprecated.in favor ofcreateFromSolverConfigXmlResource(String, File)
. or in complex casesPlannerBenchmarkConfig.createFromSolverConfig(SolverConfig, File)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation- Parameters:
solverFactory
- never null, also itsClassLoader
is reused if any was configured during creationbenchmarkDirectory
- never null
-
createFromXmlResource
public static PlannerBenchmarkFactory createFromXmlResource(String benchmarkConfigResource)
Reads an XML benchmark configuration from the classpath and uses thatPlannerBenchmarkConfig
to build aPlannerBenchmarkFactory
. The XML root element must be<plannerBenchmark>
.To read an XML solver configuration instead, use
createFromSolverConfigXmlResource(String)
.- Parameters:
benchmarkConfigResource
- never null, a classpath resource as defined byClassLoader.getResource(String)
- Returns:
- never null
-
createFromXmlResource
public static PlannerBenchmarkFactory createFromXmlResource(String benchmarkConfigResource, ClassLoader classLoader)
As defined bycreateFromXmlResource(String)
.- Parameters:
benchmarkConfigResource
- 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 PlannerBenchmarkFactory createFromXmlFile(File benchmarkConfigFile)
Reads an XML benchmark configuration from the file system and uses thatPlannerBenchmarkConfig
to build aPlannerBenchmarkFactory
.Warning: this leads to platform dependent code, it's recommend to use
createFromXmlResource(String)
instead.- Parameters:
benchmarkConfigFile
- never null- Returns:
- never null
-
createFromXmlFile
public static PlannerBenchmarkFactory createFromXmlFile(File benchmarkConfigFile, ClassLoader classLoader)
As defined bycreateFromXmlFile(File)
.- Parameters:
benchmarkConfigFile
- 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 PlannerBenchmarkFactory createFromXmlInputStream(InputStream in)
Deprecated.in favor ofPlannerBenchmarkConfig.createFromXmlInputStream(InputStream)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- Parameters:
in
- never null, gets closed- Returns:
- never null
-
createFromXmlInputStream
@Deprecated public static PlannerBenchmarkFactory createFromXmlInputStream(InputStream in, ClassLoader classLoader)
Deprecated.in favor ofPlannerBenchmarkConfig.createFromXmlInputStream(InputStream, ClassLoader)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- 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 PlannerBenchmarkFactory createFromXmlReader(Reader reader)
Deprecated.in favor ofPlannerBenchmarkConfig.createFromXmlReader(Reader)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- Parameters:
reader
- never null, gets closed- Returns:
- never null
-
createFromXmlReader
@Deprecated public static PlannerBenchmarkFactory createFromXmlReader(Reader reader, ClassLoader classLoader)
Deprecated.in favor ofPlannerBenchmarkConfig.createFromXmlReader(Reader, ClassLoader)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- 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
-
createFromFreemarkerXmlResource
public static PlannerBenchmarkFactory createFromFreemarkerXmlResource(String templateResource)
Reads an Freemarker template from the classpath that generates an XML benchmark configuration and uses thatPlannerBenchmarkConfig
to build aPlannerBenchmarkFactory
. The generated XML root element must be<plannerBenchmark>
.- Parameters:
templateResource
- never null, a classpath resource as defined byClassLoader.getResource(String)
- Returns:
- never null
- See Also:
createFromFreemarkerXmlResource(String)
-
createFromFreemarkerXmlResource
public static PlannerBenchmarkFactory createFromFreemarkerXmlResource(String templateResource, ClassLoader classLoader)
As defined bycreateFromFreemarkerXmlResource(String)
.- Parameters:
templateResource
- 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
-
createFromFreemarkerXmlResource
public static PlannerBenchmarkFactory createFromFreemarkerXmlResource(String templateResource, Object model)
As defined bycreateFromFreemarkerXmlResource(String)
.- Parameters:
templateResource
- never null, a classpath resource as defined byClassLoader.getResource(String)
model
- sometimes null- Returns:
- never null
-
createFromFreemarkerXmlResource
public static PlannerBenchmarkFactory createFromFreemarkerXmlResource(String templateResource, Object model, ClassLoader classLoader)
As defined bycreateFromFreemarkerXmlResource(String)
.- Parameters:
templateResource
- never null, a classpath resource as defined byClassLoader.getResource(String)
model
- sometimes nullclassLoader
- sometimes null, theClassLoader
to use for loading all resources andClass
es, null to use the defaultClassLoader
- Returns:
- never null
-
createFromFreemarkerXmlFile
public static PlannerBenchmarkFactory createFromFreemarkerXmlFile(File templateFile)
Reads an Freemarker template rom the file system that generates an XML benchmark configuration and uses thatPlannerBenchmarkConfig
to build aPlannerBenchmarkFactory
. The generated XML root element must be<plannerBenchmark>
.Warning: this leads to platform dependent code, it's recommend to use
createFromFreemarkerXmlResource(String)
instead.- Parameters:
templateFile
- never null- Returns:
- never null
-
createFromFreemarkerXmlFile
public static PlannerBenchmarkFactory createFromFreemarkerXmlFile(File templateFile, ClassLoader classLoader)
As defined bycreateFromFreemarkerXmlFile(File)
.- Parameters:
templateFile
- never nullclassLoader
- sometimes null, theClassLoader
to use for loading all resources andClass
es, null to use the defaultClassLoader
- Returns:
- never null
-
createFromFreemarkerXmlFile
public static PlannerBenchmarkFactory createFromFreemarkerXmlFile(File templateFile, Object model)
As defined bycreateFromFreemarkerXmlFile(File)
.- Parameters:
templateFile
- never nullmodel
- sometimes null- Returns:
- never null
-
createFromFreemarkerXmlFile
public static PlannerBenchmarkFactory createFromFreemarkerXmlFile(File templateFile, Object model, ClassLoader classLoader)
As defined bycreateFromFreemarkerXmlFile(File)
.- Parameters:
templateFile
- never nullmodel
- sometimes nullclassLoader
- sometimes null, theClassLoader
to use for loading all resources andClass
es, null to use the defaultClassLoader
- Returns:
- never null
-
createFromFreemarkerXmlInputStream
@Deprecated public static PlannerBenchmarkFactory createFromFreemarkerXmlInputStream(InputStream templateIn)
Deprecated.in favor ofPlannerBenchmarkConfig.createFromFreemarkerXmlInputStream(InputStream)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- Parameters:
templateIn
- never null, gets closed- Returns:
- never null
-
createFromFreemarkerXmlInputStream
@Deprecated public static PlannerBenchmarkFactory createFromFreemarkerXmlInputStream(InputStream templateIn, ClassLoader classLoader)
Deprecated.in favor ofPlannerBenchmarkConfig.createFromFreemarkerXmlInputStream(InputStream, ClassLoader)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- Parameters:
templateIn
- never null, gets closedclassLoader
- sometimes null, theClassLoader
to use for loading all resources andClass
es, null to use the defaultClassLoader
- Returns:
- never null
-
createFromFreemarkerXmlInputStream
@Deprecated public static PlannerBenchmarkFactory createFromFreemarkerXmlInputStream(InputStream templateIn, Object model)
Deprecated.in favor ofPlannerBenchmarkConfig.createFromFreemarkerXmlInputStream(InputStream, Object)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- Parameters:
templateIn
- never null, gets closedmodel
- sometimes null- Returns:
- never null
-
createFromFreemarkerXmlInputStream
@Deprecated public static PlannerBenchmarkFactory createFromFreemarkerXmlInputStream(InputStream templateIn, Object model, ClassLoader classLoader)
Deprecated.in favor ofPlannerBenchmarkConfig.createFromFreemarkerXmlInputStream(InputStream, Object, ClassLoader)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- Parameters:
templateIn
- never null, gets closedmodel
- sometimes nullclassLoader
- sometimes null, theClassLoader
to use for loading all resources andClass
es, null to use the defaultClassLoader
- Returns:
- never null
-
createFromFreemarkerXmlReader
@Deprecated public static PlannerBenchmarkFactory createFromFreemarkerXmlReader(Reader templateReader)
Deprecated.in favor ofPlannerBenchmarkConfig.createFromFreemarkerXmlReader(Reader)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- Parameters:
templateReader
- never null, gets closed- Returns:
- never null
-
createFromFreemarkerXmlReader
@Deprecated public static PlannerBenchmarkFactory createFromFreemarkerXmlReader(Reader templateReader, ClassLoader classLoader)
Deprecated.in favor ofPlannerBenchmarkConfig.createFromFreemarkerXmlReader(Reader, ClassLoader)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- Parameters:
templateReader
- never null, gets closedclassLoader
- sometimes null, theClassLoader
to use for loading all resources andClass
es, null to use the defaultClassLoader
- Returns:
- never null
-
createFromFreemarkerXmlReader
@Deprecated public static PlannerBenchmarkFactory createFromFreemarkerXmlReader(Reader templateReader, Object model)
Deprecated.in favor ofPlannerBenchmarkConfig.createFromFreemarkerXmlReader(Reader, Object)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- Parameters:
templateReader
- never null, gets closedmodel
- sometimes null- Returns:
- never null
-
createFromFreemarkerXmlReader
@Deprecated public static PlannerBenchmarkFactory createFromFreemarkerXmlReader(Reader templateReader, Object model, ClassLoader classLoader)
Deprecated.in favor ofPlannerBenchmarkConfig.createFromFreemarkerXmlReader(Reader, Object, ClassLoader)
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.- Parameters:
templateReader
- never null, gets closedmodel
- sometimes nullclassLoader
- sometimes null, theClassLoader
to use for loading all resources andClass
es, null to use the defaultClassLoader
- Returns:
- never null
-
create
public static PlannerBenchmarkFactory create(PlannerBenchmarkConfig benchmarkConfig)
Uses aPlannerBenchmarkConfig
to build aPlannerBenchmarkFactory
. If you don't need to manipulate thePlannerBenchmarkConfig
programmatically, usecreateFromXmlResource(String)
instead.- Parameters:
benchmarkConfig
- never null- Returns:
- never null
-
createFromKieContainerXmlResource
public static PlannerBenchmarkFactory createFromKieContainerXmlResource(String benchmarkConfigResource)
Creates a newPlannerBenchmarkFactory
that usesKieServices.getKieClasspathContainer()
.- Parameters:
benchmarkConfigResource
- never null, a classpath resource in theKieContainer
as defined byClassLoader.getResource(String)
- Returns:
- never null
-
createFromKieContainerXmlResource
public static PlannerBenchmarkFactory createFromKieContainerXmlResource(org.kie.api.builder.ReleaseId releaseId, String benchmarkConfigResource)
Creates a newPlannerBenchmarkFactory
that uses aKieModule
represented by its releaseId.- Parameters:
releaseId
- never nullbenchmarkConfigResource
- never null, a classpath resource in theKieContainer
as defined byClassLoader.getResource(String)
- Returns:
- never null
-
createFromKieContainerXmlResource
public static PlannerBenchmarkFactory createFromKieContainerXmlResource(org.kie.api.runtime.KieContainer kieContainer, String benchmarkConfigResource)
- Parameters:
kieContainer
- never nullbenchmarkConfigResource
- never null, a classpath resource in theKieContainer
as defined byClassLoader.getResource(String)
- Returns:
- never null
-
buildPlannerBenchmark
public abstract PlannerBenchmark buildPlannerBenchmark()
Creates a newPlannerBenchmark
instance.- Returns:
- never null
-
buildPlannerBenchmark
public <Solution_> PlannerBenchmark buildPlannerBenchmark(List<Solution_> problemList)
Creates a newPlannerBenchmark
instance for datasets that are already in memory.- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation- Parameters:
problemList
- never null, can be empty- Returns:
- never null
-
buildPlannerBenchmark
public abstract <Solution_> PlannerBenchmark buildPlannerBenchmark(Solution_... problems)
Creates a newPlannerBenchmark
instance for datasets that are already in memory.- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation- Parameters:
problems
- never null, can be none- Returns:
- never null
-
getPlannerBenchmarkConfig
@Deprecated public abstract PlannerBenchmarkConfig getPlannerBenchmarkConfig()
Deprecated.in favor ofPlannerBenchmarkConfig()
andcreate(PlannerBenchmarkConfig)
. Will be removed in 8.0.Deprecated. To configure aPlannerBenchmarkFactory
dynamically (without parsing XML each time), usecreate(PlannerBenchmarkConfig)
instead.This method is not thread-safe.
- Returns:
- never null
-
-