Ejemplo n.º 1
0
    public float calc_Fox_Runge_Kutta(float f, float r, float ts)
    {
        foxws.foxws fproxy = new foxws.foxws();

        float k1 = 0;
        float k2 = 0;
        float k3 = 0;
        float k4 = 0;

        k1 = fproxy.foxpop_inc(f, r); //f(y)
        float tmp = f + (ts / 2) * k1;
        k2 = fproxy.foxpop_inc((tmp), r); //f(y+(h/2)k1)
        tmp = f + (ts / 2) * k2;
        k3 = fproxy.foxpop_inc((tmp), r); //f(y+(h/2)k2)
        tmp = f + ts * k3;
        k4 = fproxy.foxpop_inc((tmp), r); //f(y+ hk3)

        f = f + ts*(k1 + 2 * k2 + 2 * k3 + k4) / 6; //y + h*(k1 + 2 * k2 + 2 * k3 + k4)/6
        return f;
    }
Ejemplo n.º 2
0
    protected double[,] hybrid_horizontal_same_ts(float r, float f, int yr, float ts, string r_integ_method, string f_integ_method)
    {
        //objective: the two models run with ts=0.1 but they exchange data at multiple of 1

        foxws.foxws fproxy = new foxws.foxws();
        rabws.rabws rproxy = new rabws.rabws();

        //the system will loop according to the defined time step
        //int lp = Convert.ToInt16(Math.Truncate(yr / ts)); //total number of loop due to the defined time step
        int lp = Convert.ToInt32(Math.Truncate(yr / 0.1)); //10 timestep in 1 year
        lp = lp + 2;
        double[,] result = new double[lp, 2];

        float rx = r;
        float ry = f;
        float fx = r;
        float fy = f;

        for (int i = 1; i < lp; i++)
        {

            if (i % (Convert.ToInt16(ts * 10)) == 0)
            {

                //run rabbit model
                if (r_integ_method == "Runge-Kutta") // for Runge-Kutta integration of rabbit
                {
                    r = calc_Rabbit_Runge_Kutta(r, f, ts);

                }
                else
                    rx = rx + rproxy.pop_inc(rx, ry) * ts; //for euler integration
                   //r = r + rabbit_model(r, f) * ts;

                //run fox model
                if (f_integ_method == "Runge-Kutta") // for Runge-Kutta integration of fox model
                {
                    f = calc_Fox_Runge_Kutta(f, r, ts);
                }
                else
                    fy = fy + fproxy.foxpop_inc(fy, fx) * ts; //for euler integration
                  //f = f + fox_model(f, r) * ts;

                if ((i % 10) == 0)  //when ts is 1,2,3, ... then the models exchange data
                {
                    ry = f;
                    fx = r;
                }

                r = rx;
                f = fy;

                if (r < 0)
                    result[i, 0] = 0;
                else
                    result[i, 0] = r;   //Convert.ToDouble(r.ToString("#.##"));

                if (f < 0)
                    result[i, 1] = 0;
                else
                    result[i, 1] = f;   // Convert.ToDouble(f.ToString("#.##"));

                if (result[i, 0] < 0) //(result[i, 0] < 1)
                {
                    result[i, 0] = 0; //if pop<0 then set the pop value to 0
                    result[i, 1] = 0;
                    break;
                }
            }
            else
            {
                if (r < 0) //(result[i, 0] < 1)
                {
                    result[i, 0] = 0; //if pop<0 then set the pop value to 0
                    result[i, 1] = 0;
                    break;
                }
                else
                {
                    result[i, 0] = r;
                    result[i, 1] = f;
                }

            }
        }

        return result;
    }