/
partition.pli
65 lines (62 loc) · 1.48 KB
/
partition.pli
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
Gutiérrez-Naranjo, M.A.; Pérez-Jiménez, M.J.; Riscos-Nú˜nez, A. A Fast P System for Finding a Balanced 2-Partition, Soft Computing, 9(9), (2005) 673–678.
*/
@model<membrane_division>
def Partition(n)
{
@mu = [[]'e []'r]'s;
@ms(e) = e{1},g{1};
@ms(r) = b,h{0};
@ms(s) = z{1};
[e{i}]'e --> -[q] +[e{i}] : 1 <= i <= n;
+[e{i}]'e --> [e{i+1}] +[e{i+1}] : 1 <= i <= n-1;
[x{1} --> a{0}]'e;
+[x{1} --> p{0}]'e;
{
+[x{i} --> x{i+1}]'e;
-[x{i} --> p]'e;
} : 2 <= i <= n;
-[q --> q{0}]'e;
-[p{0} --> p]'e;
-[a{0} --> a]'e;
-[g{1}]'e --> -[]g{0};
+[e{n}]'e --> f;
[a{0} --> #]'s;
[p{0} --> #]'s;
[g{1} --> #]'s;
-[a]'e --> []f;
[p]'e --> -[]f;
-[q{0} --> q{1}]'e;
[q{1} --> q{0}]'e;
[q{0}]'e --> +[]No{0};
-[q{1} --> q{2},c]'e;
-[c]'e --> []f;
[q{2} --> q{3}]'e;
[q{3}]'e --> +[]Yes;
-[q{3}]'e --> +[]No{0};
+[p --> f]'e;
+[a --> f]'e;
[z{i} --> z{i+1}]'s : 1 <= i <= 2*n;
[z{2*n+1} --> d{0},d{1}]'s;
d{0}[]'r --> -[d{0}]'r;
[d{1}]'s --> +[]d{1};
+[g{0} --> g]'s;
g +[]'e --> [g]'e;
-[h{0} --> h{1}]'r;
+[h{1} --> h{0}]'r;
[h{1} --> h{0}]'r;
-[b]'r --> +[]b;
g +[]'r --> -[g]'r;
b -[]'r --> [b]'r;
[g]'r --> -[]g;
+[h{0}]'r --> +[]d{2};
+[d{2}]'s --> -[]d{2};
-[No{0} --> No]'s;
-[Yes]'s --> []Yes;
-[No]'s --> []No;
}
def main()
{
call Partition(4);
@ms(e) += x{1}*10,x{2}*5,x{3}*3,x{4}*1;
}