Example #1
0
    def n_solutions(self):
	#initialize the appropriate incidence matrix
	fields = [str(c[1])+str(c[4]) for c in self.board.capacities if self.board.capacities[c] > 0]
	I = incidence_matrix.IncidenceMatrix([t.name for t in self.tileSet.set] + fields + ['constraint'])	#name collisions for tiles which are more than once available
        tmpPent = None
        for p in self.tileSet.set:
	    if p.name in self.fixedTiles:
		for c in [coos for coos in self.fixedTiles[p.name] if self.board.valid_tile_placement(coos)]:
		    I.appendRow(p.name,[str(coo[0])+str(coo[1]) for coo in c])
                    if c == [[1,2],[2,2],[2,1],[2,3],[3,2]]:
                        constraintCell = incidence_matrix.IncidenceCell(I.columnObjectOfName['X'].up.left,I.columnObjectOfName['X'].up,I.columnObjectOfName['constraint'].up,I.columnObjectOfName['constraint'], I.columnObjectOfName['constraint'],I.columnObjectOfName['X'].up.name + "_constraint")
                        constraintCell.left.right = constraintCell.right.left = constraintCell.up.down = constraintCell.down.up = constraintCell 
	    else:	
		for q in pentominos.fixed_pentominos_of(p):
		    #m = q.max()
		    for i in range(8):#self.board.size[0]-m[0]-1):
			for j in range(8):#self.board.size[1]-m[1]-1):
			    if self.board.valid_tile_placement(q.coos):
				I.appendRow(p.name,[str(c[0])+str(c[1]) for c in q.coos])
				if 'constraint' in I.columnObjectOfName:
				    tmpPent = copy.deepcopy(q).normalize()
				    if tmpPent in [pentominos.P().flip(0), pentominos.P().flip(0).turn90(), pentominos.P().flip(0).turn90().turn90(), pentominos.P().flip(0).turn90().turn90().turn90()]:
				      constraintCell = incidence_matrix.IncidenceCell(I.columnObjectOfName['P'].up.left,I.columnObjectOfName['P'].up,I.columnObjectOfName['constraint'].up,I.columnObjectOfName['constraint'], I.columnObjectOfName['constraint'],I.columnObjectOfName['P'].up.name + "_constraint")
				      constraintCell.left.right = constraintCell.right.left = constraintCell.up.down = constraintCell.down.up = constraintCell
			    q.translate_one(1)
			q.normalize_coo(1)
			q.translate_one(0)
        I.h.size = float("inf")
        I.columnObjectOfName['constraint'].size = float("inf")
	return self.solve(I, 0)
 def test_init(self):
     I = incidence_matrix.IncidenceMatrix(["0", "1", "2"])
     self.assertEqual([[['h(0)', 'root', '2', '0', 'root', 'root']],
                       [['h(0)', '0', 'root', '1', '0', '0']],
                       [['h(0)', '1', '0', '2', '1', '1']],
                       [['h(0)', '2', '1', 'root', '2', '2']]],
                      I.representation())
Example #3
0
def scott_example():
    names = ["F", "I", "L", "P", "N", "T", "U", "V", "W", "X", "Y", "Z"]
    for i in range(8):
        for j in range(8):
            if AllowOutsideHole([i, j]):
                names.append(str(i) + str(j))
    return incidence_matrix.IncidenceMatrix(names)
Example #4
0
def running_example():
    I = incidence_matrix.IncidenceMatrix(["A", "B", "C", "D", "E", "F", "G"])
    I.appendRow("C", ["E", "F"])
    I.appendRow("A", ["D", "G"])
    I.appendRow("B", ["C", "F"])
    I.appendRow("A", ["D"])
    I.appendRow("B", ["G"])
    I.appendRow("D", ["E", "G"])
    return I
Example #5
0
	def createMatrix(self):
		"""creates the columns for the matrix"""
		
		names = []
		for p in self.WorkingSet:
			names.append(p.name)
		for i in range(self.FRange):
			for j in range(self.FRange):
				if self.legal([i,j]):
					names.append(str(i)+str(j))
		return incidence_matrix.IncidenceMatrix(names)
Example #6
0
 def matrixTitels():
     """ The methode 'scott_example()' creates all ColumnObjects for:
             - all the possible pentominos
             - all positions on the actual board
         and returns the corresponding incidence Matrix """
     names = ["F", "I", "L", "P", "N", "T", "U", "V", "W", "X", "Y", "Z"]
     for i in range(self.Board.rows):
         for j in range(self.Board.columns):
             if not inHole([i,j]):
                 names.append(str(i)+str(j))
     return incidence_matrix.IncidenceMatrix(names)
Example #7
0
 def testName(self):
     example1 = [[0, 2, 8], [0, 4, 6], [0, 7, 4], [1, 1, 5], [1, 3, 3],
                 [1, 4, 2], [2, 0, 3], [2, 2, 7], [2, 5, 8], [2, 7, 9],
                 [3, 0, 9], [3, 1, 3], [3, 6, 4], [3, 7, 6], [4, 2, 6],
                 [4, 5, 4], [4, 6, 5], [4, 7, 7], [5, 1, 4], [5, 7, 8],
                 [5, 8, 2], [6, 0, 5], [6, 1, 8], [6, 3, 1], [6, 4, 4],
                 [6, 6, 2], [6, 7, 3], [6, 8, 7], [7, 2, 3], [7, 5, 8],
                 [7, 6, 8], [7, 7, 5], [8, 0, 2], [8, 4, 7], [8, 6, 8]]
     example2 = [[0, 0, 4], [0, 3, 8], [1, 6, 1], [1, 8, 6], [2, 6, 3],
                 [3, 0, 5], [3, 7, 4], [4, 4, 3], [4, 7, 2], [5, 5, 1],
                 [6, 1, 3], [6, 4, 6], [6, 6, 2], [7, 3, 5], [7, 7, 7],
                 [8, 2, 8], [8, 3, 4]]
     empty = []
     names = sudoku.sudokuListHeaders(example2)
     print(names)
     print(len(names))
     I = incidence_matrix.IncidenceMatrix(names)
     I.insertSudokuRows(example2, names)
     print(I.rows)
     I.calculatePentominoSolution(0, [])
     print(len(I.solutions))
     print(I.zacka)
     pass
 def test_calculatePentominoSolution(self):
     I = incidence_matrix.IncidenceMatrix(
         pentominos.all_pentominos_names() + pentominos.all_positions())
     I.initializeTheIncidenceMatrix()
     I.calculatePentominoSolution(0, [])
     print(incidence_matrix.IncidenceMatrix.solutions)
Example #9
0
def little_quadratic_example():
    names = ["I","L","U","V","Y"]
    for i in range(5):
        for j in range(5):
            names.append(str(i)+str(j))
    return incidence_matrix.IncidenceMatrix(names)
Example #10
0
import incidence_matrix
import pentominos
import examples
import copy


I = incidence_matrix.IncidenceMatrix(["0", "1", "2"])
print I.representation()