All Downloads are FREE. Search and download functionalities are using the official Maven repository.

APT.all-test.mac.mac1.soar Maven / Gradle / Ivy

###
### FILE               : mac1.soar
###
###
### AUTHOR             : John Laird  
###
### Last Modified:     : September 17, 1999
###
### ABSTRACT.
### This file provides a Soar system to solve the missionaries and
### cannibals problem.
###
### PROBLEM STATEMENT
### Three missionaries and three cannibals come to a river. There is a a
### boat on their bank of the river that can be used by either one or
### two persons at a time.  This boat must be used to cross the river in
### such a way that cannibals never outnumber missionaries on either
### bank of the river.
###

### DESCRIPTION.
### Simple state representation where the state has two objects: one for
### each bank of the river. Each of these has augmentations for
### missionaries, cannibals, and the boat; with their values being the
### number of the entity type on that bank of the river. This is the
### version covered in Soar 8 Tutorial.  Copying the states is more
### complex (two-level-attributes) than other versions, but initial
### state definition, operator proposal and application are simplier.
###


learn --off

###
### MISSIONARIES-AND-CANNIBALS PROBLEM SPACE:
### INITIAL-STATE
###

sp {mac*elaborate*initial*desired-state
   (state  ^superstate nil)
   -->
   ( ^name mac
        ^left-bank 
        ^right-bank  
        ^desired )
   ( ^missionaries 3
        ^cannibals 3
        ^boat 1
        ^other-bank )
   ( ^missionaries 0
        ^cannibals 0
		  ^boat 0
        ^other-bank )
   ( ^right-bank 
) (
^missionaries 3 ^cannibals 3 ^boat 1) } ### ### PROPOSE MISSIONARIES-AND-CANNIBALS OPERATORS: ### MOVE-MAC-BOAT ### sp {mac*propose*operator*move-mac-boat1 "Moves either a single missionary or a cannibal." (state ^name mac ^<< right-bank left-bank >> ) ( ^{ << cannibals missionaries >> } > 0 ^boat 1) --> ( ^operator + =) ( ^name move-mac-boat ^bank ^ 1 ^boat 1 ^types 1)} sp {mac*propose*operator*move-mac-boat2 "Moves two missionaries or two cannibals." (state ^name mac ^ << right-bank left-bank >> ) ( ^{ << cannibals missionaries >> } > 1 ^boat 1) --> ( ^operator + =) ( ^name move-mac-boat ^bank ^ 2 ^boat 1 ^types 1)} sp {mac*propose*operator*move-mac-boat11 (state ^name mac ^ << right-bank left-bank >> ) ( ^missionaries > 0 ^cannibals > 0 ^boat 1) --> ( ^operator + =) ( ^name move-mac-boat ^bank ^missionaries 1 ^cannibals 1 ^boat 1 ^types 2)} ### ### MOVE-MAC-BOAT OPERATOR IMPLEMENTATION ### sp {apply*move-mac-boat (state ^operator ) ( ^name move-mac-boat ^{ << missionaries cannibals boat >> } ^bank ) ( ^ ^other-bank ) ( ^ ) --> ( ^ - (- )) ( ^ - (+ ))} ### ### MOVE-MAC-BOAT MONITOR OPERATOR AND STATE ### sp {monitor*move-mac-boat (state ^operator ) ( ^name move-mac-boat ^{ << cannibals missionaries >> } ) --> (write (crlf) | Move | | | )} sp {monitor*state*left (state ^name mac ^left-bank ^right-bank ) ( ^missionaries ^cannibals ^boat 1) ( ^missionaries ^cannibals ^boat 0) --> (write (crlf) | M: | |, C: | | B ~~~ | | M: | |, C: | | |)} sp {monitor*state*right (state ^name mac ^left-bank ^right-bank ) ( ^missionaries ^cannibals ^boat 0) ( ^missionaries ^cannibals ^boat 1) --> (write (crlf) | M: | |, C: | | ~~~ B | | M: | |, C: | | |)} ### ### STATE SUCCESS/GOAL DETECTION ### sp {mac*detect*state*success (state ^desired ^ ) ( ^missionaries ^cannibals ) ( ^{ << right-bank left-bank >> } ) ( ^missionaries ^cannibals ) --> (write (crlf) |The problem has been solved.|) (halt)} ### ### STATE FAILURE DETECTION ### sp {mac*evaluate*state*failure*more*cannibals (state ^desired ^<< right-bank left-bank >> ) ( ^missionaries { > 0 } ^cannibals > ) --> (write (crlf) |Failure State.|) ( ^failure )} ### ### SEARCH CONTROL ### sp {mac*apply*move-mac-boat*record*last-operator*types*1 (state ^name mac ^operator ) ( ^name move-mac-boat ^bank ^{ << missionaries cannibals >> } ^types 1) --> ( ^last-operator ) ( ^types 1 ^bank ^type ^number )} sp {mac*apply*move-mac-boat*record*last-operator*types*2 (state ^name mac ^operator ) ( ^name move-mac-boat ^boat ^types 2) --> ( ^last-operator ) ( ^types 2 ^bank )} sp {mac*apply*move-mac-boat*remove*old*last-operator (state ^name mac ^operator ^.other-bank ^last-operator ) ( ^bank ) --> ( ^last-operator -)} ## If failure, undo last opertor sp {mac*select*operator*prefer*inverse*failure*types*1 (state ^name mac ^operator + ^failure ^last-operator ) ( ^name move-mac-boat ^ ^types 1) ( ^types 1 ^type ^number ) --> ( ^operator >)} sp {mac*select*operator*prefer*inverse*failure*types*2 (state ^name mac ^operator + ^failure ^last-operator.types 2) ( ^types 2) --> ( ^operator >)} ## If not failure, avoid last operator sp {mac*select*operator*avoid*inverse*not*failure*1 (state ^name mac ^operator + -^failure ^last-operator ) ( ^types 1 ^ ) ( ^types 1 ^type ^number ) --> ( ^operator < )} sp {mac*select*operator*avoid*inverse*not*failure*2 (state ^name mac ^operator + -^failure ^last-operator.types 2) ( ^types 2) --> ( ^operator < )}