/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000110.xml diagram  at 2008.03.20 15:08:46
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000110 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        _compartment_0000001_c_ = (compartment_0000001_c0 - x[3] - x[8] - x[5] - x[1])/compartment_0000001_c0;
        _compartment_0000001_totalCyclin_ = x[3] + x[8] + x[4];
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_reaction_0000001 = k1*compartment_0000001;
        rate_reaction_0000002 = compartment_0000001*(k3*_compartment_0000001_c_*x[4] - x[8]*k4);
        rate_reaction_0000003 = compartment_0000001*(k2 + k2u*x[2])*x[4];
        rate_reaction_0000004 = compartment_0000001*((bz + cz*x[3])*x[9] - x[10]*az);
        rate_reaction_0000005 = compartment_0000001*((k6 + x[6])*x[3] - (k5 + x[11])*x[8]);
        rate_reaction_0000006 = compartment_0000001*((bz + cz*x[3])*x[10] - az*x[11]);
        rate_reaction_0000007 = k10*compartment_0000001;
        rate_reaction_0000010 = k12*compartment_0000001;
        rate_reaction_0000011 = (k14*x[3]*x[0] - k15*x[5])*compartment_0000001;
        rate_reaction_0000013 = compartment_0000001*x[2]/Tau;
        rate_reaction_0000014 = compartment_0000001*((bi + ci*x[3])*x[5] - ai*x[1]);
        rate_reaction_0000015 = compartment_0000001*k13*x[0];
        rate_reaction_0000016 = compartment_0000001*k16*k16u*x[1];
        rate_reaction_0000017 = compartment_0000001*x[6]*k11;
        rate_reaction_0000018 = compartment_0000001*k11*x[7];
        rate_reaction_0000019 = compartment_0000001*k9*x[9];
        rate_reaction_0000020 = compartment_0000001*k9*x[10];
        rate_reaction_0000021 = compartment_0000001*k9*x[11];
        rate_reaction_0000022 = compartment_0000001*k8;
        rate_reaction_0000023 = compartment_0000001*(k7 + k7u*x[2])*x[3];
        rate_reaction_000008 = compartment_0000001*((bw + cw*x[3])*x[6] - aw*x[7]);
        rate_reaction_000009 = compartment_0000001*Math.pow(x[3], 2)/(Math.pow(a, 2) + Math.pow(x[3], 2))/Tau;
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        compartment_0000001 = 1.0; // initial value of $compartment_0000001
        compartment_0000001_c0 = 200.0; // initial value of $compartment_0000001.c0
        Tau = 25.0; // initial value of Tau
        a = 4.0; // initial value of a
        ai = 10.0; // initial value of ai
        aw = 10.0; // initial value of aw
        az = 10.0; // initial value of az
        bi = 0.1; // initial value of bi
        bw = 0.1; // initial value of bw
        bz = 0.1; // initial value of bz
        ci = 1.0; // initial value of ci
        cw = 1.0; // initial value of cw
        cz = 1.0; // initial value of cz
        k1 = 300.0; // initial value of k1
        k10 = 10.0; // initial value of k10
        k11 = 1.0; // initial value of k11
        k13 = 1.0; // initial value of k13
        k14 = 1.0; // initial value of k14
        k15 = 1.0; // initial value of k15
        k16 = 2.0; // initial value of k16
        k16u = 25.0; // initial value of k16u
        k2 = 5.0; // initial value of k2
        k2u = 50.0; // initial value of k2u
        k3 = 30.0; // initial value of k3
        k4 = 30.0; // initial value of k4
        k5 = 0.1; // initial value of k5
        k6 = 1.0; // initial value of k6
        k7 = 10.0; // initial value of k7
        k8 = 100.0; // initial value of k8
        k9 = 1.0; // initial value of k9
    }

    /*
     * Model variables initial values
     */
    protected double _compartment_0000001_c_;
    protected double _compartment_0000001_totalCyclin_;
    protected double rate_reaction_0000001;
    protected double rate_reaction_0000002;
    protected double rate_reaction_0000003;
    protected double rate_reaction_0000004;
    protected double rate_reaction_0000005;
    protected double rate_reaction_0000006;
    protected double rate_reaction_0000007;
    protected double rate_reaction_0000010;
    protected double rate_reaction_0000011;
    protected double rate_reaction_0000013;
    protected double rate_reaction_0000014;
    protected double rate_reaction_0000015;
    protected double rate_reaction_0000016;
    protected double rate_reaction_0000017;
    protected double rate_reaction_0000018;
    protected double rate_reaction_0000019;
    protected double rate_reaction_0000020;
    protected double rate_reaction_0000021;
    protected double rate_reaction_0000022;
    protected double rate_reaction_0000023;
    protected double rate_reaction_000008;
    protected double rate_reaction_000009;
    protected double compartment_0000001;
    protected double compartment_0000001_c0;
    protected double Tau;
    protected double a;
    protected double ai;
    protected double aw;
    protected double az;
    protected double bi;
    protected double bw;
    protected double bz;
    protected double ci;
    protected double cw;
    protected double cz;
    protected double k1;
    protected double k10;
    protected double k11;
    protected double k12;
    protected double k13;
    protected double k14;
    protected double k15;
    protected double k16;
    protected double k16u;
    protected double k2;
    protected double k2u;
    protected double k3;
    protected double k4;
    protected double k5;
    protected double k6;
    protected double k7;
    protected double k7u;
    protected double k8;
    protected double k9;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[14];
        y[0] = _compartment_0000001_c_;
        y[1] = x[0];
        y[2] = x[1];
        y[3] = _compartment_0000001_totalCyclin_;
        y[4] = x[2];
        y[5] = x[3];
        y[6] = x[4];
        y[7] = x[5];
        y[8] = x[6];
        y[9] = x[7];
        y[10] = x[8];
        y[11] = x[9];
        y[12] = x[10];
        y[13] = x[11];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[12];
        this.time = 0.0;
        x[0] = 0.0; // - $"compartment_0000001.i"
        x[1] = 0.0; // - $"compartment_0000001.ixp"
        x[2] = 0.0; // - $"compartment_0000001.u"
        x[3] = 0.1; // - $"compartment_0000001.x"
        x[4] = 0.0; // - $"compartment_0000001.y"
        x[5] = 0.0; // - $compartment_0000001.ix
        x[6] = 0.0; // - $compartment_0000001.w0
        x[7] = 0.0; // - $compartment_0000001.w1
        x[8] = 0.1; // - $compartment_0000001.x1
        x[9] = 0.0; // - $compartment_0000001.z0
        x[10] = 0.0; // - $compartment_0000001.z1
        x[11] = 0.0; // - $compartment_0000001.z2

        __internalVarInitFunc_0(time, x);
        __internalRateVarInitFunc_0(time, x);

        return x;
    }

