|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.hadoop.examples.dancing.DancingLinks<ColumnName>
public class DancingLinks<ColumnName>
A generic solver for tile laying problems using Knuth's dancing link algorithm. It provides a very fast backtracking data structure for problems that can expressed as a sparse boolean matrix where the goal is to select a subset of the rows such that each column has exactly 1 true in it. The application gives each column a name and each row is named after the set of columns that it has as true. Solutions are passed back by giving the selected rows' names. The type parameter ColumnName is the class of application's column names.
Nested Class Summary | |
---|---|
static interface |
DancingLinks.SolutionAcceptor<ColumnName>
Applications should implement this to receive the solutions to their problems. |
Constructor Summary | |
---|---|
DancingLinks()
|
Method Summary | |
---|---|
void |
addColumn(ColumnName name)
Add a column to the table |
void |
addColumn(ColumnName name,
boolean primary)
Add a column to the table |
void |
addRow(boolean[] values)
Add a row to the table. |
String |
getColumnName(int index)
Get the name of a given column as a string |
int |
getNumberColumns()
Get the number of columns. |
int |
solve(DancingLinks.SolutionAcceptor<ColumnName> output)
Solve a complete problem |
int |
solve(int[] prefix,
DancingLinks.SolutionAcceptor<ColumnName> output)
Given a prefix, find solutions under it. |
List<int[]> |
split(int depth)
Generate a list of row choices to cover the first moves. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DancingLinks()
Method Detail |
---|
public void addColumn(ColumnName name, boolean primary)
name
- The name of the column, which will be returned as part of
solutionsprimary
- Is the column required for a solution?public void addColumn(ColumnName name)
name
- The name of the column, which will be included in the solutionpublic int getNumberColumns()
public String getColumnName(int index)
index
- the index of the column
public void addRow(boolean[] values)
values
- the columns that are satisfied by this rowpublic List<int[]> split(int depth)
depth
- the length of the prefixes to generate
public int solve(int[] prefix, DancingLinks.SolutionAcceptor<ColumnName> output)
prefix
- a list of row choices that control which part of the search
tree to exploreoutput
- the output for each solution
public int solve(DancingLinks.SolutionAcceptor<ColumnName> output)
output
- the acceptor to receive answers
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |