/// <summary> /// Button to start the algorithm. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonFindOptimum_Click(object sender, System.EventArgs e) { // necessary verifications // range if (numericUpDownRangeX1Lower.Value >= numericUpDownRangeX1Upper.Value || numericUpDownRangeX2Lower.Value >= numericUpDownRangeX2Upper.Value) { MessageBox.Show(Properties.Resources.ErrorRangeInvalid, Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // expression empty if (comboBoxInputExpression.Text == "") { MessageBox.Show(Properties.Resources.ErrorExpressionEmpty, Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // problem dimension int dimension = decimal.ToInt32(numericUpDownDimension.Value); // algorithm restrictions Solver.Restrictions restrictions = new Solver.Restrictions( decimal.ToInt32(numericUpDownNumberOfIters.Value), (float)numericUpDownArgDiff.Value, (float)numericUpDownFunValDiff.Value, (float)numericUpDownMinStepSize.Value, (float)numericUpDownRangeWidth.Value ); // expression string Expression = comboBoxInputExpression.Text; // start algorithm Steps = FindOptimum( dimension, StartingPoint, restrictions, Expression, new Range((float)numericUpDownRangeX1Lower.Value, (float)numericUpDownRangeX1Upper.Value), new Range((float)numericUpDownRangeX2Lower.Value, (float)numericUpDownRangeX2Upper.Value) ); buttonShowSteps.Enabled = true; }
/// <summary> /// Start the algorithm; if the problem is 2-dimensional, visualize the results. /// </summary> /// <param name="dimension"></param> /// <param name="startingPoint"></param> /// <param name="restrictions"></param> /// <param name="expression"></param> /// <param name="horizontalRange"></param> /// <param name="verticalRange"></param> private List <float[]> FindOptimum(int dimension, float[] startingPoint, Solver.Restrictions restrictions, string expression, Range horizontalRange, Range verticalRange) { // solver instance Solver solver = new Solver(dimension, expression, restrictions); // find optimal point bool pointFound = solver.FindOptimalPoint(startingPoint); // visualize results if dim = 2 solver.VisualizeResults( pictureBoxGraph, horizontalRange, verticalRange); // print optimum in messagebox (if it was found) if (pointFound) { string optimum = string.Format("[{0}]", string.Join(", ", solver.ConsecutivePointSeries.Last())); MessageBox.Show(string.Format(Properties.Resources.MiscOptimum, optimum), Properties.Resources.InfoOptimumFound, MessageBoxButtons.OK, MessageBoxIcon.Information); } return(solver.ConsecutivePointSeries); }