├── README.md └── src └── org └── gandhim └── pso ├── PSODriver.java ├── PSOConstants.java ├── PSOUtility.java ├── Location.java ├── Velocity.java ├── Particle.java ├── ProblemSet.java └── PSOProcess.java /README.md: -------------------------------------------------------------------------------- 1 | pso-example-java 2 | ================ 3 | 4 | Particle Swarm Optimization (PSO) Sample Code using Java 5 | 6 | This project is a complete version of Particle Swarm Optimization with Java sample code described in http://gandhim.wordpress.com/2010/04/04/particle-swarm-optimization-pso-sample-code-using-java. 7 | -------------------------------------------------------------------------------- /src/org/gandhim/pso/PSODriver.java: -------------------------------------------------------------------------------- 1 | package org.gandhim.pso; 2 | 3 | /* author: gandhi - gandhi.mtm [at] gmail [dot] com - Depok, Indonesia */ 4 | 5 | // this is a driver class to execute the PSO process 6 | 7 | public class PSODriver { 8 | public static void main(String args[]) { 9 | new PSOProcess().execute(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/org/gandhim/pso/PSOConstants.java: -------------------------------------------------------------------------------- 1 | package org.gandhim.pso; 2 | 3 | /* author: gandhi - gandhi.mtm [at] gmail [dot] com - Depok, Indonesia */ 4 | 5 | // this is an interface to keep the configuration for the PSO 6 | // you can modify the value depends on your needs 7 | 8 | public interface PSOConstants { 9 | int SWARM_SIZE = 30; 10 | int MAX_ITERATION = 100; 11 | int PROBLEM_DIMENSION = 2; 12 | double C1 = 2.0; 13 | double C2 = 2.0; 14 | double W_UPPERBOUND = 1.0; 15 | double W_LOWERBOUND = 0.0; 16 | } 17 | -------------------------------------------------------------------------------- /src/org/gandhim/pso/PSOUtility.java: -------------------------------------------------------------------------------- 1 | package org.gandhim.pso; 2 | 3 | /* author: gandhi - gandhi.mtm [at] gmail [dot] com - Depok, Indonesia */ 4 | 5 | // just a simple utility class to find a minimum position on a list 6 | 7 | public class PSOUtility { 8 | public static int getMinPos(double[] list) { 9 | int pos = 0; 10 | double minValue = list[0]; 11 | 12 | for(int i=0; i swarm = new Vector(); 14 | private double[] pBest = new double[SWARM_SIZE]; 15 | private Vector pBestLocation = new Vector(); 16 | private double gBest; 17 | private Location gBestLocation; 18 | private double[] fitnessValueList = new double[SWARM_SIZE]; 19 | 20 | Random generator = new Random(); 21 | 22 | public void execute() { 23 | initializeSwarm(); 24 | updateFitnessList(); 25 | 26 | for(int i=0; i ProblemSet.ERR_TOLERANCE) { 36 | // step 1 - update pBest 37 | for(int i=0; i