void Start() { // create main library objects: camera man, solver, problem bounds camLibCam = new CLLookAtCameraMan(); psoSolver = new PSOSolver(6); // for 6 degrees of freedom VC problem psoSolver.SetSolverParameters(20, randomParticles, new float[] { 1.0f, 1.0f, 0.8f, 0.4f }); // number of particles, fraction of randomly initialized particles, c1, c2, w_init, w_end Camera unityCamera = GetComponentInParent <Camera> (); camLibCam.unityCamera = unityCamera; }
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"; }