Partition - Active membranes

Description

Well-known Partition problem, solved with P systems with active membranes.

Model in P-Lingua

The corresponding P-Lingua file is the following:

/*
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;
}

Files

  • The example does not need input data from any user nor speficic interesting outputs, so it can be run from the general app yet available and pre-loaded in MeCoSim.
  • **Model file**, P-Lingua file with the code above.
  • As in the case of the app, no scenario file with specific input is needed, so the general dummy scenario file can also be used.