/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000079.xml diagram  at 2008.03.20 15:08:00
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000079 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_0 = compartment_0*function_0(reaction_0_a, x[1]);
        rate_reaction_1 = compartment_0*function_1(reaction_1_V, x[0], reaction_1_Km);
        rate_reaction_2 = compartment_0*function_2(reaction_2_V1, x[1], reaction_2_K1);
        rate_reaction_3 = compartment_0*function_3(reaction_3_V2, x[2], x[1], reaction_3_K2);
        rate_reaction_4 = compartment_0*function_4(x[0], reaction_4_V3, x[2], reaction_4_k3);
        rate_reaction_5 = compartment_0*function_1(reaction_5_V, x[2], reaction_5_Km);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        compartment_0 = 1.0; // initial value of $compartment_0
        reaction_0_a = 0.1; // initial value of reaction_0_a
        reaction_1_Km = 0.2; // initial value of reaction_1_Km
        reaction_1_V = 0.1; // initial value of reaction_1_V
        reaction_2_K1 = 0.01; // initial value of reaction_2_K1
        reaction_2_V1 = 1.0; // initial value of reaction_2_V1
        reaction_3_K2 = 0.01; // initial value of reaction_3_K2
        reaction_3_V2 = 1.5; // initial value of reaction_3_V2
        reaction_4_V3 = 6.0; // initial value of reaction_4_V3
        reaction_4_k3 = 0.01; // initial value of reaction_4_k3
        reaction_5_Km = 0.01; // initial value of reaction_5_Km
        reaction_5_V = 2.5; // initial value of reaction_5_V
    }

    /*
     * Model variables initial values
     */
    protected double rate_reaction_0;
    protected double rate_reaction_1;
    protected double rate_reaction_2;
    protected double rate_reaction_3;
    protected double rate_reaction_4;
    protected double rate_reaction_5;
    protected double compartment_0;
    protected double reaction_0_a;
    protected double reaction_1_Km;
    protected double reaction_1_V;
    protected double reaction_2_K1;
    protected double reaction_2_V1;
    protected double reaction_3_K2;
    protected double reaction_3_V2;
    protected double reaction_4_V3;
    protected double reaction_4_k3;
    protected double reaction_5_Km;
    protected double reaction_5_V;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[3];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = x[2];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[3];
        this.time = 0.0;
        x[0] = 0.43; // - $"compartment_0.species_0"
        x[1] = 0.8; // - $"compartment_0.species_1"
        x[2] = 0.55; // - $"compartment_0.species_2"

        __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 'BIOMD0000000079.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_reaction_0-rate_reaction_1;
        result[1] = +rate_reaction_2-rate_reaction_3;
        result[2] = +rate_reaction_4-rate_reaction_5;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[3];
        __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 );
    }

    protected double function_0(double a, double Q)
    {
         return a*Q;
    }
    protected double function_1(double V, double substrate, double Km)
    {
         return V*substrate/(Km + substrate);
    }
    protected double function_2(double V1, double Q, double K1)
    {
         return V1*(1.0 - Q)/(K1 + (1.0 - Q));
    }
    protected double function_3(double V2, double R, double Q, double K2)
    {
         return V2*R*Q/(K2 + Q);
    }
    protected double function_4(double P, double V3, double R, double k3)
    {
         return P*V3*(1.0 - R)/(k3 + (1.0 - R));
    }
} // class ...