コード例 #1
0
# Search methods

import search

ab = search.GPSProblem('A', 'B', search.romania)

print(search.breadth_first_graph_search(ab).path())
print(search.depth_first_graph_search(ab).path())
print(search.branch_and_bound_search(ab).path())

# Result:
# BFS
# [<Node B>, <Node F>, <Node S>, <Node A>] : 211 + 99 + 140 = 450
# DFS
# [<Node B>, <Node P>, <Node C>, <Node D>, <Node M>, <Node L>, <Node T>, <Node A>] : 101 + 138 + 120 + 75 + 70 + 111 + 118 = 733
# BNB
# [<Node B>, <Node P>, <Node R>, <Node S>, <Node A>] : 101 + 97 + 80 + 140 = 418
コード例 #2
0
ファイル: run.py プロジェクト: AdrianLorenzoDev/path-finder
def printAllSolutions(problem):
    printSolution("Breadth First", search.breadth_first_graph_search(problem))
    printSolution("Depth First", search.depth_first_graph_search(problem))
    printSolution("Branch and bound", search.branch_and_bound_search(problem))
    printSolution("Branch and bound with subestimation",
                  search.branch_and_bound_subestimation_search(problem))
コード例 #3
0
ファイル: run.py プロジェクト: GuzmanHrz/FSI
# Search methods

import search

ab = search.GPSProblem('A', 'B', search.romania)

af = search.GPSProblem('A', 'F', search.romania)

print("Anchura:")
print search.breadth_first_graph_search(ab).path()
print("Profundidad:")
print search.depth_first_graph_search(ab).path()
print search.iterative_deepening_search(ab).path()
print search.depth_limited_search(ab).path()
print search.depth_limited_search(ab).path()
print("Branch_and_Bound ab")
print search.branch_and_bound_search(ab).path()
print("Branch_and_Bound_with_Subestimation ab")
print search.branch_and_bound_with_subestimation_search(ab).path()

print("Branch_and_Bound af")
print search.branch_and_bound_search(af).path()
print("Branch_and_Bound_with_Subestimation af")
print search.branch_and_bound_with_subestimation_search(af).path()



# Result:
# [<Node B>, <Node P>, <Node R>, <Node S>, <Node A>] : 101 + 97 + 80 + 140 = 418
# [<Node B>, <Node F>, <Node S>, <Node A>] : 211 + 99 + 140 = 450
コード例 #4
0
# Search methods

import search

ab = search.GPSProblem('A', 'B', search.romania)

print("Breadth-first Search: " +
      str(search.breadth_first_graph_search(ab).path()))
print("Depth-first Search: " + str(search.depth_first_graph_search(ab).path()))

print("\n--------------------Primera parte--------------------\n")

# Estrategia de Ramificación y Acotación (BBS):
print("Branch-and-Bound Search: " +
      str(search.branch_and_bound_search(ab).path()))

# Estrategia de Ramificación y Acotación con subestimación:
print("Branch-and-Bound-with-Underestimates Search: " +
      str(search.branch_and_bound_search_with_und(ab).path()))

# Result:
# Breadth-first Search:     [<Node B>, <Node F>, <Node S>, <Node A>] : 211 + 99 + 140 = 450
# Depth-first Search:       [<Node B>, <Node P>, <Node C>, <Node D>, <Node M>, <Node L>, <Node T>, <Node A>] : 101+138+120+75+70+111+118=733
# Branch-and-Bound Search:  [<Node B>, <Node P>, <Node R>, <Node S>, <Node A>] : 101 + 97 + 80 + 140 = 418

print("\n--------------------Segunda parte--------------------\n")
print("Ejemplo 1: Desde Oradea hasta Bucharest")

ob = search.GPSProblem('O', 'B', search.romania)
print("Branch-and-Bound Search: " +
      str(search.branch_and_bound_search(ob).path()) + "\n")
コード例 #5
0
lg = search.GPSProblem('L', 'G'
                       , search.romania)

print("Traslado de Arad a Bucarest")
print("\nBúsqueda en anchura")
nodeBFS, visitedNodesBFS = search.breadth_first_graph_search(ab)
print("\nRuta obtenida: " + str(nodeBFS.path()))
print("\nNodos visitados: " + str(visitedNodesBFS))

print("\nBúsqueda en profundidad")
nodeDFS, visitedNodesDFS = search.depth_first_graph_search(ab)
print("\nRuta obtenida: " + str(nodeDFS.path()))
print("\nNodos visitados: " + str(visitedNodesDFS))

print("\nComparación entre las búsquedas BnB con y sin subestimación")
nodeBB, visitedNodesBB = search.branch_and_bound_search(ab)
nodeBBS, visitedNodesBBS = search.branch_and_bound_subestimation_search(ab)
print("Sin subestimación: " + str(nodeBB.path()) + "\nCon subestimación: " + str(nodeBBS.path()))
print("Sin subestimación: " + str(visitedNodesBB) + "\nCon subestimación: " + str(visitedNodesBBS))

print("----------------------------------------------------------------------------------------------------------")

print("Traslado de Oradea a Eforie")
print("\nBúsqueda en anchura")
nodeBFS, visitedNodesBFS = search.breadth_first_graph_search(oe)
print("\nRuta obtenida: " + str(nodeBFS.path()))
print("\nNodos visitados: " + str(visitedNodesBFS))

print("\nBúsqueda en profundidad")
nodeDFS, visitedNodesDFS = search.depth_first_graph_search(oe)
print("\nRuta obtenida: " + str(nodeDFS.path()))
コード例 #6
0
ab = search.GPSProblem('A', 'B', search.romania)
ah = search.GPSProblem('A', 'H', search.romania)

node, count = search.breadth_first_graph_search(ab)
print('Busqueda por BFS')
print(node.path(), end='')
print('\nNodos visitados: ' + str(count) + '\n')

node, count = search.depth_first_graph_search(ab)
print('Busqueda por DFS')
print(node.path(), end='')
print('\nNodos visitados: ' + str(count) + '\n')

# Parte 1
node, count = search.branch_and_bound_search(ab)
print('Busqueda por Branch and Bound')
print(node.path(), end='')
print('\nNodos visitados: ' + str(count) + '\n')

# Parte 2
node, count = search.branch_and_bound_SubEstimation_search(ab)
print('Busqueda por Branch and Bound subestimada (heurística)')
print(node.path(), end='')
print('\nNodos visitados: ' + str(count) + '\n')

# Result:
# BFS
# [<Node B>, <Node F>, <Node S>, <Node A>] : 211 + 99 + 140 = 450
# DFS
# [<Node B>, <Node P>, <Node C>, <Node D>, <Node M>, <Node L>, <Node T>, <Node A>] : 101 + 138 + 120 + 75 + 70 + 111 + 118 = 733