From 17ff286751454dcd5aa86bef41a8e53cfb109c70 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Fri, 25 Nov 2011 12:41:39 +0000 Subject: Flatten un-maintained ex. Sun/Oracle nlpsolver extension into the repo This should make it easier to hack, and also to separate out the tangled in third party EvolutionarySolver as/when we can. --- nlpsolver/ThirdParty/EvolutionarySolver/build.xml | 74 +++ .../EvolutionarySolver/nbproject/build-impl.xml | 642 +++++++++++++++++++++ .../nbproject/genfiles.properties | 8 + .../nbproject/project.properties | 59 ++ .../EvolutionarySolver/nbproject/project.xml | 16 + .../src/net/adaptivebox/deps/DEPSAgent.java | 127 ++++ .../adaptivebox/deps/behavior/AbsGTBehavior.java | 36 ++ .../adaptivebox/deps/behavior/DEGTBehavior.java | 81 +++ .../adaptivebox/deps/behavior/PSGTBehavior.java | 117 ++++ .../src/net/adaptivebox/encode/EvalElement.java | 70 +++ .../src/net/adaptivebox/encode/EvalStruct.java | 60 ++ .../src/net/adaptivebox/encode/IEncodeEngine.java | 24 + .../src/net/adaptivebox/global/BasicArray.java | 31 + .../src/net/adaptivebox/global/BasicBound.java | 94 +++ .../src/net/adaptivebox/global/BasicTag.java | 40 ++ .../src/net/adaptivebox/global/CompareValue.java | 20 + .../src/net/adaptivebox/global/GlobalCompare.java | 46 ++ .../src/net/adaptivebox/global/GlobalFile.java | 277 +++++++++ .../src/net/adaptivebox/global/GlobalString.java | 149 +++++ .../net/adaptivebox/global/IUpdateCycleEngine.java | 24 + .../src/net/adaptivebox/global/OutputMethods.java | 50 ++ .../net/adaptivebox/global/RandomGenerator.java | 162 ++++++ .../net/adaptivebox/goodness/ACRComparator.java | 90 +++ .../net/adaptivebox/goodness/BCHComparator.java | 47 ++ .../goodness/IGoodnessCompareEngine.java | 38 ++ .../adaptivebox/goodness/PenaltyComparator.java | 41 ++ .../src/net/adaptivebox/goodness/SRComparator.java | 41 ++ .../src/net/adaptivebox/knowledge/ILibEngine.java | 30 + .../src/net/adaptivebox/knowledge/Library.java | 106 ++++ .../src/net/adaptivebox/knowledge/SearchPoint.java | 79 +++ .../net/adaptivebox/problem/ProblemEncoder.java | 123 ++++ .../problem/UnconstrainedProblemEncoder.java | 39 ++ .../src/net/adaptivebox/sco/SCAgent.java | 132 +++++ .../src/net/adaptivebox/space/BasicPoint.java | 42 ++ .../src/net/adaptivebox/space/DesignDim.java | 52 ++ .../src/net/adaptivebox/space/DesignSpace.java | 141 +++++ .../src/net/adaptivebox/space/ILocationEngine.java | 25 + 37 files changed, 3233 insertions(+) create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/build.xml create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/nbproject/build-impl.xml create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/nbproject/genfiles.properties create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/nbproject/project.properties create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/nbproject/project.xml create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/AbsGTBehavior.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/PSGTBehavior.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalElement.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalStruct.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/IEncodeEngine.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicArray.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicBound.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicTag.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/CompareValue.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalCompare.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/IUpdateCycleEngine.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/OutputMethods.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/ACRComparator.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/BCHComparator.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/IGoodnessCompareEngine.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/PenaltyComparator.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/goodness/SRComparator.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/ILibEngine.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/Library.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/SearchPoint.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/problem/ProblemEncoder.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/problem/UnconstrainedProblemEncoder.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/sco/SCAgent.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/BasicPoint.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/DesignDim.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/DesignSpace.java create mode 100755 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/ILocationEngine.java (limited to 'nlpsolver/ThirdParty/EvolutionarySolver') diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/build.xml b/nlpsolver/ThirdParty/EvolutionarySolver/build.xml new file mode 100755 index 000000000000..73ee22085284 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project EvolutionarySolver. + + + diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/nbproject/build-impl.xml b/nlpsolver/ThirdParty/EvolutionarySolver/nbproject/build-impl.xml new file mode 100755 index 000000000000..dd95469f4910 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/nbproject/build-impl.xml @@ -0,0 +1,642 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/nbproject/genfiles.properties b/nlpsolver/ThirdParty/EvolutionarySolver/nbproject/genfiles.properties new file mode 100755 index 000000000000..824bfa29c003 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=ea0a88ad +build.xml.script.CRC32=22c5d290 +build.xml.stylesheet.CRC32=958a1d3e +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=ea0a88ad +nbproject/build-impl.xml.script.CRC32=8e195e02 +nbproject/build-impl.xml.stylesheet.CRC32=65b8de21 diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/nbproject/project.properties b/nlpsolver/ThirdParty/EvolutionarySolver/nbproject/project.properties new file mode 100755 index 000000000000..3903d346a67f --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/nbproject/project.properties @@ -0,0 +1,59 @@ +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/EvolutionarySolver.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +meta.inf.dir=${src.dir}/META-INF +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/nbproject/project.xml b/nlpsolver/ThirdParty/EvolutionarySolver/nbproject/project.xml new file mode 100755 index 000000000000..a97876ee41f9 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/nbproject/project.xml @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + EvolutionarySolver + 1.6.5 + + + + + + + + + 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 100755 index 000000000000..02043f5b89f2 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java @@ -0,0 +1,127 @@ +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.*; +import net.adaptivebox.goodness.IGoodnessCompareEngine; +import net.adaptivebox.knowledge.*; +import net.adaptivebox.problem.*; +import net.adaptivebox.space.*; + +public class DEPSAgent implements ILibEngine { + + //Describes the problem to be solved + protected ProblemEncoder problemEncoder; + //Forms the goodness landscape + protected IGoodnessCompareEngine qualityComparator; + + //store the point that generated in current learning cycle + protected SearchPoint trailPoint; + + //temp variable + private AbsGTBehavior selectGTBehavior; + + //The referred library + protected Library socialLib; + //the own memory: store the point that generated in old learning cycle + protected BasicPoint pold_t; + //the own memory: store the point that generated in last learning cycle + protected BasicPoint pcurrent_t; + //the own memory: store the personal best point + protected SearchPoint pbest_t; + + //Generate-and-test Behaviors + protected DEGTBehavior deGTBehavior; + protected PSGTBehavior psGTBehavior; + public double switchP = 0.5; + + public void setLibrary(Library lib) { + socialLib = lib; + deGTBehavior.setLibrary(socialLib); + psGTBehavior.setLibrary(socialLib); + } + + public void setProblemEncoder(ProblemEncoder encoder) { + problemEncoder = encoder; + trailPoint = problemEncoder.getFreshSearchPoint(); + pold_t = problemEncoder.getFreshSearchPoint(); + pcurrent_t = problemEncoder.getFreshSearchPoint(); + } + + public void setSpecComparator(IGoodnessCompareEngine comparer) { + qualityComparator = comparer; + } + + public void setPbest(SearchPoint pbest) { + pbest_t = pbest; + } + + protected AbsGTBehavior getGTBehavior() { + if (Math.random() a generate-and-test behavior + */ +package net.adaptivebox.deps.behavior; + +import net.adaptivebox.goodness.*; +import net.adaptivebox.knowledge.*; +import net.adaptivebox.problem.*; + +abstract public class AbsGTBehavior { + //The referred social library + protected Library socialLib; + + public void setLibrary(Library lib) { + socialLib = lib; + } + + 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 100755 index 000000000000..cb0693616d4e --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java @@ -0,0 +1,81 @@ +/** + * 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�C359 + * @ 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.goodness.*; +import net.adaptivebox.global.*; +import net.adaptivebox.knowledge.*; +import net.adaptivebox.problem.*; +import net.adaptivebox.space.*; + +public class DEGTBehavior extends AbsGTBehavior implements ILibEngine { + public int DVNum = 2; //Number of differential vectors, normally be 1 or 2 + public double FACTOR = 0.5; //scale constant: (0, 1.2], normally be 0.5 + public double CR = 0.9; //crossover constant: [0, 1], normally be 0.1 or 0.9 + + //the own memory: store the point that generated in last learning cycle + protected SearchPoint pbest_t; + + public void setPbest(SearchPoint pbest) { + pbest_t = pbest; + } + + 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 a generate-and-test behavior + * + */ + +package net.adaptivebox.deps.behavior; + +import net.adaptivebox.goodness.*; +import net.adaptivebox.knowledge.*; +import net.adaptivebox.problem.*; +import net.adaptivebox.space.*; + +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; + public double weight = 0.4; //inertia weight + + 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 + protected BasicPoint pold_t; + //the own memory: store the point that generated in last learning cycle + protected BasicPoint pcurrent_t; + //the own memory: store the personal best point + protected SearchPoint pbest_t; + + public void setMemPoints(SearchPoint pbest, BasicPoint pcurrent, BasicPoint pold) { + pcurrent_t = pcurrent; + pbest_t = pbest; + pold_t = pold; + } + + public void generateBehavior(SearchPoint trailPoint, ProblemEncoder problemEncoder) { + SearchPoint gbest_t = socialLib.getGbest(); + DesignSpace designSpace = problemEncoder.getDesignSpace(); + int DIMENSION = designSpace.getDimension(); + double deltaxb, deltaxbm; + for (int b=0;bdeltaxbm) { + deltaxb = deltaxbm; + } + trailPoint.getLocation()[b] = pcurrent_t.getLocation()[b]+deltaxb; + } + } + } + + 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 100755 index 000000000000..82e4073ee4e8 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalElement.java @@ -0,0 +1,70 @@ +/** + * 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.*; + +public class EvalElement { + + //The weight for each response (target) + public double weight = 1; + /** + * The expected range of the response value, forms the following objective: + * + * NO minValue maxValue : THE ELEMENT OF BasicBound + * 1 MINDOUBLE, MINDOUBLE: the minimize objective + * 2 MAXDOUBLE, MAXDOUBLE: the maximize objective + * 3 MINDOUBLE, v : the lessthan constraint (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 + * + */ + public BasicBound targetBound = new BasicBound(); + + public EvalElement() {}; + + 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(targetValuetargetBound.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 100755 index 000000000000..ad44df1dc2d2 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/encode/EvalStruct.java @@ -0,0 +1,60 @@ +/** + * 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 + public EvalElement[] evalElems = null; + + public EvalStruct(int elemsNum) { + evalElems = new EvalElement[elemsNum]; + } + public int getSize() { + return evalElems.length; + } + + 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; imv) { + mv=v[i]; + } + } + return mv; + } + +} \ No newline at end of file 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 100755 index 000000000000..e0953d12d655 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicBound.java @@ -0,0 +1,94 @@ +/** + * Description: provide an 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 boolean isSatisfyCondition(double child){ + if(child > maxValue || child < minValue) { + return(false); + } + return(true); + } + + 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 static BasicBound getBound(double[] data) { + BasicBound bound = new BasicBound(); + if(data!=null) { + double minV, maxV; + if(data.length>0) { + bound.minValue = data[0]; + bound.maxValue = data[0]; + for(int i=1; i maxValue || value < minValue) { + value = getRandomValue(); + } + return value; + } + + public double getRandomValue(){ + return RandomGenerator.doubleRangeRandom(minValue, maxValue); + } +} \ No newline at end of file diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicTag.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicTag.java new file mode 100755 index 000000000000..29ee77fd47e0 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicTag.java @@ -0,0 +1,40 @@ +/** + * Description: defines some static constant values. + * + * @ Author Create/Modi Note + * Xiaofeng Xie Sep 22, 2000 xiaofengxie@tsinghua.org.cn + * + * @version 1.0 + * @Since MAOS1.0 + */ + +package net.adaptivebox.global; + + +public class BasicTag { + public static final String COMMAND_TAG = "%"; + public static final String TAB_TAG = "\t"; + public static final String LEFT_SMALL_BRACKET_TAG = "("; + public static final String RIGHT_SMALL_BRACKET_TAG = ")"; + public static final String LEFT_LARGE_BRACKET_TAG = "{"; + public static final String RIGHT_LARGE_BRACKET_TAG = "}"; + public static final String LEFT_BRACKET_TAG = "["; + public static final String RIGHT_BRACKET_TAG = "]"; + public static final String EQUAL_TAG = "="; + public static final String SPACE_TAG = " "; + public static final String SEMICOLON_TAG = ";"; + public static final String COLON_TAG = ":"; + public static final String COMMA_TAG = ","; + public static final String DOT_TAG = "."; + public static final String NULL_SEPERATE_TAG = " \t"; + public static final String SEPERATE_TAG = "|"; + public static final String UNDERLINE_TAG = "_"; + public static final String INC_TAG = "+"; + public static final String DEC_TAG = "-"; + public static final String ZERO_TAG = "0"; + public static final String EXP_TAG = "E"; + public static final String S_EXP_TAG = "e"; + public static final String FILE_SEP_TAG = System.getProperty("file.separator"); + public static final String RETURN_TAG = System.getProperty("line.separator"); +} + diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/CompareValue.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/CompareValue.java new file mode 100755 index 000000000000..1cd783f54404 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/CompareValue.java @@ -0,0 +1,20 @@ +/** + * Description: Global value for comparison. + * + * @ Author Create/Modi Note + * Xiaofeng Xie Jun 15, 2002 + * Xiaofeng Xie Feb 18, 2004 + * + * @version 1.0 + * @Since MAOS1.0 + */ + + +package net.adaptivebox.global; + +public class CompareValue { + public static final int LARGER_THAN = 2; + public static final int EQUAL_TO = 1; + public static final int LESS_THAN = 0; + public static final int INVALID = -1; +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalCompare.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalCompare.java new file mode 100755 index 000000000000..57fef7beb0df --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalCompare.java @@ -0,0 +1,46 @@ +/** + * Description: Global package for comparison. + * + * @ Author Create/Modi Note + * Xiaofeng Xie Jun 15, 2002 xiaofengxie@tsinghua.org.cn + * + * + * @version 1.0 + * @Since MAOS1.0 + */ + + +package net.adaptivebox.global; + +import java.util.*; + +public class GlobalCompare { + +/* compare the data1 and data2, if data1=data2, return 0 + * if data1 < data2, return LESS_THAN, else if data1 > data2, LARGER_THAN + **/ + static public int compare(double data1, double data2) { + if (data1 < data2) + return CompareValue.LESS_THAN; + else if (data1 > data2) + return CompareValue.LARGER_THAN; + else + return CompareValue.EQUAL_TO; + } + +/* check the magnitude of two array, the frontial is more important + **/ + public static int compareArray(double[] fit1, double[] fit2) { + if (fit1.length!=fit2.length) { + return CompareValue.INVALID; //error + } + for (int i=0; ifit2[i]) { + return CompareValue.LARGER_THAN; //Large than + } else if (fit1[i]0 && (realDir.endsWith("/")||realDir.endsWith("\\"))) { + realDir = dir.substring(0, dir.length()-1); + } + return realDir+BasicTag.FILE_SEP_TAG+fileName; + } + + public static String getFileName(String nameBody, String suffix) { + if (suffix==null || suffix.trim().length()==0) { + return nameBody; + } + String fileName = nameBody; + if(nameBody.endsWith(".")) { + return fileName+suffix; + } else { + return nameBody+"."+suffix; + } + } + + public static String getFileLocation(String dir, String fileNameBody, String fileNameSuffix) { + String filename = getFileName(fileNameBody, fileNameSuffix); + return getFileLocation(dir, filename); + } + + public static void clear(String fileStr) throws Exception { + File file = new File(fileStr); + if(file.isFile()) { + file.delete(); + return; + } + String[] fileNames = file.list(); + if (fileNames==null) { + return; + } + for (int i=0; i0) { + isNeglect = getFirstCharExist(str, neglectFirstChars); + } + } while (isNeglect); + return str; + } + + public static String[] getMeaningfulLines(String srcStr, String neglectFirstChars) throws Exception { + StringReader outStringReader = new StringReader(srcStr); + BufferedReader outReader = new BufferedReader(outStringReader); + Vector origData = new Vector(); + String str = null; + while(true) { + str = getMeaningfulLine(outReader, neglectFirstChars); + if (str==null) { + break; + } + origData.add(str); + } + return convert1DVectorToStringArray(origData); + } + + /** + * convert vector to 1D String array + */ + public static String[] convert1DVectorToStringArray(Vector toToConvert) { + if (toToConvert==null) return null; + String[] objs = new String[toToConvert.size()]; + for (int i=0; itypes.length) realTimes = types.length; +// boolean[] internalTypes = (boolean[])types.clone(); +// int upper = types.length-1; +// int[] indices = new int[realTimes]; +// if(realTimes==types.length) { +// for(int i=0; i=totalIndices.length) { + return totalIndices; + } + int[] indices = randomSelection(totalIndices.length, times); + for(int i=0; i 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(rnfit2[i]) { + return LARGER_THAN; //Large than + } else if (fit1[i]Math.random()) { + return GlobalCompare.compare(fit1[1], fit2[1]); + } else { + return GlobalCompare.compare(fit1[0], fit2[0]); + } + } + +} 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 100755 index 000000000000..741cba313495 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/ILibEngine.java @@ -0,0 +1,30 @@ + +/** + * 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 { + public 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 100755 index 000000000000..eb2045765594 --- /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.*; +import net.adaptivebox.goodness.*; +import net.adaptivebox.problem.*; + +public class Library { + private SearchPoint[] libPoints = new SearchPoint[0]; + protected int gIndex = -1; + + public Library(SearchPoint[] points){ + this.libPoints = points; + } + + public Library(int number, ProblemEncoder problemEncoder){ + libPoints = new SearchPoint[number]; + for (int i=0; ival==isMAX) { + val = libPoints[i].getEncodeInfo()[0]; + } + } + return val; + } + + public int getVconThanNum(double allowedCons) { + int num=0; + for(int i=0; i Location:"); + OutputMethods.outputVector(getLocation()); + System.out.println("#--> (CON & OPTIM):"); + OutputMethods.outputVector(getEncodeInfo()); + } +} \ No newline at end of file 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 100755 index 000000000000..a5deb6315954 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/problem/ProblemEncoder.java @@ -0,0 +1,123 @@ +/** + * 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.global.*; +import net.adaptivebox.space.*; +import net.adaptivebox.encode.*; +import net.adaptivebox.knowledge.*; + +public abstract class ProblemEncoder { + //Store the calculated results for the responses + double[] tempResponseSet; //temp values + double[] tempLocation; //temp values + + //the search space (S) + protected DesignSpace designSpace = null; + + // For evaluate the response vector into encoded vector double[2] + protected EvalStruct evalStruct = null; + + 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; + } + + public EvalStruct getEvalStruct() { + return evalStruct; + } + + //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); + } + + protected void setDefaultXAt(int i, double min, double max) { + DesignDim dd = new DesignDim(); + 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); + } + + protected void setDefaultYAt(int i, double min, double max, double weight) { + EvalElement ee = new EvalElement(); + ee.targetBound = new BasicBound(min, max); + ee.weight = weight; + 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]); + } + + //calcuate 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; i0) { + 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 100755 index 000000000000..6a493f37ae74 --- /dev/null +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/space/DesignSpace.java @@ -0,0 +1,141 @@ +/** + * 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; +import net.adaptivebox.global.*; + +public class DesignSpace { + //The information of all the dimension + private DesignDim[] dimProps; + + public DesignSpace(int dim) { + dimProps = new DesignDim[dim]; + } + + public DesignDim getDimAt(int index) { + return dimProps[index]; + } + + 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 annulusAdjust (double[] location){ + for (int i=0; i