Dlx.Solve<TData, TRow, TCol> Method (TData, Func<TData, IEnumerable<TRow>>, Func<TRow, IEnumerable<TCol>>, Func<TCol, Boolean>) |
Find all possible solutions to an exact cover problem given an arbitrary data structure representing
a matrix and a predicate.
Namespace: DlxLibAssembly: DlxLib (in DlxLib.dll) Version: 1.3.0.0 (1.3.0.0)
Syntaxpublic IEnumerable<Solution> Solve<TData, TRow, TCol>(
TData data,
Func<TData, IEnumerable<TRow>> iterateRows,
Func<TRow, IEnumerable<TCol>> iterateCols,
Func<TCol, bool> predicate
)
Public Function Solve(Of TData, TRow, TCol) (
data As TData,
iterateRows As Func(Of TData, IEnumerable(Of TRow)),
iterateCols As Func(Of TRow, IEnumerable(Of TCol)),
predicate As Func(Of TCol, Boolean)
) As IEnumerable(Of Solution)
public:
generic<typename TData, typename TRow, typename TCol>
IEnumerable<Solution^>^ Solve(
TData data,
Func<TData, IEnumerable<TRow>^>^ iterateRows,
Func<TRow, IEnumerable<TCol>^>^ iterateCols,
Func<TCol, bool>^ predicate
)
member Solve :
data : 'TData *
iterateRows : Func<'TData, IEnumerable<'TRow>> *
iterateCols : Func<'TRow, IEnumerable<'TCol>> *
predicate : Func<'TCol, bool> -> IEnumerable<Solution>
Parameters
- data
- Type: TData
The top-level data structure that represents the exact cover problem. - iterateRows
- Type: System.Func<TData, IEnumerable<TRow>>
A System.Func delegate that will be invoked to iterate the rows in the matrix. - iterateCols
- Type: System.Func<TRow, IEnumerable<TCol>>
A System.Func delegate that will be invoked to iterate the columns
in a particular row in the matrix. - predicate
- Type: System.Func<TCol, Boolean>
A predicate which is invoked for each value in the matrix to determine
whether the value represents a logical 1 or a logical 0 indicated by returning true
or false respectively.
Type Parameters
- TData
- The type of the data structure that represents the exact cover problem.
- TRow
- The type of the data structure that represents rows in the matrix.
- TCol
- The type of the data structure that represents columns in the matrix.
Return Value
Type:
IEnumerable<Solution>Yields
Solution objects as they are found.
Examplesvar data = new List<Tuple<char[], string>>
{
Tuple.Create(new[] {'X', 'O', 'O'}, "Some data associated with row 0"),
Tuple.Create(new[] {'O', 'X', 'O'}, "Some data associated with row 1"),
Tuple.Create(new[] {'O', 'O', 'X'}, "Some data associated with row 2")
};
var dlx = new Dlx();
var solutions = dlx.Solve(data, d => d, r => r.Item1, c => c == 'X');
See Also