两个房间规划师阻止世界Prolog

时间:2015-10-30 04:24:27

标签: prolog planning

我需要一些非常基本的帮助来解决这个问题。我有一个房间规划器,给定一个开始状态和结束状态,它使用递归解决这个问题。但是,我想为两个州(又名房间)解决这个问题。我决定设置标志是我最好的选择,因为房间的每个状态都在房间1或房间2。但是我不知道如何实现这一点。任何人都可以把我推向正确的方向吗?

为了澄清,新的州将是(ontable(X),room1)而不是ontable(X)

:- module( planner,
       [
           plan/4,change_state/3,conditions_met/2,member_state/2,
           move/3,go/2,test/0,test2/0
       ]).

:- [utils].

plan(State, Goal, _, Moves) :-  equal_set(State, Goal),
                write('moves are'), nl,
                reverse_print_stack(Moves).
plan(State, Goal, Been_list, Moves) :-
                move(Name, Preconditions, Actions),
                conditions_met(Preconditions, State),
                change_state(State, Actions, Child_state),
                not(member_state(Child_state, Been_list)),
                stack(Child_state, Been_list, New_been_list),
                stack(Name, Moves, New_moves),
            plan(Child_state, Goal, New_been_list, New_moves),!.

change_state(S, [], S).
change_state(S, [add(P)|T], S_new) :-   change_state(S, T, S2),
                    add_to_set(P, S2, S_new), !.
change_state(S, [del(P)|T], S_new) :-   change_state(S, T, S2),
                    remove_from_set(P, S2, S_new), !.
conditions_met(P, S) :- subset(P, S).

member_state(S, [H|_]) :-   equal_set(S, H).
member_state(S, [_|T]) :-   member_state(S, T).

/* move types */

move(pickup(X), [handempty, clear(X), on(X, Y)],
        [del(handempty), del(clear(X)), del(on(X, Y)),
                 add(clear(Y)), add(holding(X))]).

move(pickup(X), [handempty, clear(X), ontable(X)],
        [del(handempty), del(clear(X)), del(ontable(X)),
                 add(holding(X))]).

move(putdown(X), [holding(X)],
        [del(holding(X)), add(ontable(X)), add(clear(X)),
                  add(handempty)]).

move(stack(X, Y), [holding(X), clear(Y)],
        [del(holding(X)), del(clear(Y)), add(handempty), add(on(X, Y)),
                  add(clear(X))]).

move(goroom1, [handempty], []).
move(goroom1, [holding(X)], []).

move(goroom2, [handempty], []).
move(goroom2, [holding(X)], []).

/* run commands */

go(S, G) :- plan(S, G, [S], []).

test :- go([handempty, ontable(b), ontable(c), on(a, b), clear(c), clear(a)],
              [handempty, ontable(c), on(a,b), on(b, c), clear(a)]).

test2 :- go([handempty, ontable(b), ontable(c), on(a, b), clear(c), clear(a)],
              [handempty, ontable(a), ontable(b), on(c, b), clear(a), clear(c)]).

1 个答案:

答案 0 :(得分:0)

所以我基本上使用了标志来解决它。所以对于每个移动谓词我基本上都添加了room1和room2标志。如果它们是真的那么它就会采取行动。因此,例如在room1中的ontable(X)然后del ontable并在room1中添加holding(X)。我还添加两个谓词在房间之间移动。最大的障碍是从程序逻辑转向状态逻辑。因此,如果handempty在room1,那么它只能移动到room2! @CapelliC感谢您的建议