Ejemplo n.º 1
0
        void nMToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                NMIteration it;
                ReadNMParams(out ipNM, out it);

                NMOptimizer opt = new NMOptimizer();
                opt.Initialize(ipNM);
                listNM = new List <NMIteration>();
                it.CalcFuncAndResult(ipNM);
                listNM.Add(it);
                it = new NMIteration(it.matrX);
                it.CalcFuncAndResult(ipNM);
                int iterNum = 0;
                do
                {
                    listNM.Add(it);
                    it = (NMIteration)opt.DoIteration(it);
                    iterNum++;
                }while (it != null && iterNum < maxIt);
                lbIterNM.Items.Clear();
                lbIterNM.Items.AddRange(listNM.ToArray());
                psGraph.Clear();
                psItGraph.Clear();
                if (listNM[0].arrXRes.Length != 2)
                {
                    return;
                }
                LinePlot[] arrLp = GetPotentials(ipNM);
                foreach (LinePlot lp in arrLp)
                {
                    psGraph.Add(lp);
                    psItGraph.Add(lp);
                }
                try
                {
                    DrawNMTrajectory();
                }
                catch { }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка: " + ex.Message, "Расчеты прерваны",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        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);
        }