org.cpsolver.ifs.constant

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

- java.lang.Object
- - org.cpsolver.ifs.model.Model<V,T>
  - - org.cpsolver.ifs.constant.ConstantModel<V,T>

- Type Parameters:
    `V` - Variable
    `T` - Value
  Direct Known Subclasses:
    TimetableModel

      public class ConstantModel<V extends Variable<V,T>,T extends Value<V,T>>
      extends Model<V,T>

  Extension of the model with constant variables. Such variables are excluded from the solver process, however, they can be included in constraints. Such model can allow us to build a solution on top of another solution (e.g., committed classes in the course timetabling). Constant variable has to implement interface `ConstantVariable`, returning `ConstantVariable.isConstant()` true.
  Version:
    IFS 1.3 (Iterative Forward Search)
    Copyright (C) 2006 - 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.

- - ### Field Summary

    - ### Fields inherited from class org.cpsolver.ifs.model.Model

      `sDoubleFormat, sPercentageFormat, sTimeFormat`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConstantModel()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addVariable(V variable)` Adds a variable to the model
    `void` | `afterAssigned(Assignment<V,T> assignment, long iteration, T value)` Called after a value is assigned to its variable.
    `void` | `afterUnassigned(Assignment<V,T> assignment, long iteration, T value)` Called after a value is unassigned from its variable.
    `void` | `beforeAssigned(Assignment<V,T> assignment, long iteration, T value)` Called before a value is assigned to its variable.
    `void` | `beforeUnassigned(Assignment<V,T> assignment, long iteration, T value)` Called before a value is unassigned from its variable.
    `List<V>` | `constantVariables()` List of constant variables
    `boolean` | `hasConstantVariables()` True, if the model contains at least one constant variable.
    `boolean` | `isConstant(V variable)` True, if the given variable is constant.
    `void` | `removeVariable(V variable)` Removes a variable from the model

    - ### Methods inherited from class org.cpsolver.ifs.model.Model

      `addConstraint, addCriterion, addGlobalConstraint, addModelListener, afterAssigned, afterUnassigned, assignedVariables, assignedVariables, beforeAssigned, beforeUnassigned, bestUnassignedVariables, bestUnassignedVariables, clearAssignmentContexts, clearBest, conflictConstraints, conflictValues, conflictValues, constraints, countConstraints, countGlobalConstraints, countVariables, createAssignmentContexts, createInheritedAssignment, createReference, getBestPerturbations, getBestUnassignedVariables, getBestValue, getCriteria, getCriterion, getDefaultAssignment, getEmptyAssignment, getExtendedInfo, getExtendedInfo, getInfo, getInfo, getInfo, getInfo, getInfoProviders, getModelListeners, getPerc, getPercRev, getTotalValue, getTotalValue, getTotalValue, getTotalValue, globalConstraints, inConflict, inConflict, init, invalidateVariablesWithInitialValueCache, modelListenerOfType, nrAssignedVariables, nrAssignedVariables, nrUnassignedVariables, nrUnassignedVariables, perturbVariables, perturbVariables, perturbVariables, perturbVariables, removeConstraint, removeCriterion, removeCriterion, removeGlobalConstraint, removeModelListener, removeReference, restoreBest, restoreBest, restoreBest, saveBest, saveBest, setBestValue, setDefaultAssignment, toString, toString, unassignedHardConstraints, unassignedVariables, unassignedVariables, variables, variablesWithInitialValue, weaken`

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

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

- - ### Constructor Detail

    - #### ConstantModel

          public ConstantModel()

  - ### Method Detail

    - #### constantVariables

          public List<V> constantVariables()

      List of constant variables
      Returns:
        all constants

    - #### hasConstantVariables

          public boolean hasConstantVariables()

      True, if the model contains at least one constant variable.
      Returns:
        true, if there is at least one constant in this model

    - #### isConstant

          public boolean isConstant(V variable)

      True, if the given variable is constant.
      Parameters:
        `variable` - given variable
      Returns:
        true if constant

    - #### addVariable

          public void addVariable(V variable)

      Adds a variable to the model
      Overrides:
        `addVariable` in class `Model<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `variable` - a variable

    - #### removeVariable

          public void removeVariable(V variable)

      Removes a variable from the model
      Overrides:
        `removeVariable` in class `Model<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `variable` - a variable

    - #### beforeAssigned

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

      Called before a value is assigned to its variable. Constant variables are excluded from (re)assignment.
      Overrides:
        `beforeAssigned` in class `Model<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `value` - a value to be assigned

    - #### beforeUnassigned

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

      Called before a value is unassigned from its variable. Constant variables are excluded from (re)assignment.
      Overrides:
        `beforeUnassigned` in class `Model<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `value` - a value to be unassigned

    - #### afterAssigned

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

      Called after a value is assigned to its variable. Constant variables are excluded from (re)assignment.
      Overrides:
        `afterAssigned` in class `Model<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `value` - a value that was assigned

    - #### afterUnassigned

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

      Called after a value is unassigned from its variable. Constant variables are excluded from (re)assignment.
      Overrides:
        `afterUnassigned` in class `Model<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `value` - a value that was unassigned