prolog中的STRIPS算法不会停止

时间:2015-11-25 01:45:31

标签: prolog artificial-intelligence

我正在学习Prolog,我正在编写STRIPS算法。我正好试着写它,因为它不起作用,不幸的是,我无法理解为什么。 简单地说,程序不会停止,它会认为下一步操作是什么类型但不适用它。下面,我发布了我的程序代码,我希望有更多经验的人可以让我朝着正确的方向发展。 可能是递归错误但我找不到错误。 谢谢!

计划/ 2和动作/ 4是用世界表示文件写的谓词。

strips(Plan):-
      [worldblock_rap],
      plan(Initstate,Goallist), 
      strip1(Initstate,Goallist,RevPlan,[]),
      reverse(RevPlan, Plan).

%strips(+GoalList, +State, +Plan, +ForbiddenActions
strip1(State,Goallist,_,_):-
    there_is(State, Goallist).

 %strips(+GoalList, +State, +Plan, +ForbiddenActions

strip1(State,Goallist,Plan,ForibiddenActions):-
    %*****choose the right  action******
    action(Ac,Prec,Del,Add),
    there_is(Goal, Goallist),
        \+there_is(Goal, State),
    there_is(Add,Goal),
    \+belongs(Ac,ForibiddenActions),
    %*****************
    %******achive its precondition*******
    strip1(TmpState1,Prec,TmpPlan1,[Ac| ForibiddenActions]),
    %********************************
    %***********Update the new plan with precondition's subplan and this   action 
    apply_rule(Ac,Del,Add,TmpState1,NewState),
    append([Ac|TmpPlan1], Plan, NewPlan),
    strip1(NewState,Goallist,NewPlan,[Ac|ForibiddenActions]).

apply_rule(Ac,Dellist,Addlist,State,NewState):-
    nl,write("doing"), write(Ac), ttyflush,
    delete_list(State, Dellist,TmpState),
    append(Addlist,TmpState,NewState).

reverse([],A,A).
reverse([X|L],L1,A):-reverse(L,[X|L1],A).

delete_list([H|T], List, Final):-
    remove(H, List, Tmp),
    delete_list(T, Tmp, Final).
delete_list([], List, List).

remove(X, [X|T], T).
remove(X, [H|T], [H|R]):-
    remove(X, T, R).

append([H|T], L1, [H|L2]):-
    append(T, L1, L2).
append([], L, L).

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

there_is([], _).
there_is([X|T], L):-
    belongs(X, L),
    there_is(T, L).

1 个答案:

答案 0 :(得分:0)

这是世界区块代表的谓词:

plan([on(a,d),on(b,table),on(c,b),on(d,table),top(a),top(c)],
    [on(a,table),on(b,a),on(c,b),on(d,c),top(d)]).

action(putdown(X),
    [top(X)],
    [top(X),on(X,Y)],
    [on(X,table),top(Y)]).

action(pickup(X,Y),
    [on(X,table),top(Y)],
    [on(X,table),top(Y)],
    [on(X,Y),top(X)]).

下面是猴子世界的另一个代表。此计划程序也无法使用此文件。

plan([at(monkey,a),at(box,c),on(monkey,floor),on(box,floor),status(banana,notpick),at(banana,d)],
    [on(monkey,box),on(box,floor),status(banana,pick),at(banana,d),at(monkey,d),at(box,d)]).

action(
    go(X,Y),
    [at(monkey,X),on(monkey,floor)],
    [at(monkey,X)],
    [at(monkey,Y)]).

action(
    push(B,X,Y),
    [at(monkey,X),at(B,X),on(B,floor),on(monkey,floor)],
    [at(monkey,X),at(B,X)],
    [at(monkey,Y),at(B,Y)]).
action(
    climb_on(B),
    [at(monkey,X),at(box,X),on(monkey,floor),on(box,floor)],
    [on(monkey,floor)],
    [on(monkey,B)]).
action(
    grab(B),
    [status(B,notpick),on(monkey,box),at(B,X),at(monkey,X),at(box,X)],
    [status(B,notpick)],
    [status(B,pick)]).