/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000034.xml diagram  at 2008.03.20 15:04:13
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000034 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_reaction_0000001 = compartment_0000002*(parameter_0000027*x[13] + parameter_0000031);
        rate_reaction_0000002 = _compartment_0000002_compartment_0000001_*(parameter_0000028*x[12] + parameter_0000032);
        rate_reaction_0000003 = _compartment_0000002_compartment_0000001_*delay(0, time - (parameter_0000039));
        rate_reaction_0000004 = _compartment_0000002_compartment_0000001_*(parameter_0000030*(Math.pow(x[5], 2.0)/(Math.pow(x[5], 2.0) + Math.pow(parameter_0000010, 2.0)))*(Math.pow(parameter_0000008, 2.0)/(Math.pow(x[3], 2.0) + Math.pow(parameter_0000008, 2.0))) + parameter_0000033);
        rate_reaction_0000005 = _compartment_0000002_compartment_0000001_*parameter_0000036*x[4];
        rate_reaction_0000006 = _compartment_0000002_compartment_0000001_*parameter_0000038*x[5];
        rate_reaction_0000007 = _compartment_0000002_compartment_0000001_*parameter_0000037*x[3];
        rate_reaction_0000008 = compartment_0000002*(parameter_0000040*x[6]/(parameter_0000041 + x[6]));
        rate_reaction_0000009 = compartment_0000002*(parameter_0000040*x[7]/(parameter_0000041 + x[7]));
        rate_reaction_0000010 = compartment_0000002*(parameter_0000044*x[8]/(parameter_0000045 + x[8]));
        rate_reaction_0000011 = _compartment_0000002_compartment_0000001_*(parameter_0000042*x[0]/(parameter_0000043 + x[0]));
        rate_reaction_0000012 = _compartment_0000002_compartment_0000001_*(parameter_0000042*x[1]/(parameter_0000043 + x[1]));
        rate_reaction_0000013 = _compartment_0000002_compartment_0000001_*(parameter_0000046*x[2]/(parameter_0000047 + x[2]));
        rate_reaction_0000014 = _compartment_0000002_compartment_0000001_*parameter_0000048*x[4];
        rate_reaction_0000015 = _compartment_0000002_compartment_0000001_*parameter_0000048*x[5];
        rate_reaction_0000016 = _compartment_0000002_compartment_0000001_*parameter_0000048*x[3];
        rate_reaction_0000017 = compartment_0000002*parameter_0000048*x[6];
        rate_reaction_0000018 = compartment_0000002*parameter_0000048*x[7];
        rate_reaction_0000019 = compartment_0000002*parameter_0000048*x[8];
        rate_reaction_0000020 = _compartment_0000002_compartment_0000001_*parameter_0000048*x[0];
        rate_reaction_0000021 = _compartment_0000002_compartment_0000001_*parameter_0000048*x[1];
        rate_reaction_0000022 = _compartment_0000002_compartment_0000001_*parameter_0000048*x[2];
        __internalVar12060038535150 = parameter_0000029*x[14] + parameter_0000034;
    }

    public void Init()
    {
        initialValues = new double[15];
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        _compartment_0000002_compartment_0000001_ = 1.0; // initial value of $"compartment_0000002.compartment_0000001"
        compartment_0000002 = 1.0; // initial value of $compartment_0000002
        parameter_0000005 = 0.2; // initial value of parameter_0000005
        parameter_0000006 = 0.24; // initial value of parameter_0000006
        parameter_0000007 = 0.1; // initial value of parameter_0000007
        parameter_0000008 = 0.54; // initial value of parameter_0000008
        parameter_0000010 = 0.54; // initial value of parameter_0000010
        parameter_0000011 = 0.083; // initial value of parameter_0000011
        parameter_0000012 = 0.134; // initial value of parameter_0000012
        parameter_0000013 = 0.248; // initial value of parameter_0000013
        parameter_0000014 = 0.2124; // initial value of parameter_0000014
        parameter_0000015 = 0.2124; // initial value of parameter_0000015
        parameter_0000016 = 0.2124; // initial value of parameter_0000016
        parameter_0000017 = 1.062; // initial value of parameter_0000017
        parameter_0000018 = 1.062; // initial value of parameter_0000018
        parameter_0000019 = 1.062; // initial value of parameter_0000019
        parameter_0000023 = 2.8249; // initial value of parameter_0000023
        parameter_0000024 = 2.8249; // initial value of parameter_0000024
        parameter_0000025 = 2.8249; // initial value of parameter_0000025
        parameter_0000026 = 5.0; // initial value of parameter_0000026
        parameter_0000027 = 10.62; // initial value of parameter_0000027
        parameter_0000028 = 76.464; // initial value of parameter_0000028
        parameter_0000029 = 344.09; // initial value of parameter_0000029
        parameter_0000030 = 1.062; // initial value of parameter_0000030
        parameter_0000031 = 0.02124; // initial value of parameter_0000031
        parameter_0000032 = 0.19116; // initial value of parameter_0000032
        parameter_0000033 = 0.001062; // initial value of parameter_0000033
        parameter_0000034 = 0.38232; // initial value of parameter_0000034
        parameter_0000036 = 0.2124; // initial value of parameter_0000036
        parameter_0000037 = 0.7434; // initial value of parameter_0000037
        parameter_0000038 = 0.6903; // initial value of parameter_0000038
        parameter_0000039 = 2.8249; // initial value of parameter_0000039
        parameter_0000040 = 1.6992; // initial value of parameter_0000040
        parameter_0000041 = 0.25; // initial value of parameter_0000041
        parameter_0000042 = 0.3186; // initial value of parameter_0000042
        parameter_0000043 = 0.0010; // initial value of parameter_0000043
        parameter_0000044 = 1.6992; // initial value of parameter_0000044
        parameter_0000045 = 0.25; // initial value of parameter_0000045
        parameter_0000046 = 5.31; // initial value of parameter_0000046
        parameter_0000047 = 0.01; // initial value of parameter_0000047
        parameter_0000048 = 0.00531; // initial value of parameter_0000048
    }

    /*
     * Model variables initial values
     */
    protected double _compartment_0000002_compartment_0000001_;
    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_0000008;
    protected double rate_reaction_0000009;
    protected double rate_reaction_0000010;
    protected double rate_reaction_0000011;
    protected double rate_reaction_0000012;
    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 compartment_0000002;
    protected double __internalVar12060038535150;
    protected double parameter_0000005;
    protected double parameter_0000006;
    protected double parameter_0000007;
    protected double parameter_0000008;
    protected double parameter_0000010;
    protected double parameter_0000011;
    protected double parameter_0000012;
    protected double parameter_0000013;
    protected double parameter_0000014;
    protected double parameter_0000015;
    protected double parameter_0000016;
    protected double parameter_0000017;
    protected double parameter_0000018;
    protected double parameter_0000019;
    protected double parameter_0000023;
    protected double parameter_0000024;
    protected double parameter_0000025;
    protected double parameter_0000026;
    protected double parameter_0000027;
    protected double parameter_0000028;
    protected double parameter_0000029;
    protected double parameter_0000030;
    protected double parameter_0000031;
    protected double parameter_0000032;
    protected double parameter_0000033;
    protected double parameter_0000034;
    protected double parameter_0000036;
    protected double parameter_0000037;
    protected double parameter_0000038;
    protected double parameter_0000039;
    protected double parameter_0000040;
    protected double parameter_0000041;
    protected double parameter_0000042;
    protected double parameter_0000043;
    protected double parameter_0000044;
    protected double parameter_0000045;
    protected double parameter_0000046;
    protected double parameter_0000047;
    protected double parameter_0000048;

