From 51387dc280dadf7a29d215a72d2d0026451d2be6 Mon Sep 17 00:00:00 2001 From: Todor Balabanov Date: Sun, 12 May 2019 10:35:45 +0300 Subject: Formatting - Eclipse IDE Java Conventions with spaces for indentation. Change-Id: I0c3e50ef25bda0bc4ae59665a07848fe75507121 Reviewed-on: https://gerrit.libreoffice.org/72185 Reviewed-by: Julien Nabet Tested-by: Jenkins --- .../src/net/adaptivebox/deps/DEPSAgent.java | 29 +++---- .../adaptivebox/deps/behavior/AbsGTBehavior.java | 3 +- .../adaptivebox/deps/behavior/DEGTBehavior.java | 31 +++---- .../adaptivebox/deps/behavior/PSGTBehavior.java | 43 +++++----- .../src/net/adaptivebox/encode/EvalElement.java | 23 +++-- .../src/net/adaptivebox/encode/EvalStruct.java | 15 ++-- .../src/net/adaptivebox/encode/IEncodeEngine.java | 2 +- .../src/net/adaptivebox/global/BasicBound.java | 27 +++--- .../net/adaptivebox/global/RandomGenerator.java | 99 +++++++++++----------- .../net/adaptivebox/goodness/ACRComparator.java | 21 ++--- .../net/adaptivebox/goodness/BCHComparator.java | 17 ++-- .../goodness/IGoodnessCompareEngine.java | 7 +- .../src/net/adaptivebox/knowledge/ILibEngine.java | 3 - .../src/net/adaptivebox/knowledge/Library.java | 34 ++++---- .../src/net/adaptivebox/knowledge/SearchPoint.java | 17 ++-- .../net/adaptivebox/problem/ProblemEncoder.java | 33 ++++---- .../src/net/adaptivebox/sco/SCAgent.java | 79 ++++++++--------- .../src/net/adaptivebox/space/BasicPoint.java | 2 +- .../src/net/adaptivebox/space/DesignDim.java | 13 ++- .../src/net/adaptivebox/space/DesignSpace.java | 29 ++----- .../src/net/adaptivebox/space/ILocationEngine.java | 2 +- 21 files changed, 254 insertions(+), 275 deletions(-) (limited to 'nlpsolver/ThirdParty') diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java index 50ab8fd8c8f0..0f1240df9a1b 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java @@ -44,25 +44,25 @@ import net.adaptivebox.space.BasicPoint; public class DEPSAgent implements ILibEngine { - //Describes the problem to be solved + // Describes the problem to be solved private ProblemEncoder problemEncoder; - //Forms the goodness landscape + // Forms the goodness landscape private IGoodnessCompareEngine qualityComparator; - //store the point that generated in current learning cycle + // store the point that generated in current learning cycle private SearchPoint trailPoint; - //temp variable + // temp variable private AbsGTBehavior selectGTBehavior; - //the own memory: store the point that generated in old learning cycle + // the own memory: store the point that generated in old learning cycle private BasicPoint pold_t; - //the own memory: store the point that generated in last learning cycle + // the own memory: store the point that generated in last learning cycle private BasicPoint pcurrent_t; - //the own memory: store the personal best point + // the own memory: store the personal best point private SearchPoint pbest_t; - //Generate-and-test Behaviors + // Generate-and-test Behaviors private DEGTBehavior deGTBehavior; private PSGTBehavior psGTBehavior; public double switchP = 0.5; @@ -88,7 +88,7 @@ public class DEPSAgent implements ILibEngine { } private AbsGTBehavior getGTBehavior() { - if (Math.random()0, and the second is achieved by using + // Two normally choices for (c1, c2, weight), i.e., (2, 2, 0.4), or (1.494, + // 1.494, 0.729) + // The first is used in dissipative PSO (cf. [4]) as CL>0, and the second is + // achieved by using // constriction factors (cf. [3]) - public double c1=2; - public double c2=2; - public double weight = 0.4; //inertia weight + public double c1 = 2; + public double c2 = 2; + public double weight = 0.4; // inertia weight - public double CL=0; //See ref[4], normally be 0.001~0.005 + public double CL = 0; // See ref[4], normally be 0.001~0.005 - //the own memory: store the point that generated in old learning cycle + // the own memory: store the point that generated in old learning cycle private BasicPoint pold_t; - //the own memory: store the point that generated in last learning cycle + // the own memory: store the point that generated in last learning cycle private BasicPoint pcurrent_t; - //the own memory: store the personal best point + // the own memory: store the personal best point private SearchPoint pbest_t; public void setMemPoints(SearchPoint pbest, BasicPoint pcurrent, BasicPoint pold) { @@ -91,21 +93,21 @@ public class PSGTBehavior extends AbsGTBehavior { DesignSpace designSpace = problemEncoder.getDesignSpace(); int DIMENSION = designSpace.getDimension(); double deltaxb, deltaxbm; - for (int b=0;bdeltaxbm) { + } else if (deltaxb > deltaxbm) { deltaxb = deltaxbm; } - trailPoint.getLocation()[b] = pcurrent_t.getLocation()[b]+deltaxb; + trailPoint.getLocation()[b] = pcurrent_t.getLocation()[b] + deltaxb; } } } @@ -115,7 +117,6 @@ public class PSGTBehavior extends AbsGTBehavior { Library.replace(qualityComparator, trailPoint, pbest_t); pold_t.importLocation(pcurrent_t); pcurrent_t.importLocation(trailPoint); - } + } } - diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalElement.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalElement.java index d3ffc25d323d..85e50c9f97f8 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalElement.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalElement.java @@ -24,7 +24,7 @@ import net.adaptivebox.global.BasicBound; public class EvalElement { - //The weight for each response (target) + // The weight for each response (target) private static final double weight = 1; /** * The expected range of the response value, forms the following objective: @@ -44,26 +44,25 @@ public class EvalElement { public BasicBound targetBound = new BasicBound(); public boolean isOptType() { - return ((targetBound.minValue==BasicBound.MINDOUBLE&&targetBound.maxValue==BasicBound.MINDOUBLE)|| - (targetBound.minValue==BasicBound.MAXDOUBLE&&targetBound.maxValue==BasicBound.MAXDOUBLE)); + return ((targetBound.minValue == BasicBound.MINDOUBLE && targetBound.maxValue == BasicBound.MINDOUBLE) + || (targetBound.minValue == BasicBound.MAXDOUBLE && targetBound.maxValue == BasicBound.MAXDOUBLE)); } public double evaluateCONS(double targetValue) { - if(targetValuetargetBound.maxValue) { - return weight*(targetValue-targetBound.maxValue); + if (targetValue > targetBound.maxValue) { + return weight * (targetValue - targetBound.maxValue); } return 0; } public double evaluateOPTIM(double targetValue) { - if(targetBound.maxValue==BasicBound.MINDOUBLE) { //min mode - return weight*targetValue; - } else { //max - return -weight*targetValue; + if (targetBound.maxValue == BasicBound.MINDOUBLE) { // min mode + return weight * targetValue; + } else { // max + return -weight * targetValue; } } } - diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalStruct.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalStruct.java index 15760e23a39e..526257544091 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalStruct.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalStruct.java @@ -37,21 +37,20 @@ public class EvalStruct { evalElems[index] = dim; } - //convert response values into encoded information double[2] + // convert response values into encoded information double[2] public void evaluate(double[] evalRes, double[] targetValues) { evalRes[0] = evalRes[1] = 0; - for(int i=0; i maxValue) { + public double boundAdjust(double value) { + if (value > maxValue) { value = maxValue; } else if (value < minValue) { value = minValue; @@ -46,20 +47,18 @@ public class BasicBound { return value; } - public double annulusAdjust (double value) { - if(value > maxValue) { - double extendsLen = (value-maxValue)%getLength(); - value = minValue+extendsLen; + public double annulusAdjust(double value) { + if (value > maxValue) { + double extendsLen = (value - maxValue) % getLength(); + value = minValue + extendsLen; } else if (value < minValue) { - double extendsLen = (minValue-value)%getLength(); - value = maxValue-extendsLen; + double extendsLen = (minValue - value) % getLength(); + value = maxValue - extendsLen; } return value; } - - - public double getRandomValue(){ + public double getRandomValue() { return RandomGenerator.doubleRangeRandom(minValue, maxValue); } } diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java index 18ced86335dc..4910de990091 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java @@ -25,63 +25,60 @@ package net.adaptivebox.global; import java.util.Random; public class RandomGenerator { - /** - * Pseudo-random number generator instance. - */ - private static Random PRNG = new Random(); + /** + * Pseudo-random number generator instance. + */ + private static Random PRNG = new Random(); - /** - * This function returns a random integer number between the lowLimit and - * upLimit. - * - * @param lowLimit - * lower limits upLimit The upper limits (between which the - * random number is to be generated) - * @return int return value Example: for find [0,1,2] - */ - public static int intRangeRandom(int lowLimit, int upLimit) { - int num = lowLimit + PRNG.nextInt(upLimit - lowLimit + 1); - return num; - } - - /** - * This function returns a random float number between the lowLimit and - * upLimit. - * - * @param lowLimit - * lower limits upLimit The upper limits (between which the - * random number is to be generated) - * @return double return value - */ - public static double doubleRangeRandom(double lowLimit, double upLimit) { - double num = lowLimit + PRNG.nextDouble() * (upLimit - lowLimit); - return num; - } + /** + * This function returns a random integer number between the lowLimit and + * upLimit. + * + * @param lowLimit lower limits upLimit The upper limits (between which the + * random number is to be generated) + * @return int return value Example: for find [0,1,2] + */ + public static int intRangeRandom(int lowLimit, int upLimit) { + int num = lowLimit + PRNG.nextInt(upLimit - lowLimit + 1); + return num; + } - public static int[] randomSelection(int maxNum, int times) { - if (maxNum < 0) { - maxNum = 0; - } + /** + * This function returns a random float number between the lowLimit and upLimit. + * + * @param lowLimit lower limits upLimit The upper limits (between which the + * random number is to be generated) + * @return double return value + */ + public static double doubleRangeRandom(double lowLimit, double upLimit) { + double num = lowLimit + PRNG.nextDouble() * (upLimit - lowLimit); + return num; + } - if (times < 0) { - times = 0; - } + public static int[] randomSelection(int maxNum, int times) { + if (maxNum < 0) { + maxNum = 0; + } - int[] all = new int[maxNum]; - for (int i = 0; i < all.length; i++) { - all[i] = i; - } + if (times < 0) { + times = 0; + } - /* https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle */ - int[] indices = new int[Math.min(maxNum, times)]; - for (int i = 0, j, value; i < indices.length; i++) { - j = intRangeRandom(i, all.length - 1); + int[] all = new int[maxNum]; + for (int i = 0; i < all.length; i++) { + all[i] = i; + } - value = all[j]; - all[j] = all[i]; - indices[i] = all[i] = value; - } + /* https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle */ + int[] indices = new int[Math.min(maxNum, times)]; + for (int i = 0, j, value; i < indices.length; i++) { + j = intRangeRandom(i, all.length - 1); - return indices; + value = all[j]; + all[j] = all[i]; + indices[i] = all[i] = value; } + + return indices; + } } diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/ACRComparator.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/ACRComparator.java index 8e319d5dfa6a..22f4d4a32ba2 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/ACRComparator.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/ACRComparator.java @@ -51,7 +51,8 @@ public class ACRComparator implements IGoodnessCompareEngine, IUpdateCycleEngine public ACRComparator(Library lib, int T) { socialPool = lib; this.T = T; - //set the (epsilon_t|t=0) as the maximum CONS value among the SearchPoints in the library +// set the (epsilon_t|t=0) as the maximum CONS value among the SearchPoints in +// the library epsilon_t = lib.getExtremalVcon(true); } @@ -65,7 +66,7 @@ public class ACRComparator implements IGoodnessCompareEngine, IUpdateCycleEngine } public int compare(double[] fit1, double[] fit2) { - if(Math.max(fit1[0], fit2[0])<=Math.max(0, epsilon_t)) { //epsilon>0 + if (Math.max(fit1[0], fit2[0]) <= Math.max(0, epsilon_t)) { // epsilon>0 return compare(fit1[1], fit2[1]); } else { return compare(fit1[0], fit2[0]); @@ -73,16 +74,16 @@ public class ACRComparator implements IGoodnessCompareEngine, IUpdateCycleEngine } public void updateCycle(int t) { - //calculates the ratio - double rn = (double)socialPool.getVconThanNum(epsilon_t)/(double)socialPool.getPopSize(); - if(t>TthR*T &&T!=-1) { //Forcing sub-rule +// calculates the ratio + double rn = (double) socialPool.getVconThanNum(epsilon_t) / (double) socialPool.getPopSize(); + if (t > TthR * T && T != -1) { // Forcing sub-rule epsilon_t *= BETAF; - } else { //Ratio-keeping sub-rules - if(rn>RU) { - epsilon_t *= BETAL; //Shrink + } else { // Ratio-keeping sub-rules + if (rn > RU) { + epsilon_t *= BETAL; // Shrink } - if(rnfit2[i]) { - return LARGER_THAN; //Large than - } else if (fit1[i] fit2[i]) { + return LARGER_THAN; // Large than + } else if (fit1[i] < fit2[i]) { + return LESS_THAN; // Less than } } - return IGoodnessCompareEngine.EQUAL_TO; //same + return IGoodnessCompareEngine.EQUAL_TO; // same } public int compare(double[] fit1, double[] fit2) { diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/IGoodnessCompareEngine.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/IGoodnessCompareEngine.java index b345c1fafc46..70e227b5f610 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/IGoodnessCompareEngine.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/IGoodnessCompareEngine.java @@ -29,10 +29,9 @@ public abstract interface IGoodnessCompareEngine { int LESS_THAN = 0; /** - * check the magnitude of two IEncodeEngine - * LARGER_THAN: goodness1 is worse than goodness2 - * LESS_THAN: goodness1 is better than goodness2 - * EQUAL_TO : goodness1 is equal to goodness2 + * check the magnitude of two IEncodeEngine LARGER_THAN: goodness1 is worse than + * goodness2 LESS_THAN: goodness1 is better than goodness2 EQUAL_TO : goodness1 + * is equal to goodness2 **/ int compare(double[] goodness1, double[] goodness2); } diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/ILibEngine.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/ILibEngine.java index af5a8b2a1323..b4787c30c66e 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/ILibEngine.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/ILibEngine.java @@ -25,6 +25,3 @@ package net.adaptivebox.knowledge; public interface ILibEngine { void setLibrary(Library lib); } - - - diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/Library.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/Library.java index 3a0f82659295..841e9102a1c0 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/Library.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/Library.java @@ -33,9 +33,9 @@ public class Library { private final SearchPoint[] libPoints; private int gIndex = -1; - public Library(int number, ProblemEncoder problemEncoder){ + public Library(int number, ProblemEncoder problemEncoder) { libPoints = new SearchPoint[number]; - for (int i=0; ival==isMAX) { + double val = BasicBound.MINDOUBLE; + for (int i = 0; i < libPoints.length; i++) { + if (libPoints[i].getEncodeInfo()[0] > val == isMAX) { val = libPoints[i].getEncodeInfo()[0]; } } @@ -88,9 +91,9 @@ public class Library { } public int getVconThanNum(double allowedCons) { - int num=0; - for(int i=0; i0) { - return paramBound.minValue+Math.rint((value-paramBound.minValue)/grain)*grain; + } else if (grain > 0) { + return paramBound.minValue + Math.rint((value - paramBound.minValue) / grain) * grain; } else { - return paramBound.maxValue-Math.rint((paramBound.maxValue-value)/grain)*grain; + return paramBound.maxValue - Math.rint((paramBound.maxValue - value) / grain) * grain; } } } - diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/DesignSpace.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/DesignSpace.java index 7e7629af8e10..0c28e0006e1b 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/DesignSpace.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/DesignSpace.java @@ -27,59 +27,48 @@ package net.adaptivebox.space; public class DesignSpace { - //The information of all the dimension + // The information of all the dimension private DesignDim[] dimProps; public DesignSpace(int dim) { dimProps = new DesignDim[dim]; } - - public void setElemAt(DesignDim elem, int index) { dimProps[index] = elem; } public int getDimension() { - if (dimProps==null) { + if (dimProps == null) { return -1; } return dimProps.length; } - public double boundAdjustAt(double val, int dim){ + public double boundAdjustAt(double val, int dim) { return dimProps[dim].paramBound.boundAdjust(val); } - public void mutationAt(double[] location, int i){ + public void mutationAt(double[] location, int i) { location[i] = dimProps[i].paramBound.getRandomValue(); } - - - - - - public double getMagnitudeIn(int dimensionIndex) { return dimProps[dimensionIndex].paramBound.getLength(); } - - - - public void initializeGene(double[] tempX){ - for(int i=0;i