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:
    AbstractSolverFactory

      public abstract class SolverFactory<Solution_>
      extends Object

  Builds `Solver` instances.

  To build an instance, use `createFromXmlResource(String)` or any of the other creation methods.

  Supports tweaking the configuration programmatically before a `Solver` instance is build.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SolverFactory()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract Solver<Solution_>` | `buildSolver()` Creates a new `Solver` instance.
    `abstract SolverFactory<Solution_>` | `cloneSolverFactory()` 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`.
    `static <Solution_> SolverFactory<Solution_>` | `createEmpty()` Useful to build configuration programmatically, although it's almost always recommended to instead load a partial configuration with `createFromXmlResource(String)` and configure the remainder programmatically with `getSolverConfig()`.
    `static <Solution_> SolverFactory<Solution_>` | `createEmpty(ClassLoader classLoader)` See `createEmpty()`.
    `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_>` | `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)`
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlFile(File solverConfigFile, ClassLoader classLoader)`
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlInputStream(InputStream in)`
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlInputStream(InputStream in, ClassLoader classLoader)`
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlReader(Reader reader)`
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlReader(Reader reader, ClassLoader classLoader)`
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlResource(String solverConfigResource)`
    `static <Solution_> SolverFactory<Solution_>` | `createFromXmlResource(String solverConfigResource, ClassLoader classLoader)` See `createFromXmlResource(String)`.
    `abstract SolverConfig` | `getSolverConfig()` Allows you to programmatically change the `SolverConfig` at runtime before building the `Solver`.

    - ### 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

    - #### createFromKieContainerXmlResource

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

      Uses `KieServices.getKieClasspathContainer()`.
      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)

      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)

      Parameters:
        `kieContainer` - never null
        `solverConfigResource` - never null, a classpath resource in the `KieContainer` as defined by `ClassLoader.getResource(String)`
      Returns:
        never null

    - #### createFromXmlResource

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

      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)

      See `createFromXmlResource(String)`.
      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)

      Parameters:
        `solverConfigFile` - never null
      Returns:
        never null

    - #### createFromXmlFile

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

      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

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

      Parameters:
        `in` - never null, gets closed
      Returns:
        never null

    - #### createFromXmlInputStream

          public static <Solution_> SolverFactory<Solution_> createFromXmlInputStream(InputStream in,
                                                                                      ClassLoader classLoader)

      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

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

      Parameters:
        `reader` - never null, gets closed
      Returns:
        never null

    - #### createFromXmlReader

          public static <Solution_> SolverFactory<Solution_> createFromXmlReader(Reader reader,
                                                                                 ClassLoader classLoader)

      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

    - #### createEmpty

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

      Useful to build configuration programmatically, although it's almost always recommended to instead load a partial configuration with `createFromXmlResource(String)` and configure the remainder programmatically with `getSolverConfig()`.
      Returns:
        never null

    - #### createEmpty

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

      See `createEmpty()`.
      Parameters:
        `classLoader` - sometimes null, the `ClassLoader` to use for loading all resources and `Class`es, null to use the default `ClassLoader`
      Returns:
        never null

    - #### createEmptyFromKieContainer

          public static <Solution_> SolverFactory<Solution_> createEmptyFromKieContainer(org.kie.api.builder.ReleaseId releaseId)

      Parameters:
        `releaseId` - never null
      Returns:
        never null

    - #### createEmptyFromKieContainer

          public static <Solution_> SolverFactory<Solution_> createEmptyFromKieContainer(org.kie.api.runtime.KieContainer kieContainer)

      Parameters:
        `kieContainer` - never null
      Returns:
        never null

    - #### getSolverConfig

          public abstract SolverConfig getSolverConfig()

      Allows you to programmatically change the `SolverConfig` at runtime before building the `Solver`.

      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

          public abstract SolverFactory<Solution_> cloneSolverFactory()

      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

    - #### buildSolver

          public abstract Solver<Solution_> buildSolver()

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

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