org.cpsolver.ifs.solver

## Class ParallelSolver<V extends Variable<V,T>,T extends Value<V,T>>

- java.lang.Object
- - org.cpsolver.ifs.solver.Solver<V,T>
  - - org.cpsolver.ifs.solver.ParallelSolver<V,T>

- Type Parameters:
    `V` - Variable
    `T` - Value

      public class ParallelSolver<V extends Variable<V,T>,T extends Value<V,T>>
      extends Solver<V,T>

  Multi-threaded solver. Instead of one, a given number of solver threads are created (as defined by Parallel.NrSolvers property) and started in parallel. Each thread works with its own assignment `DefaultParallelAssignment`, but the best solution is shared among all of them.
  When `DefaultSingleAssignment` is given to the solver, only one solution is used. A neighbour is assigned to this (shared) solution when it does not create any conflicts outside of `Neighbour.assignments()`.
  Version:
    IFS 1.3 (Iterative Forward Search)
    Copyright (C) 2014 Tomáš Müller
    muller@unitime.org
    http://muller.unitime.org
    This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public License along with this library; if not see http://www.gnu.org/licenses.
  See Also:
    `Solver`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `ParallelSolver.AssignmentThread` Solver thread
    `protected class` | `ParallelSolver.SolverThread` Solver thread
    `protected class` | `ParallelSolver.SynchronizationThread` Synchronization thread

  - ### Field Summary

    - ### Fields inherited from class org.cpsolver.ifs.solver.Solver

      `iCurrentSolution, iLastSolution, iProgress, iSaveBestUnassigned, iSolverListeners, iSolverThread, iStop, sLogger, THREAD_PRIORITY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ParallelSolver(DataProperties properties)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Solution<V,T>` | `createParallelSolution(int index)` Create a solution that is to be used by a solver thread of the given index
    `Thread` | `getSolverThread()` Returns solver's thread
    `protected Solution<V,T>` | `getWorkingSolution()` Return a working (parallel) solution that contributed to the best solution last.
    `boolean` | `hasSingleSolution()` Returns true if the solver works only with one solution (regardless the number of threads it is using)
    `void` | `setInitalSolution(Model<V,T> model)` Sets initial solution
    `void` | `start()` Starts solver

    - ### Methods inherited from class org.cpsolver.ifs.solver.Solver

      `addExtension, addSolverListener, autoConfigure, clearBest, currentSolution, dispose, getExtensions, getNeighbourSelection, getPerturbationsCounter, getProperties, getSolutionComparator, getSolverListeners, getTerminationCondition, init, initSolver, isRunning, isStop, isUpdateProgress, lastSolution, onAssigned, onFailure, onFinish, onStart, onStop, removeSolverListener, setInitalSolution, setNeighbourSelection, setPerturbationsCounter, setSolutionComparator, setTerminalCondition, setUpdateProgress, stopSolver, stopSolver`

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

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

- - ### Constructor Detail

    - #### ParallelSolver

          public ParallelSolver(DataProperties properties)

  - ### Method Detail

    - #### start

          public void start()

      Starts solver
      Overrides:
        `start` in class `Solver<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### getSolverThread

          public Thread getSolverThread()

      Returns solver's thread
      Overrides:
        `getSolverThread` in class `Solver<V extends Variable<V,T>,T extends Value<V,T>>`
      Returns:
        solver's thread

    - #### setInitalSolution

          public void setInitalSolution(Model<V,T> model)

      Sets initial solution
      Overrides:
        `setInitalSolution` in class `Solver<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `model` - problem model

    - #### getWorkingSolution

          protected Solution<V,T> getWorkingSolution()

      Return a working (parallel) solution that contributed to the best solution last.
      Returns:
        working solution

    - #### createParallelSolution

          protected Solution<V,T> createParallelSolution(int index)

      Create a solution that is to be used by a solver thread of the given index
      Parameters:
        `index` - solver thread index
      Returns:
        new solution to work with

    - #### hasSingleSolution

          public boolean hasSingleSolution()

      Returns true if the solver works only with one solution (regardless the number of threads it is using)
      Overrides:
        `hasSingleSolution` in class `Solver<V extends Variable<V,T>,T extends Value<V,T>>`
      Returns:
        true if the current solution is `DefaultSingleAssignment`