home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e051 / 2.ddi / EXAMPLES / MAB.OPS < prev    next >
Encoding:
Text File  |  1987-08-08  |  9.3 KB  |  349 lines

  1. ;;;; new monkeys and bananas MAB5
  2. ;;;
  3. ;;; there is a planning phase and an execution phase
  4.  
  5. #|    to grab object1, stand on object two
  6.     to stand on object2, move object two to place, and climb
  7.     to move object2 to place, go to object2
  8.     to go to object two, etc.
  9.     try to have conjunctive goals
  10.     need goal satisfaction routine
  11.     remove pending routine
  12.     make plan to plan
  13.     make execute to execute
  14. |#
  15.  
  16. (literalize monkey
  17.     at
  18.     on
  19.     holds)
  20.  
  21.  
  22. (literalize object
  23.     name
  24.     class
  25.     at
  26.     weight
  27.     size
  28.     on)
  29.  
  30. (literalize goal
  31.     id
  32.     status        ;satisfied, active, pending
  33.     typ        ;hold, move, grab, on, climb
  34.     class
  35.     object
  36.     to
  37.     at
  38.     pending-on)
  39.  
  40. (vector-attribute pending-on)
  41.  
  42. (p get-class-of-object
  43.     (plan)
  44.     {<ingoal> (goal ^status active ^typ hold ^class <w>)}
  45.     (object ^class <w> ^name <u> ^at <p>)
  46.     --> 
  47.     (bind <name>)
  48.     (make goal ^id <name> ^status active ^typ grab ^object <u> ^at <p>)
  49.     (modify <ingoal> ^status pending ^object <u> ^pending-on <name>)) 
  50.  
  51. (p get-object-on-floor
  52.     (plan)
  53.     {<ingoal> (goal ^status active ^typ grab ^object <w> ^at <p>)}
  54.     (object ^name <w> ^at <p> ^on floor)
  55.     --> 
  56.     (bind <name>)
  57.     (make goal ^id <name> ^status active ^typ move ^object self ^to <p>)
  58.     (modify <ingoal> ^status pending ^pending-on <name>))
  59.  
  60.  
  61. (p get-object-on-ceiling
  62.     (plan)
  63.     {<ingoal> (goal ^status active ^typ grab ^object <w> ^at <p>)}
  64.     (object ^name <w> ^at <p> ^on ceiling)
  65.     (object ^class << furniture tool >> ^name <implement> ^size large
  66.         ^weight light ^at <q>)
  67.     --> 
  68.     (bind <name>)
  69.     (make goal ^id <name> ^status active ^typ on ^object <implement>
  70.            ^at <p>)
  71.     (modify <ingoal> ^status pending ^pending-on <name>))
  72.  
  73. (p get-on-object
  74.     (plan)
  75.     {<ingoal> (goal ^status active ^typ on ^object <implement> ^at <p>)}
  76.      -->
  77.     (bind <name>)
  78.     (make goal ^id <name> ^status active ^typ climb
  79.            ^object <implement> ^at <p>)
  80.     (modify <ingoal> ^status pending ^pending-on <name>))
  81.  
  82.  
  83. (p able-to-climb-on-object
  84.     (plan)
  85.     {<ingoal> (goal ^status active ^typ climb ^object <implement>
  86.             ^at <p>)}
  87.      -->
  88.     (bind <name1>)
  89.     (bind <name2>)
  90.     (bind <name3>)
  91.     (make goal ^id <name1> ^status active ^typ move
  92.            ^object <implement> ^to <p>)
  93.     (make goal ^id <name2> ^status pending ^typ move ^object self
  94.            ^to <p> ^pending-on <name1>)
  95.     (make goal ^id <name3> ^status pending ^typ hold ^object nil
  96.            ^at <p> ^pending-on <name1> <name2>)
  97.     (modify <ingoal> ^status pending
  98.              ^pending-on <name1> <name2> <name3>))
  99.  
  100.  
  101. (p move-implement-to-scene
  102.     (plan)
  103.     {<ingoal>(goal ^status active ^typ move ^object <implement>
  104.             ^to <p>)}
  105.     (object ^name <implement> ^at {<q> <> <p>})
  106.      -->
  107.     (bind <name1>)
  108.     (bind <name2>)
  109.     (bind <name3>)
  110.     (bind <name4>)
  111.     (make goal ^id <name1> ^status active ^typ move ^object self
  112.            ^to <q>)
  113.     (make goal ^id <name2> ^status pending ^typ hold ^object nil
  114.            ^at <q> ^pending-on <name1>)
  115.     (make goal ^id <name3> ^status pending ^typ grab
  116.            ^object <implement> ^at <q> ^pending-on <name1> <name2>)
  117.     (make goal ^id <name4> ^status pending ^typ move
  118.            ^object self ^to <p> ^pending-on <name3>)
  119.     (modify <ingoal> ^status pending ^pending-on <name4>))
  120.  
  121. (p move-self-to-scene
  122.     (plan)
  123.     {<ingoal> (goal ^status active ^typ move ^object self
  124.             ^to {<q> <> floor})}
  125.     {<monk> (monkey ^on {<x> <> floor} ^at {<p> <> <q>})}
  126.    -->
  127.     (bind <name>)
  128.     (make goal ^id <name> ^status active ^typ move ^object self
  129.            ^to floor ^at <p>)
  130.     (modify <ingoal> ^status pending ^pending-on <name>))
  131.  
  132.  
  133. (p move-down-to-scene
  134.     (plan)
  135.     {<ingoal> (goal ^status active ^typ move ^object self
  136.             ^to {<q> <> floor})}
  137.     {<monk> (monkey ^on {<x> <> floor} ^at <q>)}
  138.    -->
  139.     (modify <ingoal> ^to floor ^at <q>))
  140.  
  141.  
  142. ;;;;;;;;;;;;;;;;;;; EXECUTION PHASE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  143.  
  144. ;;;;;;;;;;;;; for converting pending to active ;;;;;;;;;;;;;;;;;
  145. ;;; goals pending on other goals list the other goals under the ;;;
  146. ;;; pending-on attribute.  We can detect and remove satisfied   ;;;
  147. ;;; dependencies one at a time, beginning with the first in the ;;;
  148. ;;; the list and placing nil at the end of the list for each    ;;;
  149. ;;; satisfied dependency.                                       ;;;
  150. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  151.  
  152. (p shift-from-planning
  153.     {<pwme> (plan)}
  154.     {<init> (init-done)}
  155.    -->
  156.     (remove <pwme> <init>)
  157.     (make executing)
  158.     (write (crlf)
  159.   "The plan is complete.  To see the plan, use the (WM) command." (crlf)
  160.   "To execute the plan, use the (RUN) command." (crlf))
  161.     (halt))
  162.  
  163. (p pending-to-active
  164.     (executing)
  165.     {<pgoal>
  166.     (goal ^status pending ^pending-on <other-goal>)}
  167.     (goal ^id <other-goal> ^status satisfied)
  168.     -->
  169.     (bind <x> (litval pending-on))
  170.     (bind <x> (compute <x> + 1))
  171.     (modify <pgoal> ^pending-on (substr <pgoal> <x> inf) nil))
  172.  
  173. (p nil-pending
  174.     (executing)
  175.     {<pgoal>
  176.     (goal ^status pending ^pending-on nil)}
  177.     -->
  178.     (modify <pgoal> ^status active))
  179.  
  180. ;;;;;;;;;;;;;; converting standard active goals to satisfied ;;;;;;;
  181.  
  182. (p drop-object
  183.     (executing)
  184.     {<ingoal> (goal ^status active ^typ hold ^object nil)}
  185.     {<monk> (monkey ^holds {<x> <> nil})}
  186.     {<obj> (object ^name <x>)}
  187.     -->
  188.     (write (crlf) monkey drops <x> (crlf))
  189.     (modify <monk> ^holds nil)
  190.     (modify <obj> ^on floor)
  191.     (modify <ingoal> ^status satisfied))
  192.  
  193. (p no-object-to-drop
  194.     (executing)
  195.     {<ingoal> (goal ^status active ^typ hold ^object nil)}
  196.     {<monk> (monkey ^holds nil)}
  197.     -->
  198.     (modify <ingoal> ^status satisfied))
  199.  
  200.  
  201. (p holds-now
  202.     (executing)
  203.     {<ingoal> (goal ^status active ^typ hold ^object <x>)}
  204.     {<obj> (object ^name <x> ^weight light)}
  205.     {<monk> (monkey)}
  206.     -->
  207.     (modify <monk> ^holds <x>)
  208.     (modify <obj> ^on monkey)
  209.     (write (crlf) monkey holds <x> (crlf))
  210.     (modify <ingoal> ^status satisfied))
  211.  
  212. (p holds-fails
  213.     (executing)
  214.     {<ingoal>
  215.     (goal ^status active ^typ hold ^object <x>)}
  216.     (object ^name <x> ^weight heavy)
  217.     -->
  218.     (write (crlf) <x> too heavy for monkey (crlf)))
  219.  
  220. (p move-done
  221.     (executing)
  222.     {<ingoal>
  223.     (goal ^status active ^typ move ^object <x> ^to <p>)}
  224.     {<obj> (object ^name <x>)}
  225.     -->
  226.     (modify <obj> ^at <p>)
  227.     (write (crlf) the <x> |is(are)| now at <p> (crlf))
  228.     (modify <ingoal> ^status satisfied))
  229.  
  230. (p move-self-to-floor
  231.     (executing)
  232.     {<ingoal> (goal ^status active ^typ move ^object self ^to floor
  233.             ^at <p>)}
  234.     {<monk> (monkey ^on {<x> <> floor} ^at <p>)}
  235.    -->
  236.     (modify <monk> ^on floor ^at <p>)
  237.     (write (crlf) "Monkey jumps to floor" (crlf))
  238.     (modify <ingoal> ^status satisfied))
  239.  
  240.  
  241. (p move-self
  242.     (executing)
  243.     {<ingoal>
  244.     (goal ^status active ^typ move ^object self ^to <p>)}
  245.     {<monk> (monkey ^on floor)}
  246.     -->
  247.     (modify <monk> ^at <p>)
  248.     (write (crlf) the monkey is now at <p> (crlf))
  249.     (modify <ingoal> ^status satisfied))
  250.  
  251. (p move-self-done
  252.     (executing)
  253.     {<ingoal>
  254.     (goal ^status active ^typ move ^object self ^to <p>)}
  255.     {<monk> (monkey ^on floor ^at <p>)}
  256.     -->
  257.     (modify <ingoal> ^status satisfied))
  258.  
  259. (p grab-object
  260.     (executing)
  261.     {<ingoal> (goal ^status active ^typ grab ^object <x> ^at <p>)}
  262.     {<obj> (object ^name <x> ^at <p>)}
  263.     {<monk> (monkey ^holds nil ^at <p>)}
  264.     -->
  265.     (write (crlf) "monkey grabs" <x> (crlf))
  266.     (modify <monk> ^holds <x>)
  267.     (modify <obj> ^on monkey)
  268.     (modify <ingoal> ^status satisfied))
  269.  
  270. (p gets-on
  271.     (executing)
  272.     {<ingoal> (goal ^status active ^typ on ^object <x> ^at <p>)}
  273.     (object ^name <x> ^at <p>)
  274.     {<monk> (monkey)}
  275.     -->
  276.     (modify <monk> ^on <x>)
  277.     (write (crlf) the monkey is on the <x> (crlf))
  278.     (modify <ingoal> ^status satisfied))
  279.  
  280. (p climb-on-object
  281.     (executing)
  282.     {<ingoal> (goal ^status active ^typ climb ^object <x> ^at <p>)}
  283.     (object ^name <x> ^at <p>)  
  284.     {<monk> (monkey ^at <p> ^holds nil)}
  285.     -->
  286.     (write (crlf) the monkey climbs the <x> (crlf))
  287.     (modify <monk> ^on <x>)
  288.     (modify <ingoal> ^status satisfied))
  289.  
  290. (p got-class-of-object
  291.     (executing)
  292.     {<ingoal> (goal ^status active ^typ hold ^class food ^object <u>)}
  293.     (monkey ^holds <u>)
  294.     --> 
  295.     (write (crlf) the monkey is happy to have the <u> (crlf))
  296.     (modify <ingoal> ^status satisfied)) 
  297.  
  298.  
  299. ;;;;;;;;;;;;;;;;;;; INITIALIZATION PHASE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  300.  
  301.  
  302. (p initialize
  303.     (start)
  304.     -->
  305.     (write (crlf)
  306.       "Make working memory element plan to make a plan." (crlf)))
  307.  
  308. (p initialize-plan
  309.     (plan)
  310.     -->
  311.     (write (crlf)
  312.   "In the monkeys and bananas problem, we begin with a monkey sitting" (crlf)
  313.   "on a couch.  There are some bananas on the ceiling across the room." (crlf)
  314.   "There is also a ladder in a different part of the room.  To solve" (crlf)
  315.   "the problem, we must make a plan the monkey can use to get the" (crlf)
  316.   "bananas.  Type a carriage return to see the room" (crlf))
  317.     (bind <foo> (acceptline))
  318.     (write (crlf) (crlf)
  319. "    1    2    3    4    5    6    7" 
  320.  (crlf) (crlf)
  321. "1"
  322.  (crlf) (crlf)
  323. "2            bananas"
  324.  (crlf) (crlf)) 
  325.     (write
  326. "3"
  327.  (crlf) (crlf)
  328. "4"
  329.  (crlf) (crlf)
  330. "5                          ladder"
  331.  (crlf) (crlf)
  332. "6"
  333.  (crlf)
  334. "                  monkey" (crlf)
  335. "7                   couch" (crlf) (crlf))
  336.     (make monkey ^at loc4-7 ^on couch)
  337.     (make object ^name couch ^at loc4-7 ^weight heavy ^size large
  338.              ^class furniture)
  339.     (make object ^name bananas ^on ceiling ^at loc2-2 ^size small
  340.              ^class food)
  341.     (make object ^name ladder ^on floor ^at loc6-5 ^weight light
  342.              ^size large ^class tool)
  343.     (make init-done)
  344.     (make goal ^id (genatom) ^status active ^typ hold
  345.            ^class food))
  346.  
  347.  
  348. ;;; end mab ;;;
  349.