
APT.all-test.mac.mac3-planning.soar Maven / Gradle / Ivy
###
### FILE : mac3-planning.soar
###
###
### AUTHOR(3) : John Laird [ Soar 8.1 ]
### AUTHOR(2) : Sayan Bhattacharyya [ Soar 7.0.3 ]
### AUTHOR(1) : Aladin.Akyurek [ Soar 5.1.1 ]
###
###
### CREATED(4) : May 27, 2004
### CREATED(3) : Aug 22, 1996
### CREATED(2) : May 10, 1993
### CREATED(1) : May 21, 1991
###
###
### ABSTRACT. This file provides a Soar system to solve
### the missionaries and cannibals problem. Three missionaries and
### three cannibals come to a river. There is a a boat on their side 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 side of the river.
###
### This version has a more complex state representation than mac1 and
### mac2.soar
### Copying the states is simplier (only copy the holds),
### but operator application is more complex.
multi-attributes holds 3
learn --off
pushd ../default
source simple.soar
source selection.soar
popd
###
### MISSIONARIES-AND-CANNIBALS NAME
###
sp {mac*propose*initialize
(state ^superstate nil
-^name)
-->
( ^operator + =)
( ^name initialize-mac)
}
sp {mac*apply*initialize
(state ^operator.name initialize-mac)
-->
( ^name mac
^holds
^boat
^desired )
( ^type missionaries
^number 3
^opposite
^side )
( ^type cannibals
^number 3
^opposite
^side )
( ^type missionaries
^number 0
^opposite
^side )
( ^type cannibals
^number 0
^opposite
^side )
( ^name leftbank
^opposite-of )
( ^name rightbank
^opposite-of )
}
###
### MISSIONARIES-AND-CANNIBALS PROBLEM SPACE
###
sp {mac*elaborate*problem-space
(state ^name mac)
-->
( ^problem-space )
(
^name missionaries-and-cannibals
^default-state-copy yes
^one-level-attributes boat
^two-level-attributes holds)}
###
### MISSIONARIES-AND-CANNIBALS PROBLEM SPACE OPERATORS:
### MOVE1, MOVE2, AND MOVE11
###
sp {mac*propose*operator*move1
"Moves either a single missionary or a cannibal."
(state ^problem-space.name missionaries-and-cannibals
^holds
^boat )
( ^number { <> 0 }
^side )
-->
( ^operator )
( ^name move1
^holds )}
sp {mac*propose*operator*move2
"Moves either a single missionary or a cannibal."
(state ^problem-space.name missionaries-and-cannibals
^holds
^boat )
( ^number > 1
^side )
-->
( ^operator )
( ^name move2
^holds )}
sp {mac*propose*operator*move11
"Moves either a single missionary or a cannibal."
(state ^problem-space.name missionaries-and-cannibals
^holds
^boat )
( ^type cannibals
^number { <> 0}
^side )
( ^type missionaries
^number { <> 0 }
^side )
-->
( ^operator )
( ^name move11
^holds )}
###
### MOVE OPERATOR IMPLEMENTATION
###
sp {apply*move1
(state ^operator )
( ^name << move1 move11 >>
^holds )
( ^number
^opposite )
( ^number )
-->
( ^number -
(- 1))
( ^number -
(+ 1))}
sp {apply*move2
(state ^operator )
( ^name move2
^holds )
( ^number
^opposite )
( ^number )
-->
( ^number -
(- 2))
( ^number -
(+ 2))}
sp {apply*move-boat
(state ^operator
^boat )
( ^name << move1 move2 move11 >>
^holds.side )
( ^opposite-of )
-->
( ^boat -)}
sp {monitor*move1
(state ^operator )
( ^name << move1 move11 >>
^holds.type )
-->
(write (crlf) | Move one | )}
sp {monitor*move2
(state ^operator )
( ^name move2
^holds.type )
-->
(write (crlf) | Move two | )}
sp {monitor*move-side
(state ^operator )
( ^name << move1 move2 move11 >>
^holds.side )
( ^opposite-of.name
^name )
-->
(write (crlf) | From | | to | )}
###
### MISSIONARIES-AND-CANNIBALS PROBLEM SPACE:
### STATE EVALUATION
###
###
### EVALUATION: STATE FAILURE
###
sp {mac*evaluate*state*failure*more*cannibals
(state ^desired
^holds )
( ^type missionaries
^number { > 0 }
^side )
( ^type cannibals
^number >
^side )
-->
( ^failure )
(write (crlf) |Failure - too many cannibals on side:| )}
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)
-->
( ^failure )
(write (crlf) |Failure - no operators can apply.|)}
sp {mac*evaluate*state*failure*detect-state-duplicate
(state ^holds
^desired )
( ^type missionaries
^number 0
^side )
( ^type cannibals
^number 0
^side )
(state { <> } ^desired
^holds
^tried-tied-operator)
( ^type missionaries
^number 0
^side )
( ^type cannibals
^number 0
^side )
-(state ^superstate )
-->
( ^failure )
(write (crlf) |Failure - Duplicate State.|)}
###
### EVALUATION: STATE SUCCESS/GOAL TEST
###
## This also defines implicitly the desired state
## of the problem.
#
sp {mac*detect*state*success
(state ^desired
^holds )
( ^type missionaries
^number 3
^side )
( ^type cannibals
^number 3
^side )
( ^name rightbank)
-->
( ^success )
(write (crlf) |Success.|)}
###
### 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: | | |)}