123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package psoAlgoCode;
- import java.util.Random;
- import java.util.Vector;
- public class RandomFunctions {
- static Random random = new Random();
- public static Vector<Object> nextDoubles(int dimension) {
- Vector<Object> result = new Vector<Object>();
- for (int i = 0; i < dimension; i++) {
- result.addElement(Function.lowerLimit + random.nextDouble() * (Function.upperLimit * 2));
- }
- return result;
- }
- public static Vector<Object> nextRandoms(int dimension) {
- Vector<Object> result = new Vector<Object>();
- for (int i = 0; i < dimension; i++) {
- result.addElement(random.nextDouble());
- }
- return result;
- }
- public static Vector<Object> nextBoolean(int dimension) {
- Vector<Object> result = new Vector<Object>();
- for (int i = 0; i < dimension; i++) {
- result.addElement(random.nextBoolean());
- }
- return result;
- }
- // The paper Modified binary particle swarm optimization from S. Lee states that
- // phi is a random number between 2.4 and 2.01
- public static double randomPhi() {
- double result = 0.0;
- result = (random.nextDouble() * (2.4 - 2.01)) + 2.01;
- return result;
- }
- }
|