-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreeIsland_ProductMethod
More file actions
50 lines (39 loc) · 1.14 KB
/
ThreeIsland_ProductMethod
File metadata and controls
50 lines (39 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#Product method for Three Islands, Two Wolves, Goat and the Cabbage problem
#Codes by Thilini
from nfa import *
NFA.clear()
Char_ = NFA.spec("""
0
2
0 1 1 2 2
1 2 2 0 0
2 0 0 1 1
""").map(g=int).named("Char")#.visu()
Char = NFA(
{0},
{2},
{
(p,(p,q),q)
for q in range(3)
for p in range(3)
if p != q
},
name = "Three Islands Problem",
worder=tuple
).visu()
NFA.visutext("Product method for Three Islands Problem")
actorsv = W1, W2, G, C, F = "Wolf1", "Wolf2", "Goat", "Cabb", "Farmer"
actors = fset(actorsv)
sysv = [Char.copy().named(x) for x in actorsv]
sds = [{F:(x, y), a:(x, y)} for a in actors for x in (0, 1, 2) for y in (0, 1, 2) if x != y]
def _licit(s):
return F in s if {W1, G} <= s or {W2, G} <= s or {G, C} <= s else True
def prodfilter(A, P, v, Q):
print(f'{invd(Q)[0]} {invd(Q)[1]} {invd(Q)[2]}')
return _licit(invd(Q)[0]) and _licit(invd(Q)[1]) and _licit(invd(Q)[2])
P = NFA.nsprod(*sysv,
sds=sds,
filter=prodfilter
).visu().trim().visu() #can see the previous states
print(repr(P))
P.dnice().trim().visu()