コード例 #1
0
        private void btnSolveRK_Click(object sender, EventArgs e)
        {
            this.rtbResult1.Text      = this.rtbResult2.Text = string.Empty;
            this.dgvTabRes.DataSource = null;
            this.n        = int.Parse(this.txtN.Text);
            this.setCount = this.rbN1.Checked ? 1 : 2;
            //this.gamma = double.Parse(txtGamma.Text);

            ZedGraph.GraphPane gp = this.zgcMainChart2.GraphPane;
            gp.CurveList.Clear();
            this.curves.Clear();

            this.curves.Add(this.curveName, new PointPairList());
            gp.AddCurve(this.curveName, this.curves[curveName], Color.Black, SymbolType.None);


            List <double> gammaList = new List <double>();
            List <double> p         = new List <double>();

            for (int i = 0; i < dgvGama.ColumnCount; i++)
            {
                gammaList.Add(Convert.ToDouble(dgvGama.Rows[0].Cells[i].Value));
            }

            List <TaskParameter> list = new List <TaskParameter>();

            for (int i = 0; i < dgvParameters.RowCount; i++)
            {
                TaskParameter tp = new TaskParameter(dgvParameters.ColumnCount);
                for (int j = 0; j < dgvParameters.ColumnCount; j++)
                {
                    double val = Convert.ToDouble(dgvParameters.Rows[i].Cells[j].Value);
                    tp.Param[j] = val;
                }
                list.Add(tp);
            }

            this.tps = new TaskParameters(list, gammaList);
            string mfName = this.setCount == 1 ? "MF1" : "MF2";

            this.funcDescr = new Functions_2_2(mfName, this.fnames[(sfList.SelectedItem as string).ToUpper()]);

            this.tw = new TaskWorker(tps, funcDescr.GetType(), funcDescr.MainFuncName, funcDescr.SecFuncName, funcDescr);


            this.startVector = this.setCount == 1 ? new Vector(1, double.Parse(this.txtY0.Text)) :
                               new Vector(2, double.Parse(this.txtY00.Text), double.Parse(this.txtY01.Text));

            RKVectorForm rk = new RKVectorForm(tw, curveName, double.Parse(this.txtT0.Text), double.Parse(this.txtT1.Text), startVector);

            this.res = rk.SolveWithConstH(n, RKMetodType.RK4_1);

            if (this.rbN1.Checked)
            {
                res.ForEach(r => this.curves[curveName].Add(r.X, r.Y[0]));
            }
            else
            {
                res.ForEach(r => this.curves[curveName].Add(r.Y[0], r.Y[1]));
            }
            this.zgcMainChart2.AxisChange();
            this.zgcMainChart2.Refresh();


            if (this.setCount == 1)
            {
                this.tblResList = new List <ResPointViewType1>();
                for (int i = 0; i < res.Count - 1; i++)
                {
                    (this.tblResList as List <ResPointViewType1>).Add(new ResPointViewType1(res[i].X, res[i].Y[0], -1, -1));
                }
                this.dgvTabRes.DataSource = null;
                this.dgvTabRes.DataSource = tblResList;
            }
            else
            {
                this.tblResList = new List <ResPointViewType2>();
                for (int i = 0; i < res.Count - 2; i++)
                {
                    (this.tblResList as List <ResPointViewType2>).Add(new ResPointViewType2(res[i].X, res[i].Y[0], res[i].Y[1], -1, -1));
                }
                this.dgvTabRes.DataSource = null;
                this.dgvTabRes.DataSource = tblResList;
            }
            this.dgvTabRes.RefreshDataSource();

            this.randomStartParameters = this.GetRandomStartParam();
        }
