Ejemplo n.º 1
0
def BFS_solution(E0):

    busca = BFS.BFS_algorithmcs(list_action_function=listarAcoes, execute_action_function=executarAcao, hash_function=funcaoHash, cmp_function=cmpEstados)
    
    solution = busca.BFS(E0, Eobj)
    solution.E0 = decoding(solution.E0)
    solution.Ef = decoding(solution.Ef)
    solution.states = [decoding(x) for x in solution.states]
    
    return solution.states
Ejemplo n.º 2
0
def BFS_solution(estado_inicial, estado_objetivo):

    time_init = time()
    busca = BFS.BFS_algorithmcs(list_action_function=listarAcoes,
                                execute_action_function=executarAcao,
                                hash_function=funcao_hash,
                                cmp_function=comparar_estados)

    N = len(estado_inicial)
    estado_inicial = encoding(estado_inicial)
    estado_objetivo = encoding(estado_objetivo)

    solution = busca.BFS(estado_inicial, estado_objetivo)
    solution.E0 = decoding(estado_inicial)
    solution.Ef = decoding(estado_objetivo)
    solution.states = [decoding(x) for x in solution.states]
    solution.duration = time() - time_init
    solution.deepth = busca.graph.branching_factor()
    solution.width = busca.graph.deepth_factor()

    return solution
Ejemplo n.º 3
0
#------------------------------------------------


#--Executar ações
def executarAcao(Et, acao):

    return acao


#------------------------------------------------


#--Compara igualdade de estados
# **** É possivel associar um inteiro a cada estado e
# **** assim a comparação seria direta
def cmpEstados(Ea, Eb):

    return Ea == Eb


#------------------------------------------------


def funcaoHash(Ea):
    return int(ord(Ea)) % 30

busca = BFS.BFS_algorithmcs(list_action_function=listarAcoes, execute_action_function=executarAcao, \
                           hash_function = funcaoHash, cmp_function = cmpEstados)

for step in busca.BFS(E0, Eobj):
    print("mover-se para " + str(step.action) + ", ", end=' ')