Commit 9950c9b5 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

update PSO tests so they dont fail the evacuation test.

parent e9d20529
Pipeline #77378 failed with stages
in 101 minutes and 34 seconds
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
}, },
"org.vadere.state.attributes.models.AttributesOSM" : { "org.vadere.state.attributes.models.AttributesOSM" : {
"stepCircleResolution" : 18, "stepCircleResolution" : 18,
"numberOfCircles" : 1, "numberOfCircles" : 3,
"varyStepDirection" : false, "varyStepDirection" : false,
"stepLengthIntercept" : 0.4625, "stepLengthIntercept" : 0.4625,
"stepLengthSlopeSpeed" : 0.2345, "stepLengthSlopeSpeed" : 0.2345,
......
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
}, },
"org.vadere.state.attributes.models.AttributesOSM" : { "org.vadere.state.attributes.models.AttributesOSM" : {
"stepCircleResolution" : 18, "stepCircleResolution" : 18,
"numberOfCircles" : 1, "numberOfCircles" : 3,
"varyStepDirection" : false, "varyStepDirection" : false,
"stepLengthIntercept" : 0.4625, "stepLengthIntercept" : 0.4625,
"stepLengthSlopeSpeed" : 0.2345, "stepLengthSlopeSpeed" : 0.2345,
......
...@@ -6,7 +6,9 @@ package org.vadere.util.math.pso; ...@@ -6,7 +6,9 @@ package org.vadere.util.math.pso;
public class AttributesPSO { public class AttributesPSO {
final int numberOfInformedParticles = 3; final int numberOfInformedParticles = 3;
final int swarmSize = 30; final int swarmSize = 30;
final int maxIteration = 15; final int minIteration = 4;
final int maxNoUpdate = 6;
final int maxIteration = 10;
final int problemDimension = 2; final int problemDimension = 2;
final double c1 = 2.0; final double c1 = 2.0;
final double c2 = 2.0; final double c2 = 2.0;
......
...@@ -19,12 +19,14 @@ public class PSO { ...@@ -19,12 +19,14 @@ public class PSO {
private final ICircleSector circle; private final ICircleSector circle;
private final double errorToleranz = 0.0001; private final double errorToleranz = 0.0001;
private double gBest; private double gBest;
private double gLastBest;
private VPoint gBestLocation; private VPoint gBestLocation;
private final Function<VPoint, Double> f; private final Function<VPoint, Double> f;
private int iterationCounter; private int iterationCounter;
private final double maxVelocity; private final double maxVelocity;
private final double minAngle; private final double minAngle;
private final double maxAngle; private final double maxAngle;
private int improvementIterations;
public PSO( public PSO(
@NotNull final Function<VPoint, Double> f, @NotNull final Function<VPoint, Double> f,
...@@ -44,6 +46,7 @@ public class PSO { ...@@ -44,6 +46,7 @@ public class PSO {
this.minAngle = minAngle; this.minAngle = minAngle;
this.maxAngle = maxAngle; this.maxAngle = maxAngle;
this.particles = initialSwarm(swarmPositions); this.particles = initialSwarm(swarmPositions);
this.improvementIterations = 0;
} }
public VPoint getOptimumArg() { public VPoint getOptimumArg() {
...@@ -69,20 +72,21 @@ public class PSO { ...@@ -69,20 +72,21 @@ public class PSO {
} }
public boolean hasFinished() { public boolean hasFinished() {
return iterationCounter >= attributesPSO.maxIteration || hasConverged(); return iterationCounter >= attributesPSO.maxIteration || (iterationCounter >= attributesPSO.minIteration && hasConverged());
} }
public boolean hasConverged() { public boolean hasConverged() {
return false; return improvementIterations >= attributesPSO.maxNoUpdate;
} }
public void update() { public void update() {
if (iterationCounter < attributesPSO.maxIteration) { if (!hasFinished()) {
iterationCounter++; iterationCounter++;
updateLocalBest(); updateLocalBest();
updateGlobalBest(); updateGlobalBest();
double omega = attributesPSO.wUpperBound - (iterationCounter / attributesPSO.maxIteration) * (attributesPSO.wUpperBound - attributesPSO.wLowerBound); double omega = attributesPSO.wUpperBound - (iterationCounter / attributesPSO.minIteration) * (attributesPSO.wUpperBound - attributesPSO.wLowerBound);
particles.forEach(particle -> updateParticle(particle, omega)); particles.forEach(particle -> updateParticle(particle, omega));
} }
} }
...@@ -134,7 +138,7 @@ public class PSO { ...@@ -134,7 +138,7 @@ public class PSO {
* than the old one, particles inform each other about their best values and locations. * than the old one, particles inform each other about their best values and locations.
*/ */
private void updateGlobalBest() { private void updateGlobalBest() {
double lastGBest = gBest; gLastBest = gBest;
for (Particle particle : particles) { for (Particle particle : particles) {
double globalBest = particle.getGlobalBestFitnessValue(); double globalBest = particle.getGlobalBestFitnessValue();
...@@ -144,7 +148,16 @@ public class PSO { ...@@ -144,7 +148,16 @@ public class PSO {
} }
} }
if (gBest >= lastGBest) { // no or small improvement
if (gBest >= gLastBest || Math.abs(gBest-gLastBest) < 0.001) {
improvementIterations++;
}
else {
improvementIterations = 0;
}
// no global improvement
if (gBest >= gLastBest) {
informKParticle(); informKParticle();
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment