org.cpsolver.ifs.assignment.context

## Class NeighbourSelectionWithContext<V extends Variable<V,T>,T extends Value<V,T>,C extends AssignmentContext>

- java.lang.Object
- - org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext<V,T,C>

- Type Parameters:
    `V` - Variable
    `T` - Value
    `C` - Assignment Context
  All Implemented Interfaces:
    CanHoldContext, HasAssignmentContext<V,T,C>, NeighbourSelection<V,T>
  Direct Known Subclasses:
    ExamConstruction, ExamGreatDeluge, ExamHillClimbing, ExamNeighbourSelection, ExamSimulatedAnnealing, ExamTabuSearch, FixCompleteSolutionNeighbourSelection, MetaHeuristicSearch, NeighbourSearch, ParallelConstruction, SimpleSearch

      public abstract class NeighbourSelectionWithContext<V extends Variable<V,T>,T extends Value<V,T>,C extends AssignmentContext>
      extends Object
      implements NeighbourSelection<V,T>, HasAssignmentContext<V,T,C>, CanHoldContext

  A neighborhood selection with an assignment context. In order to be able to hold multiple assignments in memory it is desired for all the assignment dependent data a selection may need (to keep its current state), to store these data in a separate class (implementing the `AssignmentContext` interface). This context is created by calling `HasAssignmentContext.createAssignmentContext(Assignment)` and accessed by `ConstraintWithContext.getContext(Assignment)`.
  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:
    `AssignmentContext`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected C` | `iContextOverride`

    - ### Fields inherited from interface org.cpsolver.ifs.assignment.context.CanHoldContext

      `sMaxSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NeighbourSelectionWithContext()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `AssignmentContextReference<V,T,C>` | `getAssignmentContextReference()` Returns an assignment context reference
    `AssignmentContext[]` | `getContext()` An array of `CanHoldContext.sMaxSize` assignment contexts
    `C` | `getContext(Assignment<V,T> assignment)` Returns an assignment context associated with this selection.
    `boolean` | `hasContextOverride()` Has context override
    `void` | `init(Solver<V,T> solver)` Criterion initialization
    `protected boolean` | `isSingleContextSolver(Solver<V,T> solver)` Returns true if there should be only one context for this neighbourhood selection.
    `void` | `setAssignmentContextReference(AssignmentContextReference<V,T,C> reference)` Store an assignment context reference that was given for the class by the `Model.createReference(HasAssignmentContext)`.

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

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

    - ### Methods inherited from interface org.cpsolver.ifs.heuristics.NeighbourSelection

      `selectNeighbour`

    - ### Methods inherited from interface org.cpsolver.ifs.assignment.context.HasAssignmentContext

      `createAssignmentContext`

- - ### Field Detail

    - #### iContextOverride

          protected C extends AssignmentContext iContextOverride

  - ### Constructor Detail

    - #### NeighbourSelectionWithContext

          public NeighbourSelectionWithContext()

  - ### Method Detail

    - #### init

          public void init(Solver<V,T> solver)

      Description copied from interface: `NeighbourSelection`
      Criterion initialization
      Specified by:
        `init` in interface `NeighbourSelection<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `solver` - current solver

    - #### isSingleContextSolver

          protected boolean isSingleContextSolver(Solver<V,T> solver)

      Returns true if there should be only one context for this neighbourhood selection.
      Parameters:
        `solver` - current solver
      Returns:
        `Solver.hasSingleSolution()`

    - #### getContext

          public C getContext(Assignment<V,T> assignment)

      Returns an assignment context associated with this selection. If there is no assignment context associated with this selection yet, one is created using the `HasAssignmentContext.createAssignmentContext(Assignment)` method. From that time on, this context is kept with the assignment.
      Specified by:
        `getContext` in interface `HasAssignmentContext<V extends Variable<V,T>,T extends Value<V,T>,C extends AssignmentContext>`
      Parameters:
        `assignment` - given assignment
      Returns:
        assignment context associated with this selection and the given assignment

    - #### getAssignmentContextReference

          public AssignmentContextReference<V,T,C> getAssignmentContextReference()

      Description copied from interface: `HasAssignmentContext`
      Returns an assignment context reference
      Specified by:
        `getAssignmentContextReference` in interface `HasAssignmentContext<V extends Variable<V,T>,T extends Value<V,T>,C extends AssignmentContext>`
      Returns:
        reference provided by the model by calling `Model.createReference(HasAssignmentContext)` during initialization

    - #### setAssignmentContextReference

          public void setAssignmentContextReference(AssignmentContextReference<V,T,C> reference)

      Description copied from interface: `HasAssignmentContext`
      Store an assignment context reference that was given for the class by the `Model.createReference(HasAssignmentContext)`.
      Specified by:
        `setAssignmentContextReference` in interface `HasAssignmentContext<V extends Variable<V,T>,T extends Value<V,T>,C extends AssignmentContext>`
      Parameters:
        `reference` - reference provided by the model by calling `Model.createReference(HasAssignmentContext)` during initialization

    - #### getContext

          public AssignmentContext[] getContext()

      Description copied from interface: `CanHoldContext`
      An array of `CanHoldContext.sMaxSize` assignment contexts
      Specified by:
        `getContext` in interface `CanHoldContext`
      Returns:
        assignment contexts

    - #### hasContextOverride

          public boolean hasContextOverride()

      Has context override
      Returns:
        true if all threads are using the same context