public LinkedList <ModRectangle> Split(double h, RuleM rule, GraphicSettings settings = null) { LinkedList <ModRectangle> rect = new LinkedList <ModRectangle>(); for (int i = 0; i < lowerCorner.Count; i++) { if (upperCorner[i] - lowerCorner[i] > h) { List <double> newLow = new List <double>(lowerCorner); newLow[i] += h; List <double> newUp = new List <double>(upperCorner); for (int j = 0; j < i; j++) { newUp[j] = Math.Min(newLow[j] + h, upperCorner[j]); } if (rule == RuleM.FIFO) { rect.AddFirst(new ModRectangle(newLow, newUp, settings)); } else { rect.AddLast(new ModRectangle(newLow, newUp, settings)); } } } return(rect); }
internal static LinkedList <T> ConcatList <T>(this LinkedList <T> current, LinkedList <T> toAdd, RuleM rule) { if (toAdd.Count == 0) { return(current); } else { while (toAdd.Count != 0) { if (rule == RuleM.FIFO) { current.AddFirst(toAdd.Pop()); } else { current.AddLast(toAdd.Dequeue()); } } } return(current); }
public static (double FunctionMinimum, int counter, int optimal, List <double> optimalPoint) Solve(OptimizingFunction function, LipzitsFunction lipzits, double precision, double epsilon, List <double> lowerBound, List <double> upperBound, RuleM ruleSubList, RuleM ruleMainList, GraphicSettings settings = null) { double lipVal = lipzits(epsilon); LinkedList <ModRectangle> rectangles = new LinkedList <ModRectangle>(); ModRectangle first = new ModRectangle(lowerBound, upperBound, settings); rectangles.AddFirst(first); int counter = 1; int optimal = counter; double currentMin = function(lowerBound); double h_base = 2d * (precision / lipVal - epsilon / lipVal); double h = h_base; List <double> optimalPoint = new List <double>(lowerBound); while (rectangles.Count != 0) { var currentRect = rectangles.Dequeue(); var iterPoint = currentRect.GetIterationPoint(h); var functionValue = function(iterPoint); if (functionValue > currentMin) { h = h_base + (functionValue - currentMin) / lipVal; } else { h = h_base; currentMin = functionValue; optimalPoint = new List <double>(iterPoint); optimal = counter; } var splitted = currentRect.Split(h, ruleSubList, settings); rectangles.ConcatList(splitted, ruleMainList); counter++; } GC.Collect(); return(currentMin, counter, optimal, optimalPoint); }