Example #1
0
        private ParticlesViewModel SetupParticlesPlot(PSOSolverData data)
        {
            var result = new ParticlesViewModel();

            Show3d.AddContent(result.SetupParticles(data));

            return(result);
        }
Example #2
0
        private async Task RunSolver()
        {
            var solverOptions = new PSOSolverOptions
            {
                NumDimensions            = 2,
                NumParticles             = 50,
                MaxEpochs                = 500,
                MinimumX                 = -10.0,
                MaximumX                 = 10.0,
                AcceptanceError          = 0.00000000,
                InertiaWeight            = 0.729,
                C1CognitiveWeight        = 1.5,
                C2SocialWeight           = 1.5,
                ParticleResetProbability = 0.001,

                // Slower convergence params for visualization

                //VelocityInitialAtenuation = 0.01
                //InertiaWeight = 0.02,
                //C1CognitiveWeight = 0.05,
                //C2SocialWeight = 0.05,
            };

            var solver = new PSOSolver(ErrorFunction, solverOptions);
            var data   = solver.Initialize();

            if (mParticles == null)
            {
                SetupFunctionPlot(data);
                mParticles = SetupParticlesPlot(data);
                Show3d.ZoomExtents();
            }


            solver.AfterEpoch += (s, d) =>
            {
                Dispatcher.Invoke(() =>
                {
                    mParticles.UpdateParticles(d.Particles);
                    mParticles.UpdateBest(d.BestGlobalPosition, Function2d(d.BestGlobalPosition));
                    UpdateStatusLabels(d);
                });

                Task.Delay(30).Wait();
            };

            StatusLabel.Content = "Particle Swarm Optimizer Running";

            var res = await solver.SolveAsync(data);

            StatusLabel.Content = "Solver finished";
        }