Prolog 人工智能语言中文论坛---打造优质Prolog学习交流园地
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Prolog 人工智能语言中文论坛---打造优质Prolog学习交流园地

一个供Prolog爱好者学习与交流的地方


您没有登录。 请登录注册

继续问问题。。。。好像我经常问啊。。。。这回是 STRIP了。。。

3 posters

向下  留言 [第1页/共1页]

xhdengfei



我需要用STRIP做一个自己的shakey,
我需要在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.

Mercury Liao


Admin

没关系,prolog很需要热情的参与者,
发问是好事,哈哈。

xhdengfei 写道:我需要用STRIP做一个自己的shakey,
我需要在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.

http://prolog.longluntan.net

xhdengfei



Very Happy Very Happy Very Happy
不太会啊。。。虽说似乎很简单的样子
Mercury Liao 写道:没关系,prolog很需要热情的参与者,
发问是好事,哈哈。

xhdengfei 写道:我需要用STRIP做一个自己的shakey,
我需要在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.

yauhsien



xhdengfei 写道:我需要用STRIP做一个自己的shakey,
我需要在action中附加类似于room1 \= room2, 这样的语句来完成让机器人去找箱子然后推箱子到指定屋子room1里头。

现在我用twig运行后,他不能运行。我不知道哪里错了,能帮我改正么?

你说的twig是 Microsoft XNA 的twig吗?

http://yauhsien.wordpress.com

yauhsien



我用Swi-Prolog试了,发现用
代码:
?- action(A,Ps,AL,DL).
只能查到基础事实。

你的三个动作 move_to(hall), move_to(Loc), push_box(Loc, hall) 都是规则形式,若改成事实应该可以查到。像 move_to(hall) 的定义,如果我写成
代码:
test_shakey(Place) :-
  plan([v1-state(hall, palace)],
      [v1-state(Place, palace)],
      Plan,_),
  print_plan(Plan).

action(move_to(hall),
  % precondition
  [ v1-state(room1,Loc)],
  % add list
  [ v1-state(hall,Loc)],
  % delete list
  [ v1-state(room1,Loc)]).

action(move_to(door),
  % precondition
  [ v1-state(room2,Loc)],
  % add list
  [ v1-state(door,Loc)],
  % delete list
  [ v1-state(room2,Loc)]).

action(move_to(hall),
  % precondition
  [ v1-state(door,Loc)],
  % add list
  [ v1-state(hall,Loc)],
  % delete list
  [ v1-state(door,Loc)]).
那麽假如我用 test_shakey(room1) 就得到 move_to(hall) ,而若用了 test_shakey(room2) 则得到 move_to(door) 和 move_to(hall) 。

还好我的 "Artificial Intelligence: A Mordern Approach" 95年的书本还留着,可以学到 STRIPS 和 Shakey 。

xhdengfei 写道:我需要用STRIP做一个自己的shakey,
我需要在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.

http://yauhsien.wordpress.com

返回页首  留言 [第1页/共1页]

您在这个论坛的权限:
不能在这个论坛回复主题