Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

DI

REDAWAUNI
VERSI
TY

COMPUTERSCI
ENCEDEPARTMENT

Ar
ti
fi
cial
int
ell
i
gence

Assi
gnment
-1
Gr
oupMember
s I
D

1.
yai
cobEshine.
..
..
..
...
..
..
.1201513
2.
yonasdemelash..
..
..
..
..1201609
3.
abebeadugna..
..
..
..
..
..
..1201766
4.
behrusher
efa.
..
...
..
..
..
..
1202081
5.
bir
hanuhruy.
..
..
..
..
..
..
..
.1200030
6.
Eli
asashenafi
..
..
..
..
..
..
.1200210

1.Mi
ssi
onar
y-and-
canni
bal
probl
em
 Thr
eemi ssionari
esandthree
cannibal
sar eononesi deofariv
er
thattheywisht o
cross.Ther eisaboatt hatcanhol d
oneort wopeople.Findanact ion
sequencet hat
bringsev er
yonesafelyt othe
opposi tebank(i
.e.Crosst heri
v er
).
Buty oumustnev er
l
eav eagroupofmi ssionaries
out numberedbycanni balsont he
samebank( i
nany
place) .
I
denti
fyt
hesetofpossi
ble
st
atesandoper
ator
s

Soluti
on: -
State:confi
gurat
ion
ofmi ssionari
es
andcanni balsand
boatoneachsi de
ofriver.
Operat ors:Mov e
boatcont ai
ning
somesetof
occupant sacr oss
theriver( i
neither
dir
ect i
on)t othe
othersi de.
=>INITIALSTATE: -
3mi ssionar i
esand
3cannibalsand
boatonthenear
bank.
=>SUCCEROR
FUNCTION: -
canni
balsmov e
boatcontai
ning
somesetof
occupantsacross
theri
ver(i
net her
dir
ect ion)tothe
othersi de.
=>CONSTRANT: -
missi onarycan
nev erbeout
memberby
canni balsoneither
si
deoft her i
ver
el
set hemi ssi
onary
ki
lled.
=>ACTI ON:-torai
d
theboatwi ththe
maximum t wo
person(1or2)i n
eit
herdirecti
onof
theotherside.
=>GOALTEST: -
mov eallthe
missionaryand
cannibalsacross
theriver.
=>PATHCOST:-
requi
redmi
nimum
numberofmoves.
Twocondit
ionmustbeconsiderwhen
tr
anspor
tmissi
onar
y-and-
cannibal
.

1.Numberofmi ssi
onar yshould
greaterthanorequal to
cannibals(cannibalsshoul dlessthan
missionary )b/ccannibal eats
missionary .
2.Theboatshoul dnotcont ai
nsmore
thantwopassenger .
LetCst andsf orcannibalsandM
standsformi ssionary
.
1.Twocanni balscrossov er:
2. Onecomesback:
3.Twocanni balsgoov eragai
n:
4. Onecomesback: MMMCB
5.Twomi ssionar i
escr oss:
6.
Amissionary&canni balret
urn:
7.
Twomi ssionari
escr ossagain:
8.
Acannibal r
eturns:
9.
Twocanni balscross:
10.
Onereturns:
11Andbringsov erthet hi
rd:
Constructthest
atespaceoft
he
problem usingsui
tabl
e
representati
on
I
nit
ialst
ate
1 2
MMMCCC 00000
CMMM - -
--
--
--
---
-R---
--
---
--
--
>CC
CCMMM <- -
---
--
-I-
- --
--
--
---
--
-C
MMM ---
---
--
--
--
--V---
--
--
---
--
>CCC
CMMM<- -
--
--
--
--E---
--
--
--
---
--
-CC
CM --
--
--
---
--
--
--
--R---
--
--
--
-->CCMM
CCMM <---
--
--
---
--
--
---
--
--
---
--
CM
CC--
--
---
--
--
--
--
---
--
--
---
--
--
---
>MMM
CCC<--
--
--
--
---
--
--
---
--
--
---
--
--
-MMM
C--
--
--
--
--
---
--
--
--
---
--
---
--
--
>CCMMM
CC<--
--
---
--
--
--
---
--
--
---CMMM
000--
--
--
--
--
---
--
--
---
->CCCMMM