/*
 * code for algebraic rules calculations
 */

/*
 * end of code for algebraic rules calculations
 */

    protected void calculateRates(double time, double[] x)
    {

        __internalVarInitFunc_0(time, x);
        __internalRateVarInitFunc_0(time, x);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000110.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_reaction_0000010-rate_reaction_0000011-rate_reaction_0000015;
        result[1] = +rate_reaction_0000014-rate_reaction_0000016;
        result[2] = -rate_reaction_0000013+rate_reaction_000009;
        result[3] = -rate_reaction_0000005-rate_reaction_0000011+rate_reaction_0000016-rate_reaction_0000023;
        result[4] = +rate_reaction_0000001-rate_reaction_0000002-rate_reaction_0000003;
        result[5] = +rate_reaction_0000011-rate_reaction_0000014;
        result[6] = +rate_reaction_0000007-rate_reaction_0000017-rate_reaction_000008;
        result[7] = -rate_reaction_0000018+rate_reaction_000008;
        result[8] = +rate_reaction_0000002+rate_reaction_0000005;
        result[9] = -rate_reaction_0000004-rate_reaction_0000019+rate_reaction_0000022;
        result[10] = +rate_reaction_0000004-rate_reaction_0000006-rate_reaction_0000020;
        result[11] = +rate_reaction_0000006-rate_reaction_0000021;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[12];
        __internalDyDt_0(time, x, result);
        return result;
    }
    public double[] dy_dt(double time, double[] x)
    {
        this.time = time;
        calculateRates( time,x );

        return calculateResult( time,x );
    }

} // class ...