public IIteration DoIteration(IIteration prevIter)
        {
            it = (HJIteration)prevIter;
            double f = ip.GetFuncValue(it.arrX);

            while (it.arrE == null)
            {
                f = ip.GetFuncValue(it.arrX);
                double[] arrENext, arrXNext;
                double   fNext = Research(it.arrX, out arrENext, out arrXNext);
                if (Math.Abs(fNext - f) < ip.fEpsilon)
                {
                    for (int i = 0; i < it.arrXDelta.Length; i++)
                    {
                        it.arrXDelta[i] /= 2;
                    }
                    for (int i = 0; i < it.arrXDelta.Length; i++)
                    {
                        if (it.arrXDelta[i] < ip.xEpsilon)
                        {
                            it.CalcResult(ip);
                            return(null);
                        }
                    }
                }
                else
                {
                    it.arrE = arrENext;
                }
            }
            double[] arrXSmp = new double[it.arrX.Length];
            for (int i = 0; i < arrXSmp.Length; i++)
            {
                arrXSmp[i] = it.arrX[i] + it.arrE[i] * it.mult;
            }
            double fSmp = ip.GetFuncValue(arrXSmp);

            if (Math.Abs(fSmp - f) < ip.fEpsilon || fSmp > f)
            {
                it.fRes = f;
                return(new HJIteration(it.arrX, it.arrXDelta, null, 1));
            }
            double[]    arrXRes, arrERes;
            double      fRes = Research(arrXSmp, out arrERes, out arrXRes);
            HJIteration itNext;

            if (Math.Abs(fRes - f) < ip.fEpsilon)
            {
                it.fRes = f;
                itNext  = new HJIteration(it.arrX, it.arrXDelta, null, 1);
            }
            else
            {
                it.fRes = fSmp;
                itNext  = new HJIteration(arrXSmp, it.arrXDelta, it.arrE, it.mult + 1);
            }
            return(itNext);
        }
Ejemplo n.º 2
0
 void lbIterHJ_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         HJIteration it = (HJIteration)lbIterHJ.SelectedItem;
         wb.DocumentText = it.ToHtml(ipHJ, d);
         DrawHJIteration(it);
     }
     catch { }
 }
Ejemplo n.º 3
0
        void hJToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                HJIteration it;
                ReadHJParams(out ipHJ, out it);

                HJOptimizer opt = new HJOptimizer();
                opt.Initialize(ipHJ);
                listHJ = new List <HJIteration>();
                it.CalcResult(ipHJ);
                listHJ.Add(it);
                it = new HJIteration(it.arrX, it.arrXDelta);
                it.CalcResult(ipHJ);
                int iterNum = 0;
                do
                {
                    listHJ.Add(it);
                    it = (HJIteration)opt.DoIteration(it);
                    iterNum++;
                }while (it != null && iterNum < maxIt);
                lbIterHJ.Items.Clear();
                lbIterHJ.Items.AddRange(listHJ.ToArray());
                psGraph.Clear();
                psItGraph.Clear();
                if (listHJ[0].arrX.Length != 2)
                {
                    return;
                }
                LinePlot[] arrLp = GetPotentials(ipHJ);
                foreach (LinePlot lp in arrLp)
                {
                    psGraph.Add(lp);
                    psItGraph.Add(lp);
                }
                try
                {
                    DrawHJTrajectory();
                }
                catch { }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка: " + ex.Message, "Расчеты прерваны",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 4
0
        void ReadHJParams(out HJInitialParams ip, out HJIteration it)
        {
            string[] arrName = new string[dgvX.RowCount];
            for (int i = 0; i < dgvX.RowCount; i++)
            {
                arrName[i] = (string)dgvX.Rows[i].Cells["Имя"].Value;
            }
            ip = new HJInitialParams(double.Parse(tbXEps.Text), double.Parse(tbFEps.Text),
                                     arrName, arrName, tbExpression.Text);

            double[] arrX      = new double[dgvXHJ.RowCount];
            double[] arrXDelta = new double[dgvXHJ.RowCount];
            for (int i = 0; i < dgvXHJ.RowCount; i++)
            {
                arrX[i]      = (double)dgvXHJ.Rows[i].Cells["Точка"].Value;
                arrXDelta[i] = (double)dgvXHJ.Rows[i].Cells["Шаг"].Value;
            }
            it = new HJIteration(arrX, arrXDelta);
        }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
            return;

            NMOptimizer     opt = new NMOptimizer();
            NMInitialParams ip  = new NMInitialParams(1, 0.5, 2, 0.001,
                                                      new string[] { "x", "y" },
                                                      new string[] { "x", "y" },
                                                      "x ^ 2 + y ^ 2");

            opt.Initialize(ip);
            List <NMIteration> listIter = new List <NMIteration>();
            NMIteration        it       = new NMIteration(new double[][] { new double[] { 1, 2 }, new double[] { 5, 6 }, new double[] { 7, 10 } });

            it.CalcFuncAndResult(ip);
            do
            {
                listIter.Add(it);
                it = (NMIteration)opt.DoIteration(it);
            }while (it != null);

            HJOptimizer     opt2 = new HJOptimizer();
            HJInitialParams ip2  = new HJInitialParams(0.01, 0.1,
                                                       new string[] { "x", "y" }, new string[] { "x", "y" },
                                                       "x * x + 2 * x + 1 + y * y + 2 * y + 1");

            opt2.Initialize(ip2);
            List <HJIteration> listIter2 = new List <HJIteration>();
            HJIteration        it2       = new HJIteration(new double[] { 20, 20 }, new double[] { 0.1, 0.1 }, null, 1);

            it2.CalcResult(ip2);
            do
            {
                listIter2.Add(it2);
                it2 = (HJIteration)opt2.DoIteration(it2);
            }while (it2 != null);
        }
Ejemplo n.º 6
0
        void DrawHJIteration(HJIteration it)
        {
            ReadGraphParams();
            if (it.arrX.Length != 2)
            {
                throw new Exception();
            }
            psItGraph.Remove(lpItLast, false);
            psItGraph.Remove(ppItLast, false);
            ppItLast = new PointPlot(new Marker(Marker.MarkerType.Circle, 4));
            ppItLast.OrdinateData = new double[] { it.arrX[1] };
            ppItLast.AbscissaData = new double[] { it.arrX[0] };
            psItGraph.Add(ppItLast);

            psItGraph.XAxis1.WorldMin = xMin;
            psItGraph.XAxis1.WorldMax = xMax;
            psItGraph.YAxis1.WorldMin = yMin;
            psItGraph.YAxis1.WorldMax = yMax;
            psItGraph.XAxis1.Label    = (string)dgvX.Rows[0].Cells["Имя"].Value;
            psItGraph.YAxis1.Label    = (string)dgvX.Rows[1].Cells["Имя"].Value;
            psItGraph.Refresh();
        }