public List <OptimizationVariable> CalculateCoordinateSearch(out double functionResult, double epselon) { List <Variable> currentVariables = new List <Variable>(); double[] shifts = new double[this.StartVariables.Count * 2]; for (int i = 0; i < this.StartVariables.Count; i++) { currentVariables.Add(new Variable(this.StartVariables[i].Name, this.StartVariables[i].Value)); shifts[i] = 0; } int currenIteration = 0; double oldValue, newValue; do { oldValue = this.Function.GetResultValue(currentVariables); for (int i = 0; i < this.StartVariables.Count; i++) { currentVariables[i].Value += this.CalculationStep; shifts[i * 2] = this.Function.GetResultValue(currentVariables); currentVariables[i].Value -= 2 * this.CalculationStep; shifts[i * 2 + 1] = this.Function.GetResultValue(currentVariables); currentVariables[i].Value += this.CalculationStep; } int minimalShiftIndex = this.GetMinIndex(shifts); int parameterIndex = minimalShiftIndex / 2; if (minimalShiftIndex % 2 == 0) { currentVariables[parameterIndex].Value += this.CalculationStep; } else { currentVariables[parameterIndex].Value -= this.CalculationStep; } newValue = this.Function.GetResultValue(currentVariables); currenIteration++; } while (Math.Abs(newValue - oldValue) > epselon && currenIteration < this.MaxIterationCount); List <OptimizationVariable> result = OptimizationVariable.ConvertVariablesToOptimizationVariables(currentVariables); functionResult = newValue; return(result); }
public List <OptimizationVariable> CalculateBrouteForce(out double functionResult) { List <OptimizationVariable> result = new List <OptimizationVariable>(); this.broutForceMin = double.MaxValue; this.brouteForceResult = new List <Variable>(); this.currentBrouteForceParameters = new List <Variable>(); foreach (OptimizationVariable variable in this.StartVariables) { this.brouteForceResult.Add(new Variable(variable.Name, variable.Value)); this.currentBrouteForceParameters.Add(new Variable(variable.Name, variable.Value)); } this.BustOptions(0); result = OptimizationVariable.ConvertVariablesToOptimizationVariables(this.brouteForceResult); functionResult = this.broutForceMin; return(result); }