0
votes

I'm learning Prolog and I'm writing STRIPS algorithm. Exactly I try to write it because it doesn’t work and unfortunately, I can't understand why. Simply, the program doesn't stop, it thinks what kind is next action but doesn't apply it. Below, I post a code of my program, I hope that there will be somebody with more experience could put me in right direction. May be the recursion is wrong but I can't find a mistakes. Thank you!

The plan/2 and action/4 are predicate written in world representation file.

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
Can you give us the first predicate to help you for debugging ?Tanorix

1 Answers

0
votes

This the predicate of world block representation:

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)]).

Below there is onother representation of monkey world. Also with this file the planner doesn't work.

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)]).