private ParticleSwarmOptimization CreatePsoRastriginSample() { ParticleSwarmOptimization pso = new ParticleSwarmOptimization(); #region Problem Configuration var problem = new SingleObjectiveTestFunctionProblem(); var provider = new SOTFInstanceProvider(); problem.Load(provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name == "Rastrigin Function"))); problem.SolutionCreatorParameter.Value = new UniformRandomRealVectorCreator(); #endregion #region Algorithm Configuration pso.Name = "Particle Swarm Optimization - Rastrigin"; pso.Description = "A particle swarm optimization algorithm which solves the 2-dimensional Rastrigin test function."; pso.Problem = problem; pso.Inertia.Value = 0.721; pso.MaxIterations.Value = 200; pso.NeighborBestAttraction.Value = 1.193; pso.PersonalBestAttraction.Value = 1.193; pso.SwarmSize.Value = 40; pso.TopologyInitializer = pso.TopologyInitializerParameter.ValidValues.OfType <SPSORandomTopologyInitializer>().First(); pso.TopologyUpdater = pso.TopologyUpdaterParameter.ValidValues.OfType <SPSOAdaptiveRandomTopologyUpdater>().First(); pso.Seed.Value = 0; pso.SetSeedRandomly.Value = true; #endregion pso.Engine = new ParallelEngine.ParallelEngine(); return(pso); }
private ParticleSwarmOptimization CreatePsoSchwefelSample() { ParticleSwarmOptimization pso = new ParticleSwarmOptimization(); #region Problem Configuration var problem = new SingleObjectiveTestFunctionProblem(); problem.BestKnownQuality.Value = 0.0; problem.BestKnownSolutionParameter.Value = new RealVector(new double[] { 420.968746, 420.968746 }); problem.Bounds = new DoubleMatrix(new double[, ] { { -500, 500 } }); problem.EvaluatorParameter.Value = new SchwefelEvaluator(); problem.Maximization.Value = false; problem.ProblemSize.Value = 2; problem.SolutionCreatorParameter.Value = new UniformRandomRealVectorCreator(); #endregion #region Algorithm Configuration pso.Name = "Particle Swarm Optimization - Schwefel"; pso.Description = "A particle swarm optimization algorithm which solves the 2-dimensional Schwefel test function (based on the description in Pedersen, M.E.H. (2010). PhD thesis. University of Southampton)"; pso.Problem = problem; pso.Inertia.Value = 10; pso.MaxIterations.Value = 1000; pso.NeighborBestAttraction.Value = 0.5; pso.PersonalBestAttraction.Value = -0.01; pso.SwarmSize.Value = 50; var inertiaUpdater = pso.InertiaUpdaterParameter.ValidValues .OfType <ExponentialDiscreteDoubleValueModifier>() .Single(); inertiaUpdater.StartValueParameter.Value = new DoubleValue(10); inertiaUpdater.EndValueParameter.Value = new DoubleValue(1); pso.InertiaUpdater = inertiaUpdater; pso.ParticleCreator = pso.ParticleCreatorParameter.ValidValues .OfType <RealVectorParticleCreator>() .Single(); var swarmUpdater = pso.SwarmUpdaterParameter.ValidValues .OfType <RealVectorSwarmUpdater>() .Single(); swarmUpdater.VelocityBoundsIndexParameter.ActualName = "Iterations"; swarmUpdater.VelocityBoundsParameter.Value = new DoubleMatrix(new double[, ] { { -10, 10 } }); swarmUpdater.VelocityBoundsStartValueParameter.Value = new DoubleValue(10.0); swarmUpdater.VelocityBoundsEndValueParameter.Value = new DoubleValue(1.0); swarmUpdater.VelocityBoundsScalingOperatorParameter.Value = swarmUpdater.VelocityBoundsScalingOperatorParameter.ValidValues .OfType <ExponentialDiscreteDoubleValueModifier>() .Single(); pso.TopologyInitializer = null; pso.TopologyUpdater = null; pso.SwarmUpdater = swarmUpdater; pso.Seed.Value = 0; pso.SetSeedRandomly.Value = true; #endregion pso.Engine = new ParallelEngine.ParallelEngine(); return(pso); }
private SimulatedAnnealing CreateSimulatedAnnealingRastriginSample() { SimulatedAnnealing sa = new SimulatedAnnealing(); #region Problem Configuration var problem = new SingleObjectiveTestFunctionProblem(); problem.BestKnownQuality.Value = 0.0; problem.BestKnownSolutionParameter.Value = new RealVector(new double[] { 0, 0 }); problem.Bounds = new DoubleMatrix(new double[, ] { { -5.12, 5.12 } }); problem.EvaluatorParameter.Value = new RastriginEvaluator(); problem.Maximization.Value = false; problem.ProblemSize.Value = 2; problem.SolutionCreatorParameter.Value = new UniformRandomRealVectorCreator(); #endregion #region Algorithm Configuration sa.Name = "Simulated Annealing - Rastrigin"; sa.Description = "A simulated annealing algorithm that solves the 2-dimensional Rastrigin test function"; sa.Problem = problem; var annealingOperator = sa.AnnealingOperatorParameter.ValidValues .OfType <ExponentialDiscreteDoubleValueModifier>() .Single(); annealingOperator.StartIndexParameter.Value = new IntValue(0); sa.AnnealingOperator = annealingOperator; sa.EndTemperature.Value = 1E-6; sa.InnerIterations.Value = 50; sa.MaximumIterations.Value = 100; var moveEvaluator = sa.MoveEvaluatorParameter.ValidValues .OfType <RastriginAdditiveMoveEvaluator>() .Single(); moveEvaluator.A.Value = 10; sa.MoveEvaluator = moveEvaluator; var moveGenerator = sa.MoveGeneratorParameter.ValidValues .OfType <StochasticNormalMultiMoveGenerator>() .Single(); moveGenerator.SigmaParameter.Value = new DoubleValue(1); sa.MoveGenerator = moveGenerator; sa.MoveMaker = sa.MoveMakerParameter.ValidValues .OfType <AdditiveMoveMaker>() .Single(); sa.Seed.Value = 0; sa.SetSeedRandomly.Value = true; sa.StartTemperature.Value = 1; #endregion sa.Engine = new ParallelEngine.ParallelEngine(); return(sa); }
private ParticleSwarmOptimization CreatePsoSchwefelSample() { ParticleSwarmOptimization pso = new ParticleSwarmOptimization(); #region Problem Configuration var problem = new SingleObjectiveTestFunctionProblem(); problem.BestKnownQuality.Value = 0.0; problem.BestKnownSolutionParameter.Value = new RealVector(new double[] { 420.968746, 420.968746 }); problem.Bounds = new DoubleMatrix(new double[,] { { -500, 500 } }); problem.EvaluatorParameter.Value = new SchwefelEvaluator(); problem.Maximization.Value = false; problem.ProblemSize.Value = 2; problem.SolutionCreatorParameter.Value = new UniformRandomRealVectorCreator(); #endregion #region Algorithm Configuration pso.Name = "Particle Swarm Optimization - Schwefel"; pso.Description = "A particle swarm optimization algorithm which solves the 2-dimensional Schwefel test function (based on the description in Pedersen, M.E.H. (2010). PhD thesis. University of Southampton)"; pso.Problem = problem; pso.Inertia.Value = 10; pso.MaxIterations.Value = 1000; pso.NeighborBestAttraction.Value = 0.5; pso.PersonalBestAttraction.Value = -0.01; pso.SwarmSize.Value = 50; var inertiaUpdater = pso.InertiaUpdaterParameter.ValidValues .OfType<ExponentialDiscreteDoubleValueModifier>() .Single(); inertiaUpdater.StartValueParameter.Value = new DoubleValue(10); inertiaUpdater.EndValueParameter.Value = new DoubleValue(1); pso.InertiaUpdater = inertiaUpdater; pso.ParticleCreator = pso.ParticleCreatorParameter.ValidValues .OfType<RealVectorParticleCreator>() .Single(); var swarmUpdater = pso.SwarmUpdaterParameter.ValidValues .OfType<RealVectorSwarmUpdater>() .Single(); swarmUpdater.VelocityBoundsIndexParameter.ActualName = "Iterations"; swarmUpdater.VelocityBoundsParameter.Value = new DoubleMatrix(new double[,] { { -10, 10 } }); swarmUpdater.VelocityBoundsStartValueParameter.Value = new DoubleValue(10.0); swarmUpdater.VelocityBoundsEndValueParameter.Value = new DoubleValue(1.0); swarmUpdater.VelocityBoundsScalingOperatorParameter.Value = swarmUpdater.VelocityBoundsScalingOperatorParameter.ValidValues .OfType<ExponentialDiscreteDoubleValueModifier>() .Single(); pso.TopologyInitializer = null; pso.TopologyUpdater = null; pso.SwarmUpdater = swarmUpdater; pso.Seed.Value = 0; pso.SetSeedRandomly.Value = true; #endregion pso.Engine = new ParallelEngine.ParallelEngine(); return pso; }
private EvolutionStrategy CreateEsGriewankSample() { EvolutionStrategy es = new EvolutionStrategy(); #region Problem Configuration SingleObjectiveTestFunctionProblem problem = new SingleObjectiveTestFunctionProblem(); problem.ProblemSize.Value = 10; problem.EvaluatorParameter.Value = new GriewankEvaluator(); problem.SolutionCreatorParameter.Value = new UniformRandomRealVectorCreator(); problem.Maximization.Value = false; problem.Bounds = new DoubleMatrix(new double[, ] { { -600, 600 } }); problem.BestKnownQuality.Value = 0; problem.BestKnownSolutionParameter.Value = new RealVector(10); problem.Name = "Single Objective Test Function"; problem.Description = "Test function with real valued inputs and a single objective."; #endregion #region Algorithm Configuration es.Name = "Evolution Strategy - Griewank"; es.Description = "An evolution strategy which solves the 10-dimensional Griewank test function"; es.Problem = problem; SamplesUtils.ConfigureEvolutionStrategyParameters <AverageCrossover, NormalAllPositionsManipulator, StdDevStrategyVectorCreator, StdDevStrategyVectorCrossover, StdDevStrategyVectorManipulator>( es, 20, 500, 2, 200, false); StdDevStrategyVectorCreator strategyCreator = (StdDevStrategyVectorCreator)es.StrategyParameterCreator; strategyCreator.BoundsParameter.Value = new DoubleMatrix(new double[, ] { { 1, 20 } }); StdDevStrategyVectorManipulator strategyManipulator = (StdDevStrategyVectorManipulator)es.StrategyParameterManipulator; strategyManipulator.BoundsParameter.Value = new DoubleMatrix(new double[, ] { { 1E-12, 30 } }); strategyManipulator.GeneralLearningRateParameter.Value = new DoubleValue(0.22360679774997896); strategyManipulator.LearningRateParameter.Value = new DoubleValue(0.39763536438352531); #endregion return(es); }
private SimulatedAnnealing CreateSimulatedAnnealingRastriginSample() { SimulatedAnnealing sa = new SimulatedAnnealing(); #region Problem Configuration var problem = new SingleObjectiveTestFunctionProblem(); problem.BestKnownQuality.Value = 0.0; problem.BestKnownSolutionParameter.Value = new RealVector(new double[] { 0, 0 }); problem.Bounds = new DoubleMatrix(new double[,] { { -5.12, 5.12 } }); problem.EvaluatorParameter.Value = new RastriginEvaluator(); problem.Maximization.Value = false; problem.ProblemSize.Value = 2; problem.SolutionCreatorParameter.Value = new UniformRandomRealVectorCreator(); #endregion #region Algorithm Configuration sa.Name = "Simulated Annealing - Rastrigin"; sa.Description = "A simulated annealing algorithm that solves the 2-dimensional Rastrigin test function"; sa.Problem = problem; var annealingOperator = sa.AnnealingOperatorParameter.ValidValues .OfType<ExponentialDiscreteDoubleValueModifier>() .Single(); annealingOperator.StartIndexParameter.Value = new IntValue(0); sa.AnnealingOperator = annealingOperator; sa.EndTemperature.Value = 1E-6; sa.InnerIterations.Value = 50; sa.MaximumIterations.Value = 100; var moveEvaluator = sa.MoveEvaluatorParameter.ValidValues .OfType<RastriginAdditiveMoveEvaluator>() .Single(); moveEvaluator.A.Value = 10; sa.MoveEvaluator = moveEvaluator; var moveGenerator = sa.MoveGeneratorParameter.ValidValues .OfType<StochasticNormalMultiMoveGenerator>() .Single(); moveGenerator.SigmaParameter.Value = new DoubleValue(1); sa.MoveGenerator = moveGenerator; sa.MoveMaker = sa.MoveMakerParameter.ValidValues .OfType<AdditiveMoveMaker>() .Single(); sa.Seed.Value = 0; sa.SetSeedRandomly.Value = true; sa.StartTemperature.Value = 1; #endregion sa.Engine = new ParallelEngine.ParallelEngine(); return sa; }
private EvolutionStrategy CreateEsGriewankSample() { EvolutionStrategy es = new EvolutionStrategy(); #region Problem Configuration SingleObjectiveTestFunctionProblem problem = new SingleObjectiveTestFunctionProblem(); problem.ProblemSize.Value = 10; problem.EvaluatorParameter.Value = new GriewankEvaluator(); problem.SolutionCreatorParameter.Value = new UniformRandomRealVectorCreator(); problem.Maximization.Value = false; problem.Bounds = new DoubleMatrix(new double[,] { { -600, 600 } }); problem.BestKnownQuality.Value = 0; problem.BestKnownSolutionParameter.Value = new RealVector(10); problem.Name = "Single Objective Test Function"; problem.Description = "Test function with real valued inputs and a single objective."; #endregion #region Algorithm Configuration es.Name = "Evolution Strategy - Griewank"; es.Description = "An evolution strategy which solves the 10-dimensional Griewank test function"; es.Problem = problem; SamplesUtils.ConfigureEvolutionStrategyParameters<AverageCrossover, NormalAllPositionsManipulator, StdDevStrategyVectorCreator, StdDevStrategyVectorCrossover, StdDevStrategyVectorManipulator>( es, 20, 500, 2, 200, false); StdDevStrategyVectorCreator strategyCreator = (StdDevStrategyVectorCreator)es.StrategyParameterCreator; strategyCreator.BoundsParameter.Value = new DoubleMatrix(new double[,] { { 1, 20 } }); StdDevStrategyVectorManipulator strategyManipulator = (StdDevStrategyVectorManipulator)es.StrategyParameterManipulator; strategyManipulator.BoundsParameter.Value = new DoubleMatrix(new double[,] { { 1E-12, 30 } }); strategyManipulator.GeneralLearningRateParameter.Value = new DoubleValue(0.22360679774997896); strategyManipulator.LearningRateParameter.Value = new DoubleValue(0.39763536438352531); #endregion return es; }