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
Inherited Members
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 SourceAllPossibleValues
Contains the possible values for the current puzzle.
Declaration
public ReadOnlySpan<int> AllPossibleValues { get; }
Property Value
Type | Description |
---|---|
System.ReadOnlySpan<System.Int32> |
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 SourceCreate(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 |
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[] |
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[]> |
GetUnsatisfiedRequiredObjectives()
Gets all the currently unsatisfied Objectives.
Declaration
public IEnumerable<Objective> GetUnsatisfiedRequiredObjectives()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Objective> |
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> |