
APT.all-test.mac.mac1-planning.soar Maven / Gradle / Ivy
###
### FILE : mac1.soar
###
###
### AUTHOR : John Laird
###
### Last Modified: : September 16, 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 is simplier.
###
learn --on
pushd ../default
source simple.soar
source selection.soar
popd
###
### MISSIONARIES-AND-CANNIBALS NAME
###
sp {top-state*elaborate*missionaries-and-cannibals
(state ^superstate nil)
-->
( ^name mac)}
###
### MISSIONARIES-AND-CANNIBALS PROBLEM SPACE
###
sp {mac*elaborate*problem-space
(state ^name mac)
-->
( ^problem-space )
(
^name missionaries-and-cannibals
^default-state-copy yes
^two-level-attributes right-bank left-bank)}
###
### MISSIONARIES-AND-CANNIBALS INITIAL-STATE
###
sp {mac*elaborate*initial-state
(state ^superstate nil
^name mac)
-->
( ^right-bank
^left-bank
^desired )
( ^missionaries 0
^cannibals 0
^boat 0
^other-bank )
( ^missionaries 3
^cannibals 3
^boat 1
^other-bank )
( ^right-bank )
( ^missionaries 3
^cannibals 3
^boat 1)
}
###
### MISSIONARIES-AND-CANNIBALS OPERATORS:
###
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 OPERATOR IMPLEMENTATION
###
sp {apply*move-mac-boat
(state ^operator )
( ^name move-mac-boat
^{ << missionaries cannibals boat >> }
^bank
^types )
( ^
^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 )
-->
( ^success )
(write (crlf) |Success!|)}
###
### STATE FAILURE DETECTION
###
sp {mac*evaluate*state*failure*more*cannibals
(state ^desired
^<< right-bank left-bank >> )
( ^missionaries { > 0 }
^cannibals > )
-->
(write (crlf) |Failure!|)
( ^failure )}
sp {mac*evaluate*state*failure*state-no-change
(state ^desired
^problem-space.name missionaries-and-cannibals)
(state ^superstate
^attribute state
^quiescence t
^impasse no-change)
-->
(write (crlf) |######## STATE NO-CHANGE Failure! #########|)
( ^failure )}
###
### DUPLICATE STATE DETECTION
###
sp {mac*evaluate*state*failure*duplicate
(state ^desired
^right-bank
^left-bank )
( ^missionaries ^cannibals ^boat )
( ^missionaries ^cannibals ^boat )
(state { <> }
^right-bank
^left-bank
^tried-tied-operator)
( ^missionaries ^cannibals ^boat )
( ^missionaries ^cannibals ^boat )
-(state ^superstate )
-->
(write (crlf) |Duplicate State Detected.|)
( ^failure )}
###
### SEARCH CONTROL
### Commented out because not required with look-ahead
#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 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 -)}
#######
sp {monitor*move-mac-boat*evaluation
(state ^operator )
( ^name evaluate-operator
^operator )
( ^name move-mac-boat
^{ << cannibals missionaries >> } )
-->
(write (crlf) | Evaluate move | | | )}