public IOutBlackBoxParam Calculate(double x1, double x2) { cost = 0; int i = 0; foreach (IBlackBox blackBox in task.BlackBoxes) { if (blackBox.Info != "Узел") { this.functions[i].PIn = Parametr(blackBox.PIn, x1, x2); this.functions[i].POut = Parametr(blackBox.POut, x1, x2); this.functions[i].QOut = Convert.ToDouble(blackBox.QOut, provider); this.functions[i].TIn = Convert.ToDouble(blackBox.TIn, provider); this.functions[i].CIn = Convert.ToDouble(blackBox.СIn, provider); this.functions[i].DIn = Convert.ToDouble(blackBox.DIn, provider); this.functions[i].Calculate(); cost += this.functions[i].EZ; i++; } } OutBlackBoxParam param = new OutBlackBoxParam(cost); return(param); }
/// <summary> /// Здесь находится сам алгоритм оптимизации ф-и /// </summary> /// <returns>результат работы алгоритма</returns> public override DataFormat.IOutBlackBoxParam Calculate() { //double k = -1, cost = -1; int n = 0; //количество успешных вычислений функции double cost = double.MaxValue; IOutBlackBoxParam a; for (double i = this.parametr.x1_min; i <= this.parametr.x1_max; i += h) { for (double j = this.parametr.x2_min; j <= this.parametr.x2_max; j += h) { if (((j / i) <= this.parametr.x2_x1_max) && ((j / i) >= this.parametr.x2_x1_min)) { try { a = Function(i, j); n++; } catch { a = new OutBlackBoxParam(Double.MaxValue); // Double.MaxValue; } //a = Function(34.946777049892944, 50.93829138975363); if (n == 1) { cost = a.Cost; } else if (a.Cost < cost) { cost = a.Cost; } } } } return(new DataFormat.OutBlackBoxParam(cost)); }