コード例 #2
0
        private void btnSolveRAlg2_Click(object sender, EventArgs e)
        {
            try
            {
                this.btnSolveRAlg2.Enabled = false;
                int tick = Environment.TickCount;
                this.inf2 = null;
                //List<List<double>> sp = this.GetRandomStartParam();
                List <List <double> > sp = this.randomStartParameters;

                RAlgSolver ra = new RAlgSolver(this.tw, this.res, sp, this.startVector);
                ra.FUNCT = new RAlgSolver.FUNCTDelegate(ra.FUNCT4);
                ra.R_Algorithm();

                for (int i = 0; i < res.Count - this.setCount; i++)
                {
                    if (this.setCount == 1)
                    {
                        (this.tblResList as List <ResPointViewType1>)[i].M2 = ra.itab[i];
                    }
                    else
                    {
                        (this.tblResList as List <ResPointViewType2>)[i].M2 = ra.itab[i];
                    }
                }
                this.dgvTabRes.RefreshDataSource();

                Dictionary <double, int> tt = this.GetTT(this.res, ra.itab);

                StringBuilder sb = new StringBuilder();

                //-- draw res ---
                if (!this.curves.ContainsKey(this.curveName2))
                {
                    this.curves.Add(this.curveName2, new PointPairList());
                    LineItem curve = new LineItem(this.curveName2, this.curves[curveName2], Color.Blue, SymbolType.None);
                    curve.Line.Style = System.Drawing.Drawing2D.DashStyle.DashDot;
                    curve.Line.Width = 2;
                    this.zgcMainChart2.GraphPane.CurveList.Add(curve);
                }
                else
                {
                    this.curves[this.curveName2].Clear();
                }

                int k = 0;
                List <TaskParameter> listDraw = new List <TaskParameter>();
                for (int i = 0; i < tps.Count; i++)
                {
                    TaskParameter tpDraw = new TaskParameter(tps[i].Param.Length);
                    string        line   = string.Format("{0}) ", i);
                    for (int j = 0; j < tps[0].Param.Length; j++)
                    {
                        tpDraw.Param[j] = ra.x[k];
                        line           += string.Format("a{0}={1:f6} ", j, ra.x[k]);
                        k++;
                    }
                    sb.AppendLine(line);
                    listDraw.Add(tpDraw);
                }
                sb.AppendLine("-----");
                sb.Append(string.Format("f={0}", ra.f));
                rtbResult2.Text = sb.ToString();

                TaskParameters tps1 = new TaskParameters(listDraw, tt);
                TaskWorker     tw1  = new TaskWorker(tps1, this.funcDescr.GetType(), this.funcDescr.MainFuncName, this.funcDescr.SecFuncName, this.funcDescr);
                RKVectorForm   rk1  = new RKVectorForm(tw1, curveName2, double.Parse(this.txtT0.Text), double.Parse(this.txtT1.Text), this.startVector);
                RKResults      res1 = rk1.SolveWithConstH(n, RKMetodType.RK2_1);

                //if (this.setCount == 1)
                //{
                //    res1.ForEach(r => this.curves[this.curveName2].Add(r.X, r.Y[0]));
                //}
                //else
                //{
                //    res1.ForEach(r => this.curves[this.curveName2].Add(r.Y[0], r.Y[1]));
                //}
                int nn = this.setCount == 1 ? 1 : 2;
                for (int i = 0; i < res1.Count - nn; i++)
                {
                    if (nn == 1)
                    {
                        this.curves[curveName2].Add(res1[i].X, res1[i].Y[0]);
                    }
                    else
                    {
                        this.curves[curveName2].Add(res1[i].Y[0], res1[i].Y[1]);
                    }
                }
                this.zgcMainChart2.AxisChange();
                this.zgcMainChart2.Refresh();

                this.ra2 = ra;
                double t = ((Environment.TickCount - tick) / (double)1000);

                this.rtbResult2.Text += string.Format("\r\n-----\r\ntime = {0} sec", t);
                this.inf2             = string.Format("Result: f = {0:f6} time = {1} sec", ra.f, t);
            }
            finally
            {
                this.btnSolveRAlg2.Enabled = true;
            }
        }
