From c728bb5420f19eb6fbec859ec927f35d772694be Mon Sep 17 00:00:00 2001 From: Todor Balabanov Date: Thu, 2 May 2019 15:17:38 +0300 Subject: Generate behavior code simplification and very small speed-up. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib13080e4c21738affa129d12a07f5380f665e7a4 Reviewed-on: https://gerrit.libreoffice.org/71673 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- .../adaptivebox/deps/behavior/DEGTBehavior.java | 61 +++++++++++++++++----- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'nlpsolver') 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