Exemple #1
0
        public static void TestInavlidFunction <T>(IOOOptimizer <T> opt, T parameters, InvalidFunc TypeFunc)
        {
            OOOptimizationProblem problem = null;

            switch (TypeFunc)
            {
            case InvalidFunc.NaNFunc:
            {
                problem = new OOOptimizationProblem(FunctionNaN, LowerBounds, UpperBounds);
                break;
            }

            case InvalidFunc.NegInfFunc:
            {
                problem = new OOOptimizationProblem(FunctionNegInf, LowerBounds, UpperBounds);
                break;
            }

            case InvalidFunc.PosInfFunc:
            {
                problem = new OOOptimizationProblem(FunctionPosInf, LowerBounds, UpperBounds);
                break;
            }
            }

            opt.Minimize(parameters, problem);
        }
        private static void Test <T>(IOOOptimizer <T> Opt, T Parameters, IOOOptProblem Problem, string Method)
        {
            Agent bestSolution = null;

            Opt.Minimize(Parameters, Problem);

            bestSolution = Opt.Solution;

            for (int i = 1; i < 10; i++)
            {
                Opt.Minimize(Parameters, Problem);

                if (Opt.Solution.Objs[0] < bestSolution.Objs[0])
                {
                    bestSolution = Opt.Solution;
                }
            }

            Console.WriteLine($"Method: {Method}.");
            Console.WriteLine($"Solution: f(x) = {bestSolution.Objs[0]}, x = ({bestSolution.Point[0]}, {bestSolution.Point[1]}).");
            Console.WriteLine();
        }
Exemple #3
0
        public static bool TestCancel <T>(IOOOptimizer <T> Opt, T Parameters)
        {
            CancellationTokenSource tokenSource = new CancellationTokenSource();

            CancellationToken token = tokenSource.Token;

            OOOptimizationProblem problem = new OOOptimizationProblem(TargetFunction, LowerBounds, UpperBounds);

            Task task = Task.Factory.StartNew(() => { Thread.Sleep(3000); Opt.Minimize(Parameters, problem, token); }, token);

            tokenSource.Cancel();

            try
            {
                task.Wait();
            }
            catch (AggregateException)
            {
            }

            return(!task.IsCanceled);
        }
Exemple #4
0
        public static void TestWrongParams <T>(IOOOptimizer <T> opt) where T : struct
        {
            T parameters = default(T);

            opt.Minimize(parameters, new OOOptimizationProblem(TargetFunction, LowerBounds, UpperBounds));
        }
Exemple #5
0
        public static bool TestOptimizer <T>(IOOOptimizer <T> Opt, T Parameters)
        {
            Opt.Minimize(Parameters, new OOOptimizationProblem(TargetFunction, LowerBounds, UpperBounds));

            return(Opt.Solution == null);
        }