static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Form1()); //DeliveryOptimizer opt = new DeliveryOptimizer(new double[] { 2, 3, 5, 2, 1 }, 5); DeliveryOptimizer opt = new DeliveryOptimizer("ln(x + 10)", 10, 3); double[] arrT, arrQ, arrV; opt.Optimize(out arrT, out arrQ, out arrV); }
void doCalcToolStripMenuItem_Click(object sender, EventArgs e) { try { string expr = tbExpr.Text; double tMax = double.Parse(tbTMax.Text); int n = int.Parse(tbN.Text); double cSt = double.Parse(tbCSt.Text); double cDl = double.Parse(tbCDl.Text); double[] arrTFunc = null, arrVFunc = null; DeliveryOptimizer opt; if (rbAn.Checked) { opt = new DeliveryOptimizer(expr, tMax, n, cSt, cDl); } else { arrTFunc = new double[dgvFn.RowCount - 1]; arrVFunc = new double[dgvFn.RowCount - 1]; for (int i = 0; i < dgvFn.RowCount - 1; i++) { arrTFunc[i] = (double)dgvFn.Rows[i].Cells[0].Value; arrVFunc[i] = (double)dgvFn.Rows[i].Cells[1].Value; } opt = new DeliveryOptimizer(arrTFunc, arrVFunc, n, cSt, cDl); } double[] arrTPrev = null, arrV = null; for (int i = 0; i < 10; i++) { opt.Optimize(arrTPrev, out arrT, out arrQ, out arrV, out cStSum, out cDlSum); arrTPrev = arrT; } opt.GetTheorFunc(out arrTFunc, out arrVFunc); ps.Clear(); LinePlot lp = new LinePlot(); lp.AbscissaData = arrT; lp.OrdinateData = arrV; ps.Add(lp); LinePlot lpFunc = new LinePlot(); lpFunc.AbscissaData = arrTFunc; lpFunc.OrdinateData = arrVFunc; lpFunc.Pen = Pens.Red; ps.Add(lpFunc); ps.XAxis1.Label = "t"; ps.YAxis1.Label = "V(t)"; ps.Refresh(); dgvTQ.Rows.Clear(); dgvTQ.RowCount = n; for (int i = 0; i < n; i++) { dgvTQ.Rows[i].Cells["t"].Value = arrT[i]; dgvTQ.Rows[i].Cells["Q"].Value = arrQ[i]; } tbCStSum.Text = cStSum.ToString(); tbCDlSum.Text = cDlSum.ToString(); QSum = 0; for (int i = 0; i < arrQ.Length; i++) { QSum += arrQ[i]; } tbQSum.Text = QSum.ToString(); } catch { MessageBox.Show("Проверьте исходные данные"); } }