[Libreoffice-commits] core.git: nlpsolver/ThirdParty
Todor Balabanov (via logerrit)
logerrit at kemper.freedesktop.org
Sun May 12 02:19:58 UTC 2019
nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java | 61 +++++++---
1 file changed, 48 insertions(+), 13 deletions(-)
New commits:
commit c728bb5420f19eb6fbec859ec927f35d772694be
Author: Todor Balabanov <todor.balabanov at gmail.com>
AuthorDate: Thu May 2 15:17:38 2019 +0300
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sun May 12 04:04:54 2019 +0200
Generate behavior code simplification and very small speed-up.
Change-Id: Ib13080e4c21738affa129d12a07f5380f665e7a4
Reviewed-on: https://gerrit.libreoffice.org/71673
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java
index a58a66196372..dc7f7400cd58 100644
--- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java
@@ -48,24 +48,59 @@ public class DEGTBehavior extends AbsGTBehavior implements ILibEngine {
pbest_t = pbest;
}
+ /**
+ * Crossover and mutation for a single vector element done in a single step.
+ *
+ * @param index
+ * Index of the trial vector element to be changed.
+ * @param trialVector
+ * Trial vector reference.
+ * @param globalVector
+ * Global best found vector reference.
+ * @param differenceVectors
+ * List of vectors used for difference delta calculation.
+ */
+ private void crossoverAndMutation(int index, double trialVector[], double globalVector[], BasicPoint differenceVectors[]) {
+ double delta = 0D;
+
+ for (int i = 0; i < differenceVectors.length; i++) {
+ delta += (i % 2 == 0 ? +1D : -1D) * differenceVectors[i].getLocation()[index];
+ }
+
+ trialVector[index] = globalVector[index] + FACTOR * delta;
+ }
+
@Override
public void generateBehavior(SearchPoint trailPoint, ProblemEncoder problemEncoder) {
- SearchPoint gbest_t = socialLib.getGbest();
-
BasicPoint[] referPoints = getReferPoints();
int DIMENSION = problemEncoder.getDesignSpace().getDimension();
- int rj = RandomGenerator.intRangeRandom(0, DIMENSION-1);
- for (int k=0; k<DIMENSION; k++) {
- if (Math.random()<CR || k == DIMENSION-1) {
- double Dabcd = 0;
- for(int i=0; i<referPoints.length; i++) {
- Dabcd += (i%2==0 ? +1D : -1D)*referPoints[i].getLocation()[rj];
- }
- trailPoint.getLocation()[rj] = gbest_t.getLocation()[rj]+FACTOR*Dabcd;
- } else {
- trailPoint.getLocation()[rj] = pbest_t.getLocation()[rj];
+ int guaranteeIndex = RandomGenerator.intRangeRandom(0, DIMENSION - 1);
+
+ double[] trailVector = trailPoint.getLocation();
+ double[] locaclVector = pbest_t.getLocation();
+ double[] globalVector = socialLib.getGbest().getLocation();
+
+ /* Handle first part of the trial vector. */
+ for (int index = 0; index < guaranteeIndex; index++) {
+ if (CR <= Math.random()) {
+ trailVector[index] = locaclVector[index];
+ continue;
}
- rj = (rj+1)%DIMENSION;
+
+ crossoverAndMutation(index, trailVector, globalVector, referPoints);
+ }
+
+ /* Guarantee for at least one change in the trial vector. */
+ crossoverAndMutation(guaranteeIndex, trailVector, globalVector, referPoints);
+
+ /* Handle second part of the trial vector. */
+ for (int index = guaranteeIndex + 1; index < DIMENSION; index++) {
+ if (CR <= Math.random()) {
+ trailVector[index] = locaclVector[index];
+ continue;
+ }
+
+ crossoverAndMutation(index, trailVector, globalVector, referPoints);
}
}
More information about the Libreoffice-commits
mailing list