Lab 1 ai

 Dfs.pl

s[a,b).

s(a,c).

s(b,d).

s(b,e).

s(c,f).

s(c,g).

s(d,h).

s(e,i).

s(e,j).

s(f,k).

goal(f).

goal(j).

solve(Start,Solution):-

breadthfirst([[Start]],Solution).

breadthfirst([[Node | Path] ].[Node|Path]]:-

goal(Node).

breadthfirst([Path | Paths] Solution):-

extend(Path,NewPaths),

write(NewPaths),

nl,

conc(Paths,NewPaths, Paths1),

breadthfirst(Paths1,Solution).

extend([NodePath],NewPaths):-

bagof([NewNode, Node | Path),(s(Node, NewNode),not(member(NewNode, [Node | Path]))),NewPaths),!.

extend([]).

conc([],L,L).

Scanned with OKEN Scanner

bfs.pl

s(a,b).

s(a,c).

s(b,d).

s(b,e).

s(c,f).

s(c,g). /

s(d,h).

s(e,i).

s(e,j).

s(f,k).

goal(f).

goal(j).

member(X,[X|_]).

member(X,_|Tail]):-

member(X,Tail).

solve(Node,Solution):-

depthfirst([],Node,Solution).

depthfirst(Path, Node,[Node | Path]):-

goal(Node).

depthfirst(Path,Node,Sol):-

s(Node,Node1),

not(member(Node1,Path)),

depthfirst([Node | Path], Node1,Sol).

Scanned with OKEN Scanner

conc([X/L1],L2,[X|L3]):-

write('conc'),

write(X),

write(''),

write(L1),

write(' '),

write(L2),

conc(L1,L2,L3).

Scanned with OKEN Scanner

Comments

Popular posts from this blog

Web