Ejemplo n.º 1
0
    def __init__(self, gb):
        self.network = filereader.GameBoardToConstraintNetwork(gb)
        self.trail = trail.masterTrailVariable
        self.hassolution = False
        self.gameboard = gb

        self.numAssignments = 0
        self.numBacktracks = 0
        self.preprocessing_startTime = 0
        self.preprocessing_endTime = 0
        self.startTime = None
        self.endTime = None

        # refers to which variable selection heuristic in use(0 means default,
        # 1 means MRV, 2 means DEGREE)
        self.varHeuristics = 0
        # refers to which value selection heuristic in use(0 means default, 1
        # means LCV)
        self.valHeuristics = 0
        # refers to which consistency check will be run(0 for backtracking, 1
        # for forward checking, 2 for arc consistency)
        self.cChecks = []
        # self.runCheckOnce = False
        self.tokens = []  # tokens(heuristics to use)

        # build list of houses
        # e.g. for N=9, house length = 27, houses[0:8]are the row houses,
        # 9:17 are the column houses, and 18:26 are the block houses
        self.houses = [[] for x in range(self.gameboard.N * 3)]
        self.colhouseoffset = self.gameboard.N
        self.blockhouseoffset = self.gameboard.N * 2
        for i in self.network.variables:
            self.houses[i.row].append(i)
            self.houses[i.col + self.colhouseoffset].append(i)
            self.houses[i.block + self.blockhouseoffset].append(i)
Ejemplo n.º 2
0
    def __init__(self, gb):
        self.network = filereader.GameBoardToConstraintNetwork(gb)
        self.trail = trail.masterTrailVariable
        self.hassolution = False
        self.gameboard = gb

        self.numAssignments = 0
        self.numBacktracks = 0
        self.preprocessing_startTime = 0
        self.preprocessing_endTime = 0
        self.startTime = None
        self.endTime = None

        self.varHeuristics = 0
        self.valHeuristics = 0
        self.cChecks = 0
Ejemplo n.º 3
0
    def __init__(self, gb):
        self.network = filereader.GameBoardToConstraintNetwork(gb)
        self.trail = trail.masterTrailVariable
        self.hassolution = False
        self.gameboard = gb

        self.numAssignments = 0
        self.numBacktracks = 0
        self.preprocessing_startTime = 0
        self.preprocessing_endTime = 0
        self.startTime = None
        self.endTime = None

        self.varHeuristics = 0  # refers to which variable selection heuristic in use(0 means default, 1 means MRV, 2 means DEGREE)
        self.valHeuristics = 0  # refers to which value selection heuristic in use(0 means default, 1 means LCV)
        self.cChecks = 0  # refers to which consistency check will be run(0 for backtracking, 1 for forward checking, 2 for arc consistency)
        self.heuristicChecks = 0
        # self.runCheckOnce = False
        self.tokens = []  # tokens(heuristics to use)
Ejemplo n.º 4
0
    return output


if __name__ == '__main__':
    # Check command-line arguments.
    print('Python version:', sys.version)

    GB = gameboard.GameBoard(12, 3, 4,
                             [[0 for j in range(12)] for i in range(12)])
    print(GB)

    TOTAL_START = time.time()
    sudokudata = filereader.SudokuFileReader(sys.argv[1])
    print(sudokudata)
    cn = filereader.GameBoardToConstraintNetwork(sudokudata)
    print(cn)
    solver = btsolver.BTSolver(sudokudata)

    #three examples of how you would change the various aspects of solver
    #   solver.setConsistencyChecks(btsolver.ConsistencyCheck['None'])
    #   solver.setValueSelectionHeuristic(btsolver.ValueSelectionHeuristic['None'])
    #   solver.setVariableSelectionHeuristic(btsolver.VariableSelectionHeuristic['None'])
    tokens = sys.argv[4:]
    solver.setTokens(tokens)
    '''once you have implemented more heuristics, you can add the appropriate lines to this conditional clause'''
    if len(sys.argv) < 4:
        raise ValueError("Program did not received enough correct argument.")
    if len(sys.argv
           ) == 4 or sys.argv[4] == 'BT':  #no options detected or say BT
        print("Default option tokens detected: Backtracking Search (BT)")