org.cpsolver.ifs.model

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

- java.lang.Object
- - org.cpsolver.ifs.model.LazyNeighbour<V,T>

- Type Parameters:
    `V` - Variable
    `T` - Value
  All Implemented Interfaces:
    Neighbour<V,T>
  Direct Known Subclasses:
    LazySwap

      public abstract class LazyNeighbour<V extends Variable<V,T>,T extends Value<V,T>>
      extends Object
      implements Neighbour<V,T>

  Lazy neigbour (a change of the overall solution value is unknown before the neighbour is assigned, it is possible to undo the neighbour instead). This neighbour is useful when it is two expensive to compute change of overall solution value before the variable is reassigned. It is possible to undo the neighbour instead. Search strategy has to implement `LazyNeighbour.LazyNeighbourAcceptanceCriterion`.
  Version:
    IFS 1.3 (Iterative Forward Search)
    Copyright (C) 2013 - 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/.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `LazyNeighbour.LazyNeighbourAcceptanceCriterion<V extends Variable<V,T>,T extends Value<V,T>>` Neighbour acceptance criterion interface (to be implemented by search strategies that are using `LazyNeighbour`.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LazyNeighbour()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `assign(Assignment<V,T> assignment, long iteration)` Assign neighbour, check given acceptance criterion, and undo assignment if the change is not accepted.
    `protected abstract void` | `doAssign(Assignment<V,T> assignment, long iteration)` Perform assignment
    `LazyNeighbour.LazyNeighbourAcceptanceCriterion<V,T>` | `getAcceptanceCriterion()` Return acceptance criterion (to be used by a search strategy before the neighbour is accepted, so that it can be undone if desired)
    `abstract Model<V,T>` | `getModel()` Return problem model (it is needed in order to be able to get overall solution value before and after the assignment of this neighbour)
    `void` | `setAcceptanceCriterion(LazyNeighbour.LazyNeighbourAcceptanceCriterion<V,T> criterion)` Set acceptance criterion (to be used by a search strategy before the neighbour is accepted, so that it can be undone if desired)
    `protected abstract void` | `undoAssign(Assignment<V,T> assignment, long iteration)` Undo assignment
    `double` | `value(Assignment<V,T> assignment)` Return -1 (neighbour is always accepted).

    - ### 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.model.Neighbour

      `assignments`

- - ### Constructor Detail

    - #### LazyNeighbour

          public LazyNeighbour()

  - ### Method Detail

    - #### setAcceptanceCriterion

          public void setAcceptanceCriterion(LazyNeighbour.LazyNeighbourAcceptanceCriterion<V,T> criterion)

      Set acceptance criterion (to be used by a search strategy before the neighbour is accepted, so that it can be undone if desired)
      Parameters:
        `criterion` - acceptance criterion

    - #### getAcceptanceCriterion

          public LazyNeighbour.LazyNeighbourAcceptanceCriterion<V,T> getAcceptanceCriterion()

      Return acceptance criterion (to be used by a search strategy before the neighbour is accepted, so that it can be undone if desired)
      Returns:
        acceptance criterion

    - #### assign

          public void assign(Assignment<V,T> assignment,
                             long iteration)

      Assign neighbour, check given acceptance criterion, and undo assignment if the change is not accepted.
      Specified by:
        `assign` in interface `Neighbour<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration

    - #### value

          public double value(Assignment<V,T> assignment)

      Return -1 (neighbour is always accepted). The search strategy that is using this neighbour must implement `LazyNeighbour.LazyNeighbourAcceptanceCriterion`.
      Specified by:
        `value` in interface `Neighbour<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `assignment` - current assignment
      Returns:
        difference in the solution value when assigned

    - #### doAssign

          protected abstract void doAssign(Assignment<V,T> assignment,
                                           long iteration)

      Perform assignment
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration

    - #### undoAssign

          protected abstract void undoAssign(Assignment<V,T> assignment,
                                             long iteration)

      Undo assignment
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration

    - #### getModel

          public abstract Model<V,T> getModel()

      Return problem model (it is needed in order to be able to get overall solution value before and after the assignment of this neighbour)
      Returns:
        problem model