Prolog深度优先搜索?

时间:2014-02-28 13:54:17

标签: prolog

我为深度优先搜索编写了以下Prolog代码:

dfs(OPEN,CLOSE,END):-
        OPEN=[],!,fail
        ;
            OPEN=[X|_],X=END,!,true
            ;
            getChildren(X,[],ChL),CLOSE2=[X|CLOSE],add(ChL,OPEN,CLOSE2,OPENF),
            dfs(OPENF,CLOSE2,END).

getChildren(X,ChL,ChLF):-
    parent(X,Ch),not(member(Ch,ChL)),!,ChL2=[Ch|ChL],
    getChildren(X,ChL2,ChLF)
    ;
    ChLF=ChL.


member(X,[X|_]).
member(X,[_|T]):-
    member(X,T).


add([],OPEN,_,OPENF):-OPENF=OPEN,!.
add(ChL,OPEN,CLOSE,OPENF):-
    ChL=[H|T],not(member(H,OPEN)),not(member(H,CLOSE)),!,
    OPEN2=[H|OPEN],add(T,OPEN2,CLOSE,OPENF)
    ;
    ChL=[_|T],add(T,OPEN,CLOSE,OPENF).

但是,我收到以下错误:

the variable is not bounded in this clause  X

0 个答案:

没有答案