diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
commit | 267c6f2ac71f92999e969232431ba04678e7437e (patch) | |
tree | 358c9467650e1d0a1d7227a21dac2e3d08b622b2 /nlpsolver/ThirdParty | |
parent | Initial commit. (diff) | |
download | libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip |
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'nlpsolver/ThirdParty')
23 files changed, 1589 insertions, 0 deletions
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/Manifest.mf b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/Manifest.mf new file mode 100644 index 0000000000..139597f9cb --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/Manifest.mf @@ -0,0 +1,2 @@ + + diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java new file mode 100644 index 0000000000..3a08df39f5 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java @@ -0,0 +1,128 @@ +package net.adaptivebox.deps; + +/** + * Description: The description of agent with hybrid differential evolution and particle swarm. + * + * @ Author Create/Modi Note + * Xiaofeng Xie Jun 10, 2004 + * Xiaofeng Xie Jul 01, 2008 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + * + * @version 1.0 + * @Since MAOS1.0 + * + * @References: + * [1] Zhang W J, Xie X F. DEPSO: hybrid particle swarm with differential + * evolution operator. IEEE International Conference on Systems, Man & Cybernetics, + * Washington D C, USA, 2003: 3816-3821 + * [2] X F Xie, W J Zhang. SWAF: swarm algorithm framework for numerical + * optimization. Genetic and Evolutionary Computation Conference (GECCO), + * Seattle, WA, USA, 2004: 238-250 + * -> an agent perspective + */ + +import net.adaptivebox.deps.behavior.AbsGTBehavior; +import net.adaptivebox.deps.behavior.DEGTBehavior; +import net.adaptivebox.deps.behavior.PSGTBehavior; +import net.adaptivebox.global.RandomGenerator; +import net.adaptivebox.goodness.IGoodnessCompareEngine; +import net.adaptivebox.knowledge.ILibEngine; +import net.adaptivebox.knowledge.Library; +import net.adaptivebox.knowledge.SearchPoint; +import net.adaptivebox.problem.ProblemEncoder; +import net.adaptivebox.space.BasicPoint; + +public class DEPSAgent { + + // Describes the problem to be solved + private ProblemEncoder problemEncoder; + + // Forms the goodness landscape + private IGoodnessCompareEngine qualityComparator; + + // store the point that generated in current learning cycle + private SearchPoint trailPoint; + + // temp variable + private AbsGTBehavior selectGTBehavior; + + // 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 + private BasicPoint pcurrent_t; + + // the own memory: store the personal best point + private SearchPoint pbest_t; + + // Generate-and-test behaviors. + private DEGTBehavior deGTBehavior; + private PSGTBehavior psGTBehavior; + + private double switchP = 0.5; + + public DEPSAgent(ProblemEncoder encoder, DEGTBehavior deGTBehavior, PSGTBehavior psGTBehavior, + double switchP, IGoodnessCompareEngine comparer, SearchPoint pbest) { + this.switchP = switchP; + + problemEncoder = encoder; + + qualityComparator = comparer; + + trailPoint = problemEncoder.getFreshSearchPoint(); + pold_t = problemEncoder.getFreshSearchPoint(); + pcurrent_t = problemEncoder.getFreshSearchPoint(); + pbest_t = pbest; + + this.deGTBehavior = deGTBehavior; + this.deGTBehavior.setMemPoints(pbest_t, pcurrent_t, pold_t); + + this.psGTBehavior = psGTBehavior; + this.psGTBehavior.setMemPoints(pbest_t, pcurrent_t, pold_t); + } + + public void setSpecComparator(IGoodnessCompareEngine comparer) { + qualityComparator = comparer; + } + + private AbsGTBehavior getGTBehavior() { + if (RandomGenerator.doubleZeroOneRandom() < switchP) { + return deGTBehavior; + } else { + return psGTBehavior; + } + } + + public void setGTBehavior(AbsGTBehavior gtBehavior) { + gtBehavior.setMemPoints(pbest_t, pcurrent_t, pold_t); + } + + public void generatePoint() { + // generates a new point in the search space (S) based on + // its memory and the library + selectGTBehavior = getGTBehavior(); + selectGTBehavior.generateBehavior(trailPoint, problemEncoder); + + // evaluate into goodness information + problemEncoder.evaluate(trailPoint); + } + + public void learn() { + selectGTBehavior.testBehavior(trailPoint, qualityComparator); + } + + public SearchPoint getMGState() { + return trailPoint; + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/AbsGTBehavior.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/AbsGTBehavior.java new file mode 100644 index 0000000000..2701c9dee9 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/AbsGTBehavior.java @@ -0,0 +1,43 @@ +/** + * Description: The description of generate-and-test behavior. + * + * + * Author Create/Modi Note + * Xiaofeng Xie May 17, 2004 + * Xiaofeng Xie Jul 01, 2008 + * + * @version 1.0 + * @Since MAOS1.0 + * + * @References: + * [1] X F Xie, W J Zhang. SWAF: swarm algorithm framework for numerical + * optimization. Genetic and Evolutionary Computation Conference (GECCO), + * Seattle, WA, USA, 2004: 238-250 + * -> a generate-and-test behavior + */ +package net.adaptivebox.deps.behavior; + +import net.adaptivebox.goodness.IGoodnessCompareEngine; +import net.adaptivebox.knowledge.ILibEngine; +import net.adaptivebox.knowledge.Library; +import net.adaptivebox.knowledge.SearchPoint; +import net.adaptivebox.problem.ProblemEncoder; +import net.adaptivebox.space.BasicPoint; + +abstract public class AbsGTBehavior implements ILibEngine { + // The referred social library + protected Library socialLib; + + // the own memory: store the personal best point + protected SearchPoint pbest_t; + + public void setLibrary(Library lib) { + socialLib = lib; + } + + abstract public void setMemPoints(SearchPoint pbest, BasicPoint pcurrent, BasicPoint pold); + + abstract public void generateBehavior(SearchPoint trailPoint, ProblemEncoder problemEncoder); + + abstract public void testBehavior(SearchPoint trailPoint, IGoodnessCompareEngine qualityComparator); +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java new file mode 100644 index 0000000000..c9ca0ef82e --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java @@ -0,0 +1,122 @@ +/** + * Description: The description of differential evolution Generate-and-Test Behavior. + + #Supported parameters: + NAME VALUE_type Range DefaultV Description + FACTOR real (0, 1.2] 0.5 DEAgent: scale constant + CR real [0, 1] 0.9 DEAgent: crossover constant + //Other choices for FACTOR and CR: (0.5, 0.1) + + * + * Author Create/Modi Note + * Xiaofeng Xie May 11, 2004 + * Xiaofeng Xie Jul 01, 2008 + * + * @version 1.0 + * @Since MAOS1.0 + * + * @References: + * [1] Storn R, Price K. Differential evolution - a simple and efficient + * heuristic for global optimization over continuous spaces. Journal of + * Global Optimization, 1997, 11: 341-359 + * The original differential evolution idea + * [2] X F Xie, W J Zhang. SWAF: swarm algorithm framework for numerical + * optimization. Genetic and Evolutionary Computation Conference (GECCO), + * Seattle, WA, USA, 2004: 238-250 + * -> a generate-and-test behavior + */ + +package net.adaptivebox.deps.behavior; + +import net.adaptivebox.global.RandomGenerator; +import net.adaptivebox.goodness.IGoodnessCompareEngine; +import net.adaptivebox.knowledge.Library; +import net.adaptivebox.knowledge.SearchPoint; +import net.adaptivebox.problem.ProblemEncoder; +import net.adaptivebox.space.BasicPoint; + +public class DEGTBehavior extends AbsGTBehavior { + //Number of differential vectors, normally be 1 or 2 + private static final int DVNum = 2; + + //scale constant: (0, 1.2], normally be 0.5 + public double MIN_FACTOR = 0.5; + + //scale constant: (0, 1.2], normally be 0.5 + public double MAX_FACTOR = 0.5; + + //crossover constant: [0, 1], normally be 0.1 or 0.9 + public double CR = 0.9; + + @Override + public void setMemPoints(SearchPoint pbest, BasicPoint pcurrent, BasicPoint pold) { + 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] + RandomGenerator.doubleRangeRandom(MIN_FACTOR, MAX_FACTOR) * delta; + } + + @Override + public void generateBehavior(SearchPoint trailPoint, ProblemEncoder problemEncoder) { + BasicPoint[] referPoints = getReferPoints(); + int DIMENSION = problemEncoder.getDesignSpace().getDimension(); + 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 <= RandomGenerator.doubleZeroOneRandom()) { + trailVector[index] = locaclVector[index]; + continue; + } + + 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 <= RandomGenerator.doubleZeroOneRandom()) { + trailVector[index] = locaclVector[index]; + continue; + } + + crossoverAndMutation(index, trailVector, globalVector, referPoints); + } + } + + @Override + public void testBehavior(SearchPoint trailPoint, IGoodnessCompareEngine qualityComparator) { + Library.replace(qualityComparator, trailPoint, pbest_t); + } + + private SearchPoint[] getReferPoints() { + SearchPoint[] referPoints = new SearchPoint[DVNum * 2]; + for (int i = 0; i < referPoints.length; i++) { + referPoints[i] = socialLib.getRandomPoint(); + } + return referPoints; + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java new file mode 100644 index 0000000000..68bf5a10ed --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java @@ -0,0 +1,132 @@ +/** + * Description: The description of particle swarm (PS) Generate-and-test Behavior. + * + #Supported parameters: + NAME VALUE_type Range DefaultV Description + c1 real [0, 2] 1.494 PSAgent: learning factor for pbest + c2 real [0, 2] 1.494 PSAgent: learning factor for gbest + w real [0, 1] 0.729 PSAgent: inertia weight + CL real [0, 0.1] 0 PSAgent: chaos factor + //Other choices for c1, c2, w, and CL: (2, 2, 0.4, 0.001) + + * Author Create/Modi Note + * Xiaofeng Xie May 11, 2004 + * Xiaofeng Xie Jul 01, 2008 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + * + * @version 1.0 + * @Since MAOS1.0 + * + * References: + * [1] Kennedy J, Eberhart R C. Particle swarm optimization. IEEE Int. Conf. on + * Neural Networks, Perth, Australia, 1995: 1942-1948 + * For original particle swarm idea + * [2] Shi Y H, Eberhart R C. A Modified Particle Swarm Optimizer. IEEE Inter. Conf. + * on Evolutionary Computation, Anchorage, Alaska, 1998: 69-73 + * For the inertia weight: adjust the trade-off between exploitation & exploration + * [3] Clerc M, Kennedy J. The particle swarm - explosion, stability, and + * convergence in a multidimensional complex space. IEEE Trans. on Evolutionary + * Computation. 2002, 6 (1): 58-73 + * Constriction factor: ensures the convergence + * [4] Xie X F, Zhang W J, Yang Z L. A dissipative particle swarm optimization. + * Congress on Evolutionary Computation, Hawaii, USA, 2002: 1456-1461 + * The CL parameter + * [5] Xie X F, Zhang W J, Bi D C. Optimizing semiconductor devices by self- + * organizing particle swarm. Congress on Evolutionary Computation, Oregon, USA, + * 2004: 2017-2022 + * Further experimental analysis on the convergence of PSO + * [6] X F Xie, W J Zhang. SWAF: swarm algorithm framework for numerical + * optimization. Genetic and Evolutionary Computation Conference (GECCO), + * Seattle, WA, USA, 2004: 238-250 + * -> a generate-and-test behavior + * + */ + +package net.adaptivebox.deps.behavior; + +import net.adaptivebox.global.RandomGenerator; +import net.adaptivebox.goodness.IGoodnessCompareEngine; +import net.adaptivebox.knowledge.Library; +import net.adaptivebox.knowledge.SearchPoint; +import net.adaptivebox.problem.ProblemEncoder; +import net.adaptivebox.space.BasicPoint; +import net.adaptivebox.space.DesignSpace; + +public class PSGTBehavior extends AbsGTBehavior { + // 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; + + //inertia weight + public double weight = 0.4; + + //See ref[4], normally be 0.001~0.005 + public double CL = 0; + + // 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 + private BasicPoint pcurrent_t; + + @Override + public void setMemPoints(SearchPoint pbest, BasicPoint pcurrent, BasicPoint pold) { + pcurrent_t = pcurrent; + pbest_t = pbest; + pold_t = pold; + } + + @Override + public void generateBehavior(SearchPoint trailPoint, ProblemEncoder problemEncoder) { + 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(); + for (int b = 0; b < DIMENSION; b++) { + if (RandomGenerator.doubleZeroOneRandom() < CL) { + designSpace.mutationAt(trailPointLocation, b); + continue; + } + + double deltaxb = weight * (pcurrent_t_location[b] - pold_t_location[b]) + + c1 * RandomGenerator.doubleZeroOneRandom() * (pbest_t_location[b] - pcurrent_t_location[b]) + + c2 * RandomGenerator.doubleZeroOneRandom() * (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; + } + } + + @Override + public void testBehavior(SearchPoint trailPoint, IGoodnessCompareEngine qualityComparator) { + 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 new file mode 100644 index 0000000000..85e50c9f97 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalElement.java @@ -0,0 +1,68 @@ +/** + * Description: provide the information for evaluating of a response (target) + * + * Author Create/Modi Note + * Xiaofeng Xie Mar 1, 2003 + * Xiaofeng Xie May 11, 2004 +* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + */ + +package net.adaptivebox.encode; + +import net.adaptivebox.global.BasicBound; + +public class EvalElement { + + // The weight for each response (target) + private static final double weight = 1; + /** + * The expected range of the response value, forms the following objective: + * + * <pre> + * NO minValue maxValue : THE ELEMENT OF BasicBound + * 1 MINDOUBLE, MINDOUBLE: the minimize objective + * 2 MAXDOUBLE, MAXDOUBLE: the maximize objective + * 3 MINDOUBLE, v : the less than constraint {@literal (<v)} + * 4 v , MAXDOUBLE: the larger than constraint {@literal (>v)} + * 5 v1 , v2 : the region constraint, i.e. belongs to [v1, v2] + * + * OPTIM type: the No.1 and No.2 + * CONS type: the last three + * </pre> + */ + 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)); + } + + public double evaluateCONS(double targetValue) { + if (targetValue < targetBound.minValue) { + return weight * (targetBound.minValue - targetValue); + } + 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; + } + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalStruct.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalStruct.java new file mode 100644 index 0000000000..db37ddb39f --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalStruct.java @@ -0,0 +1,56 @@ +/** + * Description: provide the information for evaluating a set of targets values + * into encoded information (For formation the goodness landscape by comparing) + * + * Author Create/Modi Note + * Xiaofeng Xie Mar 1, 2003 + * Xiaofeng Xie May 11, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + * + * @References: + * [1] Deb K. An efficient constraint handling method for genetic algorithms. + * Computer Methods in Applied Mechanics and Engineering, 2000, 186(2-4): 311-338 + */ + +package net.adaptivebox.encode; + +public class EvalStruct { + // The information for evaluating all the responses + private EvalElement[] evalElems = null; + + public EvalStruct(int elemsNum) { + evalElems = new EvalElement[elemsNum]; + } + + public void setElemAt(EvalElement dim, int index) { + evalElems[index] = dim; + } + + // 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 < evalElems.length; i++) { + if (evalElems[i].isOptType()) { + // The objectives (OPTIM type) + // The multi-objective will be translated into single-objective + evalRes[1] += evalElems[i].evaluateOPTIM(targetValues[i]); + } else { + // The constraints (CONS type) + // If evalRes[0] equals to 0, then be a feasible point, i.e. satisfies + // all the constraints + evalRes[0] += evalElems[i].evaluateCONS(targetValues[i]); + } + } + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/IEncodeEngine.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/IEncodeEngine.java new file mode 100644 index 0000000000..56f791c41a --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/IEncodeEngine.java @@ -0,0 +1,24 @@ +/** + * Description: provide the encoded information for objectives + * + * Author Create/Modi Note + * Xiaofeng Xie Feb 10, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + */ + +package net.adaptivebox.encode; + +public interface IEncodeEngine { + double[] getEncodeInfo(); +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicBound.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicBound.java new file mode 100644 index 0000000000..6ed1089d9c --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicBound.java @@ -0,0 +1,64 @@ +/** + * Description: provide a bound, and the corresponding operations + * + * Author Create/Modi Note + * Xiaofeng Xie Oct. 9, 2002 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + */ + +package net.adaptivebox.global; + +public class BasicBound { + public static final double MINDOUBLE = -1e308; + public static final double MAXDOUBLE = 1e308; + + public double minValue = MINDOUBLE; + public double maxValue = MAXDOUBLE; + + public BasicBound() { + } + + public BasicBound(double min, double max) { + minValue = Math.min(min, max); + maxValue = Math.max(min, max); + } + + public double getLength() { + return Math.abs(maxValue - minValue); + } + + public double boundAdjust(double value) { + if (value > maxValue) { + value = maxValue; + } else if (value < minValue) { + value = minValue; + } + return value; + } + + 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; + } + return value; + } + + public double getRandomValue() { + return RandomGenerator.doubleRangeRandom(minValue, maxValue); + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/IUpdateCycleEngine.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/IUpdateCycleEngine.java new file mode 100644 index 0000000000..0b4db684f7 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/IUpdateCycleEngine.java @@ -0,0 +1,24 @@ +/** + * Description: provide the interface for updating according to the cycle number + * + * Author Create/Modi Note + * Xiaofeng Xie Feb 18, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + */ + +package net.adaptivebox.global; + +public interface IUpdateCycleEngine { + void updateCycle(int t); +}
\ No newline at end of file diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java new file mode 100644 index 0000000000..245149e87c --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java @@ -0,0 +1,108 @@ +/** + * Description: For generating random numbers. + * + * Author Create/Modi Note + * Xiaofeng Xie Feb 22, 2001 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + * + * @version 1.0 + * @Since MAOS1.0 + */ + +package net.adaptivebox.global; + +import java.util.Random; +import java.security.SecureRandom; + +public class RandomGenerator { + /** + * Pseudo-random number generator instance. + */ + private static Random PRNG = new Random(); + + /** + * Switch between weaker, but faster pseudo-random number generator and + * stronger, but slower. + * + * @param stronger activation of secure pseudo random generator flag + */ + public static void useStrongerGenerator(boolean stronger) { + if(stronger == true) { + PRNG = new SecureRandom(); + } else { + 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 float number between the zero (inclusive) and one (exclusive). + * + * @return double value in the range [0, 1) + */ + public static double doubleZeroOneRandom() { + return PRNG.nextDouble(); + } + + public static int[] randomSelection(int maxNum, int times) { + if (maxNum < 0) { + maxNum = 0; + } + + if (times < 0) { + times = 0; + } + + int[] all = new int[maxNum]; + for (int i = 0; i < all.length; i++) { + all[i] = i; + } + + /* 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); + + 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 new file mode 100644 index 0000000000..284549506c --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/ACRComparator.java @@ -0,0 +1,91 @@ +/** + * Description: For comparison of goodness in landscape with loosed constraints + * which varied adaptively according to the social information. + * + * Applied domain: efficiently for ridge class feasible space (SF), such as + * the problem with equality constraints + * + * Author Create/Modi Note + * Xiaofeng Xie Jun 24, 2003 Created + * Xiaofeng Xie May 11, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + * + * @version 1.0 + * @Since MAOS1.2 + * + * [1] Xie X F, Zhang W J, Bi D C. Handling equality constraints by adaptive + * relaxing rule for swarm algorithms. Congress on Evolutionary Computation, + * Oregon, USA, 2004 + */ + +package net.adaptivebox.goodness; + +import net.adaptivebox.global.IUpdateCycleEngine; +import net.adaptivebox.knowledge.Library; + +public class ACRComparator implements IGoodnessCompareEngine, IUpdateCycleEngine { + private final Library socialPool; + private double epsilon_t = 0; + + private static final double RU = 0.75; + private static final double RL = 0.25; + private static final double BETAF = 0.618; + private static final double BETAL = 0.618; + private static final double BETAU = 1.382; + + private final double T; + + private static final double TthR = 0.5; + + 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 + epsilon_t = lib.getExtremalVcon(true); + } + + private static int compare(double data1, double data2) { + if (data1 < data2) + return LESS_THAN; + else if (data1 > data2) + return LARGER_THAN; + else + return EQUAL_TO; + } + + public int compare(double[] fit1, double[] fit2) { + 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]); + } + } + + 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 + epsilon_t *= BETAF; + } else { // Ratio-keeping sub-rules + if (rn > RU) { + epsilon_t *= BETAL; // Shrink + } + if (rn < RL) { + epsilon_t *= BETAU; // Relax + } + } + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/BCHComparator.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/BCHComparator.java new file mode 100644 index 0000000000..8140650dd6 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/BCHComparator.java @@ -0,0 +1,46 @@ +/** + * Description: For formation the basic goodness landscape. + * + * Author Create/Modi Note + * Xiaofeng Xie Jun 24, 2003 Created + * Xiaofeng Xie May 11, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + * + * @version 1.0 + * @Since MAOS1.2 + * + * [1] Deb K. An efficient constraint handling method for genetic algorithms. + * Computer Methods in Applied Mechanics and Engineering, 2000, 186(2-4): 311-338 + */ + +package net.adaptivebox.goodness; + +public class BCHComparator implements IGoodnessCompareEngine { + + /* check the magnitude of two array, the frontal is more important */ + private static int compareArray(double[] fit1, double[] fit2) { + for (int i = 0; i < fit1.length; i++) { + 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 + } + + public int compare(double[] fit1, double[] fit2) { + return compareArray(fit1, fit2); + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/IGoodnessCompareEngine.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/IGoodnessCompareEngine.java new file mode 100644 index 0000000000..17a85993d5 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/IGoodnessCompareEngine.java @@ -0,0 +1,41 @@ +/** + * Description: For comparison of goodness. + * + * Author Create/Modi Note + * Xiaofeng Xie Feb 19, 2004 + * Xiaofeng Xie May 11, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + * + * @version 1.0 + * @Since MAOS1.2 + */ + +package net.adaptivebox.goodness; + +public abstract interface IGoodnessCompareEngine { + int LARGER_THAN = 2; + int EQUAL_TO = 1; + 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 + */ + 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 new file mode 100644 index 0000000000..b4787c30c6 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/ILibEngine.java @@ -0,0 +1,27 @@ + +/** + * Description: set the library. + * + * Author Create/Modi Note + * Xiaofeng Xie May 14, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + * + * @version 1.1 + * @Since MAOS1.0 + */ +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 new file mode 100644 index 0000000000..76e57ac760 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/Library.java @@ -0,0 +1,106 @@ + +/** + * Description: Contains a set of points. + * + * Author Create/Modi Note + * Xiaofeng Xie Mar 7, 2003 + * Xiaofeng Xie May 3, 2003 + * Xiaofeng Xie May 11, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + * + * @version 1.1 + * @Since MAOS1.0 + */ +package net.adaptivebox.knowledge; + +import net.adaptivebox.global.BasicBound; +import net.adaptivebox.global.RandomGenerator; +import net.adaptivebox.goodness.IGoodnessCompareEngine; +import net.adaptivebox.problem.ProblemEncoder; + +public class Library { + private final SearchPoint[] libPoints; + private int gIndex = -1; + + public Library(int number, ProblemEncoder problemEncoder) { + libPoints = new SearchPoint[number]; + for (int i = 0; i < number; i++) { + libPoints[i] = problemEncoder.getEncodedSearchPoint(); + } + } + + public SearchPoint getGbest() { + return getSelectedPoint(gIndex); + } + + public void refreshGbest(IGoodnessCompareEngine qualityComparator) { + gIndex = tournamentSelection(qualityComparator, getPopSize() - 1, true); + } + + public int getPopSize() { + return libPoints.length; + } + + public SearchPoint getSelectedPoint(int index) { + return libPoints[index]; + } + + public SearchPoint getRandomPoint() { + return libPoints[RandomGenerator.intRangeRandom(0, libPoints.length - 1)]; + } + + public static boolean replace(IGoodnessCompareEngine comparator, SearchPoint outPoint, + SearchPoint tobeReplacedPoint) { + boolean isBetter = false; + if (comparator.compare(outPoint.getEncodeInfo(), + tobeReplacedPoint.getEncodeInfo()) < IGoodnessCompareEngine.LARGER_THAN) { + tobeReplacedPoint.importPoint(outPoint); + isBetter = true; + } + return isBetter; + } + + public int tournamentSelection(IGoodnessCompareEngine comparator, int times, boolean isBetter) { + int[] indices = RandomGenerator.randomSelection(getPopSize(), times); + int currentIndex = indices[0]; + for (int i = 1; i < indices.length; i++) { + int compareValue = comparator.compare(libPoints[indices[i]].getEncodeInfo(), + libPoints[currentIndex].getEncodeInfo()); + if (isBetter == (compareValue < IGoodnessCompareEngine.LARGER_THAN)) { + currentIndex = indices[i]; + } + } + return currentIndex; + } + + public double getExtremalVcon(boolean 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]; + } + } + return val; + } + + public int getVconThanNum(double allowedCons) { + int num = 0; + for (int i = 0; i < libPoints.length; i++) { + if (libPoints[i].getEncodeInfo()[0] <= allowedCons) { + num++; + } + } + return num; + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/SearchPoint.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/SearchPoint.java new file mode 100644 index 0000000000..df13efc74d --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/SearchPoint.java @@ -0,0 +1,70 @@ +/** + * Description: provide the location and encoded goodness information + * + * Author Create/Modi Note + * Xiaofeng Xie Mar 1, 2003 + * Xiaofeng Xie May 11, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + */ +package net.adaptivebox.knowledge; + +import net.adaptivebox.encode.IEncodeEngine; +import net.adaptivebox.global.BasicBound; +import net.adaptivebox.space.BasicPoint; + +public class SearchPoint extends BasicPoint implements IEncodeEngine { + // store the encode information for goodness evaluation + // encodeInfo[0]: the sum of constraints (if it equals to 0, then be a feasible point) + // encodeInfo[1]: the value of objective function + private final double[] encodeInfo = new double[2]; + private double objectiveValue; + + public SearchPoint(int dim) { + super(dim); + for (int i = 0; i < encodeInfo.length; i++) { + encodeInfo[i] = BasicBound.MAXDOUBLE; + } + } + + public double[] getEncodeInfo() { + return encodeInfo; + } + + private void importEncodeInfo(double[] info) { + System.arraycopy(info, 0, encodeInfo, 0, encodeInfo.length); + } + + private void importEncodeInfo(IEncodeEngine point) { + importEncodeInfo(point.getEncodeInfo()); + } + + // Replace self by given point + public void importPoint(SearchPoint point) { + importLocation(point); + importEncodeInfo(point); + setObjectiveValue(point.getObjectiveValue()); + } + + public double getObjectiveValue() { + return objectiveValue; + } + + public void setObjectiveValue(double objectiveValue) { + this.objectiveValue = objectiveValue; + } + + public boolean isFeasible() { + return encodeInfo[0] == 0; // no constraint violations + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/problem/ProblemEncoder.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/problem/ProblemEncoder.java new file mode 100644 index 0000000000..674d275420 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/problem/ProblemEncoder.java @@ -0,0 +1,109 @@ +/** + * Description: Encodes the specified problem into encoded information for + * forming the goodness landscape. + * + * Author Create/Modi Note + * Xiaofeng Xie May 31, 2000 + * Xiaofeng Xie Sep. 19, 2002 + * Xiaofeng Xie Mar. 01, 2003 + * Xiaofeng Xie May 11, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + * + * @version 1.0 + * @Since MAOS1.0 + */ + +package net.adaptivebox.problem; + +import net.adaptivebox.encode.EvalElement; +import net.adaptivebox.encode.EvalStruct; +import net.adaptivebox.global.BasicBound; +import net.adaptivebox.knowledge.SearchPoint; +import net.adaptivebox.space.DesignDim; +import net.adaptivebox.space.DesignSpace; + +public abstract class ProblemEncoder { + // Store the calculated results for the responses + private final double[] tempResponseSet; // temp values + private final double[] tempLocation; // temp values + + // the search space (S) + private final DesignSpace designSpace; + + // For evaluate the response vector into encoded vector double[2] + private final EvalStruct evalStruct; + + protected ProblemEncoder(int paramNum, int targetNum) throws Exception { + designSpace = new DesignSpace(paramNum); + evalStruct = new EvalStruct(targetNum); + tempLocation = new double[paramNum]; + tempResponseSet = new double[targetNum]; + } + + public DesignSpace getDesignSpace() { + return designSpace; + } + + // set the default information for each dimension of search space (S) + protected void setDefaultXAt(int i, double min, double max, double grain) { + DesignDim dd = new DesignDim(); + dd.grain = grain; + dd.paramBound = new BasicBound(min, max); + designSpace.setElemAt(dd, i); + } + + // set the default information for evaluation each response + protected void setDefaultYAt(int i, double min, double max) { + EvalElement ee = new EvalElement(); + ee.targetBound = new BasicBound(min, max); + evalStruct.setElemAt(ee, i); + } + + // get a fresh point + public SearchPoint getFreshSearchPoint() { + return new SearchPoint(designSpace.getDimension()); + } + + // get an encoded point + public SearchPoint getEncodedSearchPoint() { + SearchPoint point = getFreshSearchPoint(); + designSpace.initializeGene(point.getLocation()); + evaluate(point); + return point; + } + + // evaluate the point into encoded information + public void evaluate(SearchPoint point) { + // copy to temp point + System.arraycopy(point.getLocation(), 0, this.tempLocation, 0, tempLocation.length); + + // mapping the temp point to original search space S + designSpace.getMappingPoint(tempLocation); + + // calculate based on the temp point + calcTargets(tempResponseSet, tempLocation); + evalStruct.evaluate(point.getEncodeInfo(), tempResponseSet); + point.setObjectiveValue(tempResponseSet[0]); + } + + // calculate each response, must be implemented + abstract protected double calcTargetAt(int index, double[] VX); + + // calculate all the responses VY[] based on given point VX[] + private void calcTargets(double[] VY, double[] VX) { + for (int i = 0; i < VY.length; i++) { + VY[i] = calcTargetAt(i, VX); + } + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/sco/SCAgent.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/sco/SCAgent.java new file mode 100644 index 0000000000..a09d0dcfd6 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/sco/SCAgent.java @@ -0,0 +1,143 @@ +package net.adaptivebox.sco; + +/** + * Description: The description of social cognitive agent. + * + * @Information source: a) external library (L); b) the own memory: a point that + * generated in the last learning cycle + * + * @Coefficients: TaoB and TaoW + * + * @ Author Create/Modi Note + * Xiaofeng Xie Mar 11, 2003 + * Xiaofeng Xie May 11, 2004 + * Xiaofeng Xie May 20, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + * + * @version 1.0 + * @Since MAOS1.0 + * + * @References: + * [1] Xie X F, Zhang W J. Solving engineering design problems by social cognitive + * optimization. Genetic and Evolutionary Computation Conference, 2004: 261-262 + */ + +import net.adaptivebox.problem.ProblemEncoder; +import net.adaptivebox.space.DesignSpace; +import net.adaptivebox.space.ILocationEngine; +import net.adaptivebox.global.RandomGenerator; +import net.adaptivebox.goodness.IGoodnessCompareEngine; +import net.adaptivebox.knowledge.Library; +import net.adaptivebox.knowledge.SearchPoint; + +public class SCAgent { + + // Describes the problem to be solved (encode the point into intermediate information) + private ProblemEncoder problemEncoder; + + // Forms the goodness landscape + private IGoodnessCompareEngine specComparator; + + // the coefficients of SCAgent + private static final int TaoB = 2; + + // The early version set TaoW as the size of external library (NL), but 4 is often enough + private static final int TaoW = 4; + + // The referred external library + private Library externalLib; + + // store the point that generated in current learning cycle + private SearchPoint trailPoint; + + // the own memory: store the point that generated in last learning cycle + private SearchPoint pcurrent_t; + + public void setExternalLib(Library lib) { + externalLib = lib; + } + + public void setProblemEncoder(ProblemEncoder encoder) { + problemEncoder = encoder; + trailPoint = problemEncoder.getFreshSearchPoint(); + pcurrent_t = problemEncoder.getEncodedSearchPoint(); + } + + public void setSpecComparator(IGoodnessCompareEngine comparer) { + specComparator = comparer; + } + + public SearchPoint generatePoint() { + // generate a new point + generatePoint(trailPoint); + + // evaluate the generated point + problemEncoder.evaluate(trailPoint); + return trailPoint; + } + + private void generatePoint(ILocationEngine tempPoint) { + SearchPoint Xmodel, Xrefer, libBPoint; + + // choose Selects a better point (libBPoint) from externalLib (L) based + // on tournament selection + int xb = externalLib.tournamentSelection(specComparator, TaoB, true); + libBPoint = externalLib.getSelectedPoint(xb); + + // Compares pcurrent_t with libBPoint + // The better one becomes model point (Xmodel) + // The worse one becomes refer point (Xrefer) + if (specComparator.compare(pcurrent_t.getEncodeInfo(), + libBPoint.getEncodeInfo()) == IGoodnessCompareEngine.LARGER_THAN) { + Xmodel = libBPoint; + Xrefer = pcurrent_t; + } else { + Xmodel = pcurrent_t; + Xrefer = libBPoint; + } + + // observational learning: generates a new point near the model point, which + // the variation range is decided by the difference of Xmodel and Xrefer + inferPoint(tempPoint, Xmodel, Xrefer, problemEncoder.getDesignSpace()); + } + + // 1. Update the current point into the external library + // 2. Replace the current point by the generated point + public void updateInfo() { + // Selects a bad point kw from TaoW points in Library + int xw = externalLib.tournamentSelection(specComparator, TaoW, false); + + // Replaces kw with pcurrent_t + externalLib.getSelectedPoint(xw).importPoint(pcurrent_t); + + // Replaces pcurrent_t (x(t)) with trailPoint (x(t+1)) + pcurrent_t.importPoint(trailPoint); + } + + // 1---model point, 2---refer point + private boolean inferPoint(ILocationEngine newPoint, ILocationEngine point1, ILocationEngine point2, + DesignSpace space) { + double[] newLoc = newPoint.getLocation(); + double[] real1 = point1.getLocation(); + double[] real2 = point2.getLocation(); + + for (int i = 0; i < newLoc.length; i++) { + newLoc[i] = real1[i] * 2 - real2[i]; + // boundary handling + newLoc[i] = space.boundAdjustAt(newLoc[i], i); + newLoc[i] = RandomGenerator.doubleRangeRandom(newLoc[i], real2[i]); + } + return true; + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/BasicPoint.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/BasicPoint.java new file mode 100644 index 0000000000..9f6c2ec01d --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/BasicPoint.java @@ -0,0 +1,42 @@ +/** + * Description: provide the location information of a point + * + * Author Create/Modi Note + * Xiaofeng Xie Mar 1, 2003 + * Xiaofeng Xie May 11, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + */ + +package net.adaptivebox.space; + +public class BasicPoint implements ILocationEngine { + // store the location information in the search space (S) + private final double[] location; + + public BasicPoint(int dim) { + location = new double[dim]; + } + + public double[] getLocation() { + return location; + } + + public void importLocation(double[] pointLoc) { + System.arraycopy(pointLoc, 0, location, 0, pointLoc.length); + } + + public void importLocation(ILocationEngine point) { + importLocation(point.getLocation()); + } +}
\ No newline at end of file diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/DesignDim.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/DesignDim.java new file mode 100644 index 0000000000..f8f283bf19 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/DesignDim.java @@ -0,0 +1,45 @@ +/** + * Description: provide the information for goodness evaluation of a target + * + * Author Create/Modi Note + * Xiaofeng Xie Mar 1, 2003 + * Xiaofeng Xie May 3, 2004 Add grain value + * Xiaofeng Xie May 11, 2004 Add crowd distance + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + */ + +package net.adaptivebox.space; + +import net.adaptivebox.global.BasicBound; + +public class DesignDim { + // To discrete space with the given step. For example, for an integer variable, + // The grain value can be set as 1. + public double grain = 0; + public BasicBound paramBound = new BasicBound(); // the range of a parameter + + public boolean isDiscrete() { + return grain != 0; + } + + public double getGrainedValue(double value) { + if (grain == 0) { + return value; + } 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; + } + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/DesignSpace.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/DesignSpace.java new file mode 100644 index 0000000000..7d93079360 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/DesignSpace.java @@ -0,0 +1,73 @@ +/** + * Description: provide the information for the search space (S) + * + * Author Create/Modi Note + * Xiaofeng Xie Mar 2, 2003 + * Xiaofeng Xie May 11, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + * + * @References: + * [1] Zhang W J, Xie X F, Bi D C. Handling boundary constraints for numerical + * optimization by particle swarm flying in periodic search space. Congress + * on Evolutionary Computation, Oregon, USA, 2004 + * especially for particle swarm agent + */ + +package net.adaptivebox.space; + +public class DesignSpace { + // 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) { + return -1; + } + return dimProps.length; + } + + public double boundAdjustAt(double val, int dim) { + return dimProps[dim].paramBound.boundAdjust(val); + } + + 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 < tempX.length; i++) + tempX[i] = dimProps[i].paramBound.getRandomValue(); // Global.RandomGenerator.doubleRangeRandom(9.8, 10); + } + + public void getMappingPoint(double[] point) { + for (int i = 0; i < getDimension(); i++) { + point[i] = dimProps[i].paramBound.annulusAdjust(point[i]); + if (dimProps[i].isDiscrete()) { + point[i] = dimProps[i].getGrainedValue(point[i]); + } + } + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/ILocationEngine.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/ILocationEngine.java new file mode 100644 index 0000000000..6b839df6e4 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/ILocationEngine.java @@ -0,0 +1,25 @@ +/** + * Description: provide the information for location + * + * Author Create/Modi Note + * Xiaofeng Xie May 3, 2003 + * Xiaofeng Xie May 11, 2004 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Please acknowledge the author(s) if you use this code in any way. + */ + +package net.adaptivebox.space; + +public interface ILocationEngine { + double[] getLocation(); +} |