def bool2board(name): M = readFile(name) B = generateBoardFromMinisatOutput(M) printBoard(B)
def board2bool(name): # generate the DIMACS file from the input file global N global SizeTable M = readFile(name) # read the whole file # calculate the global variables N = getN(M) # calculate the dimension of the board from the input SizeTable = int(pow(N+2,2)) # calculate the size of the extended board B = generateExtendedBoardFromInput(M) # Board with initial configuration (0/1) BI = generateIndexBoard(N+2) # Each cell contains its index in the DIMACS file nAlives = len(M)-1 # Nr. of Alive cells nCells = int(pow(N,2)) # Total nr. of cells nVars = int( SizeTable + NAUX * nCells ) # number of cells(in the extended board) + NAUX(31) Tseitin variables per cell nClauses = NAUX * nCells * 3 # auxiliary variables, NAUX(31) * cell * 3 clauses nClauses = nClauses + 4 * N + 4 # margin of zeros, 1 per cell on the margin nClauses = nClauses + 4 * ( N - 2 ) # no three in a row, add 1 clause per cell on the side(not corners) nClauses = nClauses +(nCells-nAlives) * 3 # dead cells add 3 clauses nClauses = nClauses + nAlives * 3 # alive cells add 3 clauses print 'c Alive Cells', nAlives print 'c', name # file used to generate this one print 'p cnf', nVars, nClauses # DIMACS header generateRules(B, BI) # generates all rules
def bool2board(name): M = readFile(name) if M[0][0]=='UNSAT': print 'UNSAT PROBLEM' return B = generateBoardFromMinisatExtendedOutput(M) # check no 1's in margin printBoard(B)
def checkResults(name1, name2): M1 = readFile(name1) M2 = readFile(name2) if M2[0][0] == "UNSAT": print "UNSAT PROBLEM" return B1 = generateBoardFromInput(M1) # read Input file B2 = generateBoardFromMinisatExtendedOutput(M2) # read Result compare(B1, B2) # add * for new checkers (and ! for errors) n = len(B2) * 2 print "-" * n printBoard(B1) print "-" * n print " " print "-" * n printBoard(B2) print "-" * n
def board2bool(name): M = readFile(name) B = generateBoardFromInput(M) n = len(B) BI = generateIndexBoard(len(B)) BHM = generateHowManyBoard(B) BDC = generateBoardCellsAround(B,BI,n,0) # printBoard(B) # printBoard(BI) # printBoard(BHM) # printBoard(BDC) generateRules(B, BI, BHM, BDC)