Skip to content

Commit d536374

Browse files
committed
max velocity
1 parent de20ca9 commit d536374

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

controller/GUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private void onCBChange(){
101101

102102
@FXML
103103
public void run() {
104-
BA b = new BA();
104+
PSO b = new PSO();
105105
b.run();
106106

107107
Gantt best = b.getBestSolution();

controller/PSO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void run() {
3030

3131
//update position and velocity
3232
for(Particle p : population) {
33-
p.updateVelocity(globalBest,importanceOfPersonalBest, importanceOfNeighbourhoodBest);
33+
p.updateVelocity(globalBest,importanceOfPersonalBest, importanceOfNeighbourhoodBest, maxVelocity);
3434
p.updatePosition();
3535
}
3636

model/utils/Particle.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public Particle() {
2828
bestFitness = currentFitness;
2929
}
3030

31-
public void updateVelocity(Chromosome g, double C1, double C2) {
31+
public void updateVelocity(Chromosome g, double C1, double C2, double maxVelocity) {
3232
double[][] R1 = new double[g.getWeights().length][g.getWeights()[0].length];
3333
double[][] R2 = new double[g.getWeights().length][g.getWeights()[0].length];
3434

@@ -43,6 +43,15 @@ public void updateVelocity(Chromosome g, double C1, double C2) {
4343
double[][] global = matrixOperation(C2, g.getWeights(), x.getWeights(), R2);
4444

4545
v = sumMatrix(v, personal, global);
46+
47+
for (int i = 0; i < v.length; i++) {
48+
for (int j = 0; j < v[0].length;j++) {
49+
if(v[i][j] > maxVelocity){
50+
v[i][j] = maxVelocity;
51+
}
52+
}
53+
}
54+
4655
}
4756

4857
public void updatePosition() {

0 commit comments

Comments
 (0)