Пример #1
0
def main():
	boardNo = inputValidation('Choose board (0-6): ')

	board, x_dimension, y_dimension, row_specs, column_specs = readBoard(boardNo)
	initiate(board)
	# draw_board(board, True)

	rowVars = generateVariables(row_specs, x_dimension, 0)
	colVars = generateVariables(column_specs, y_dimension, 1)

	initNode = Node(rowVars, colVars, None, x_dimension, y_dimension)

	if not initNode.checkIfGoalState() and not initNode.checkIfContradiction():
		initNode.revise()
		x, opennodes, closednodes = searchAlgorithm(1, initNode)
		print ""
		print "Number of search nodes generated:\t\t", len(opennodes) + len(closednodes)
		print "Search nodes expanded:\t\t\t\t\t", len(closednodes)
		print "Nodes on path from root to solution:\t", findLengthSolution(x, 0)
		x.drawBoard(opennodes, closednodes, True)
Пример #2
0
def main():
	sys.setrecursionlimit(10000)
	boardNo = inputValidation('Choose board (0-5): ')
	k = inputValidation('Choose domain size: ')
	graph = readBoard(boards[boardNo])
	initiate(graph)
	variables = create_Variables(graph, k)

	node = Node(variables, None)

	if not node.checkIfGoalState() and not node.checkIfContradiction():
		x, opennodes, closednodes = searchAlgorithm(1, node)
		numberOfUnsatisfiedConstraints = getCountUsatConstraints(x)
		numNonColoredVars = getNumNonColoredVars(x)
		print "Number of unsatisfied constraints:\t\t", numberOfUnsatisfiedConstraints
		print "Number of variables without color:\t\t", numNonColoredVars
		print "Nodes in the search tree:\t\t\t\t", len(opennodes) + len(closednodes)
		print "Number of nodes popped and expanded:\t", len(closednodes)
		print "Length of path from root to solution:\t", findLengthSolution(x, 0)

		x.drawBoard(opennodes, closednodes, True)
Пример #3
0
def run(board, algorithm, heuristic, ninjaMode):
    initiate(board.boardMatrix)

    initNode = Module1Node(None, 0, 0, board.startXY[0], board.startXY[1],
                           board, heuristic, ninjaMode)
    if ninjaMode:
        initNode = Module1NinjaNode(None, 0, 0, board.startXY[0],
                                    board.startXY[1], board, heuristic,
                                    ninjaMode)

    x, openNodes, closedNodes = searchAlgorithm(algorithm, initNode)

    if x.xPos == board.goalXY[0] or x.yPos == board.goalXY[1]:
        print
        print "Results:"
        print "\tLength of solution:\t", findLengthSolution(x, 0)
        print "\tSearched nodes:\t\t", len(openNodes) + len(closedNodes)
        print "\t\tOpen nodes:\t\t", len(openNodes)
        print "\t\tClosed nodes:\t", len(closedNodes)

    drawBoard(x, board.boardMatrix, board.startXY, board.goalXY, openNodes,
              closedNodes, True)
Пример #4
0
def main():
    boardNo = inputValidation('Choose board (0-6): ')

    board, x_dimension, y_dimension, row_specs, column_specs = readBoard(
        boardNo)
    initiate(board)
    # draw_board(board, True)

    rowVars = generateVariables(row_specs, x_dimension, 0)
    colVars = generateVariables(column_specs, y_dimension, 1)

    initNode = Node(rowVars, colVars, None, x_dimension, y_dimension)

    if not initNode.checkIfGoalState() and not initNode.checkIfContradiction():
        initNode.revise()
        x, opennodes, closednodes = searchAlgorithm(1, initNode)
        print ""
        print "Number of search nodes generated:\t\t", len(opennodes) + len(
            closednodes)
        print "Search nodes expanded:\t\t\t\t\t", len(closednodes)
        print "Nodes on path from root to solution:\t", findLengthSolution(
            x, 0)
        x.drawBoard(opennodes, closednodes, True)
Пример #5
0
def main():
    sys.setrecursionlimit(10000)
    boardNo = inputValidation('Choose board (0-5): ')
    k = inputValidation('Choose domain size: ')
    graph = readBoard(boards[boardNo])
    initiate(graph)
    variables = create_Variables(graph, k)

    node = Node(variables, None)

    if not node.checkIfGoalState() and not node.checkIfContradiction():
        x, opennodes, closednodes = searchAlgorithm(1, node)
        numberOfUnsatisfiedConstraints = getCountUsatConstraints(x)
        numNonColoredVars = getNumNonColoredVars(x)
        print "Number of unsatisfied constraints:\t\t", numberOfUnsatisfiedConstraints
        print "Number of variables without color:\t\t", numNonColoredVars
        print "Nodes in the search tree:\t\t\t\t", len(opennodes) + len(
            closednodes)
        print "Number of nodes popped and expanded:\t", len(closednodes)
        print "Length of path from root to solution:\t", findLengthSolution(
            x, 0)

        x.drawBoard(opennodes, closednodes, True)