Show / Hide Table of Contents

Class ConstraintUtil

Provides utilities for easily implementing constraints.

Inheritance
object
ConstraintUtil
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: SudokuSpice.ConstraintBased.Constraints
Assembly: SudokuSpice.dll
Syntax
public static class ConstraintUtil

Methods

| Edit this page View Source

TryAddObjectiveForPossibilityIndex(ReadOnlySpan<Possibility?[]?>, int, ExactCoverGraph, int, 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
ReadOnlySpan<Possibility[]> squares

The squares to add Possibilitys from.

int possibilityIndex

The value index of the possible value within the squares.

ExactCoverGraph graph

The graph for the current puzzle being solved.

int requiredCount

The number of possibilities required to satisfy the new Objective.

Objective objective

The new objective, if successful, else null.

Returns
Type Description
bool

False if the objective could not be added, for example because not enough Possibility objects were still possible to satisfy it, else true.

| Edit this page View Source

TryAddOptionalObjectiveForPossibilityIndex(ReadOnlySpan<Possibility?[]?>, int, int, 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
ReadOnlySpan<Possibility[]> squares

The squares to add Possibilitys from.

int possibilityIndex

The value index of the possible value within the squares.

int requiredCount

The number of possibilities required to satisfy the new OptionalObjective.

OptionalObjective objective

The new optional objective, if successful, else null.

Returns
Type Description
bool

False if the objective could not be added, for example because not enough Possibility objects were still possible to satisfy it, else true.

| Edit this page View Source

TryCheckForSetValues(IReadOnlyPuzzle, ExactCoverGraph, ReadOnlySpan<Coordinate>, Span<bool>)

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.

ReadOnlySpan<Coordinate> squareCoordinates

The coordinates to check.

Span<bool> isValueIndexPresentInSquares

An array that will be updated to indicate which values are set.

Returns
Type Description
bool

False if a value is duplicated in the given coordinates.

| Edit this page View Source

TryDropPossibilitiesAtIndex(ReadOnlySpan<Possibility?[]?>, int)

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
ReadOnlySpan<Possibility[]> squares

The squares to drop, if not null.

int possibilityIndex

The index of the possibility within the squares.

Returns
Type Description
bool

True if all the squares were dropped safely (eg. without resulting in any Objective that can no longer be satisfied).

| Edit this page View Source

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.

ReadOnlySpan<Coordinate> squareCoordinates

The coordinates that must contain unique values.

ExactCoverGraph graph

The exact-cover graph for the current puzzle.

Returns
Type Description
bool

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.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX