Package edu.uky.ai.csp.kr

# Class Solution

java.lang.Object
edu.uky.ai.csp.kr.Solution

All Implemented Interfaces:
  `java.lang.Cloneable`

    public class Solution
    extends java.lang.Object
    implements java.lang.Cloneable

A solution to a constraint satisfaction problem is an assignment of values to the problem's variables.

A solution is complete when every variable has exactly 1 value in its domain.

A solution can be a partial solution, meaning that we have not yet narrowed down the domains of all variables to a single value.

A solution is impossible if any of its assigned variables (those with 1 value in the domain) violate a constraint in the problem or if any variable has a domain with no values in it (i.e. no legal value).

Author:
  Stephen G. Ware

- ## Field Summary

  Fields
  Modifier and Type | Field | Description
  --- | --- | ---
  `Problem` | `problem` | The problem this solution is potentially a solution for

- ## Constructor Summary

  Constructors
  Constructor | Description
  --- | ---
  `Solution​(Problem problem)` | Constructs a new solution object for a given problem.

- ## Method Summary

  Modifier and Type | Method | Description
  --- | --- | ---
  `Solution` | `clone()` |
  `int` | `countDescendants()` | Returns the number of descendant solutions that were generated from this object.
  `Domain` | `getDomain​(Variable variable)` | Returns the domain (i.e.
  `boolean` | `isComplete()` | A solution is complete if every variable has a domain of size exactly 1 and none of the problem's constraints are violated.
  `boolean` | `isImpossible()` | A solution is impossible if any variable has a domain of size 0 (i.e.
  `int` | `size()` | The size of a solution is the sum of the sizes of all domains which have more than 1 value.
  `boolean` | `test​(Constraint constraint, java.lang.Object left, java.lang.Object right)` | Given some constraint and two candidate values for the constraint's variables, this method checks if the constraint would be violated by those values.
  `java.lang.String` | `toString()` |

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

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

- ## Field Details

  - ### problem

    public final Problem problem
    The problem this solution is potentially a solution for

- ## Constructor Details

  - ### Solution

    public Solution​(Problem problem)
    Constructs a new solution object for a given problem. The domains of all variables will be set to their domains in the initial state of the problem.
    Parameters:
      `problem` - the problem that this object will potentially be a solution for

- ## Method Details

  - ### toString

    public java.lang.String toString()
    Overrides:
      `toString` in class `java.lang.Object`

  - ### clone

    public Solution clone()
    Overrides:
      `clone` in class `java.lang.Object`

  - ### countDescendants

    public int countDescendants()
    Returns the number of descendant solutions that were generated from this object.
    Returns:
      the number of descendants

  - ### isComplete

    public boolean isComplete()
    A solution is complete if every variable has a domain of size exactly 1 and none of the problem's constraints are violated.
    Returns:
      true if this solution is complete, false otherwise

  - ### isImpossible

    public boolean isImpossible()
    A solution is impossible if any variable has a domain of size 0 (i.e. no legal value) or if any of the problem's constraints have been violated.
    Returns:
      true if this solution can never be complete

  - ### size

    public int size()
    The size of a solution is the sum of the sizes of all domains which have more than 1 value. This implies that size is 0 for a complete solution. The size of a solution is a simple representation of how much work remains to be done before this solution is complete.
    Returns:
      the size of the solution

  - ### getDomain

    public Domain getDomain​(Variable variable)
    Returns the domain (i.e. the set of possible values) for a given variable in this solution.
    Parameters:
      `variable` - the variable
    Returns:
      the variable's domain

  - ### test

    public boolean test​(Constraint constraint, java.lang.Object left, java.lang.Object right)
    Given some constraint and two candidate values for the constraint's variables, this method checks if the constraint would be violated by those values.
    Parameters:
      `constraint` - the constraint to check
      `left` - the value for the constraint's left variable
      `right` - the value for the constraint's right variable
    Returns:
      true if the values do not violate the constraint, false otherwise