Пример #1
0
        private void btnRalgirithmClick(object sender, EventArgs e)
        {
            var cs = new CancellationTokenSource();
            var t  = new Task <RAlgSolver>(() =>
            {
                chart1.Series.Clear();
                GetValuesFromForm();
                _sensorsResults = GetValue(_lambda1, _ro1, _c1, _lambda2, _ro2, _c2, _tl, _t0, _tr, _l, _k, _nodesCount, _sensorsCount, true, true, chart1);

                var ra   = new RAlgSolver();
                ra.FUNCT = RAlgFunction;
                ra.R_Algorithm();
                return(ra);
            }, cs.Token);

            t.ContinueWith(task =>
            {
                richTextBox1.Text += string.Format("\tk={0:f3} lambda1={1:f3} lambda2={2:f3} f={3:f4}\r\n", task.Result.x[0], task.Result.x[1], task.Result.x[2], task.Result.f, chart1);

                //if (MessageBox.Show("Do you want to draw result?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    chart2.Series.Clear();
                    _sensorsResults = GetValue(task.Result.x[1], _ro1, _c1, task.Result.x[2], _ro2, _c2, _tl, _t0, _tr, _l, task.Result.x[0], _nodesCount, _sensorsCount, true, false, chart2);
                }
            }, cs.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext());

            t.ContinueWith(task =>
            {
                MessageBox.Show(Resources.ErrorString);
            }, cs.Token, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.FromCurrentSynchronizationContext());

            t.Start(TaskScheduler.FromCurrentSynchronizationContext());
        }
Пример #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            var ra = new RAlgSolver(2);

            ra.FUNCT = testFunction;
            ra.R_Algorithm();
            MessageBox.Show(string.Format("x1: {0:f3} x2: {1:f3}", ra.x[0], ra.x[1]));
        }
Пример #3
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;
            }
        }