我需要用STRIP做一个自己的shakey,
我需要在action中附加类似于room1 \= room2, 这样的语句来完成让机器人去找箱子然后推箱子到指定屋子room1里头。
现在我用twig运行后,他不能运行。我不知道哪里错了,能帮我改正么?
我需要在action中附加类似于room1 \= room2, 这样的语句来完成让机器人去找箱子然后推箱子到指定屋子room1里头。
现在我用twig运行后,他不能运行。我不知道哪里错了,能帮我改正么?
- 代码:
test_shakey :-
plan([v1-state(room1,room2)],
[v1-state(Room,room1)],
Plan,_),
print_plan(Plan).
action(move_to(hall),
% precondition
[ v1-state(Rloc,Loc)],
% add list
[ v1-state(hall,Loc)],
% delete list
[ v1-state(Rloc,Loc)]) :-
Loc \= room1,
Rloc \= Loc,
Rloc \= hall.
action(move_to(Loc),
% preconditions
[ v1-state(hall,Loc) ],
% add list
[ v1-state(Loc,Loc)],
% delete list
[ v1-state(hall,Loc)]) :-
Loc \= room1,
Loc \= hall.
action(push_box(hall,room1),
% preconditions
[ v1-state(hall,hall) ],
% add list
[ v1-state(room1,room1)],
% delete list
[ v1-state(hall,hall)]).
action(push_box(Loc,hall),
% preconditions
[ v1-state(Loc,Loc) ],
% add list
[ v1-state(hall,hall)],
% delete list
[ v1-state(Loc,hall)]) :-
Loc \= room1,
Loc \= hall.
%%
%% DO NOTE MODIFY ANY OF THE CODE BELOW
%%
:- public test_shakey/0.
print_plan(Plan) :-
(member(Action, Plan), write(Action), nl, fail) ; true.
plan(Goals, State, [], State) :-
subset(Goals, State),!.
plan(Goals, Initial, Plan, Final) :-
pick_action(Action,
Initial, Goals,
Preconditions, AddList, DeleteList),
plan(Preconditions, Initial, StartPlan, BeforeState),
simulate(AddList, DeleteList, BeforeState, AfterState),
plan(Goals, AfterState, EndPlan, Final),
append(StartPlan, [Action | EndPlan], Plan).
pick_action(Action,
Initial, Goals,
Preconditions, AddList, DeleteList) :-
unsatisfied_goal(Goal, Goals, Initial),
action(Action, Preconditions, AddList, DeleteList),
member(Goal, AddList).
%% unsatisfies_goal(?Goal, +GoalList, +State)
% True if Goal is in GoalList and not in State.
unsatisfied_goal(Goal, GoalList, State) :-
member(Goal, GoalList),
\+ member(Goal, State).
%% simulate(+Action, +State, -NewState)
% True if running Action in State would result in NewState.
simulate(AddList, DeleteList, State, NewState):-
subtract(State, DeleteList, TmpState),
union(AddList, TmpState, NewState).
%%
%% Set utilities
%%
%% subset(+Sub, +Super)
% True if Sub is a Subset of Super.
subset([], _).
subset([First | Rest], Super) :-
member(First, Super),
subset(Rest, Super).
%% subtract(Set, RemoveSet, ResultSet)
% True if ResultSet is all elements of Set that aren't in RemoveSet.
subtract([], _, []).
subtract([ First | Rest ], Remove, [ First | RestResult ]) :-
\+ member(First, Remove),
!,
subtract(Rest, Remove, RestResult).
subtract([ _ | Rest], Remove, RestResult) :-
subtract(Rest, Remove, RestResult).
%% union(Set1, Set2, Result)
% True if Result is the union of Set1 and Set2.
union([], Set, Set).
union([ First | Rest ], Set, [ First | RestResult ]) :-
\+ member(First, Set),
!,
union(Rest, Set, RestResult).
union([ _ | Rest ], Set, Result) :-
union(Rest, Set, Result).
:- external action/4.