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); } }
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); }