Пример #1
0
 public RealEvolutionStrategy11(IEvaluation <double, double> evaluation, IStopCondition stopCondition,
                                ARealMutationES11Adaptation mutationAdaptation, int?seed = null)
     : base(evaluation, stopCondition, new OptimizationState <double>(evaluation.tMaxValue))
 {
     this.mutationAdaptation = mutationAdaptation;
     randomGeneration        = new RealRandomGenerator(evaluation.pcConstraint, seed);
 }
Пример #2
0
 public RealRandomSearch(IEvaluation <double, double> evaluation, IStopCondition stopCondition, int?seed = null)
 {
     Result             = null;
     this.evaluation    = evaluation;
     this.stopCondition = stopCondition;
     generator          = new RealRandomGenerator(evaluation.pcConstraint, seed);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="FireworksAlgorithm2012"/> class.
        /// </summary>
        /// <param name="problem">The problem to be solved by the algorithm.</param>
        /// <param name="stopCondition">The stop condition for the algorithm.</param>
        /// <param name="settings">The algorithm settings.</param>
        public FireworksAlgorithm2012(Problem problem, IStopCondition stopCondition, FireworksAlgorithmSettings2012 settings)
            : base(problem, stopCondition, settings)
        {
            this.Randomizer = new DefaultRandom();
            this.BestWorstFireworkSelector = new ExtremumFireworkSelector(problem.Target);
            this.Distribution            = new NormalDistribution(FireworksAlgorithm2012.normalDistributionMean, FireworksAlgorithm2012.normalDistributionStdDev);
            this.InitialSparkGenerator   = new InitialSparkGenerator(problem.Dimensions, problem.InitialRanges, this.Randomizer);
            this.ExplosionSparkGenerator = new ExplosionSparkGenerator(problem.Dimensions, this.Randomizer);
            this.SpecificSparkGenerator  = new GaussianSparkGenerator(problem.Dimensions, this.Distribution, this.Randomizer);
            this.DistanceCalculator      = new EuclideanDistance(problem.Dimensions);
            this.LocationSelector        = new DistanceBasedFireworkSelector(this.DistanceCalculator, this.BestWorstFireworkSelector, this.Settings.LocationsNumber);
            this.SamplingSelector        = new BestFireworkSelector(new Func <IEnumerable <Firework>, Firework>(this.BestWorstFireworkSelector.SelectBest));
            this.ExploderSettings        = new ExploderSettings
            {
                ExplosionSparksNumberModifier    = settings.ExplosionSparksNumberModifier,
                ExplosionSparksNumberLowerBound  = settings.ExplosionSparksNumberLowerBound,
                ExplosionSparksNumberUpperBound  = settings.ExplosionSparksNumberUpperBound,
                ExplosionSparksMaximumAmplitude  = settings.ExplosionSparksMaximumAmplitude,
                SpecificSparksPerExplosionNumber = settings.SpecificSparksPerExplosionNumber
            };

            this.Exploder               = new Exploder(this.ExploderSettings, this.BestWorstFireworkSelector);
            this.Differentiator         = new Differentiator();
            this.PolynomialFit          = new PolynomialFit(this.Settings.FunctionOrder);
            this.FunctionSolver         = new Solver();
            this.EliteStrategyGenerator = new LS2EliteStrategyGenerator(problem.Dimensions, this.PolynomialFit, this.Differentiator, this.FunctionSolver);
        }
Пример #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="Interpolation"></param>
 /// <param name="StopCondition"></param>
 /// <param name="StopConditionSeparate"></param>
 public EmDecomposition_2(
     Func<IList<double>, IList<double>, IList<double>, IList<double>> Interpolation, 
     IStopCondition StopCondition, 
     IStopCondition StopConditionSeparate)
     : base(Interpolation, StopCondition, StopConditionSeparate)
 {
 }
Пример #5
0
 public AOptimizer(IEvaluation <Element, EvaluationResult> evaluation, IStopCondition stopCondition,
                   AOptimizationState <Element, EvaluationResult, OptimizationResult> state)
 {
     this.evaluation    = evaluation;
     this.stopCondition = stopCondition;
     this.state         = state;
 }
Пример #6
0
 public NSGA2(IEvaluation <Element, Tuple <double, double> > evaluation, IStopCondition stopCondition, AGenerator <Element> generator,
              IDominationComparer dominationComparer, ACrossover crossover, IMutation <Element> mutation, int populationSize,
              int?seed = null)
     : base(evaluation, stopCondition, generator, new NSGA2Selection(2, evaluation.tMaxValue, dominationComparer, true, seed),
            crossover, mutation, populationSize, seed)
 {
 }
Пример #7
0
 public ASimpleOptimizer(IEvaluation <Element, double> evaluation, IStopCondition stopCondition, AGenerator <Element> generator)
 {
     Result             = null;
     this.evaluation    = evaluation;
     this.stopCondition = stopCondition;
     this.generator     = generator;
 }
Пример #8
0
 public GeneticAlgorithm(IEvaluation <Element, double> evaluation, IStopCondition stopCondition, AGenerator <Element> generator,
                         ASelection <double> selection, ACrossover crossover, IMutation <Element> mutation, int populationSize,
                         int?seed = null)
     : base(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize,
            new OptimizationState <Element>(evaluation.tMaxValue), seed)
 {
 }
Пример #9
0
 public RealEvolutionStrategy11(IEvaluation <double, double> evaluation, IStopCondition stopCondition, ARealMutationES11Adaptation mutationAdaptation, int?seed = null)
 {
     Result                  = null;
     this.evaluation         = evaluation;
     this.stopCondition      = stopCondition;
     this.mutationAdaptation = mutationAdaptation;
     randomGeneration        = new RealRandomGenerator(evaluation.pcConstraint, seed);
 }
Пример #10
0
        /// <summary>
        /// Adds the specified stop condition to the chain with AND operation.
        /// </summary>
        /// <param name="anotherStopCondition">Another stop condition.</param>
        /// <returns>Stop condition chain with added <paramref name="anotherStopCondition"/>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException"> if <paramref name="anotherStopCondition"/>
        /// is <c>null</c>.</exception>
        public StopConditionChain And(IStopCondition anotherStopCondition)
        {
            if (anotherStopCondition == null)
            {
                throw new ArgumentNullException(nameof(anotherStopCondition));
            }

            return(this.AddStopCondition(anotherStopCondition, StopConditionChain.AggregationOperator.And));
        }
Пример #11
0
        public GeneticAlgorithm(IEvaluation <Element, EvaluationResult> evaluation, IStopCondition stopCondition, AGenerator <Element> generator,
                                ASelection <EvaluationResult> selection, ACrossover crossover, IMutation <Element> mutation, int populationSize,
                                AOptimizationState <Element, EvaluationResult, OptimizationResult> state, int?seed = null)
            : base(evaluation, stopCondition, generator, selection, mutation, populationSize, state)
        {
            this.crossover = crossover;

            indices  = Utils.CreateIndexList(populationSize);
            shuffler = new Shuffler(seed);
        }
Пример #12
0
        public void Constructor_NegativeParams_ArgumentNullExceptionThrown(
            Problem problem,
            IStopCondition stopCondition,
            FireworksAlgorithmSettings settings,
            string expectedParamName)
        {
            ArgumentNullException actualException = Assert.Throws <ArgumentNullException>(() => new FireworksAlgorithm(problem, stopCondition, settings));

            Assert.NotNull(actualException);
            Assert.Equal(expectedParamName, actualException.ParamName);
        }
Пример #13
0
        /// <summary>
        /// Creates a new instance of <see cref="StopConditionChain"/> and adds
        /// the specified stop condition as first in the chain.
        /// </summary>
        /// <param name="firstStopCondition">The first stop condition.</param>
        /// <returns>A new instance of <see cref="StopConditionChain"/> with
        /// <paramref name="firstStopCondition"/> as first in the chain.</returns>
        /// <exception cref="System.ArgumentNullException"> if <paramref name="firstStopCondition"/>
        /// is <c>null</c>.</exception>
        public static StopConditionChain From(IStopCondition firstStopCondition)
        {
            if (firstStopCondition == null)
            {
                throw new ArgumentNullException(nameof(firstStopCondition));
            }

            StopConditionChain chain = new StopConditionChain();

            Debug.Assert(chain.stopConditions != null, "Chain stop condition collection is null");

            chain.stopConditions.Add(firstStopCondition);

            return(chain);
        }
Пример #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FireworksAlgorithmBase{TSettings}"/> class.
        /// </summary>
        /// <param name="problem">The problem to be solved by the algorithm.</param>
        /// <param name="stopCondition">The stop condition for the algorithm.</param>
        /// <param name="settings">The algorithm settings.</param>
        /// <exception cref="System.ArgumentNullException"> if <paramref name="problem"/>
        /// or <paramref name="stopCondition"/> or <paramref name="settings"/> is
        /// <c>null</c>.</exception>
        protected FireworksAlgorithmBase(Problem problem, IStopCondition stopCondition, TSettings settings)
        {
            if (problem == null)
            {
                throw new ArgumentNullException(nameof(problem));
            }

            if (stopCondition == null)
            {
                throw new ArgumentNullException(nameof(stopCondition));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            this.ProblemToSolve = problem;
            this.StopCondition  = stopCondition;
            this.Settings       = settings;
        }
Пример #15
0
        public CMAES(IEvaluation <double, double> evaluation, IStopCondition stopCondition, double initSigma, int?seed = null)
            : base(evaluation, stopCondition, new OptimizationState <double>(evaluation.tMaxValue))
        {
            this.initSigma = initSigma;

            normalRNG     = new NormalRealRandom(seed);
            realGenerator = new RealRandomGenerator(evaluation.pcConstraint, seed);

            int N = evaluation.iSize;

            previousMeans = Vector <double> .Build.Dense(N);

            means = Vector <double> .Build.Dense(N);

            covarianceMatrix = Matrix <double> .Build.Dense(N, N);

            selectionParameters  = new SelectionParameters(N);
            stepSizeParameters   = new StepSizeParameters(N, initSigma);
            adaptationParameters = new AdaptationParameters(N, selectionParameters);

            sampledPopulation = new List <Individual>(selectionParameters.Lambda);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FireworksAlgorithm"/> class.
        /// </summary>
        /// <param name="problem">The problem to be solved by the algorithm.</param>
        /// <param name="stopCondition">The stop condition for the algorithm.</param>
        /// <param name="settings">The algorithm settings.</param>
        public FireworksAlgorithm(Problem problem, IStopCondition stopCondition, FireworksAlgorithmSettings settings)
            : base(problem, stopCondition, settings)
        {
            this.Randomizer = new DefaultRandom();
            this.BestWorstFireworkSelector = new ExtremumFireworkSelector(problem.Target);
            this.Distribution            = new NormalDistribution(FireworksAlgorithm.normalDistributionMean, FireworksAlgorithm.normalDistributionStdDev);
            this.InitialSparkGenerator   = new InitialSparkGenerator(problem.Dimensions, problem.InitialRanges, this.Randomizer);
            this.ExplosionSparkGenerator = new ExplosionSparkGenerator(problem.Dimensions, this.Randomizer);
            this.SpecificSparkGenerator  = new GaussianSparkGenerator(problem.Dimensions, this.Distribution, this.Randomizer);
            this.DistanceCalculator      = new EuclideanDistance(problem.Dimensions);
            this.LocationSelector        = new DistanceBasedFireworkSelector(this.DistanceCalculator, this.BestWorstFireworkSelector, this.Settings.LocationsNumber);
            this.ExploderSettings        = new ExploderSettings
            {
                ExplosionSparksNumberModifier    = settings.ExplosionSparksNumberModifier,
                ExplosionSparksNumberLowerBound  = settings.ExplosionSparksNumberLowerBound,
                ExplosionSparksNumberUpperBound  = settings.ExplosionSparksNumberUpperBound,
                ExplosionSparksMaximumAmplitude  = settings.ExplosionSparksMaximumAmplitude,
                SpecificSparksPerExplosionNumber = settings.SpecificSparksPerExplosionNumber
            };

            this.Exploder = new Exploder(this.ExploderSettings, this.BestWorstFireworkSelector);
        }
Пример #17
0
        /// <summary>
        /// Adds the stop condition to the chain and ties it to the chain with specified
        /// operator.
        /// </summary>
        /// <param name="anotherStopCondition">Another stop condition.</param>
        /// <param name="mode">The mode (operator).</param>
        /// <returns>Stop condition chain with added <paramref name="anotherStopCondition"/>.</returns>
        /// <exception cref="System.ArgumentOutOfRangeException"> if <paramref name="mode"/>
        /// differs from one of the supported operations or is the default one.</exception>
        /// <exception cref="System.InvalidOperationException"> if trying to add new stop condition
        /// with the operator that differs from previous ones.</exception>
        private StopConditionChain AddStopCondition(IStopCondition anotherStopCondition, StopConditionChain.AggregationOperator mode)
        {
            if (mode == StopConditionChain.AggregationOperator.None)
            {
                throw new ArgumentOutOfRangeException(nameof(mode));
            }

            if (this.aggregationMode == StopConditionChain.AggregationOperator.None)
            {
                this.aggregationMode = mode;
            }

            if (this.aggregationMode != mode)
            {
                throw new InvalidOperationException();
            }

            Debug.Assert(this.stopConditions != null, "Stop condition collection is null");

            this.stopConditions.Add(anotherStopCondition);
            return(this);
        }
Пример #18
0
 /// <summary>
 /// 
 /// </summary>
 public EmDecomposition(
     Func<IList<double>, IList<double>, IList<double>, IList<double>> Interpolation, 
     IStopCondition StopCriterion, 
     IStopCondition StopSiftCriterion)
 {
     this.InterpolationMethod = Interpolation;
     this.StopConditionSeparate = StopSiftCriterion;
     this.StopCondition = StopCriterion;
 }
        public APopulationOptimizer(IEvaluation <Element, EvaluationResult> evaluation, IStopCondition stopCondition, AGenerator <Element> generator,
                                    ASelection <EvaluationResult> selection, IMutation <Element> mutation, int populationSize,
                                    AOptimizationState <Element, EvaluationResult, OptimizationResult> state)
            : base(evaluation, stopCondition, state)
        {
            this.generator = generator;
            this.selection = selection;
            this.mutation  = mutation;

            this.populationSize = populationSize;
            population          = new List <Individual <Element, EvaluationResult> >();
        }
Пример #20
0
 protected void RegisterStopCondition(IStopCondition stopCondition)
 {
     _stopConditions.Add(stopCondition);
 }
Пример #21
0
 public BinaryRandomSearch(IEvaluation <bool, double> evaluation, IStopCondition stopCondition, int?seed = null)
     : base(evaluation, stopCondition, new BinaryRandomGenerator(evaluation.pcConstraint, seed))
 {
 }
 public ClusteringGeneticAlgorithm(IEvaluation <Element, Tuple <double, double> > evaluation, IStopCondition stopCondition,
                                   AGenerator <Element> generator, ASelection <Tuple <double, double> > selection, ACrossover crossover,
                                   IMutation <Element> mutation, int populationSize, int clusters, int?seed = null)
     : base(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize, seed)
 {
     no_clusters = clusters;
     rng         = seed.HasValue ? new Random(seed.Value) : new Random();
 }
Пример #23
0
 public RealRandomSearch(IEvaluation <double, double> evaluation, IStopCondition stopCondition, int?seed = null)
     : base(evaluation, stopCondition, new RealRandomGenerator(evaluation.pcConstraint, seed))
 {
 }
Пример #24
0
 public SamplingOptimizer(IEvaluation <Element, double> evaluation, IStopCondition stopCondition, AGenerator <Element> generator)
     : base(evaluation, stopCondition, new OptimizationState <Element>(evaluation.tMaxValue))
 {
     this.generator = generator;
 }