123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package psoAlgoCode;
- import java.util.Vector;
- public class Particle {
- //Number of dimensions of the particle
- private int dim;
- //Value for the local best -> best value for this particle so far
- private double local_best;
- //Current value of the particle -> value in this iteration
- private double actual_value;
-
- //Each particle possesses a position and a velocity in every dimension
- private Coordinate<Vector<Object>> posAdvanced;
- private Coordinate<Vector<Object>> velAdvanced;
- //The corresponding position for the local best value
- private Coordinate<Vector<Object>> localBestPosAdv;
- /**
- * Create a particle
- * @param dimensions number of dimensions for this particle
- */
- public Particle(int dimensions) {
- this.dim = dimensions;
- posAdvanced = new Coordinate<Vector<Object>>();
- velAdvanced = new Coordinate<Vector<Object>>();
- local_best = Double.POSITIVE_INFINITY;
- actual_value = Double.POSITIVE_INFINITY;
- }
- // Getters
- public int getDimensions() {
- return dim;
- }
- public Coordinate<Vector<Object>> getPositionAdv() {
- return posAdvanced;
- }
- public Coordinate<Vector<Object>> getVelocityAdv() {
- return velAdvanced;
- }
- public Coordinate<Vector<Object>> getBestLocalPosAdv() {
- return localBestPosAdv;
- }
- public double getLocalBestValue() {
- return local_best;
- }
- public double getActualValue() {
- return actual_value;
- }
- // Setters
- public void setDimensions(int dim) {
- this.dim = dim;
- }
- public void setPositionAdv(Coordinate<Vector<Object>> new_pos) {
- this.posAdvanced = new_pos;
- }
- public void setVelocityAdv(Coordinate<Vector<Object>> new_vel) {
- this.velAdvanced = new_vel;
- }
- public void setActualValue(double v) {
- this.actual_value = v;
- }
- // Update Functions
- public void updateLocalBest() {
- if (actual_value < local_best) {
- this.local_best = this.actual_value;
- this.localBestPosAdv = this.posAdvanced;
- }
- }
- }
|