/*
 * Returns "historical" variables in one array
 */
    public double[] getHistory(double t, double[] extendedY)
    {
        double[] history = new double[1];
        history[0] = extendedY[15];
        return history;
    }

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[16];
        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] = __internalVar12060038535150;
        y[10] = x[9];
        y[11] = x[10];
        y[12] = x[11];
        y[13] = x[12];
        y[14] = x[13];
        y[15] = x[14];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[15];
        this.time = 0.0;
        x[0] = 0.0010; // - $"compartment_0000002.compartment_0000001.species_0000001"
        x[1] = 0.0010; // - $"compartment_0000002.compartment_0000001.species_0000002"
        x[2] = 0.0010; // - $"compartment_0000002.compartment_0000001.species_0000003"
        x[3] = 0.0010; // - $"compartment_0000002.compartment_0000001.species_0000007"
        x[4] = 0.0010; // - $"compartment_0000002.compartment_0000001.species_0000008"
        x[5] = 0.0010; // - $"compartment_0000002.compartment_0000001.species_0000009"
        x[6] = 0.0010; // - $"compartment_0000002.species_0000004"
        x[7] = 0.0010; // - $"compartment_0000002.species_0000005"
        x[8] = 0.0010; // - $"compartment_0000002.species_0000006"
        x[9] = 0.0; // - parameter_0000001
        x[10] = 0.0; // - parameter_0000002
        x[11] = 0.0; // - parameter_0000003
        x[12] = 0.0; // - parameter_0000020
        x[13] = 0.0; // - parameter_0000021
        x[14] = 0.0; // - parameter_0000022

        __internalRateVarInitFunc_0(time, x);

        return x;
    }

    public double[] getInitialValuesOfHistorycal()
    {
        double[] z = new double[1];
        __internalVar12060038535150 = 0.38232;
        z[0] = __internalVar12060038535150;
        return z;
    }
