Пример #1
0
        private List <String> Lab2CheckAdaptationAgainstContinuousProblemsWithDomainKnowledge <A>(int?seed, int maxIter = 1000) where A : ARealMutationES11Adaptation
        {
            List <String> resultData = new List <String>();

            IEvaluation <double>[] benchmarkProblems = GenerateProblems();
            foreach (var problem in benchmarkProblems)
            {
                problem.pcConstraint.tGetLowerBound(0);;
                List <double> sigmas = Enumerable.Repeat(0.1, problem.iSize).ToList();

                IterationsStopCondition stopCondition = new IterationsStopCondition(problem.dMaxValue, maxIter);
                RealGaussianMutation    mutation      = new RealGaussianMutation(sigmas, problem, seed);
                var mutationAdaptation = (A)Activator.CreateInstance(typeof(A), mutation, problem);

                RealEvolutionStrategy11 optimizer = new RealEvolutionStrategy11(problem, stopCondition, mutationAdaptation, seed);

                optimizer.Run();

                resultData.Add(FormatSave(optimizer));

                ReportOptimizationResult(optimizer.Result);
            }

            return(resultData);
        }
Пример #2
0
        private static OptimizationResult <double> RunExperiment(IEvaluation <double> evaluation, int maxIterations, double sigma, bool adjustSigmas, int adaptation, int?seed = null, int archiveSize = 1, double modifier = 1.0)
        {
            lock (evaluation)
            {
                IterationsStopCondition stopCondition = new IterationsStopCondition(evaluation.dMaxValue, maxIterations);
                List <double>           sigmas;
                if (adjustSigmas)
                {
                    sigmas = AdjustSigmas(evaluation, sigma);
                }
                else
                {
                    sigmas = Enumerable.Repeat(sigma, evaluation.iSize).ToList();
                }
                RealGaussianMutation        mutation = new RealGaussianMutation(sigmas, evaluation, seed);
                ARealMutationES11Adaptation mutationAdaptation;
                switch (adaptation)
                {
                case 0:
                    mutationAdaptation = new RealNullRealMutationES11Adaptation(mutation);
                    break;

                case 1:
                    mutationAdaptation = new RealOneFifthRuleMutationES11Adaptation(archiveSize, modifier, mutation);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                RealEvolutionStrategy11 es11 = new RealEvolutionStrategy11(evaluation, stopCondition, mutationAdaptation, seed);
                es11.Run();
                return(es11.Result);
            }
        }
        private List <String> Lab3CheckMineHistory(int?seed)
        {
            List <String> resultData = new List <String>();

            IEvaluation <double>[] benchmarkProblems = GenerateProblems();

            foreach (var problem in benchmarkProblems)
            {
                problem.pcConstraint.tGetLowerBound(0);
                List <double> sigmas = Enumerable.Repeat(0.1, problem.iSize).ToList();

                IterationsStopCondition stopCondition = new IterationsStopCondition(problem.dMaxValue, 10000);
                RealGaussianMutation    mutation      = new RealGaussianMutation(sigmas, problem, seed);
                var mutationAdaptation = new RealOneFifthRuleMutationES11Adaptation(5, 20, mutation);

                RealEvolutionStrategy11 optimizer = new RealEvolutionStrategy11(problem, stopCondition, mutationAdaptation, seed);

                optimizer.Run();

                resultData.Add(FormatSave(optimizer));

                ReportOptimizationResult(optimizer.Result);
            }

            return(resultData);
        }
Пример #4
0
        private static void Lab2Step2Sphere(int?seed, int variables)
        {
            CRealStep2SphereEvaluation step2SphereEvaluation = new CRealStep2SphereEvaluation(variables);

            List <double> sigmas = Enumerable.Repeat(0.1, step2SphereEvaluation.iSize).ToList();

            IterationsStopCondition            stopCondition      = new IterationsStopCondition(step2SphereEvaluation.dMaxValue, 1000);
            RealGaussianMutation               mutation           = new RealGaussianMutation(sigmas, step2SphereEvaluation, seed);
            RealNullRealMutationES11Adaptation mutationAdaptation = new RealNullRealMutationES11Adaptation(mutation);

            RealEvolutionStrategy11 es11 = new RealEvolutionStrategy11(step2SphereEvaluation, stopCondition, mutationAdaptation, seed);

            es11.Run();

            ReportOptimizationResult(es11.Result);
        }
Пример #5
0
        private static string RunExperiment(IEvaluation <double> evaluation, string method, string problemInfo, int maxIterations, int parameter, int?seed = null)
        {
            lock (evaluation)
            {
                IterationsStopCondition stopCondition = new IterationsStopCondition(evaluation.dMaxValue, maxIterations);

                if (method == "RS")
                {
                    RealRandomSearch rs = new RealRandomSearch(evaluation, stopCondition, seed);
                    rs.Run();
                    return(ResultToString(problemInfo, method, rs.Result));
                }
                else if (method == "ES11")
                {
                    List <double>        sigmas   = Enumerable.Repeat(0.1, evaluation.iSize).ToList();
                    RealGaussianMutation mutation = new RealGaussianMutation(sigmas, evaluation, seed);
                    RealNullRealMutationES11Adaptation mutationAdaptation = new RealNullRealMutationES11Adaptation(mutation);

                    RealEvolutionStrategy11 es11 = new RealEvolutionStrategy11(evaluation, stopCondition, mutationAdaptation, seed);

                    es11.Run();

                    return(ResultToString(problemInfo, method, es11.Result));
                }
                else if (method == "RestartingES11")
                {
                    List <double>        sigmas   = Enumerable.Repeat(0.1, evaluation.iSize).ToList();
                    RealGaussianMutation mutation = new RealGaussianMutation(sigmas, evaluation, seed);
                    RealNullRealMutationES11Adaptation mutationAdaptation = new RealNullRealMutationES11Adaptation(mutation);

                    RealRestartingEvolutionStrategy11 es11 = new RealRestartingEvolutionStrategy11(evaluation, stopCondition, mutationAdaptation, parameter, seed);

                    es11.Run();

                    return(ResultToString(problemInfo, method, es11.Result));
                }
                else if (method == "PoorMansCMAES")
                {
                    List <double>        sigmas   = Enumerable.Repeat(0.1, evaluation.iSize).ToList();
                    RealGaussianMutation mutation = new RealGaussianMutation(sigmas, evaluation, seed);
                    RealNullRealMutationES11Adaptation mutationAdaptation = new RealNullRealMutationES11Adaptation(mutation);

                    PoorMansCMAES pmcmaes = new PoorMansCMAES(evaluation, stopCondition, mutationAdaptation, parameter, seed);

                    pmcmaes.Run();

                    return(ResultToString(problemInfo, method, pmcmaes.Result));
                }
                else if (method == "CMAES")
                {
                    CMAES cmaes = new CMAES(evaluation, stopCondition, 1, seed);

                    cmaes.Run();

                    return(ResultToString(problemInfo, method, cmaes.Result));
                }
                else
                {
                    throw new ArgumentException();
                }
            }
        }