org.optaplanner.core.api.solver

## Class SolverFactory<Solution_>

- java.lang.Object
- - org.optaplanner.core.api.solver.SolverFactory<Solution_>

- Type Parameters:
    `Solution_` - the solution type, the class with the `PlanningSolution` annotation
  Direct Known Subclasses:
    DefaultSolverFactory

      public abstract class SolverFactory<Solution_>
      extends Object

  Creates `Solver` instances. Most applications only need one SolverFactory.

  To create a SolverFactory, use `createFromXmlResource(String)`. To change the configuration programmatically, create a `SolverConfig` first and then use `create(SolverConfig)`.

  These methods are thread-safe unless explicitly stated otherwise.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SolverFactory()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract Solver<Solution_>` | `buildSolver()` Creates a new `Solver` instance.
    `abstract SolverFactory<Solution_>` | `cloneSolverFactory()` Deprecated. in favor of `SolverConfig.SolverConfig(SolverConfig)` and `create(SolverConfig)`. Will be removed in 8.0.
    `static <Solution_> SolverFactory<Solution_>` | `create(SolverConfig solverConfig)` Uses a `SolverConfig` to build a `SolverFactory`.
    `static <Solution_> SolverFactory<Solution_>` | `createEmpty()` Deprecated. in favor of `SolverConfig()` and `create(SolverConfig)`. Will be removed in 8.0.
    `static <Solution_> SolverFactory<Solution_>` | `createEmpty(ClassLoader classLoader)` Deprecated. in favor of `SolverConfig(ClassLoader)` and `create(SolverConfig)`. Will be removed in 8.0.
    `static <Solution_> SolverFactory<Solution_>` | `createEmptyFromKieContainer(org.kie.api.runtime.KieContainer kieContainer)`
    `static <Solution_> SolverFactory<Solution_>` | `createEmptyFromKieContainer(org.kie.api.builder.ReleaseId releaseId)`
    `static <Solution_> SolverFactory<Solution_>` | `createFromKieContainer(org.kie.api.runtime.KieContainer kieContainer, SolverConfig solverConfig)`
    `static <Solution_> SolverFactory<Solution_>` | `createFromKieContainerXmlResource(org.kie.api.runtime.KieContainer kieContainer, String solverConfigResource)`
    `static <Solution_> SolverFactory<Solution_>` | `createFromKieContainerXmlResource(org.kie.api.builder.ReleaseId releaseId, String solverConfigResource)`
    `static <Solution_> SolverFactory<Solution_>` | `createFromKieContainerXmlResource(String solverConfigResource)` Uses `KieServices.getKieClasspathContainer()`.
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlFile(File solverConfigFile)` Reads an XML solver configuration from the file system and uses that `SolverConfig` to build a `SolverFactory`.
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlFile(File solverConfigFile, ClassLoader classLoader)` As defined by `createFromXmlFile(File)`.
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlInputStream(InputStream in)` Deprecated. in favor of `SolverConfig.createFromXmlInputStream(InputStream)` and `create(SolverConfig)`. Will be removed in 8.0.
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlInputStream(InputStream in, ClassLoader classLoader)` Deprecated. in favor of `SolverConfig.createFromXmlInputStream(InputStream, ClassLoader)` and `create(SolverConfig)`. Will be removed in 8.0.
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlReader(Reader reader)` Deprecated. in favor of `SolverConfig.createFromXmlReader(Reader)` and `create(SolverConfig)`. Will be removed in 8.0.
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlReader(Reader reader, ClassLoader classLoader)` Deprecated. in favor of `SolverConfig.createFromXmlReader(Reader, ClassLoader)` and `create(SolverConfig)`. Will be removed in 8.0.
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlResource(String solverConfigResource)` Reads an XML solver configuration from the classpath and uses that `SolverConfig` to build a `SolverFactory`.
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlResource(String solverConfigResource, ClassLoader classLoader)` As defined by `createFromXmlResource(String)`.
    `abstract ScoreDirectorFactory<Solution_>` | `getScoreDirectorFactory()` Useful to reuse the `Score` calculation (for example in a UI) and to explain the `Score` to the user with the `ConstraintMatchTotal` and `Indictment` API.
    `abstract SolverConfig` | `getSolverConfig()` Deprecated. in favor of `SolverConfig.SolverConfig(SolverConfig)` and `create(SolverConfig)`. Will be removed in 8.0.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SolverFactory

          public SolverFactory()

  - ### Method Detail

    - #### createFromXmlResource

          public static <Solution_> SolverFactory<Solution_> createFromXmlResource(String solverConfigResource)

      Reads an XML solver configuration from the classpath and uses that `SolverConfig` to build a `SolverFactory`. The XML root element must be `<solver>`.
      Type Parameters:
        `Solution_` - the solution type, the class with the `PlanningSolution` annotation
      Parameters:
        `solverConfigResource` - never null, a classpath resource as defined by `ClassLoader.getResource(String)`
      Returns:
        never null

    - #### createFromXmlResource

          public static <Solution_> SolverFactory<Solution_> createFromXmlResource(String solverConfigResource,
                                                                                   ClassLoader classLoader)

      As defined by `createFromXmlResource(String)`.
      Type Parameters:
        `Solution_` - the solution type, the class with the `PlanningSolution` annotation
      Parameters:
        `solverConfigResource` - never null, a classpath resource as defined by `ClassLoader.getResource(String)`
        `classLoader` - sometimes null, the `ClassLoader` to use for loading all resources and `Class`es, null to use the default `ClassLoader`
      Returns:
        never null

    - #### createFromXmlFile

          public static <Solution_> SolverFactory<Solution_> createFromXmlFile(File solverConfigFile)

      Reads an XML solver configuration from the file system and uses that `SolverConfig` to build a `SolverFactory`.

      Warning: this leads to platform dependent code, it's recommend to use `createFromXmlResource(String)` instead.

      Type Parameters:
        `Solution_` - the solution type, the class with the `PlanningSolution` annotation
      Parameters:
        `solverConfigFile` - never null
      Returns:
        never null

    - #### createFromXmlFile

          public static <Solution_> SolverFactory<Solution_> createFromXmlFile(File solverConfigFile,
                                                                               ClassLoader classLoader)

      As defined by `createFromXmlFile(File)`.
      Type Parameters:
        `Solution_` - the solution type, the class with the `PlanningSolution` annotation
      Parameters:
        `solverConfigFile` - never null
        `classLoader` - sometimes null, the `ClassLoader` to use for loading all resources and `Class`es, null to use the default `ClassLoader`
      Returns:
        never null

    - #### createFromXmlInputStream

          @Deprecated
          public static <Solution_> SolverFactory<Solution_> createFromXmlInputStream(InputStream in)

      Deprecated. in favor of `SolverConfig.createFromXmlInputStream(InputStream)` and `create(SolverConfig)`. Will be removed in 8.0.
      Type Parameters:
        `Solution_` - the solution type, the class with the `PlanningSolution` 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 of `SolverConfig.createFromXmlInputStream(InputStream, ClassLoader)` and `create(SolverConfig)`. Will be removed in 8.0.
      Type Parameters:
        `Solution_` - the solution type, the class with the `PlanningSolution` annotation
      Parameters:
        `in` - never null, gets closed
        `classLoader` - sometimes null, the `ClassLoader` to use for loading all resources and `Class`es, null to use the default `ClassLoader`
      Returns:
        never null

    - #### createFromXmlReader

          @Deprecated
          public static <Solution_> SolverFactory<Solution_> createFromXmlReader(Reader reader)

      Deprecated. in favor of `SolverConfig.createFromXmlReader(Reader)` and `create(SolverConfig)`. Will be removed in 8.0.
      Type Parameters:
        `Solution_` - the solution type, the class with the `PlanningSolution` 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 of `SolverConfig.createFromXmlReader(Reader, ClassLoader)` and `create(SolverConfig)`. Will be removed in 8.0.
      Type Parameters:
        `Solution_` - the solution type, the class with the `PlanningSolution` annotation
      Parameters:
        `reader` - never null, gets closed
        `classLoader` - sometimes null, the `ClassLoader` to use for loading all resources and `Class`es, null to use the default `ClassLoader`
      Returns:
        never null

    - #### create

          public static <Solution_> SolverFactory<Solution_> create(SolverConfig solverConfig)

      Uses a `SolverConfig` to build a `SolverFactory`. If you don't need to manipulate the `SolverConfig` programmatically, use `createFromXmlResource(String)` instead.
      Type Parameters:
        `Solution_` - the solution type, the class with the `PlanningSolution` annotation
      Parameters:
        `solverConfig` - never null
      Returns:
        never null

    - #### createEmpty

          @Deprecated
          public static <Solution_> SolverFactory<Solution_> createEmpty()

      Deprecated. in favor of `SolverConfig()` and `create(SolverConfig)`. Will be removed in 8.0.
      To build configuration programmatically, use `SolverConfig()` instead, although it's often recommended to instead load a partial configuration with `SolverConfig.createFromXmlResource(String)`.
      Type Parameters:
        `Solution_` - the solution type, the class with the `PlanningSolution` annotation
      Returns:
        never null

    - #### createEmpty

          @Deprecated
          public static <Solution_> SolverFactory<Solution_> createEmpty(ClassLoader classLoader)

      Deprecated. in favor of `SolverConfig(ClassLoader)` and `create(SolverConfig)`. Will be removed in 8.0.
      As defined by `createEmpty()`.
      Type Parameters:
        `Solution_` - the solution type, the class with the `PlanningSolution` annotation
      Parameters:
        `classLoader` - sometimes null, the `ClassLoader` to use for loading all resources and `Class`es, null to use the default `ClassLoader`
      Returns:
        never null

    - #### createFromKieContainerXmlResource

          public static <Solution_> SolverFactory<Solution_> createFromKieContainerXmlResource(String solverConfigResource)

      Uses `KieServices.getKieClasspathContainer()`.
      Type Parameters:
        `Solution_` - the solution type, the class with the `PlanningSolution` annotation
      Parameters:
        `solverConfigResource` - never null, a classpath resource in the `KieContainer` as defined by `ClassLoader.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 the `PlanningSolution` annotation
      Parameters:
        `releaseId` - never null
        `solverConfigResource` - never null, a classpath resource in the `KieContainer` as defined by `ClassLoader.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 the `PlanningSolution` annotation
      Parameters:
        `kieContainer` - never null
        `solverConfigResource` - never null, a classpath resource in the `KieContainer` as defined by `ClassLoader.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 the `PlanningSolution` 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 the `PlanningSolution` annotation
      Parameters:
        `kieContainer` - never null
        `solverConfig` - 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 the `PlanningSolution` annotation
      Parameters:
        `kieContainer` - never null
      Returns:
        never null

    - #### buildSolver

          public abstract Solver<Solution_> buildSolver()

      Creates a new `Solver` instance.
      Returns:
        never null

    - #### getScoreDirectorFactory

          public abstract ScoreDirectorFactory<Solution_> getScoreDirectorFactory()

      Useful to reuse the `Score` calculation (for example in a UI) and to explain the `Score` to the user with the `ConstraintMatchTotal` and `Indictment` API.
      Returns:
        never null

    - #### getSolverConfig

          @Deprecated
          public abstract SolverConfig getSolverConfig()

      Deprecated. in favor of `SolverConfig.SolverConfig(SolverConfig)` and `create(SolverConfig)`. Will be removed in 8.0.
      Deprecated. To configure a `SolverFactory` dynamically (without parsing XML each time), use `create(SolverConfig)` instead.

      This method is not thread-safe. To configure a `SolverConfig` differently for parallel requests, build a template `SolverFactory` from XML and clone it `cloneSolverFactory()` for each request, before before calling this method.

      Returns:
        never null

    - #### cloneSolverFactory

          @Deprecated
          public abstract SolverFactory<Solution_> cloneSolverFactory()

      Deprecated. in favor of `SolverConfig.SolverConfig(SolverConfig)` and `create(SolverConfig)`. Will be removed in 8.0.
      Deprecated. To configure a `SolverFactory` dynamically (without parsing XML each time), use `SolverConfig.SolverConfig(SolverConfig)` and `create(SolverConfig)` instead.

      Build a `SolverFactory` quickly (without parsing XML) that builds the exact same `Solver` with `buildSolver()`, but can also be modified with `getSolverConfig()` to build a different `Solver` without affecting the original `SolverFactory`.

      Returns:
        never null, often a different `SolverFactory` subclass implementation than this instance

Copyright © 2006–2020 JBoss by Red Hat. All rights reserved.