/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000038.xml diagram  at 2008.03.20 15:04:17
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000038 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_v1 = compartment*(v1_k1f*_compartment_PEP_*x[12] - v1_k1r*x[11]);
        rate_v10 = compartment*(v10_k10f*x[5] - v10_k10r*x[3]*_compartment_GlcP_);
        rate_v2 = compartment*(v2_k2f*x[11] - v2_k2r*_compartment_Pyr_*x[6]);
        rate_v3 = compartment*(v3_k3f*x[6]*x[8] - v3_k3r*x[7]);
        rate_v4 = compartment*(v4_k4f*x[7] - v4_k4r*x[12]*x[9]);
        rate_v5 = compartment*(v5_k5f*x[9]*x[0] - v5_k5r*x[10]);
        rate_v6 = compartment*(v6_k6f*x[10] - v6_k6r*x[8]*x[1]);
        rate_v7 = compartment*(v7_k7f*x[1]*x[3] - v7_k7r*x[2]);
        rate_v8 = compartment*(v8_k8f*x[2] - v8_k8r*x[0]*x[4]);
        rate_v9 = compartment*(v9_k9f*x[4]*_compartment_Glc_ - v9_k9r*x[5]);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        _compartment_Glc_ = 500.0; // initial value of $"compartment.Glc"
        _compartment_GlcP_ = 50.0; // initial value of $"compartment.GlcP"
        _compartment_PEP_ = 2800.0; // initial value of $"compartment.PEP"
        _compartment_Pyr_ = 900.0; // initial value of $"compartment.Pyr"
        compartment = 1.0; // initial value of $compartment
        v10_k10f = 4800.0; // initial value of v10_k10f
        v10_k10r = 0.0054; // initial value of v10_k10r
        v1_k1f = 1960.0; // initial value of v1_k1f
        v1_k1r = 480000.0; // initial value of v1_k1r
        v2_k2f = 108000.0; // initial value of v2_k2f
        v2_k2r = 294.0; // initial value of v2_k2r
        v3_k3f = 14000.0; // initial value of v3_k3f
        v3_k3r = 14000.0; // initial value of v3_k3r
        v4_k4f = 84000.0; // initial value of v4_k4f
        v4_k4r = 3360.0; // initial value of v4_k4r
        v5_k5f = 21960.0; // initial value of v5_k5f
        v5_k5r = 21960.0; // initial value of v5_k5r
        v6_k6f = 4392.0; // initial value of v6_k6f
        v6_k6r = 3384.0; // initial value of v6_k6r
        v7_k7f = 880.0; // initial value of v7_k7f
        v7_k7r = 880.0; // initial value of v7_k7r
        v8_k8f = 2640.0; // initial value of v8_k8f
        v8_k8r = 960.0; // initial value of v8_k8r
        v9_k9f = 260.0; // initial value of v9_k9f
        v9_k9r = 389.0; // initial value of v9_k9r
    }

    /*
     * Model variables initial values
     */
    protected double _compartment_Glc_;
    protected double _compartment_GlcP_;
    protected double _compartment_PEP_;
    protected double _compartment_Pyr_;
    protected double rate_v1;
    protected double rate_v10;
    protected double rate_v2;
    protected double rate_v3;
    protected double rate_v4;
    protected double rate_v5;
    protected double rate_v6;
    protected double rate_v7;
    protected double rate_v8;
    protected double rate_v9;
    protected double compartment;
    protected double v10_k10f;
    protected double v10_k10r;
    protected double v1_k1f;
    protected double v1_k1r;
    protected double v2_k2f;
    protected double v2_k2r;
    protected double v3_k3f;
    protected double v3_k3r;
    protected double v4_k4f;
    protected double v4_k4r;
    protected double v5_k5f;
    protected double v5_k5r;
    protected double v6_k6f;
    protected double v6_k6r;
    protected double v7_k7f;
    protected double v7_k7r;
    protected double v8_k8f;
    protected double v8_k8r;
    protected double v9_k9f;
    protected double v9_k9r;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[13];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = x[2];
        y[3] = x[3];
        y[4] = x[4];
        y[5] = x[5];
        y[6] = x[6];
        y[7] = x[7];
        y[8] = x[8];
        y[9] = x[9];
        y[10] = x[10];
        y[11] = x[11];
        y[12] = x[12];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[13];
        this.time = 0.0;
        x[0] = 20.0; // - $"compartment.EIIA"
        x[1] = 20.0; // - $"compartment.EIIAP"
        x[2] = 0.0; // - $"compartment.EIIAPIICB"
        x[3] = 5.0; // - $"compartment.EIICB"
        x[4] = 5.0; // - $"compartment.EIICBP"
        x[5] = 0.0; // - $"compartment.EIICBPGlc"
        x[6] = 2.0; // - $"compartment.EIP"
        x[7] = 0.0; // - $"compartment.EIPHPr"
        x[8] = 25.0; // - $"compartment.HPr"
        x[9] = 25.0; // - $"compartment.HPrP"
        x[10] = 0.0; // - $"compartment.HPrPIIA"
        x[11] = 0.0; // - $"compartment.PyrPI"
        x[12] = 3.0; // - $compartment.EI

        __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)
    {

        __internalRateVarInitFunc_0(time, x);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000038.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_v5+rate_v8;
        result[1] = +rate_v6-rate_v7;
        result[2] = +rate_v7-rate_v8;
        result[3] = +rate_v10-rate_v7;
        result[4] = +rate_v8-rate_v9;
        result[5] = -rate_v10+rate_v9;
        result[6] = +rate_v2-rate_v3;
        result[7] = +rate_v3-rate_v4;
        result[8] = -rate_v3+rate_v6;
        result[9] = +rate_v4-rate_v5;
        result[10] = +rate_v5-rate_v6;
        result[11] = +rate_v1-rate_v2;
        result[12] = -rate_v1+rate_v4;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[13];
        __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 ...