/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000084.xml diagram  at 2008.03.20 15:08:05
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000084 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 = v1_Vm1*x[0]/(v1_Km1 + x[0]);
        rate_v2 = v2_Vm2*x[1]/(v2_Km2 + x[1]);
        rate_v3 = v3_k3*x[0]*x[5]/(v3_Km3 + x[5]);
        rate_v4 = v4_Vm4*x[2]/(v4_Km4 + x[2]);
        rate_v5 = v5_k5*x[2]*x[6]/(v5_Km5 + x[6]);
        rate_v6 = v6_Vm6*x[3]/(v6_Km6 + x[3]);
        rate_v7 = v7_k7*x[3]*x[7]/(v7_Km7 + x[7]);
        rate_v8 = v8_Vm8*x[4]/v8_Km8/(1 + x[4]/v8_Km8 + v8_Inh/v8_Ki8);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        v1_Km1 = 0.1; // initial value of v1_Km1
        v1_Vm1 = 1.0; // initial value of v1_Vm1
        v2_Km2 = 0.1; // initial value of v2_Km2
        v2_Vm2 = 0.01; // initial value of v2_Vm2
        v3_Km3 = 0.1; // initial value of v3_Km3
        v3_k3 = 1.0; // initial value of v3_k3
        v4_Km4 = 1.0; // initial value of v4_Km4
        v4_Vm4 = 0.3; // initial value of v4_Vm4
        v5_Km5 = 0.1; // initial value of v5_Km5
        v5_k5 = 1.0; // initial value of v5_k5
        v6_Km6 = 1.0; // initial value of v6_Km6
        v6_Vm6 = 0.3; // initial value of v6_Vm6
        v7_Km7 = 0.1; // initial value of v7_Km7
        v7_k7 = 1.0; // initial value of v7_k7
        v8_Ki8 = 1.0; // initial value of v8_Ki8
        v8_Km8 = 1.0; // initial value of v8_Km8
        v8_Vm8 = 0.3; // initial value of v8_Vm8
    }

    /*
     * Model variables initial values
     */
    protected double rate_v1;
    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 v1_Km1;
    protected double v1_Vm1;
    protected double v2_Km2;
    protected double v2_Vm2;
    protected double v3_Km3;
    protected double v3_k3;
    protected double v4_Km4;
    protected double v4_Vm4;
    protected double v5_Km5;
    protected double v5_k5;
    protected double v6_Km6;
    protected double v6_Vm6;
    protected double v7_Km7;
    protected double v7_k7;
    protected double v8_Inh;
    protected double v8_Ki8;
    protected double v8_Km8;
    protected double v8_Vm8;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[8];
        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];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[8];
        this.time = 0.0;
        x[0] = 0.5; // - $"compartment.R"
        x[1] = 0.0; // - $"compartment.Rin"
        x[2] = 0.0; // - $"compartment.x1p"
        x[3] = 0.0; // - $"compartment.x2p"
        x[4] = 0.0; // - $"compartment.x3p"
        x[5] = 1.0; // - $compartment.x1
        x[6] = 1.0; // - $compartment.x2
        x[7] = 1.0; // - $compartment.x3

        __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 'BIOMD0000000084.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_v1+rate_v2;
        result[1] = +rate_v1-rate_v2;
        result[2] = +rate_v3-rate_v4;
        result[3] = +rate_v5-rate_v6;
        result[4] = +rate_v7-rate_v8;
        result[5] = -rate_v3+rate_v4;
        result[6] = -rate_v5+rate_v6;
        result[7] = -rate_v7+rate_v8;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[8];
        __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 ...