⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example.java

📁 JSwarn 是微粒群优化(PSO) 程序包被写在Java. 设计要求极小的工作成绩使用(在配件箱外面) 虽然同样高模件。
💻 JAVA
字号:
package net.sourceforge.jswarm_pso.example_2;import net.sourceforge.jswarm_pso.Swarm;/** * An extremely simple swarm optimization example * Minimize Rastrigin's function * 		f( x1 , x2 ) = 20.0 + (x1 * x1) + (x2 * x2) - 10.0 * (Math.cos(2 * Math.PI * x1) + Math.cos(2 * Math.PI * x2)); * Solution is (obviously): [ 0, 0 ] *  * @author Pablo Cingolani <pcingola@sinectis.com> */public class Example {	public static void main(String[] args) {		System.out.println("Example of Particle Swarm Optimization: Optimizing Rastrijin's funtion");		// Create a swarm (using 'MyParticle' as sample particle and 'MyFitnessFunction' as finess function)		Swarm swarm = new Swarm(Swarm.DEFAULT_NUMBER_OF_PARTICLES, new MyParticle(), new MyFitnessFunction());		// Tune swarm's update parameters (if needed)		swarm.setInertia(0.95);		swarm.setParticleIncrement(0.8);		swarm.setGlobalIncrement(0.8);		// Set position (and velocity) constraints. I.e.: where to look for solutions		swarm.setMaxPosition(100);		swarm.setMinPosition(-100);		// Show a 2D graph		int numberOfIterations = 5000;		int displayEvery = numberOfIterations / 100 + 1;		SwarmShow2D ss2d = new SwarmShow2D(swarm, numberOfIterations, displayEvery, true);		ss2d.run();		// Show best position		double bestPosition[] = ss2d.getSwarm().getBestPosition();		System.out.println("Best position: [" + bestPosition[0] + ", " + bestPosition[1] + " ]\nBest fitness: " + ss2d.getSwarm().getBestFitness() + "\nKnown Solution: [0.0, 0.0]");	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -