static DihtomiaRectangle GetRectangle(LinkedList <DihtomiaRectangle> list, RuleD rule)
        {
            switch (rule)
            {
            case RuleD.FIFO:
                return(list.Dequeue());

            case RuleD.LIFO:
                return(list.Pop());

            case RuleD.MINQ:
                return(list.GetWithMinQ());

            default:
                return(list.Dequeue());
            }
        }
        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, RuleD rule, GraphicSettings settings = null)
        {
            double lipConst = lipzits(epsilon);
            LinkedList <DihtomiaRectangle> rectangles = new LinkedList <DihtomiaRectangle>();
            DihtomiaRectangle first = new DihtomiaRectangle(lowerBound, upperBound, settings);

            first.EvalQ(function, lipConst);
            rectangles.AddFirst(first);
            int           counter = 1;
            int           optimal = counter;
            List <double> optimalPoint;
            double        currentMin = Math.Min(function(lowerBound), function(first.center));

            if (function(lowerBound) < function(first.center))
            {
                optimalPoint = new List <double>(lowerBound);
            }
            else
            {
                optimalPoint = new List <double>(first.center);
            }
            if (first.Q >= currentMin - epsilon)
            {
                return(currentMin, counter, optimal, optimalPoint);
            }
            while (rectangles.Count != 0)
            {
                var current  = GetRectangle(rectangles, rule);
                var newRects = current.SplitByMaxSide(settings);
                newRects.first.EvalQ(function, lipConst);
                newRects.second.EvalQ(function, lipConst);
                double funcInFirst  = function(newRects.first.center);
                double funcInSecond = function(newRects.second.center);
                if (currentMin < Math.Min(funcInFirst, funcInSecond))
                {
                    if (newRects.first.Q < (currentMin - epsilon) && newRects.first.GetMaxSide().max >= (2d * precision / lipConst))
                    {
                        rectangles.AddFirst(newRects.first);
                    }
                    if (newRects.second.Q < (currentMin - epsilon) && newRects.second.GetMaxSide().max >= (2d * precision / lipConst))
                    {
                        rectangles.AddFirst(newRects.second);
                    }
                }
                else
                {
                    if (funcInFirst < funcInSecond)
                    {
                        currentMin = funcInFirst;
                        rectangles.AddFirst(newRects.first);
                        optimalPoint = new List <double>(newRects.first.center);
                    }
                    else
                    {
                        currentMin = funcInSecond;
                        rectangles.AddFirst(newRects.second);
                        optimalPoint = new List <double>(newRects.second.center);
                    }
                    rectangles.RemoveWorse(currentMin, epsilon);
                    optimal = counter;
                }
                counter++;
            }
            GC.Collect();
            return(currentMin, counter, optimal, optimalPoint);
        }