summaryrefslogtreecommitdiff
path: root/nlpsolver
diff options
context:
space:
mode:
authorTodor Balabanov <todor.balabanov@gmail.com>2021-06-14 15:14:20 +0300
committerTomaž Vajngerl <quikee@gmail.com>2021-06-15 06:03:52 +0200
commitb3bf90ec5fb3d4c6379288081e63d944cda8d5a4 (patch)
tree6cb50357c668d6bd724eed05e5b4a075ab692ffb /nlpsolver
parentde7356c2e0cb099fac396808b5a86a0393b48e5f (diff)
Fewer array reference calls make the code more readable and more efficient.
Change-Id: I7416633a735078a4e0e857f050ea7bfaadba310c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117158 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Tested-by: Jenkins
Diffstat (limited to 'nlpsolver')
-rw-r--r--nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java40
1 files changed, 24 insertions, 16 deletions
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java
index 13c605b63780..dd61355f86fd 100644
--- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java
@@ -92,27 +92,35 @@ public class PSGTBehavior extends AbsGTBehavior {
@Override
public void generateBehavior(SearchPoint trailPoint, ProblemEncoder problemEncoder) {
- SearchPoint gbest_t = socialLib.getGbest();
DesignSpace designSpace = problemEncoder.getDesignSpace();
+
+ double[] pold_t_location = pold_t.getLocation();
+ double[] pbest_t_location = pbest_t.getLocation();
+ double[] pcurrent_t_location = pcurrent_t.getLocation();
+ double[] gbest_t_location = socialLib.getGbest().getLocation();
+ double[] trailPointLocation = trailPoint.getLocation();
+
int DIMENSION = designSpace.getDimension();
- double deltaxb, deltaxbm;
for (int b = 0; b < DIMENSION; b++) {
if (Math.random() < CL) {
- designSpace.mutationAt(trailPoint.getLocation(), b);
- } else {
- deltaxb = weight * (pcurrent_t.getLocation()[b] - pold_t.getLocation()[b])
- + c1 * Math.random() * (pbest_t.getLocation()[b] - pcurrent_t.getLocation()[b])
- + c2 * Math.random() * (gbest_t.getLocation()[b] - pcurrent_t.getLocation()[b]);
-
- // limitation for delta_x
- deltaxbm = 0.5 * designSpace.getMagnitudeIn(b);
- if (deltaxb < -deltaxbm) {
- deltaxb = -deltaxbm;
- } else if (deltaxb > deltaxbm) {
- deltaxb = deltaxbm;
- }
- trailPoint.getLocation()[b] = pcurrent_t.getLocation()[b] + deltaxb;
+ designSpace.mutationAt(trailPointLocation, b);
+ continue;
}
+
+ double deltaxb = weight * (pcurrent_t_location[b] - pold_t_location[b])
+ + c1 * Math.random() * (pbest_t_location[b] - pcurrent_t_location[b])
+ + c2 * Math.random() * (gbest_t_location[b] - pcurrent_t_location[b]);
+
+ // limitation for delta_x
+ double deltaxbm = 0.5 * designSpace.getMagnitudeIn(b);
+
+ if (deltaxb < -deltaxbm) {
+ deltaxb = -deltaxbm;
+ } else if (deltaxb > deltaxbm) {
+ deltaxb = deltaxbm;
+ }
+
+ trailPointLocation[b] = pcurrent_t_location[b] + deltaxb;
}
}