Example #1
0
def gera_caminho(inicial_state, grafo):


	lista, permutaciones = ler_arquivo(Obj=EightPuzzleUCS, grafo=grafo)
	goal_state = None
	indice = permutaciones.index(inicial_state)
	inicial = lista[indice]

	inicio = time.time()
	goal_state, frontier = UCS(inicial, lista)

	node = goal_state
	caminho = []
	deep = 1
	while node.state != inicial_state:
		if node.move[0] == 3:
			move = "Esquerda"
		elif node.move[0] == 2:
			move = "Baixo"
		if node.move[0] == 1:
			move = "Direita"
		elif node.move[0] == 0:
			move = "Cima"
		caminho.insert(0,move)
		node = lista[node.move[1]]
		if node.state != inicial_state:
			deep = deep + 1
	
	final = time.time()
	print("Profundidade: "+str(deep))
	print("Tempo gasto: "+str(final-inicio))
	print("Alocação de memória do UCS da Fronteira: "+str(sys.getsizeof(frontier)))
	

	print(caminho)
def gera_caminho(inicial_state, grafo):

    lista, permutaciones = ler_arquivo(Obj=EightPuzzleBFS, grafo=grafo)
    goal_state = None
    indice = permutaciones.index(inicial_state)
    inicial = lista[indice]

    inicio = time.time()
    deep, goal_state, frontier = BFS(inicial, lista)
    fim = time.time()

    print("Tempo de execuçaõ: " + str(fim - inicio))
    print("Profundidade: " + str(deep))
    print("Alocação de memória do BFS da Fronteira: " +
          str(sys.getsizeof(frontier)))

    node = goal_state
    caminho = []
    while node.state != inicial_state:
        #print(node.move)
        if node.move[0] == 3:
            move = "Esquerda"
        elif node.move[0] == 2:
            move = "Baixo"
        if node.move[0] == 1:
            move = "Direita"
        elif node.move[0] == 0:
            move = "Cima"
        caminho.insert(0, move)
        node = lista[node.move[1]]

    print(caminho)
Example #3
0
def gera_caminho(inicial_state, grafo, heurist):

    lista, permutaciones = ler_arquivo(Obj=EightPuzzleHILL,
                                       grafo=grafo,
                                       heristi=heurist)
    goal_state = None
    indice = permutaciones.index(inicial_state)
    inicial = lista[indice]

    inicio = time.time()
    while goal_state == None:
        goal_state = Hill_Climbing(inicial, lista)

    #print("Alocação de memória do Hill-Climbing da Fronteira: "+str(sys.getsizeof(frontier)))

    node = goal_state
    caminho = []
    deep = 1

    while node.state != list(inicial_state):
        print(node.mov)
        if node.mov[0] == 3:
            move = "Esquerda"
        elif node.mov[0] == 2:
            move = "Baixo"
        if node.mov[0] == 1:
            move = "Direita"
        elif node.mov[0] == 0:
            move = "Cima"
        caminho.insert(0, move)
        node = lista[node.mov[1]]

        if (node.state != list(inicial_state)):
            deep = deep + 1

    final = time.time()
    print("Tempo gasto: " + str(final - inicio))
    print("Profundidade: " + str(deep))
    print(caminho)