Exemplo n.º 1
0
def searchPathBetweenCities(firstCity, secondCity):
    cities = search.GPSProblem(firstCity, secondCity, search.romania)
    nodeBB, expandedNodesBB = search.branch_and_bound_graph_search(cities)
    nodeBBE, expandedNodesBBE = search.branch_and_bound_estimate_graph_search(cities)

    print("Without heuristic: " + str(nodeBB.path()) + "\nWith heuristic: " + str(nodeBBE.path()))
    print("Without heuristic: " + str(expandedNodesBB) + "\nWith heuristic: " + str(expandedNodesBBE))

    return expandedNodesBB, expandedNodesBBE
Exemplo n.º 2
0
# Search methods

import search

ab = search.GPSProblem('A', 'B', search.romania)
tv = search.GPSProblem('T', 'V', search.romania)
uz = search.GPSProblem('U', 'Z', search.romania)

node,count=search.breadth_first_graph_search(ab)
print("Camino recorrido anchura", node.path(), "Nodos visitados:", count)
print("**************************")
node,count=search.depth_first_graph_search(ab)
print("Camino recorrido profundidad", node.path(), "Nodos visitados:", count)
print("**************************")

node,count=search.branch_and_bound_graph_search(ab)
print("Camino recorrido ramificación y acotación A-B", node.path(), "Nodos visitados:", count)
print("**************************")
node,count=search.branch_and_bound_subestimation_graph_search(ab)
print("Camino recorrido ramificación y acotación con subestimación A-B", node.path(), "Nodos visitados:", count)
print("**************************")

node,count=search.branch_and_bound_graph_search(tv)
print("Camino recorrido ramificación y acotación T-V", node.path(), "Nodos visitados:", count)
print("**************************")
node,count=search.branch_and_bound_subestimation_graph_search(tv)
print("Camino recorrido ramificación y acotación con subestimación T-V", node.path(), "Nodos visitados:", count)
print("**************************")

node,count=search.branch_and_bound_graph_search(uz)
print("Camino recorrido ramificación y acotación U-Z", node.path(), "Nodos visitados:", count)
Exemplo n.º 3
0
nt = search.GPSProblem('N', 'T', search.romania)
eo = search.GPSProblem('E', 'O', search.romania)
zv = search.GPSProblem('Z', 'V', search.romania)

#print("Breadth First Search")
#print search.breadth_first_graph_search(ab).path()

#print("Depth First Search")
#print search.depth_first_graph_search(ab).path()
# print search.iterative_deepening_search(ab).path()
# print search.depth_limited_search(ab).path()

print("Mapa de Carreteras de la Ciudad de Rumanía")
print("De la ciudad A a la ciudad B")
print("Branch and Bound Search")
print search.branch_and_bound_graph_search(ab).path()
print "Se expanden: " + str(search.get_nexpandnodes())

print('\n')

print("Branch and Bound with Underestimation Search")
print search.branch_and_bound_with_underestimation_graph_search(ab, ab.h).path()
print "Se expanden: " + str(search.get_nexpandnodes())

print('\n')

print("De la ciudad C a la ciudad N")
print("Branch and Bound Search")
print search.branch_and_bound_graph_search(cn).path()
print "Se expanden: " + str(search.get_nexpandnodes())
Exemplo n.º 4
0
# Search methods

import search

ab = search.GPSProblem('A', 'B', search.romania)
al = search.GPSProblem('A', 'L', search.romania)
fc = search.GPSProblem('F', 'C', search.romania)

print search.breadth_first_graph_search(ab).path()
print search.depth_first_graph_search(ab).path()
#print search.iterative_deepening_search(ab).path()
#print search.depth_limited_search(ab).path()
print search.branch_and_bound_graph_search(ab).path()
print search.branch_and_bound_with_underestimation(ab).path()
print search.branch_and_bound_graph_search(fc).path()
print search.branch_and_bound_with_underestimation(fc).path()


#print search.astar_search(ab).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
# Search methods

import search

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

print "Breadth Search : "
path, expansion = search.breadth_first_graph_search(ab)
path = [x for x in reversed(path.path())]
print "Ruta : %s --> %d Expansiones" % (path, expansion)

print "\nDepth Search : "
path, expansion = search.depth_first_graph_search(ab)
path = [x for x in reversed(path.path())]
print "Ruta : %s --> %d Expansiones" % (path, expansion)

print "\nBranch and Bound : "
path, expansion = search.branch_and_bound_graph_search(ab)
print path.path()
path = [x for x in reversed(path.path())]
print "Ruta : %s --> %d Expansiones" % (path, expansion)

print "\nSubestimated Branch and Bound : "
path, expansion = search.subestimated_branch_and_bound_graph_search(ab)
path = [x for x in reversed(path.path())]
print "Ruta : %s --> %d Expansiones" % (path, expansion)

# 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
Exemplo n.º 6
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_graph_search(ab).path())
print(search.heuristics_graph_search(ab).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
Exemplo n.º 7
0
        ])

        for way_case in ways:
            orig_node, goal_node = way_case
            problem = search.GPSProblem(orig_node, goal_node, search.romania)

            print('******************************** Way(',
                  orig_node,
                  ', ',
                  goal_node,
                  ')',
                  sep='')

            # bfs_node, num_bfs = search.breadth_first_graph_search(problem)
            # dfs_node, num_dfs = search.depth_first_graph_search(problem)
            bbs_node, vnum_bbs, num_bbs = search.branch_and_bound_graph_search(
                problem)
            bbes_node, vnum_bbes, num_bbes = search.branch_and_bound_with_underestimation_graph_search(
                problem)

            # bfs_node_path = bfs_node.path()
            # dfs_node_path = dfs_node.path()
            bbs_node_path = bbs_node.path()
            bbes_node_path = bbes_node.path()

            # print('BFS: ', bfs_node_path, ', cost = ', bfs_node.path_cost, ', expanded_nodes = ', num_bfs, sep='')
            # print('DFS: ', dfs_node_path, ', cost = ', dfs_node.path_cost, ', expanded_nodes = ', num_dfs, sep='')
            print('BBS: ',
                  bbs_node_path,
                  ', cost = ',
                  bbs_node.path_cost,
                  ', expanded_nodes = ',