public GridBruteForce(BasicData input, double step) : base(input) { if (step <= 0) { throw new ArgumentException(); } this.StepSize = Math.Abs(step); this.e = 1 + MathExpr.GetPrecision(StepSize); }
public static List <Series> Isolines(Optimize.BasicData input) { double x1step = input.Bounds.X1Interval / (double)x1stepcount; double x2step = input.Bounds.X2Interval / (double)x2stepcount; var list = new List <Point>(); var list_good = new List <Point>(); for (int i = 0; i < x1stepcount; i++) { double x1 = input.Bounds.X1Lower + x1step * i; for (int j = 0; j < x2stepcount; j++) { double x2 = input.Bounds.X2Lower + x2step * j; double y = input.Function.Calc(x1, x2); list.Add(new Point(x1, x2, y)); if (input.CheckRestrictions(x1, x2)) { list_good.Add(new Point(x1, x2, y)); } } } ; double min = list.AsParallel().Min(p => p.Y); double max = list.AsParallel().Max(p => p.Y); double step = (max - min) / steps; var ss = new List <Series>(); ss.Add(PlacePoints(list_good, $"Restrictions", Color.LightGreen, 1)); System.Threading.Tasks.Parallel.For(1, steps, (i) => { int ey = 1 + MathExpr.GetPrecision(min + i * step); double y = MathExpr.Round(min + i * step, ey); double delta_y = Math.Pow(step, -ey) / 1.5; var list2 = list.Where(p => p.Y > y - delta_y && p.Y < y + delta_y); var s = PlacePoints(list2, $"Iso{i}", SystemColors.Highlight, 1); int index = new Random().Next(s.Points.Count / 3, s.Points.Count / 3 * 2); if (index > 0) { s.Points[index].Label = y.ToString(); } ss.Add(s); }); return(ss); }
public override void RunOptimization() { Stopwatch stw = new Stopwatch(); stw.Start(); CheckStartPoint(); Points = new List <Point>(); Points.Add(StartPoint); uint iter = 0; Point prevPoint = StartPoint; int e = 3 + MathExpr.GetPrecision(Epsylon); while (step1 > Epsylon || step2 > Epsylon) { iter++; bool x1_success = false; bool x2_success = false; double pr_x2 = MathExpr.Round(prevPoint.X2, e); double x1Upper = MathExpr.Round(prevPoint.X1 + step1, e); if (Data.CheckRestrictions(x1Upper, pr_x2)) { double y = Data.Function.Calc(x1Upper, pr_x2); if (IsBetter(y, prevPoint.Y)) { prevPoint = new Point(x1Upper, pr_x2, y); x1_success = true; } } double x1Lower = MathExpr.Round(prevPoint.X1 - step1, e); if (Data.CheckRestrictions(x1Lower, pr_x2)) { double y = Data.Function.Calc(x1Lower, pr_x2); if (IsBetter(y, prevPoint.Y)) { prevPoint = new Point(x1Lower, pr_x2, y); x1_success = true; } } if (!x1_success) { step1 /= div; double x2Upper = MathExpr.Round(prevPoint.X2 + step2, e); double pr_x1 = MathExpr.Round(prevPoint.X1, e); if (Data.CheckRestrictions(pr_x1, x2Upper)) { double y = Data.Function.Calc(pr_x1, x2Upper); if (IsBetter(y, prevPoint.Y)) { prevPoint = new Point(pr_x1, x2Upper, y); x2_success = true; } } double x2Lower = MathExpr.Round(prevPoint.X2 - step2, e); if (Data.CheckRestrictions(pr_x1, x2Lower)) { double y = Data.Function.Calc(prevPoint.X1, x2Lower); if (IsBetter(y, prevPoint.Y)) { prevPoint = new Point(pr_x1, x2Lower, y); x2_success = true; } } } Points.Add(prevPoint); if (x1_success || x2_success) { continue; } else { step1 /= div; step2 /= div; } } stw.Stop(); Duration = stw.Elapsed.TotalMilliseconds; Result = Points.Last(); Iterations = iter; }