Пример #1
0
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 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)