Esempio n. 1
0
# Search methods

import search

ab = search.GPSProblem('A', 'B'
                       , search.romania)
oc = search.GPSProblem('O', 'C'
                       , search.romania)
sd = search.GPSProblem('S', 'D'
                       , search.romania)
tf = search.GPSProblem('T', 'F'
                       , search.romania)
lp = search.GPSProblem('L', 'P'
                       , search.romania)
nm = search.GPSProblem('N', 'M'
                       , search.romania)

print("Ejecuciones con Busqueda en Anchura")
node, count = search.breadth_first_graph_search(ab)
print(node.path(), end='')
print(" Nº de nodos visitados: ", end='')
print(count)

print("Ejecuciones con Busqueda en Profundidad")
node, count = search.depth_first_graph_search(ab)
print(node.path(), end='')
print(" Nº de nodos visitados: ", end='')
print(count)

print("-----------------------------------------------")
print("Ejecuciones con Nodos A-B")
Esempio 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)
Esempio n. 3
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.acota(ab).path())
print(search.acotaheu(ab).path())

ab = search.GPSProblem('T', 'N', search.romania)

print(search.acota(ab).path())
print(search.acotaheu(ab).path())

ab = search.GPSProblem('Z', 'S', search.romania)

print(search.acota(ab).path())
print(search.acotaheu(ab).path())
#print search.iterative_deepening_search(ab).path()
#print search.depth_limited_search(ab).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
Esempio n. 4
0
# -*- coding: utf-8 -*-

# Search methods
import search

sl = search.GPSProblem('S', 'L', search.romania)

## De Oradea a Giurgiu ##
# Ramificacion y acotacion con subestimacion: 26 (9 expansiones)
# FIFO: 148 (54 expansiones)
# STACK: 31 (tras quitar la lista cerrada hace un bucle infinito)
og = search.GPSProblem('O', 'G', search.romania)

## De Arad a Bucharest ##
# Ramificacion y acotacion con subestimacion: 15 (5 expansiones)
# FIFO: 59 (21 expansiones)
# STACK: 23 (tras quitar la lista cerrada hace un bucle infinito)
ab = search.GPSProblem('A', 'B', search.romania)

## De Craiova a Fagaras ##
# Ramificacion y acotacion con subestimacion: 21 (7 expansiones)
# FIFO: 61 (21 expansiones)
# STACK: 22 (tras quitar la lista cerrada hace un bucle infinito)
cf = search.GPSProblem('C', 'F', search.romania)

result = [0] * 20

result[0] = search.busqueda_ramificacion_subestimacion(ab)
result[1] = search.busqueda_ramificacion_subestimacion(cf)
result[2] = search.busqueda_ramificacion_subestimacion(sl)
result[3] = search.busqueda_ramificacion_subestimacion(og)
Esempio n. 5
0
# Search methods

import search

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

print("A -> B")
node, count = search.ramificacion_acotacion_search(ab)
print("Ramificación y acotación\n", "Camino: ", node.path(),
      " ~ Nodos visitados: ", count)
node, count = search.ram_acot_subest_search(ab)
print("Ramificación y acotación con subestimación\n", "Camino: ", node.path(),
      " ~ Nodos visitados: ", count)

print("\n----------------------------\n")

print("A -> R")

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

node, count = search.ramificacion_acotacion_search(ab)
print("Ramificación y acotación\n", "Camino: ", node.path(),
      " ~ Nodos visitados: ", count)
node, count = search.ram_acot_subest_search(ab)
print("Ramificación y acotación con subestimación\n", "Camino: ", node.path(),
      " ~ Nodos visitados: ", count)

print("\n----------------------------\n")

print("A -> N")
Esempio n. 6
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
Esempio n. 7
0
# Search methods

import search

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

tf = search.GPSProblem('T', 'F', search.romania)