2.Goat,Wol fandCabbagepr obl


em
 Afarmerr et
urnsf r
om themar ket,
wher eheboughtagoat ,acabbage
andawol f.On
thewayhomehemustcr ossar i
ver
.
Hi sboatissmal landunabl eto
transportmor e
thanoneofhi spurchases.Hecannot
l
eav ethegoatal onewitht hecabbage
(because
thegoatwoul deati t
),norhecanleav
e
thegoatal onewiththewol f(
because
the
goatwoul dbeeat en).Howcant he
farmergetev er
ythingsafelyonthe
otherside?
Ident
ifythesetofpossi bl
estat
esand
operators
SOLUTI
ON
weshoul
dconsi
dert
hist
hings
1.
cabbageeat
enbygoat
2.
goateat
enbywolf
LetGgoat s,Ccabbage, Ff orf armer
andW f orwol f
.
States:ast ateiscomposedoff our
number srepresentingthenumberof
goats, wolfs,cabbages, boatt r
ips.At
thest artstatethereis(1, 1,1, 1).
Oper ators:fr
om eachst at et he
possi bl
eoper atorsare:movewol f,
movecabbages, movegoat .Int otal
,
therear e4oper ators.(
al so, farmer
hims.
INISIALSTATE: -whent he
farmer ,
goat ,
cabbageandwol ffound
onmar ketsideofr iverthati scall
ed
i
nisialstate.
CONSTRANT: -goatandcabbagenot
foundt ogetherwi thoutf ar
mer .
-wolfandgoatnotf oundt ogetherwith
outfarmer .
ACTI ON:-tocrossr iverindi rect
ionof
home.
GOALTEST: -moveal lthe
cabbage, goat,
wol facr osst heriveri
n
ordertogoi nghome.
PATHCOST: -requiredmi nimum
numberofmoves.

Thef ir
ststepthatmustbet akenisto
l
ett hegoatgoacr osst heriver
,asany
otheract i
onswillr
esultinthegoator
thecabbagebei ngeat en.Whent he
farmerr et
urnstotheor igi
nalside,he
hast hechoiceoftakingei t
herthewol f
ort hecabbageacrossnext .Ifhetakes
thewol facross,
hewoul dhavet o
returntogetthecabbage, r
esulti
ngin
thewol feati
ngthegoat .Ifhetakesthe
cabbageacr osssecond, hewi llneed
tor et
ur ntogett hewol f,resulti
ngin
thecabbagebei ngeatenbyt hegoat .
Thedi lemmai ssolvedbyt akingthe
wol f(
ort hecabbage)overand
bringi
ngt hegoatback.Nowhecan
takethecabbage( orthewol f
)over ,
andf i
nal l
yr eturntof etcht hegoat .
Hisact ionsi nthesol utionar e
summar i
zedi nt hefoll
owi ngst eps:
1.Taket hegoatover
2.Ret urn
3.Taket hewol forcabbageover
4.Ret urnwi tht hegoat
5.Taket hecabbageorwol fover
6.Ret urn
7.Takegoatover
Thust her ear esevencr ossings,four
forwar dandt hreeback.
Constructthest
atespaceoft
he
problem usi
ngsuitabl
e
representat
ion

I
nit
ial
GCW<- -
--
-R---
--
--
--
->000
WC- -
--
--
---
--
--
--
--
I--
---
--
--
--
->FG
FWC<---
--
---
--
--
--
V- -
--
--
--
---
--
G
W----
--
--
--
--
---
--
--
-E---
--
--
--
--
>FCG
FGW<---
---
--
--
--
--
-R---
--
--
---
--
C
G--
---
--
--
---
--
--
--
--
--
--
---
--
--
->FWC
FG<---
--
--
---
--
--
--
--
--
---
--
--
--
-WC
0000-
--
--
--
--
--
--
--
--
--
--
--
--
->FGWC

You might also like