• Viernes 29 de Marzo de 2024, 13:57

Autor Tema:  Busqueda Anchura Y Profuncidad  (Leído 7745 veces)

hector_frcs

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
Busqueda Anchura Y Profuncidad
« en: Miércoles 17 de Agosto de 2005, 19:46 »
0
El ejercicio comprende en desarrollar la busqqueda Heuristica, los tipos de anchura y de profundidad en prolog, bueno mira yo se desarrollar los ejercicios pero se  me ha hecho muy complicado desarrollarlos en prolog espero q tu como  un fanatico del prolog me puedas ayudar.

hector_frcs@hotmail.com




Hector

luka_ghost

  • Nuevo Miembro
  • *
  • Mensajes: 2
    • Ver Perfil
Re: Busqueda Anchura Y Profuncidad
« Respuesta #1 en: Jueves 4 de Mayo de 2006, 06:19 »
0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Patron de la busqueda en profundidad
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% resolver (Id_Problema,Solucion)
resolver(Problema,[Eo|Solucion]) :-
   inicial(Problema,Eo),
   resolver(Problema,Eo,[Eo],Solucion).

% resolver(Id_Problema,Ei,Visitados,Solucion)
resolver(Problema,En,_,[]) :-
   final(Problema,En).

resolver(Problema,Ei,Visitados,[En|Es]) :-
   proximo_estado(Problema,Ei,En),
   no_esta(En,Visitados),
   resolver(Problema,En,[En|Visitados],Es).

% Funcion auxiliar
no_esta(_,[]).
no_esta(X,[Y|Ys]) :-
   X \== Y,
   no_esta(X,Ys).

Tambien puedes hacer uso de esta otra variante :

%Resuelve almacenando en 'FoundPath' los movimientos realizados.
solve(Goal,Goal,FoundPath,FoundPath):- !.
solve(State,_Goal,[_Current|Path],_FoundPath):- member(State,Path),!,fail.
solve(State1,Goal,Path,FoundPath):- proximo_estado(hzog, State1,State2), solve(State2,Goal,[State2|Path],FoundPath).

%LLamada inicial para resolver y escribir todas las posibles soluciones
solution(FoundPath):-   
   inicial(hzog, Start),    
   final(hzog, Goal),
   solve(Start,Goal,[Start],FoundPath).

Espero que te haya servido de ayuda
Saludos... ;)