com.act365.sudoku
Class Composer

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.act365.sudoku.Composer
All Implemented Interfaces:
java.lang.Runnable

public class Composer
extends java.lang.Thread

A Composer object attempts to compose valid Su Doku puzzles with the MostCandidates strategy. It runs as a thread because composition is a lengthy process that the caller might well choose to terminate.


Field Summary
static int defaultThreads
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Composer(GridContainer gridContainer, int boxesAcross, int maxSolns, int maxMasks, int maxUnwinds, int maxComplexity, MaskFactory maskFactory, int nSolvers, int composeSolverThreshold, java.io.PrintStream debug, boolean useNative, boolean leastCandidatesHybridFilter)
          Generates a new thread that will attempt to construct a Su Doku puzzle with 'maskSize' cells on initial display.
 
Method Summary
 void addSolution(int solverIndex)
          Called by a Solver object in order to indicate that a solution has been found.
static void main(java.lang.String[] args)
          Command-line app to compose Su Doku puzzles.
 void run()
          Starts a Composer thread.
 void solverFinished(int solverIndex)
          Called by a Solver object in order to indicate that all possible solutions to the puzzle have been considered.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultThreads

public static final int defaultThreads
See Also:
Constant Field Values
Constructor Detail

Composer

public Composer(GridContainer gridContainer,
                int boxesAcross,
                int maxSolns,
                int maxMasks,
                int maxUnwinds,
                int maxComplexity,
                MaskFactory maskFactory,
                int nSolvers,
                int composeSolverThreshold,
                java.io.PrintStream debug,
                boolean useNative,
                boolean leastCandidatesHybridFilter)
         throws java.lang.Exception
Generates a new thread that will attempt to construct a Su Doku puzzle with 'maskSize' cells on initial display. The puzzle will be copied into 'grid'. When 'randomize' is selected, the mask will be selected randomly and the RadomMostCandidates strategy will be used to complete it.

Parameters:
gridContainer - object to be notified when a puzzle has been composed
boxesAcross -
maxSolns - maximum number of solutions to find (0 for no limit)
maxMasks - maximum number of masks to use (0 for no limit)
maxUnwinds - maximum permitted number of unwinds (0 for no limit)
maxComplexity - maximum permitted complexity (0 for no limit)
maskFactory - factory to generate the masks
nSolvers - number of solver threads to run
composeSolverThreshold - tree depth beyond which the compose solver will be invoked
debug - optional debug stream (set to null for no debug)
Method Detail

addSolution

public void addSolution(int solverIndex)
Called by a Solver object in order to indicate that a solution has been found.

Parameters:
solverIndex - index of the reporting solver
See Also:
Solver

solverFinished

public void solverFinished(int solverIndex)
Called by a Solver object in order to indicate that all possible solutions to the puzzle have been considered.

Parameters:
solverIndex - index of finished solver
See Also:
Solver

run

public void run()
Starts a Composer thread. The thread will start a number of Solvers and collate the returned results.

See Also:
Solver

main

public static void main(java.lang.String[] args)
Command-line app to compose Su Doku puzzles.
Composer [-a across] [-d down] [-ms max solns|-mm max masks] [-mu max unwinds] [-s solvers] [-c threshold] [-r] [-v] -i|#cells
[-a across] [-d down] define the dimensions of the puzzles to be composed. The default values are three in each dimension.
[-ms max solns|-mm max masks] defines optional termination conditions. The app will exit if max solns puzzles have been generated or max masks masks have been considered, whichever occurs sooner.
[-mu max unwinds] stipulates a limit on the number of unwinds permitted on a single mask.
[-mu max unwinds] stipulates a limit on the complexity permitted on a single mask.
[-s solvers] stipulates the number of solver (or, equivalently, threads) to execute simultaneously. The default is 3.
[-c threshold] stipulates the tree depth beyond which the compose solver will be invoked. The default value is 0.
[-r] stipulates whether a random initial mask should be used. The default is no.
[-v] stipualtes whether the Composer should run in verbose mode. The default is no.
[-n] stipulates that the native library should be loaded
[-f] stipulates that the output from the Least Candidates Hybrid compose solver should be filter, i.e. that LCH II should be used.
-i stipulates that the initial mask should be read from standard input.
#cells stipulates the number of initially-filled cells to appear in the puzzles.