Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.92 KB | None | 0 0
  1. %   Figure 17.5  A simple means-ends planner.
  2.  
  3. %   A simple means-ends planner
  4. %   plan( State, Goals, Plan, FinalState)
  5.  
  6. plan( State, Goals, [], State)  :-                 % Plan is empty
  7.   satisfied( State, Goals).                        % Goals true in State
  8.  
  9. %  The way plan is decomposed into stages by conc, the
  10. %  precondition plan (PrePlan) is found in breadth-first
  11. %  fashion. However, the length of the rest of plan is not
  12. %  restricted and goals are achieved in depth-first style.
  13.  
  14. plan( State, Goals, Plan, FinalState)  :-
  15.   conc( PrePlan, [Action | PostPlan], Plan),        % Divide plan
  16.   select( State, Goals, Goal),                      % Select a goal
  17.   achieves( Action, Goal),                          % Relevant action
  18.   can( Action, Condition),
  19.   plan( State, Condition, PrePlan, MidState1),      % Enable Action
  20.   apply( MidState1, Action, MidState2),             % Apply Action
  21.   plan( MidState2, Goals, PostPlan, FinalState).    % Achieve remaining goals
  22.  
  23. % satisfied( State, Goals): Goals are true in State
  24.  
  25. satisfied( State, []).
  26.  
  27. satisfied( State, [Goal | Goals])  :-
  28.   member( Goal, State),
  29.   satisfied( State, Goals).
  30.  
  31. select( State, Goals, Goal)  :-
  32.   member( Goal, Goals),
  33.   not member( Goal, State).                % Goal not satisfied already
  34.  
  35. % achieves( Action, Goal): Goal is add-list of Action
  36.  
  37. achieves( Action, Goal)  :-
  38.   adds( Action, Goals),
  39.   member( Goal, Goals).
  40.  
  41. % apply( State, Action, NewState): Action executed in State produces NewState
  42.  
  43. apply( State, Action, NewState)  :-
  44.   deletes( Action, DelList),
  45.   delete_all( State, DelList, State1), !,
  46.   adds( Action, AddList),
  47.   conc( AddList, State1, NewState).
  48.  
  49. %  delete_all( L1, L2, Diff) if Diff is set-difference of L1 and L2
  50.  
  51. delete_all( [], _, []).
  52.  
  53. delete_all( [X | L1], L2, Diff)  :-
  54.   member( X, L2),  !,
  55.   delete_all( L1, L2, Diff).
  56.  
  57. delete_all( [X | L1], L2, [X | Diff])  :-
  58.   delete_all( L1, L2, Diff).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement