public void BeeDown(double min, double max, int count, int t, int maxmax = 100) { Vectors old = Vectors.Union2(cnew.SubVector(t), d.SubVector(t)); //slau.GaussSelection(t); //cnew= var r = BeeHiveAlgorithm.GetGlobalMin(this.F, (t) * 2, min, max, 1e-15, count, 60, old, maxmax); //$"Hive method ---> {r.Item2}".Show(); VecToCD(r.Item1); ErrorsMasL[t - 1] = r.Item2; Functional ff = (Point x) => { double s = 0; for (int i = 0; i < t; i++) { s += cnew[i] * alpha(x, i) + d[i] * beta(x, i); } return(Math.Abs(s - KursMethods.U(x))); }; ErrorsMasQ[t - 1] = IntegralClass.Integral(ff, CIRCLE - 1); }
public void HiveTest() { Func <Vectors, double> f = BeeHiveAlgorithm.Parabol; var s = BeeHiveAlgorithm.GetGlobalMin(f, 2, -100, 100, eps: 1e-15, countpoints: 400, maxcountstep: 200); $"f от {s.Item1} = {s.Item2}".Show(); f = BeeHiveAlgorithm.Rastr; s = BeeHiveAlgorithm.GetGlobalMin(f, 2, -100, 100, eps: 1e-15, countpoints: 400, maxcountstep: 200); $"f от {s.Item1} = {s.Item2}".Show(); f = BeeHiveAlgorithm.Shvel; s = BeeHiveAlgorithm.GetGlobalMin(f, 2, -100, 100, eps: 1e-15, countpoints: 400, maxcountstep: 200); $"f от {s.Item1} = {s.Item2}".Show(); }
public static Tuple <double[], double[], int[], Func <Point, double> > LastMethod2(int n, int g, int cu, SLAUpok SYSTEM = null, SLAUpok SYSTEMQ = null) { ForDesigion.Building(n, g, cu, SYSTEM, SYSTEMQ); double[] ErrorsMasL = new double[n], ErrorsMasQ = new double[n]; int[] Times = new int[n]; var tmp = new BiharmonicEquation(); double range = 200; Vectors old = Vectors.Union2(tmp.cnew, tmp.d); var r = BeeHiveAlgorithm.GetGlobalMin(tmp.F, 2 * n, -range, range, 1e-15, 1200, 60, old, -1); for (int t = 0; t < n; t++) { Functional fif = (Point x) => { double s = 0; for (int i = 0; i < t; i++) { s += tmp.cnew[i] * alpha(x, i) + tmp.d[i] * beta(x, i); } return(Math.Abs(s - KursMethods.U(x))); }; ErrorsMasQ[t] = IntegralClass.Integral(fif, CIRCLE - 1); ErrorsMasL[t] = tmp.F(Vectors.Union2(tmp.cnew.SubVector(t), tmp.d.SubVector(t))); } Func <Point, double> ff = (Point x) => { double s = 0; for (int i = 0; i < tmp.dim; i++) { s += tmp.cnew[i] * alpha(x, i) + tmp.d[i] * beta(x, i); } return(s); }; return(new Tuple <double[], double[], int[], Func <Point, double> >(ErrorsMasL, ErrorsMasQ, Times, ff)); }
public static void BeeHiveExamples() { double rastr(double v) => v * v - 10 * Math.Cos(2 * Math.PI * v); double shvel(double v) => - v * Math.Sin(Math.Sqrt(v.Abs())); // 1D functions var(argmin, min) = BeeHiveAlgorithm.GetGlobalMin(rastr, minimum: -5, maximum: 5, eps: 1e-15, countpoints: 100, maxiter: 100); $"min = {min}, argmin = {argmin}".Show(); // min = -9,973897874017823, argmin = 0,011472797486931086 (argmin, min) = BeeHiveAlgorithm.GetGlobalMin(shvel, minimum: -150, maximum: 150, eps: 1e-15, countpoints: 100, maxiter: 100); $"min = {min}, argmin = {argmin}".Show(); // min = -122,45163537317933, argmin = -126,64228803478181 // 2D functions // u can write -func to find the maximum of function var(argmin2, _) = BeeHiveAlgorithm.GetGlobalMin((Point p) => - shvel(p.x) - shvel(p.y), minimum: new Point(-150, -150), maximum: new Point(150, 150), eps: 1e-15, countpoints: 300, maxiter: 200); argmin2.Show(); // (125,85246982052922 , 133,86488312389702) // u don't need only smooth functions! (argmin2, _) = BeeHiveAlgorithm.GetGlobalMin((Point p) => - shvel(p.x) - shvel(p.y) + RandomNumbers.NextDouble2(-1, 1), minimum: new Point(-150, -150), maximum: new Point(150, 150), eps: 1e-15, countpoints: 500, maxiter: 200); argmin2.Show(); // (124,97163349762559 , 126,79389473050833) // u can use 3D+ functions var(argmin3, _) = BeeHiveAlgorithm.GetGlobalMin((Vectors v) => Math.Sin(v[0]).Abs() * rastr(v[1]) * shvel(v[2]).Abs() + shvel(v[3]), minimum: new Vectors(-100, -100, -100, -50), maximum: new Vectors(100, 50, 50, 50), eps: 1e-15, countpoints: 500, maxiter: 500); argmin3.Show(); // ( 48,37734238244593 0,09753305930644274 -60,919505648780614 46,69636117760092 ) }