Package org.optaplanner.core.api.solver

## Interface SolverFactory<Solution_>

- Type Parameters:
    `Solution_` - the solution type, the class with the `PlanningSolution` annotation
  All Known Implementing Classes:
    `DefaultSolverFactory`

      public interface SolverFactory<Solution_>

  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.

- - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Solver<Solution_>` | `buildSolver()` | Creates a new `Solver` instance.
    `static <Solution_> SolverFactory<Solution_>` | `create​(SolverConfig solverConfig)` | Uses a `SolverConfig` to build a `SolverFactory`.
    `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_>` | `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)`.

- - ### Method Detail

    - #### createFromXmlResource

          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

          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

          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

          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

    - #### create

          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

    - #### buildSolver

          Solver<Solution_> buildSolver()

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