コード例 #3
0
        private object view_ViewAction(ViewEventType type, ViewEventArgs args)
        {
            switch (type)
            {
            case ViewEventType.Exit:
            {
                alive = false;
                break;
            }

            case ViewEventType.StartSolving1:
            {
                string fname     = args.Parameters[0].ToString();
                string curveName = args.Parameters[1].ToString();
                var    fe        = new FunctionExecuter(typeof(Functions), fname);
                var    r         = new Random();
                double y0        = z1min + r.NextDouble() * (z1max - z1min);
                var    rk        = new RKVectorForm(fe, curveName, t0, t1, new Vector(1, y0));
                rk.OnResultGenerated += rk_OnResultGenerated;
                rk.SolveWithConstH(rkN, RKMetodType.RK4_1);
                break;
            }

            case ViewEventType.StartSolving2:
            {
                string fname      = args.Parameters[0].ToString();
                var    curveNames = args.Parameters[1] as string[, ];
                var    fe         = new FunctionExecuter(typeof(Functions), fname);

                double h1      = (z1max - z1min) / (randN);
                double h2      = (z2max - z2min) / (randN);
                var    results = new Dictionary <string, RKResults>();
                for (int i = 0; i < randN; i++)
                {
                    for (int j = 0; j < randN; j++)
                    {
                        double z00 = z1min + i * h1;
                        double z01 = z2min + j * h2;
                        var    rk  = new RKVectorForm(fe, curveNames[i, j], t0, t1, new Vector(2, z00, z01));
                        rk.OnSolvingDone += rk_OnSolvingDone;
                        RKResults res = rk.SolveWithConstH(rkN, RKMetodType.RK4_1);
                        results.Add(curveNames[i, j], res);
                    }
                }
                break;
            }

            case ViewEventType.SolvePodhod2Type1:
            {
                string fname     = args.Parameters[0].ToString();
                string curveName = args.Parameters[1].ToString();
                var    fe        = new FunctionExecuter(typeof(Functions), fname);

                var rk = new RKVectorForm(fe, curveName, t0, t1, new Vector(1, y0));

                rk.OnResultGenerated += rk_OnResultGenerated;
                rk.OnSolvingDone     += rk_OnSolvingDoneType1;
                rk.SolveWithConstH(rkN, RKMetodType.RK4_1);
                break;
            }

            case ViewEventType.SolovePodhod2Type2:
            {
                string fname     = args.Parameters[0].ToString();
                string curveName = args.Parameters[1].ToString();
                var    fe        = new FunctionExecuter(typeof(Functions), fname);

                var rk = new RKVectorForm(fe, curveName, t0, t1, new Vector(2, y00, y01));

                rk.OnResultGenerated += rk_OnResGenForType2;
                rk.OnSolvingDone     += rk_OnSolvingDoneType2;
                rk.SolveWithConstH(rkN, RKMetodType.RK4_1);
                break;
            }

            case ViewEventType.SolovePodhod2Type2Mass:
            {
                string fname      = args.Parameters[0].ToString();
                var    curveNames = args.Parameters[1] as string[, ];
                var    fe         = new FunctionExecuter(typeof(Functions), fname);

                double h1      = (z1max - z1min) / (randN);
                double h2      = (z2max - z2min) / (randN);
                var    results = new Dictionary <string, RKResults>();
                for (int i = 0; i < randN; i++)
                {
                    for (int j = 0; j < randN; j++)
                    {
                        double z00 = z1min + i * h1;
                        double z01 = z2min + j * h2;
                        var    rk  = new RKVectorForm(fe, curveNames[i, j], t0, t1, new Vector(2, z00, z01));
                        //rk.OnResultGenerated += new RKResultGeneratedDelegate(rk_OnResGenForType2);
                        //rk.OnSolvingDone += new RKSolvingDoneDelegate(rk_OnSolvingDoneType2);
                        RKResults res = rk.SolveWithConstH(rkN, RKMetodType.RK4_1);
                        results.Add(curveNames[i, j], res);
                    }
                }

                view.SendSolvingResultType2Mass(results, fe);

                break;
            }

            case ViewEventType.UpdateParams:
            {
                t0  = (double)args.Parameters[0];
                t1  = (double)args.Parameters[1];
                y0  = (double)args.Parameters[2];
                y00 = (double)args.Parameters[3];
                y01 = (double)args.Parameters[4];

                rkN   = Convert.ToInt32(args.Parameters[5]);
                randN = Convert.ToInt32(args.Parameters[6]);
                z1min = (double)args.Parameters[7];
                z1max = (double)args.Parameters[8];
                z2min = (double)args.Parameters[9];
                z2max = (double)args.Parameters[10];
                break;
            }
            }
            return(null);
        }