summaryrefslogtreecommitdiff
path: root/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2011-11-25 12:41:39 +0000
committerMichael Meeks <michael.meeks@suse.com>2011-11-28 11:06:59 +0000
commit17ff286751454dcd5aa86bef41a8e53cfb109c70 (patch)
tree615db0eda5afe21aa7c5b9db57416d34ed11c464 /nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge
parente46454b676bedc5585456cc37c63c9e4ff7deaad (diff)
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.
Diffstat (limited to 'nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge')
-rwxr-xr-xnlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/ILibEngine.java30
-rwxr-xr-xnlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/Library.java106
-rwxr-xr-xnlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/SearchPoint.java79
3 files changed, 215 insertions, 0 deletions
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; 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 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 100755
index 000000000000..0085ff7e481e
--- /dev/null
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/SearchPoint.java
@@ -0,0 +1,79 @@
+/**
+ * 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.global.*;
+import net.adaptivebox.space.*;
+import net.adaptivebox.encode.*;
+
+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 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) {
+ for(int i=0; i<encodeInfo.length; i++) {
+ encodeInfo[i] = info[i];
+ }
+ }
+
+ 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
+ }
+
+ public void outputSelf() {
+ System.out.println("#--> Location:");
+ OutputMethods.outputVector(getLocation());
+ System.out.println("#--> (CON & OPTIM):");
+ OutputMethods.outputVector(getEncodeInfo());
+ }
+} \ No newline at end of file