nm = search.GPSProblem('N', 'M', 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 "-----Camino de A a B-----"
print "Sin subestimacion: ", search.Ramificacion_search(ab).path()
print "Con subestimacion: ", search.RamificacionConSubestimacion_search(
    ab).path()

print "-----Camino de T a F-----"
print "Sin subestimacion: ", search.Ramificacion_search(tf).path()
print "Con subestimacion: ", search.RamificacionConSubestimacion_search(
    tf).path()

print "-----Camino de N a M-----"
print "Sin subestimacion: ", search.Ramificacion_search(nm).path()
print "Con subestimacion: ", search.RamificacionConSubestimacion_search(
    nm).path()

#print search.astar_search(ab).path()
Esempio n. 8
0
# Search methods

import search

ab = search.GPSProblem('D', 'F'
                       , search.romania)

print(search.breadth_first_graph_search(ab).path())
print(search.depth_first_graph_search(ab).path())
print(search.my_gestor(ab).path())
print(search.my_best_gestor(ab).path())

# Result:
#20
#[<Node F>, <Node S>, <Node R>, <Node C>, <Node D>] : 99 + 80 + 146 + 120 = 445
#6
#[<Node F>, <Node B>, <Node P>, <Node C>, <Node D>] : 211 + 101 + 138 + 120 = 570
#21
#[<Node F>, <Node S>, <Node R>, <Node C>, <Node D>] : 99 + 80 + 146 + 120 = 445
#13
#[<Node F>, <Node S>, <Node R>, <Node C>, <Node D>] : 99 + 80 + 146 + 120 = 445
Esempio n. 9
0
# Search methods

import search

a = "Lowest cost first:"
b = "Heuristic and cost lower sum first:"

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

oe = search.GPSProblem('O', 'E', search.romania)

so = search.GPSProblem('S', 'O', search.romania)

ln = search.GPSProblem('L', 'N', search.romania)

print("*** Search A -> B ***")
print a
print search.lowest_cost_first_graph_search(ab).path()
print b
print search.heuristic_first_graph_search(ab).path()

print("*** Search O -> E ***")
print a
print search.lowest_cost_first_graph_search(oe).path()
print b
print search.heuristic_first_graph_search(oe).path()

print("*** Search S -> O ***")
print a
print search.lowest_cost_first_graph_search(so).path()
print b
Esempio n. 10
0
# Search methods

import search

ab = search.GPSProblem('A', 'B', search.romania)
cd = search.GPSProblem('C', 'D', search.romania)
ef = search.GPSProblem('E', 'F', search.romania)
gh = search.GPSProblem('G', 'H', search.romania)
"""
print search.breadth_first_graph_search(ab).path() #anchura
print search.depth_first_graph_search(ab).path() #profundidad
print search.iterative_deepening_search(ab).path()
print search.depth_limited_search(ab).path()
"""
print search.ramificacion_search(ab).path()  #ramificacion
print search.ramificacion_subestimacion_search(ab).path()  #ramificacion
print "----------------------------------------------"
print search.ramificacion_search(cd).path()  #ramificacion
print search.ramificacion_subestimacion_search(cd).path()  #ramificacion
print "----------------------------------------------"
print search.ramificacion_search(ef).path()  #ramificacion
print search.ramificacion_subestimacion_search(ef).path()  #ramificacion
print "----------------------------------------------"
print search.ramificacion_search(gh).path()  #ramificacion
print search.ramificacion_subestimacion_search(gh).path()  #ramificacion

#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
Esempio n. 11
0
# Search methods

import search

#ab = search.GPSProblem('SA', 'NT' , search.australia)
ab = search.GPSProblem('A', 'B', search.romania)
ro = search.GPSProblem('R', 'O', search.romania)
sb = search.GPSProblem('S', 'B', search.romania)
tp = search.GPSProblem('T', 'P', search.romania)
vc = search.GPSProblem('V', 'C', search.romania)
zu = search.GPSProblem('Z', 'U', search.romania)

print("------ RECORRIDO ARAD - BUCHAREST ------")
print("Búsqueda en anchura: " + str(search.breadth_first_graph_search(ab).path())) #Anchura
print("Búsqueda en Profundidad" +str(search.depth_first_graph_search(ab).path()))  #Profundidad
print("Búsqueda ramificación y acotación" +str(search.ramificacion_acotacion(ab).path())) #ramificacion y acotacion.
print("Búsqueda ramificación y acotación con subestimación" + str(search.ramificacion_subestimacion(ab).path()))

print("\n------ RECORRIDO ORADEA - RIMNICU VILCEA ------")
print("Búsqueda en anchura: " + str(search.breadth_first_graph_search(ro).path())) #Anchura
print("Búsqueda en Profundidad" +str(search.depth_first_graph_search(ro).path()))  #Profundidad
print("Búsqueda ramificación y acotación" +str(search.ramificacion_acotacion(ro).path())) #ramificacion y acotacion.
print("Búsqueda ramificación y acotación con subestimación" + str(search.ramificacion_subestimacion(ro).path()))

print("\n------ RECORRIDO SIBIU - BUCHAREST ------")
print("Búsqueda en anchura: " + str(search.breadth_first_graph_search(sb).path())) #Anchura
print("Búsqueda en Profundidad" +str(search.depth_first_graph_search(sb).path()))  #Profundidad
print("Búsqueda ramificación y acotación" +str(search.ramificacion_acotacion(sb).path())) #ramificacion y acotacion.
print("Búsqueda ramificación y acotación con subestimación" + str(search.ramificacion_subestimacion(sb).path()))

print("\n------ RECORRIDO TIMISOARA - PITESTI ------")
Esempio n. 12
0
# Search methods

import search

ab = (search.GPSProblem('A', 'B', search.romania))
ld = (search.GPSProblem('L', 'D', search.romania))
sp = (search.GPSProblem('S', 'P', search.romania))
on = (search.GPSProblem('O', 'N', search.romania))
cv = (search.GPSProblem('C', 'V', search.romania))
iu = (search.GPSProblem('I', 'U', search.romania))

print("Resultado de B a A")
print(search.ramificacionYSalto(ab).path())
print(search.ramificacionYSaltoConSubestimacion(ab).path(), "\n")

print("Resultado de D a L")
print(search.ramificacionYSalto(ld).path())
print(search.ramificacionYSaltoConSubestimacion(ld).path(), "\n")

print("Resultado de P a S")
print(search.ramificacionYSalto(sp).path())
print(search.ramificacionYSaltoConSubestimacion(sp).path(), "\n")

print("Resultado de N a O")
print(search.ramificacionYSalto(on).path())
print(search.ramificacionYSaltoConSubestimacion(on).path(), "\n")

print("Resultado de V a C")
print(search.ramificacionYSalto(cv).path())
print(search.ramificacionYSaltoConSubestimacion(cv).path(), "\n")
Esempio n. 13
0
# Search methods

import search

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

print "============================================================"
print "                         A --> B"
#print "Busqueda en anchura"
#print (search.breadth_first_graph_search(ab).path())
#print "____________________________________________________________"
#print "Buqueda en profundidad"
#print (search.depth_first_graph_search(ab).path())
#print search.iterative_deepening_search(ab).path()
#print search.depth_limited_search(ab).path()
print "____________________________________________________________"
print "Busqueda ramificacion y acotacion "
print(search.ramiAcota_first_graph_search(ab).path())
print "____________________________________________________________"
print "Busqueda ramificacion y acotacion con subestimacion"
print(search.ramiAcotaSub_first_graph_search(ab).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
print "============================================================"
print "                         C --> O"
#print "Busqueda en anchura"
Esempio n. 14
0
from __future__ import print_function
import search

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

# print search.breadth_first_graph_search(ab).path()
# print search.depth_first_graph_search(ab).path()
print(search.ramificacion_acotacion_graph_search(ab).path())

print(search.raminifacion_acotacion_graph_search_subestimated(ab).path())
# print search.iterative_deepening_search(ab).path()
# print search.depth_limited_search(ab).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
Esempio n. 15
0
# Search methods

import search

ab = search.GPSProblem('S', 'P', search.romania)

print('Búsqueda anchura')
print(search.breadth_first_graph_search(ab).path())
print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
print('Búsqueda profundidad')
print(search.depth_first_graph_search(ab).path())
print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
print('Rafimifación y salto')
print(search.bab(ab).path())
print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
print('Rafimifación y salto con Subestimacion')
print(search.babSub(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
Esempio n. 16
0
File: run.py Progetto: 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
Esempio n. 17
0
# Search methods

import search

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

print(" _______ANCHURA______")
print(search.breadth_first_graph_search(ab).path())
print()
print("________PROFUNDIDAD___")
print(search.depth_first_graph_search(ab).path())
print()
print("________RAMIFICACIÓN Y ACOTACIÓN______")
print(search.branchAndBound(ab).path())
print()
print("______RAMIFICACIÓN Y ACOTACIÓN CON SUBESTIMACIÓN____")
print(search.branchAndBoundSubestimation(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 """

print("\nTraza del camino AC")

ac = search.GPSProblem('A', 'C', search.romania)

print(search.breadth_first_graph_search(ac).path())  ## anchura
print(search.depth_first_graph_search(ac).path())  ## profundidad
print(search.branchAndBound(ac).path())
print(search.branchAndBoundSubestimation(ac).path())  # Coste+h

print("\nTraza del camino GZ")
Esempio n. 18
0
# Search methods

import search

ab = search.GPSProblem('A', 'B', search.romania)
an = search.GPSProblem('A', 'N', search.romania)
no = search.GPSProblem('N', 'O', search.romania)

print "Trayecto A-B:"
print "Busqueda en anchura: ",search.breadth_first_graph_search(ab).path()
print "Busqueda en profundidad: ",search.depth_first_graph_search(ab).path()
print "Busqueda por Ramificacion y Acotacion: ",search.ram_acot_graph_search(ab).path()
print "Busqueda por Ramificacion y Acotacion con subestimacion: ",search.ram_acot_sub_graph_search(ab).path()

print "\nTrayecto A-N:"
print "Busqueda en anchura: ", search.breadth_first_graph_search(an).path()
print "Busqueda en profundidad: ",search.depth_first_graph_search(an).path()
print "Busqueda por Ramificacion y Acotacion: ",search.ram_acot_graph_search(an).path()
print "Busqueda por Ramificacion y Acotacion con subestimacion: ",search.ram_acot_sub_graph_search(an).path()

print "\nTrayecto N-O:"
print "Busqueda en anchura: ",search.breadth_first_graph_search(no).path()
print "Busqueda en profundidad: ",search.depth_first_graph_search(no).path()
print "Busqueda por Ramificacion y Acotacion: ",search.ram_acot_graph_search(no).path()
print "Busqueda por Ramificacion y Acotacion con subestimacion: ",search.ram_acot_sub_graph_search(no).path()

#print search.iterative_deepening_search(ab).path()
#print search.depth_limited_search(ab).path()

#print search.astar_search(ab).path()
Esempio n. 19
0
# Search methods

import search

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

print('----------Búsqueda en anchura AB------------')
print(search.breadth_first_graph_search(ab).path())
print('----------Búsqueda en profundidad AB------------')
print(search.depth_first_graph_search(ab).path())
print('----------Ramificación y acotación AB ------------')
print(search.ram_aco(ab).path())
print('----------Ramificación y acotación con subestimación AB------------')
print(search.ram_aco_sub(ab).path())

print('********************************************************************')

print('----------Búsqueda en anchura SP------------')
print(search.breadth_first_graph_search(sp).path())
print('----------Búsqueda en profundidad SP------------')
print(search.depth_first_graph_search(sp).path())
print('----------Ramificación y acotación SP------------')
print(search.ram_aco(sp).path())
print('----------Ramificación y acotación con subestimación SP------------')
print(search.ram_aco_sub(sp).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
Esempio n. 20
0
# Search methods

import search

print("Prueba 1 de A a B")
ab = search.GPSProblem('A', 'B', search.romania)

print("Breadth_First:", search.breadth_first_graph_search(ab).path())
print("Depth_First: ", search.depth_first_graph_search(ab).path())
print("Recorrido y profundidad: ", search.recorrido_y_profundidad(ab).path())
print("Recorrido y profundidad con subestimación: ",
      search.recorrido_y_profundidad_subestimacion(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
print("\nPrueba 2 de I a B")
ib = search.GPSProblem('I', 'B', search.romania)

print("Breadth_First:", search.breadth_first_graph_search(ib).path())
print("Depth_First: ", search.depth_first_graph_search(ib).path())
print("Recorrido y profundidad: ", search.recorrido_y_profundidad(ib).path())
print("Recorrido y profundidad con subestimación: ",
      search.recorrido_y_profundidad_subestimacion(ib).path())

print("\nPrueba 3 de C a B")
cb = search.GPSProblem('C', 'B', search.romania)

print("Breadth_First:", search.breadth_first_graph_search(cb).path())
print("Depth_First: ", search.depth_first_graph_search(cb).path())
print("Recorrido y profundidad: ", search.recorrido_y_profundidad(cb).path())
print("Recorrido y profundidad con subestimación: ",
Esempio n. 21
0
# Search methods

import search

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

print(search.breadth_first_graph_search(sb).path())
print(search.depth_first_graph_search(sb).path())
#print (search.iterative_deepening_search(ab).path())
#print (search.depth_limited_search(ab).path())

#print (search.ramification_first_graph_search(ab).path())
print(search.ramification_first_graph_search(sb).path())

print(search.ramification_substimation(sb).path())
print(search.ramification_substimation(sb).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
Esempio n. 22
0
# Search methods

import search

ab = search.GPSProblem('A', 'B', search.romania)
sg = search.GPSProblem('S', 'G', search.romania)
tp = search.GPSProblem('T', 'P', search.romania)

#print "Busqueda en anchura"
#print search.breadth_first_graph_search(ab).path()

#print "Busqueda en profundidad"
#print search.depth_first_graph_search(ab).path()

print "Ramificacion y acotacion"
print search.RamificacionAcotacion(ab).path()

print "Ramificacion y acotacion con heuristica"
print search.RamificacionAcotacionHeuristica(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
Esempio n. 23
0
File: run.py Progetto: Angeles1/FSI
# Search methods

import search

ab = search.GPSProblem('O', 'N', search.romania)

print "---------------------Busqueda en Anchura----------"

print search.breadth_first_graph_search(ab).path()
print "---------------------Busqueda en Profundidad----------"

print search.depth_first_graph_search(ab).path()
#print search.iterative_deepening_search(ab).path()
#print search.depth_limited_search(ab).path()

print "---------------------Branch and Bound----------"
print search.ramificacion_y_acotacion(ab).path()

print "---------------------Branch and Bound subestimated--"
print search.ramificacion_y_acotacion_subestimacion(ab).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
Esempio n. 24
0
# Search methods

import search

print('#' * 15)
print('# A - B #')
print('#' * 15)
ab = search.GPSProblem('A', 'B', search.romania)
print("Busqueda en anchura")
finalNode = search.breadth_first_graph_search(ab)
print('{} {}'.format(finalNode.path(), finalNode.path_cost))
print('-' * 15)
print("Busqueda en profundid")
finalNode = search.depth_first_graph_search(ab)
print('{} {}'.format(finalNode.path(), finalNode.path_cost))
print('-' * 15)
print("Branch and Bound")
finalNode = search.bnb(ab)
print('{} {}'.format(finalNode.path(), finalNode.path_cost))
print('-' * 15)
print("Branch and Bound con subestimacion")
finalNode = search.bnb_subestimation(ab)
print('{} {}'.format(finalNode.path(), finalNode.path_cost))
print('-' * 15)

print('#' * 15)
print('# T - R #')
print('#' * 15)
tr = search.GPSProblem('T', 'R', search.romania)
print("Busqueda en anchura")
finalNode = search.breadth_first_graph_search(tr)
Esempio n. 25
0
# Search methods
# -*- coding: utf-8 -*-
import search

ab = search.GPSProblem('A', 'B', search.romania)
cn = search.GPSProblem('C', 'N', search.romania)
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')
# Search methods

import search

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

oe = search.GPSProblem('O', 'E', search.romania)

uo = search.GPSProblem('U', 'O', search.romania)

es = search.GPSProblem('E', 'S', search.romania)

er = search.GPSProblem('E', 'R', search.romania)

print("#######FROM A TO B#######")
print("######Breadth Search#######")
print(search.breadth_first_graph_search(ab).path())
print("######Depth Search#######")
print(search.depth_first_graph_search(ab).path())
print("######Branch and Bound#######")
print(search.RAMACOT_search(ab).path())
print("######Branch and Bound with hint#######")
print(search.RAMACOTHINT_search(ab).path())
print("###################################")
print("#######FROM O TO E#######")
print("######Branch and Bound#######")
print(search.RAMACOT_search(oe).path())
print("######Branch and Bound with hint#######")
print(search.RAMACOTHINT_search(oe).path())
print("###################################")
print("#######FROM U TO O#######")
Esempio n. 27
0
# Search methods

import search

ab = search.GPSProblem('A', 'B', search.romania)
on = search.GPSProblem('O', 'N', search.romania)
lr = search.GPSProblem('L', 'R', search.romania)
hz = search.GPSProblem('H', 'Z', search.romania)
do = search.GPSProblem('D', 'O', search.romania)
lista = [ab, on, lr, hz, do]
while len(lista) > 0:
    x = lista.pop()
    print "\n-----------------------------------------------------------------------"
    print "\nnivel-anchura, FIFO"
    print search.breadth_first_graph_search(x).path()
    print "\nprofundidad-altura, LIFO-pila-stack"
    print search.depth_first_graph_search(x).path()

    #print search.best_first_graph_search(ab,2).path()
    print "\nramificacion y acotacion"
    print search.ramificacionacotacion_first_graph_search(x).path()
    print "\nramificacion y acotacion con subestimacion"
    print search.ramificacionacotacionconsubestimacion_first_graph_search(
        x).path()

    #print search.iterative_deepening_search(ab).path()
    #print search.depth_limited_search(ab).path()

    #print search.astar_search(ab).path()

    # Result:
Esempio n. 28
0
# Search methods

import search

ab = search.GPSProblem('A', 'B', search.romania)
ap = search.GPSProblem('A', 'P', search.romania)
av = search.GPSProblem('A', 'V', search.romania)
ag = search.GPSProblem('A', 'G', search.romania)


print search.graph_searchRA(ab).path()

print search.graph_searchRAS(ab).path()

print search.graph_searchRA(ap).path()

print search.graph_searchRAS(ap).path()

print search.graph_searchRA(av).path()

print search.graph_searchRAS(av).path()

print search.graph_searchRA(ag).path()

print search.graph_searchRAS(ag).path()


# print ab.h(search.Node(ab.initial))

#print search.iterative_deepening_search(ab).path()
#print search.depth_limited_search(ab).path()
Esempio n. 29
0
# Search methods

import search

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

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

print(search.ramificación_y_acotación(ab).path())
print(search.ramificación_y_acotación_con_subestimación(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
Esempio n. 30
0
# Search methods

import search

ab = search.GPSProblem('A', 'B', search.romania)
an = search.GPSProblem('A', 'N', search.romania)
on = search.GPSProblem('O', 'N', search.romania)
ob = search.GPSProblem('O', 'B', search.romania)
aa = search.GPSProblem('A', 'A', search.romania)

outfile = open('Busquedas.txt', 'w')

print "Camino A-B: "
outfile.write("Camino A-B:\n")
outfile.write("Busqueda primero en anchura --> ")
outfile.close()
print search.breadth_first_graph_search(ab).path()
outfile = open('Busquedas.txt', 'a')
outfile.write("Busqueda primero en profundidad --> ")
outfile.close()
print search.depth_first_graph_search(ab).path()
outfile = open('Busquedas.txt', 'a')
outfile.write("Ramificacion y acotacion --> ")
outfile.close()
print search.busqueda1(ab).path()
outfile = open('Busquedas.txt', 'a')
outfile.write("Ramificacion y acotacion con subestimacion --> ")
outfile.close()
print search.busqueda(ab).path()

outfile = open("Busquedas.txt", 'a')