Class ConstraintUtil
Provides utilities for easily implementing constraints.
Inheritance
Inherited Members
Namespace: SudokuSpice.ConstraintBased.Constraints
Assembly: SudokuSpice.dll
Syntax
public static class ConstraintUtil
Methods
| Improve this Doc View SourceTryAddObjectiveForPossibilityIndex(ReadOnlySpan<Possibility[]>, Int32, ExactCoverGraph, Int32, out Objective)
Add an Objective connecting all the Possibilitys at the
given possibilityIndex
on the given squares
.
Skips null squares, null possibilities, and any possibilities in a known state (i.e.
dropped or selected).
Declaration
public static bool TryAddObjectiveForPossibilityIndex(ReadOnlySpan<Possibility[]> squares, int possibilityIndex, ExactCoverGraph graph, int requiredCount, out Objective objective)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<Possibility[]> | squares | The squares to add Possibilitys from. |
System.Int32 | possibilityIndex | The value index of the possible value within the squares. |
ExactCoverGraph | graph | The graph for the current puzzle being solved. |
System.Int32 | requiredCount | The number of possibilities required to satisfy the new Objective. |
Objective | objective | The new objective, if successful, else null. |
Returns
Type | Description |
---|---|
System.Boolean | False if the objective could not be added, for example because not enough Possibility objects were still possible to satisfy it, else true. |
TryAddOptionalObjectiveForPossibilityIndex(ReadOnlySpan<Possibility[]>, Int32, Int32, out OptionalObjective)
Add an OptionalObjective connecting all the
Possibilitys at the given possibilityIndex
on the
given squares
. Skips null squares, null possibilities, and any
possibilities in a known state (i.e. dropped or selected).
Declaration
public static bool TryAddOptionalObjectiveForPossibilityIndex(ReadOnlySpan<Possibility[]> squares, int possibilityIndex, int requiredCount, out OptionalObjective objective)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<Possibility[]> | squares | The squares to add Possibilitys from. |
System.Int32 | possibilityIndex | The value index of the possible value within the squares. |
System.Int32 | requiredCount | The number of possibilities required to satisfy the new OptionalObjective. |
OptionalObjective | objective | The new optional objective, if successful, else null. |
Returns
Type | Description |
---|---|
System.Boolean | False if the objective could not be added, for example because not enough Possibility objects were still possible to satisfy it, else true. |
TryCheckForSetValues(IReadOnlyPuzzle, ExactCoverGraph, ReadOnlySpan<Coordinate>, Span<Boolean>)
Tries to fill the isValueIndexPresentInSquares
span according to
which value indices are already set in the given list of
squareCoordinates
. Each index is true if that value is already set.
Results are only complete if this returns true. If it returns false, no guarantees are
made as to the state of isValueIndexPresentInSquares
.
Declaration
public static bool TryCheckForSetValues(IReadOnlyPuzzle puzzle, ExactCoverGraph graph, ReadOnlySpan<Coordinate> squareCoordinates, Span<bool> isValueIndexPresentInSquares)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyPuzzle | puzzle | The current puzzle being solved. |
ExactCoverGraph | graph | The graph for the puzzle being solved. |
System.ReadOnlySpan<Coordinate> | squareCoordinates | The coordinates to check. |
System.Span<System.Boolean> | isValueIndexPresentInSquares | An array that will be updated to indicate which values are set. |
Returns
Type | Description |
---|---|
System.Boolean | False if a value is duplicated in the given coordinates. |
TryDropPossibilitiesAtIndex(ReadOnlySpan<Possibility[]>, Int32)
Drops Possibilitys with the given possibilityIndex
from the given set of squares
. Null squares and possible values are
ignored.
If this returns false, there is no guarantee as to the state of the given
squares
. Some may have been dropped.
Declaration
public static bool TryDropPossibilitiesAtIndex(ReadOnlySpan<Possibility[]> squares, int possibilityIndex)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<Possibility[]> | squares | The squares to drop, if not null. |
System.Int32 | possibilityIndex | The index of the possibility within the squares. |
Returns
Type | Description |
---|---|
System.Boolean | True if all the |
TryImplementUniquenessConstraintForSquares(IReadOnlyPuzzle, ReadOnlySpan<Coordinate>, ExactCoverGraph)
Enforces uniqueness of the values at the given coordinates.
Declaration
public static bool TryImplementUniquenessConstraintForSquares(IReadOnlyPuzzle puzzle, ReadOnlySpan<Coordinate> squareCoordinates, ExactCoverGraph graph)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyPuzzle | puzzle | The puzzle being solved. |
System.ReadOnlySpan<Coordinate> | squareCoordinates | The coordinates that must contain unique values. |
ExactCoverGraph | graph | The exact-cover graph for the current puzzle. |
Returns
Type | Description |
---|---|
System.Boolean | False if the puzzle violates uniquness for the given coordinates, else true. |
Remarks
This drops any Possibilitys that are no longer possible, and adds Objectives to enforce this constraint for the ones that are still possible.