org.cpsolver.ifs.example.csp

## Class CSPBinaryConstraint

- java.lang.Object
- - org.cpsolver.ifs.model.Constraint<V,T>
  - - org.cpsolver.ifs.model.BinaryConstraint<CSPVariable,CSPValue>
    - - org.cpsolver.ifs.example.csp.CSPBinaryConstraint

- All Implemented Interfaces:
    Comparable<Constraint<CSPVariable,CSPValue>>

      public class CSPBinaryConstraint
      extends BinaryConstraint<CSPVariable,CSPValue>

  CSP binary constraint.
  This class only implements the generation of a binary CSP constraint and the consistency check.
  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.Constraint

      `iConstraintListeners, iId`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CSPBinaryConstraint(int id, int nrCompatiblePairs)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `computeConflicts(Assignment<CSPVariable,CSPValue> assignment, CSPValue aValue, Set<CSPValue> conflicts)` Add the other variable to the set of conflicts, if it is not compatible with the given value.
    `String` | `getName()` Constraint's name -- for printing purposes
    `void` | `init(Random rndNumGen)` Initializes the constraint.
    `boolean` | `isConsistent(CSPValue value1, CSPValue value2)` True if the pair of given values is compatible.

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

      `addVariable, another, first, isFirst, second`

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

      `addConstraintListener, assigned, assignedVariables, compareTo, computeConflictsNoForwardCheck, constraintListeners, countAssignedVariables, countVariables, equals, getDescription, getId, getModel, hashCode, inConflict, isHard, removeConstraintListener, removeVariable, setModel, unassigned, variables`

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

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

- - ### Constructor Detail

    - #### CSPBinaryConstraint

          public CSPBinaryConstraint(int id,
                                     int nrCompatiblePairs)

      Constructor
      Parameters:
        `id` - constraint id
        `nrCompatiblePairs` - number of compatible pairs of values in the constraint

  - ### Method Detail

    - #### init

          public void init(Random rndNumGen)

      Initializes the constraint. Randomly generates the given number of compatible pairs of values.
      Parameters:
        `rndNumGen` - random number generator

    - #### isConsistent

          public boolean isConsistent(CSPValue value1,
                                      CSPValue value2)

      True if the pair of given values is compatible.
      Overrides:
        `isConsistent` in class `Constraint<CSPVariable,CSPValue>`
      Parameters:
        `value1` - a value
        `value2` - a value
      Returns:
        true if the constraint is ok with the assignment

    - #### computeConflicts

          public void computeConflicts(Assignment<CSPVariable,CSPValue> assignment,
                                       CSPValue aValue,
                                       Set<CSPValue> conflicts)

      Add the other variable to the set of conflicts, if it is not compatible with the given value.
      Specified by:
        `computeConflicts` in class `Constraint<CSPVariable,CSPValue>`
      Parameters:
        `assignment` - current assignment
        `aValue` - value to be assigned to its variable
        `conflicts` - resultant set of conflicting values

    - #### getName

          public String getName()

      Description copied from class: `Constraint`
      Constraint's name -- for printing purposes
      Overrides:
        `getName` in class `Constraint<CSPVariable,CSPValue>`
      Returns:
        constraint name