/*
 * 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 'BIOMD0000000034.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_reaction_0000010-rate_reaction_0000011-rate_reaction_0000020;
        result[1] = +rate_reaction_0000011-rate_reaction_0000012-rate_reaction_0000021;
        result[2] = +rate_reaction_0000012-rate_reaction_0000013-rate_reaction_0000022;
        result[3] = +rate_reaction_0000002-rate_reaction_0000007-rate_reaction_0000016;
        result[4] = +rate_reaction_0000004-rate_reaction_0000005-rate_reaction_0000014;
        result[5] = +rate_reaction_0000003-rate_reaction_0000006-rate_reaction_0000015;
        result[6] = +rate_reaction_0000001-rate_reaction_0000008-rate_reaction_0000017;
        result[7] = +rate_reaction_0000008-rate_reaction_0000009-rate_reaction_0000018;
        result[8] = +rate_reaction_0000009-rate_reaction_0000010-rate_reaction_0000019;
        result[9] = +parameter_0000017*(x[4]/(x[4] + parameter_0000011))*(parameter_0000005/(parameter_0000005 + x[0] + x[1] + x[2]))*(1.0 - x[9]) - parameter_0000014*x[9];
        result[10] = +parameter_0000018*(x[4]/(x[4] + parameter_0000012))*(parameter_0000006/(parameter_0000006 + x[0] + x[1] + x[2]))*(1.0 - x[10]) - parameter_0000015*x[10];
        result[11] = +parameter_0000019*(x[4]/(x[4] + parameter_0000013))*(parameter_0000007/(parameter_0000007 + x[0] + x[1] + x[2]))*(1.0 - x[11]) - parameter_0000016*x[11];
        result[12] = +(Math.pow(x[9], parameter_0000026) - x[12])/parameter_0000023;
        result[13] = +(Math.pow(x[10], parameter_0000026) - x[13])/parameter_0000024;
        result[14] = +(Math.pow(x[11], parameter_0000026) - x[14])/parameter_0000025;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[15];
        __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 ...