Show / Hide Table of Contents

Class ExactCoverGraph

Holds an exact-cover graph for the current puzzle being solved.

This is an extension of the exact-cover matrix concept. Rows of the exact-cover matrix, i.e. a specific location and possible value for that location, are represented by Possibility objects. These are linked together by IObjective objects, which represent the columns of an exact-cover matrix.

For example, the RowUniquenessConstraint uses a required Objective to link all the Possibility objects on a single row that have the same possible value. This way, when one of these possibilities is selected, then the others are all dropped.

To extend the concept into a larger graph, this also uses OptionalObjectives to create subgroups over Possibility objects and/or other OptionalObjective objects. This allows for much more complex constraints, such as the MagicSquaresConstraint.

Inheritance
System.Object
ExactCoverGraph
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: SudokuSpice.ConstraintBased
Assembly: SudokuSpice.dll
Syntax
public sealed class ExactCoverGraph
Remarks

The ExactCoverGraph adds Possibility objects for all the unset coordinates in a puzzle on creation, as well as Objective objects that group all the possible values for each location. These effectively implements the constraint: "Each coordinate in the puzzle must have one and only one value."

Properties

| Improve this Doc View Source

AllPossibleValues

Contains the possible values for the current puzzle.

Declaration
public ReadOnlySpan<int> AllPossibleValues { get; }
Property Value
Type Description
System.ReadOnlySpan<System.Int32>
| Improve this Doc View Source

ValuesToIndices

Maps possible values for the puzzle to indices in the AllPossibleValues array.

Declaration
public IReadOnlyDictionary<int, int> ValuesToIndices { get; }
Property Value
Type Description
System.Collections.Generic.IReadOnlyDictionary<System.Int32, System.Int32>

Methods

| Improve this Doc View Source

Create(IReadOnlyPuzzle)

Creates an exact-cover graph for solving the given puzzle.

This adds Possibility objects for all the unset coordinates in a puzzle on creation, as well as Objective objects that group all the possible values for each location. These effectively implements the constraint: "Each square in the puzzle must have one and only one value."

Declaration
public static ExactCoverGraph Create(IReadOnlyPuzzle puzzle)
Parameters
Type Name Description
IReadOnlyPuzzle puzzle

The puzzle to solve.

Returns
Type Description
ExactCoverGraph
| Improve this Doc View Source

GetAllPossibilitiesAt(Coordinate)

Gets the possibilities at the given Coordinate. This returns null if the square's value was preset in the current puzzle being solved.

Declaration
public Possibility[] GetAllPossibilitiesAt(in Coordinate c)
Parameters
Type Name Description
Coordinate c
Returns
Type Description
Possibility[]
| Improve this Doc View Source

GetPossibilitiesOnRow(Int32)

Gets all the possiblities, grouped by column, on the requested row.

Indexing the result looks like:

var row = graph.GetSquaresOnRow(rowIndex); var possibility = row[columnIndex][valueIndex];

Declaration
public ReadOnlySpan<Possibility[]> GetPossibilitiesOnRow(int row)
Parameters
Type Name Description
System.Int32 row

A zero-based row index.

Returns
Type Description
System.ReadOnlySpan<Possibility[]>
| Improve this Doc View Source

GetUnsatisfiedRequiredObjectives()

Gets all the currently unsatisfied Objectives.

Declaration
public IEnumerable<Objective> GetUnsatisfiedRequiredObjectives()
Returns
Type Description
System.Collections.Generic.IEnumerable<Objective>
| Improve this Doc View Source

GetUnsatisfiedRequiredObjectivesWithConcretePossibilities()

Gets all the currently unsatisfied Objectives that have at least one concrete Possibility as a direct possibility.

Declaration
public IEnumerable<Objective> GetUnsatisfiedRequiredObjectivesWithConcretePossibilities()
Returns
Type Description
System.Collections.Generic.IEnumerable<Objective>

See Also

https://en.wikipedia.org/wiki/Exact_cover
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX