org.cpsolver.ifs.assignment

## Interface Assignment<V extends Variable<V,T>,T extends Value<V,T>>

- Type Parameters:
    `V` - Variable
    `T` - Value
  All Known Subinterfaces:
    InheritedAssignment<V,T>
  All Known Implementing Classes:
    AssignmentAbstract, AssignmentArray, AssignmentMap, DefaultInheritedAssignment, DefaultParallelAssignment, DefaultSingleAssignment, EmptyAssignment, InheritedAssignmentArray, OptimisticInheritedAssignment

      public interface Assignment<V extends Variable<V,T>,T extends Value<V,T>>

  An assignment of all the variable of a `Model`. This class decouples an assignment of variables (classes extending `Variable`) to their values (classes extending `Value`) from the `Model`. This is needed for any kind of parallel computations, or in general, to be able to hold multiple different assignments in memory.
  This class also include translation of `AssignmentContextReference` to `AssignmentContext`, so that each constraint, criterion, neighborhood selection etc. can hold its own assignment dependent information. See `ConstraintWithContext` or `NeighbourSelectionWithContext` for more details.
  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:
    `Variable`, `Value`, `Model`, `AssignmentContext`

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `T` | `assign(long iteration, T value)` Assign the given value to its variable.
    `Collection<T>` | `assignedValues()` The list of assigned values in the assignment.
    `Collection<V>` | `assignedVariables()` The list of assigned variables in the assignment.
    `<C extends AssignmentContext> void` | `clearContext(AssignmentContextReference<V,T,C> reference)` Clear an assignment context that is associated with the given a reference.
    `<C extends AssignmentContext> C` | `getAssignmentContext(AssignmentContextReference<V,T,C> reference)` Assignment context for a reference.
    `int` | `getIndex()` Assignment index.
    `long` | `getIteration(V variable)` Returns iteration of the last assignment.
    `T` | `getValue(V variable)` Returns assignment of a variable, null if not assigned Replacement for `Variable.getAssignment()`.
    `int` | `nrAssignedVariables()` Number of assigned variables in this assignment.
    `int` | `nrUnassignedVariables(Model<V,T> model)` Number of assigned variables in the assignment.
    `T` | `unassign(long iteration, V variable)` Unassign the given variable.
    `T` | `unassign(long iteration, V variable, T value)` Unassign the given variable, but only if the current assignment differs from the given value.
    `Collection<V>` | `unassignedVariables(Model<V,T> model)` The list of variables of the model that have no value in this assignment.

- - ### Method Detail

    - #### getIndex

          int getIndex()

      Assignment index. Unique identification of the assignment, starting with zero. This can be used to increase the speed of the search by storing individual values on the variables and an array (indexed by this number).
      Returns:
        assignment index, -1 if not to be used

    - #### getValue

          T getValue(V variable)

      Returns assignment of a variable, null if not assigned Replacement for `Variable.getAssignment()`.
      Parameters:
        `variable` - problem variable
      Returns:
        currently assigned value

    - #### getIteration

          long getIteration(V variable)

      Returns iteration of the last assignment. Replacement for `Variable.getLastIteration()`.
      Parameters:
        `variable` - problem variable
      Returns:
        iteration of the last assignment

    - #### assign

          T assign(long iteration,
                   T value)

      Assign the given value to its variable. Replacement for `Variable.assign(int, Value)`.
      Parameters:
        `iteration` - current iteration
        `value` - a new value to be assigned to variable `Value.variable()`.
      Returns:
        previous assignment of the variable, null if it was not assigned

    - #### unassign

          T unassign(long iteration,
                     V variable)

      Unassign the given variable. Replacement for `Variable.unassign(int)`.
      Parameters:
        `iteration` - current iteration
        `variable` - variable to be unassigned
      Returns:
        previous assignment of the variable, null if it was not assigned

    - #### unassign

          T unassign(long iteration,
                     V variable,
                     T value)

      Unassign the given variable, but only if the current assignment differs from the given value. Replacement for `Variable.unassign(int)`.
      Parameters:
        `iteration` - current iteration
        `variable` - variable to be unassigned
        `value` - target value
      Returns:
        previous assignment of the variable, null if it was not assigned

    - #### nrAssignedVariables

          int nrAssignedVariables()

      Number of assigned variables in this assignment. Replacement for `Model.nrAssignedVariables()`.
      Returns:
        number of assigned variables in this assignment

    - #### assignedVariables

          Collection<V> assignedVariables()

      The list of assigned variables in the assignment. That is all the variables that `getValue(Variable)` is not null in this assignment. Replacement for `Model.assignedVariables()`.
      Returns:
        a collection of assigned variable in this assignment

    - #### assignedValues

          Collection<T> assignedValues()

      The list of assigned values in the assignment. That is a collection of `getValue(Variable)` for all assigned variables in this assignment.
      Returns:
        a collection of assigned values in this assignment

    - #### nrUnassignedVariables

          int nrUnassignedVariables(Model<V,T> model)

      Number of assigned variables in the assignment. Replacement for `Model.nrUnassignedVariables()`.
      Parameters:
        `model` - existing model (the assignment does not keep track about all existing variables, that is what the `Model.variables()` is for)
      Returns:
        number of not assigned variables in this assignment

    - #### unassignedVariables

          Collection<V> unassignedVariables(Model<V,T> model)

      The list of variables of the model that have no value in this assignment. That is all the variables of the model that `getValue(Variable)` is null in this assignment. Replacement for `Model.unassignedVariables()`
      Parameters:
        `model` - existing model (the assignment does not keep track about all existing variables, that is what the `Model.variables()` is for)
      Returns:
        a collection of all not assigned variables in this assignment

    - #### getAssignmentContext

          <C extends AssignmentContext> C getAssignmentContext(AssignmentContextReference<V,T,C> reference)

      Assignment context for a reference. This can be used to keep assignment dependent computations (e.g., see `ConstraintWithContext`).
      Type Parameters:
        `C` - assignment context type
      Parameters:
        `reference` - a reference (which can be stored within the model, e.g., as an instance variable of a constraint)
      Returns:
        an `AssignmentContext`

    - #### clearContext

          <C extends AssignmentContext> void clearContext(AssignmentContextReference<V,T,C> reference)

      Clear an assignment context that is associated with the given a reference. If there is any created for the reference.
      Type Parameters:
        `C` - assignment context type
      Parameters:
        `reference` - a reference (which can be stored within the model, e.g., as an instance variable of a constraint)