Пример #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);
        }
Пример #2
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);
        }