Last active
December 20, 2015 07:49
-
-
Save Bernardoow/6096314 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NB: | |
def __init__(self,Lista): | |
self.ListaDeCaminho = Lista | |
self.Direcao = None | |
self.Custo = 0 | |
def addUmaListaDeCaminho(self,Lista): | |
for e in Lista: | |
self.ListaDeCaminho.append(e) | |
def addUmPasso(self,Passo): | |
self.ListaDeCaminho.append(Passo) | |
def addCusto(self,Custo): | |
self.Custo=Custo | |
def addLugarAtual(self,lugar): | |
self.Lugar = lugar | |
def addDirecao(self,Direcao): | |
self.Direcao = Direcao | |
def retornaListaDeCaminho(self): | |
if count(self.ListaDeCaminho)==0: | |
return None | |
else: | |
return self.ListaDeCaminho | |
def retornarCusto(self): | |
return self.Custo | |
def retornarDirecao(self): | |
return self.Direcao | |
def retornarLugarAtual(self): | |
return self.Lugar | |
def depthFirstSearch(problem): | |
No = NB([]) | |
No.addLugarAtual(problem.getStartState()) | |
print 'ber',No,No.retornarCusto(),No.retornarLugarAtual() | |
caminho = [] | |
Visitados = [] | |
fechados = [] | |
caminho = buscaEmProfundidadeRecursaoNovaVersao(problem, No, Visitados,caminho) | |
util.raiseNotDefined() | |
def buscaEmProfundidadeRecursaoNovaVersao(problem, NoParametro, Visitados,Caminho): | |
if(problem.isGoalState(NoParametro.retornarLugarAtual())): | |
Caminho = No.retornaListaDeCaminho() | |
return | |
print 'osad',NoParametro.retornarLugarAtual(),'sadsadsadsadsasa' | |
sucessores = problem.getSuccessors(NoParametro.retornarLugarAtual()) | |
sucessores.reverse() | |
for x in sucessores: | |
Noo = NB([]) | |
Noo.addLugarAtual(x[1]) | |
Noo.addCusto(NoParametro.retornarCusto()+x[2]) | |
Noo.addDirecao(x[1]) | |
print NoParametro.retornarListaDeCaminho(),"asdsad" | |
Noo.addUmaListaDeCaminho(NoParametro.retornarListaDeCaminho()) | |
Noo.addUmPasso(x[1]) | |
if Visitados.count(Noo.retornarLugarAtual()) == 0: | |
Visitados.append(Noo.retornarLugarAtual()) | |
buscaEmProfundidadeRecursaoNovaVersao(problem, Noo.retornarLugarAtual(), Visitados, Caminho) | |
return | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment