Пример #1
0
        public static Vector GetSolutionTask1(Vector p, Matrix f, FunctionLib.Function phi,
                                              double nu, double L, double TIME,
                                              double aa, int N, int M)
        {
            double h   = MyMath.GetStep(N, 0d, L);
            double tau = MyMath.GetStep(M, 0d, TIME);
            Vector u0  = new Vector(N);
            Vector fu  = new Vector(N);

            for (int i = 0; i < N; i++)
            {
                u0[i] = phi(i * h);
            }

            for (int iter_t = 0; iter_t < M; iter_t++)
            {
                for (int i = 0; i < N; i++)
                {
                    fu[i] = f[iter_t, i];
                }
                u0 = SolveSliceTask1(u0, fu, p, nu, h, tau, aa, iter_t);
            }

            return(u0);
        }
Пример #2
0
        public static Matrix GetSolutionTask2(FunctionLib.Function y, Vector x_T,
                                              double nu, double L, double TIME,
                                              double aa, int N, int M)
        {
            double h   = MyMath.GetStep(N, 0d, L);
            double tau = MyMath.GetStep(M, 0d, TIME);
            Vector u0  = new Vector(N);
            Vector fu  = new Vector(N);
            Matrix KSI = new Matrix(M, N);

            for (int i = 0; i < N; i++)
            {
                u0[i]         = 2d * (x_T[i] - y(i * h));
                KSI[M - 1, i] = u0[i];
            }

            for (int iter_t = 1; iter_t < M; iter_t++)
            {
                for (int j = 0; j < N; j++)
                {
                    KSI[M - 1 - iter_t, j] = u0[j];
                }

                u0 = SolveSliceTask2(u0, nu, h, tau, aa);
            }

            return(KSI);
        }
Пример #3
0
        public Vector CalculateIteration()
        {
            calc_u = DifferentialEquation.GetSolutionTask1(manage_p, manage_f, phi, nu, L, T, aa, GRID_SIZE, TIME_SIZE);

            Matrix KSI = DifferentialEquation.GetSolutionTask2(y, calc_u, nu, L, T, aa, GRID_SIZE, TIME_SIZE);

            Vector ksi_l = new Vector(TIME_SIZE);

            for (int i = 0; i < TIME_SIZE; i++)
            {
                ksi_l[i] = KSI[i, GRID_SIZE - 1];
            }
            double alpha = alpha_old;

            double tau = MyMath.GetStep(TIME_SIZE, 0d, T);
            double h   = MyMath.GetStep(GRID_SIZE, 0d, L);

            switch (pickAlpha)
            {
            case PickAlpha.Lipshiz:
                alpha = ChooseAlpha_LipMethod();
                break;

            case PickAlpha.Divide:
                if (ITERATION > 0)
                {
                    alpha = ChooseAlpha_DivideMethod(alpha_old);
                }
                break;

            case PickAlpha.Lipshiz_CG:
                if (ITERATION > 0)
                {
                    alpha = ChooseAplpha_LipMethodForConditionalGradient(KSI, manage_f, alpha, tau, h);
                }
                //alpha = 1d / (ITERATION + 1);
                break;

            case PickAlpha.SUM:
                alpha = ChooseAlpha_Sum();
                break;

            case PickAlpha.Projection:
                alpha = ChooseAlpha_Projection(KSI, manage_f, alpha, R, tau, h);
                break;

            default:
                break;
            }



            manage_p = DifferentialEquation.GrdientProjection(manage_p, ksi_l, alpha, aa, P_MIN, P_MAX);
            //manage_f = DifferentialEquation.GrdientProjectionByF(manage_f, KSI, alpha, R, h, tau);
            ITERATION++;
            calc_u_old = calc_u;
            alpha_old  = alpha;
            return(manage_p);
        }
Пример #4
0
        public OptimalManaging(double LengthVal, double TimeVal,
                               double sq_a, double Nu, int TIME_M, int LEN_N,
                               double eps1, double eps2,
                               FunctionLib.Function distrib_y,
                               FunctionLib.Function env_temperature_p,
                               FunctionLib.Function temperature0,
                               FunctionLib.Function2d temperature_sourses,
                               double pmin, double pmax, double INT_R)
        {
            ITERATION = 0;
            L         = LengthVal;
            T         = TimeVal;
            aa        = sq_a;
            nu        = Nu;
            R         = INT_R;

            TIME_SIZE = TIME_M;
            GRID_SIZE = LEN_N;

            EPS1  = eps1;
            EPS2  = eps2;
            P_MAX = pmax;
            P_MIN = pmin;
            double C0 = Get_C0();
            double C1 = Get_C1();

            LIP = Math.Sqrt(2d * C0 * C1);

            manage_p = new Vector(TIME_SIZE);

            y   = distrib_y;
            p   = env_temperature_p;
            phi = temperature0;
            f   = temperature_sourses;

            alpha_old = 5d;

            double tau = MyMath.GetStep(TIME_SIZE, 0d, T);
            double h   = MyMath.GetStep(GRID_SIZE, 0d, L);

            for (int i = 0; i < TIME_SIZE; i++)
            {
                manage_p[i] = p(tau * i);
            }

            manage_f = new Matrix(TIME_SIZE, GRID_SIZE);
            for (int i = 0; i < TIME_SIZE; i++)
            {
                for (int j = 0; j < GRID_SIZE; j++)
                {
                    manage_f[i, j] = f(h * j, tau * i);
                }
            }

            //Vector temp = MyMath.GetVectorFunction(GRID_SIZE, 0d, LengthVal, y);
            //R = MyMath.TrapezoidMethod(temp, h);
        }
Пример #5
0
        public double Functional_J(Vector calc_u)
        {
            double h      = MyMath.GetStep(GRID_SIZE, 0d, L);
            Vector calc_y = new Vector(GRID_SIZE);
            Vector err    = new Vector(GRID_SIZE);

            for (int i = 0; i < GRID_SIZE; i++)
            {
                err[i] = (calc_u[i] - y(h * i)) * (calc_u[i] - y(h * i));
            }


            return(MyMath.RiemannSum(err.ToArray, h));
        }