summaryrefslogtreecommitdiffstats
path: root/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global
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/global
parentreorganise some resize logic (diff)
downloadcore-17ff286751454dcd5aa86bef41a8e53cfb109c70.tar.gz
core-17ff286751454dcd5aa86bef41a8e53cfb109c70.zip
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/global')
-rwxr-xr-xnlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicArray.java31
-rwxr-xr-xnlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicBound.java94
-rwxr-xr-xnlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicTag.java40
-rwxr-xr-xnlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/CompareValue.java20
-rwxr-xr-xnlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalCompare.java46
-rwxr-xr-xnlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java277
-rwxr-xr-xnlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java149
-rwxr-xr-xnlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/IUpdateCycleEngine.java24
-rwxr-xr-xnlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/OutputMethods.java50
-rwxr-xr-xnlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java162
10 files changed, 893 insertions, 0 deletions
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicArray.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicArray.java
new file mode 100755
index 000000000000..4071cf8c7540
--- /dev/null
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicArray.java
@@ -0,0 +1,31 @@
+/**
+ * Description: basic operations on Arrays
+ *
+ * @ Author Create/Modi Note
+ * Xiaofeng Xie Oct. 9, 2002
+ *
+ */
+
+package net.adaptivebox.global;
+
+public class BasicArray {
+ public static double getMinValue(double[] v) {
+ double mv = Double.MAX_VALUE;
+ for (int i=0; i<v.length; i++) {
+ if (v[i]<mv) {
+ mv=v[i];
+ }
+ }
+ return mv;
+ }
+ public static double getMaxValue(double[] v) {
+ double mv = -Double.MAX_VALUE;
+ for (int i=0; i<v.length; i++) {
+ if (v[i]>mv) {
+ 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<data.length; i++) {
+ bound.minValue = Math.min(bound.minValue, data[i]);
+ bound.maxValue = Math.max(bound.maxValue, data[i]);
+ }
+
+ }
+ }
+ return bound;
+ }
+
+ public double randomAdjust (double value){
+ if(value > 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; i<fit1.length; i++) {
+ if (fit1[i]>fit2[i]) {
+ return CompareValue.LARGER_THAN; //Large than
+ } else if (fit1[i]<fit2[i]){
+ return CompareValue.LESS_THAN; //Less than
+ }
+ }
+ return CompareValue.EQUAL_TO; //same
+ }
+}
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java
new file mode 100755
index 000000000000..3dc20c6266d9
--- /dev/null
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java
@@ -0,0 +1,277 @@
+/**
+ * Description: Global package for file operations.
+ *
+ * @ Author Create/Modi Note
+ * Xiaofeng Xie Jun 15, 2002
+ *
+ * @version 1.0
+ * @Since MAOS1.0
+ */
+
+
+package net.adaptivebox.global;
+
+import java.io.*;
+import java.util.*;
+
+public class GlobalFile {
+
+// used by the createTempDir to give an index of temp number.
+ private static int counter = -1;
+
+/**
+ * Create a temp directory in the given directory.
+ * @param prefix the prefix for the directory.
+ * @param directory the directory that the temp dirctory placed.
+ * @return If a temp directory is created, return a File Object, else
+ * return null.
+ */
+ public static File createTempDir(String prefix, String directory) throws IOException {
+ File f = null;
+ String tempDir;
+ boolean isCreated = false;
+ do {
+ if (counter == -1) {
+ counter = new Random().nextInt() & 0xffff;
+ }
+ counter++;
+ if (prefix == null) throw new NullPointerException();
+ if (prefix.length() < 3)
+ throw new IllegalArgumentException("Prefix string too short");
+ if (directory == null) {
+ tempDir = prefix+counter;
+ } else {
+ tempDir = getFileLocation(directory,prefix+counter);
+ }
+ f = new File(tempDir);
+ isCreated = f.mkdir();
+ } while (!isCreated);
+ return f;
+ }
+
+/**
+ * Add the given text string to the end of a given file.
+ * @param inStr The string to be added.
+ * @param fileStr the name of the file to be added.
+ */
+ public static void addStringToFile(String inStr, String fileStr) throws Exception {
+
+ RandomAccessFile raFile = new RandomAccessFile(fileStr,"rw");
+ raFile.seek(raFile.length());
+ raFile.writeBytes(inStr);
+ raFile.close();
+
+
+// String oldFileStr = getStringFromFile(fileStr);
+// String newFileStr = inStr;
+// if (oldFileStr != null) {
+// newFileStr = oldFileStr+inStr;
+// }
+// saveStringToFile(newFileStr,fileStr);
+
+ }
+
+ public static Object loadObjectFromFile(String fileName) throws Exception {
+ FileInputStream fis = new FileInputStream(fileName);
+ ObjectInputStream ois = new ObjectInputStream(fis);
+ Object obj = ois.readObject();
+ ois.close();
+ return obj;
+ }
+
+ public static void saveObjectToFile(String fileName, Object obj) throws Exception {
+ FileOutputStream ostream = new FileOutputStream(fileName);
+ ObjectOutputStream p = new ObjectOutputStream(ostream);
+ p.writeObject(obj);
+ p.flush();
+ ostream.close();
+ }
+
+/**
+ * Save the given text string to a given file.
+ * @param inStr The string to be saved.
+ * @param fileStr the name of the file to be saved.
+ */
+ public static void saveStringToFile(String inStr, String fileStr) throws Exception{
+ new File(new File(fileStr).getParent()).mkdirs();
+ FileOutputStream pspOutputStream = new FileOutputStream(new File(fileStr));
+ pspOutputStream.write(inStr.getBytes());
+ pspOutputStream.close();
+ }
+
+/**
+ * Load text string from a given file.
+ * @param fileStr the name of the file to be loaded.
+ * @return A text string that is the content of the file. if the given file is
+ * not exist, then return null.
+ */
+ public static String getStringFromFile(String fileStr) throws Exception {
+ String getStr = null;
+ FileInputStream pspInputStream = new FileInputStream(fileStr);
+ byte[] pspFileBuffer = new byte[pspInputStream.available()];
+ pspInputStream.read(pspFileBuffer);
+ pspInputStream.close();
+ getStr = new String(pspFileBuffer);
+ return(getStr);
+ }
+
+/**
+ * Load curve data from a specified file.
+ * @param fileStr the name of the file to be loaded.
+ * @return A Vector that include the curve data.
+ */
+ public static Vector getCurveDataFromFile(String fileName) {
+ File file = new File(fileName);
+ if(!file.exists()){
+ //showMessage();
+ return null;
+ }
+ //open data file
+ FileInputStream inStream = null;
+ BufferedReader inReader = null;
+ try{
+ inStream = new FileInputStream(file);
+ inReader = new BufferedReader(new InputStreamReader(inStream));
+ }catch(Exception e){
+ //showMessage();
+ return null;//Data file open error.
+ }
+ Vector xaxes = new Vector(1,1);
+ Vector yaxes = new Vector(1,1);
+ try{
+ StringTokenizer st;
+ String s;
+ boolean start = false;
+ while(inReader.ready()!=false){
+ st = new StringTokenizer(inReader.readLine());
+ over:{
+ while(!st.hasMoreTokens()){//Justify blank lines.
+ if(inReader.ready()!=false){
+ st = new StringTokenizer(inReader.readLine());
+ }else
+ break over;
+ }
+ s = st.nextToken();
+ if((!start)&&(!s.startsWith("@")))
+ break over;
+ if(!start){
+ start = true;
+ break over;
+ }
+ if(s.startsWith("#")||s.startsWith("$")||s.startsWith("/")) break over;//Justify comment line.
+ Double xaxis = null;
+ Double yaxis = null;
+ try{
+ xaxis = Double.valueOf(s);
+ xaxes.addElement(xaxis);
+ }catch(Exception e){
+ //showMessage();
+ inReader.close();
+ inStream.close();
+ return null;//Data file data format error.
+ }
+ s = st.nextToken();
+ try{
+ yaxis = Double.valueOf(s);
+ yaxes.addElement(yaxis);
+ }catch(Exception e){
+ //showMessage();
+ inReader.close();
+ inStream.close();
+ return null;//Data file data format error.
+ }
+ }
+ }
+ }catch(Exception e){
+ //showMessage();
+ return null;//Uncertain data file error.
+ }
+ Vector curveData = new Vector();
+ curveData.addElement(xaxes);
+ curveData.addElement(yaxes);
+ return(curveData);
+ }
+
+/**
+ * Get a full path of a given file name and a directory name.
+ * @param fileName the name of the file.
+ * @param dir the name of directory.
+ * @return The full path.
+ */
+ public static String getFileLocation(String dir, String fileName) {
+ String realDir = dir;
+ while (realDir.length()>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; i<fileNames.length; i++) {
+ String newFileName = GlobalFile.getFileLocation(fileStr,fileNames[i]);
+ clear(newFileName);
+ }
+ file.delete();
+ }
+
+ public static String getFilePrefix(String fileStr) {
+ int index = fileStr.lastIndexOf(BasicTag.DOT_TAG);
+ if(index==-1) index = fileStr.length();
+ return fileStr.substring(0, index);
+ }
+
+ public static String getFileSuffix(String fileStr) {
+ String[] subNames = GlobalString.tokenize(fileStr, BasicTag.DOT_TAG);
+ int subNameLen = subNames.length;
+ if(subNameLen==1) return "";
+ else return subNames[subNameLen-1];
+ }
+
+ public static String createTempImageFile(String origFile) throws Exception {
+ return createTempImageFile(origFile, "img", ".inf");
+ }
+
+ public static String createTempImageFile(String origFile, String prefix, String suffix) throws Exception {
+ File outputFile = createTempFile(prefix, suffix);
+ outputFile.deleteOnExit();
+ copyFile(outputFile.getAbsolutePath(), origFile);
+ return outputFile.getAbsolutePath();
+ }
+
+ public static void copyFile(String imgFile, String origFile) throws Exception {
+ String fileContent = GlobalFile.getStringFromFile(origFile);
+ GlobalFile.saveStringToFile(fileContent, imgFile);
+ }
+
+ public static File createTempFile(String prefix, String suffix) throws Exception {
+ String realSuffix = suffix;
+ if (!realSuffix.startsWith(".")) realSuffix = "."+suffix;
+ return File.createTempFile(prefix, realSuffix);
+ }
+}
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java
new file mode 100755
index 000000000000..7ca0e2973c66
--- /dev/null
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java
@@ -0,0 +1,149 @@
+/**
+ * Description: operations for the a text string.
+ *
+ * @ Author Create/Modi Note
+ * Xiaofeng Xie Feb 22, 2001
+ * Xiaofeng Xie May 12, 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.global;
+
+import java.io.*;
+import java.util.*;
+
+public class GlobalString {
+ public static final String NEGLECT_TAG = "#$@";
+ public static final String EQUAL_TAG = "=";
+
+/**
+ * Tokenize a String with given key.
+ * @param input the String to be tokenized.
+ * @param tokenKey the delimiters.
+ * @return a String array that include the elements of input string that
+ * divided by the tokenKey.
+ */
+ public static String[] tokenize(String input , String tokenKey) {
+ Vector v = new Vector();
+ StringTokenizer t = new StringTokenizer(input, tokenKey);
+ String cmd[];
+ while (t.hasMoreTokens())
+ v.addElement(t.nextToken());
+ cmd = new String[v.size()];
+ for (int i = 0; i < cmd.length; i++)
+ cmd[i] = (String) v.elementAt(i);
+ return cmd;
+ }
+
+ public static String[] getMeaningfulLines(String srcStr) throws Exception {
+ return getMeaningfulLines(srcStr, NEGLECT_TAG);
+ }
+
+ public static String getMeaningfulLine(BufferedReader outReader) throws Exception {
+ return getMeaningfulLine(outReader, NEGLECT_TAG);
+ }
+
+ public static int getCharLoc(char data, String str) {
+ for(int i=0; i<str.length(); i++) {
+ if(str.charAt(i)==data) return i;
+ }
+ return -1;
+ }
+ public static String trim(String origStr, String discardStr) {
+ String str = origStr;
+ do {
+ if(str.length()==0) return str;
+ if(getCharLoc(str.charAt(0), discardStr)!=-1) str = str.substring(1);
+ else if(getCharLoc(str.charAt(str.length()-1), discardStr)!=-1) str = str.substring(0, str.length()-1);
+ else {return str;}
+ } while(true);
+ }
+
+ public static boolean getFirstCharExist(String str, String chars) throws Exception {
+ int neglectFirstCharLength = chars.length();
+ for(int i=0; i<neglectFirstCharLength; i++) {
+ if(str.startsWith(chars.substring(i, i+1))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static String getMeaningfulLine(BufferedReader outReader, String neglectFirstChars) throws Exception {
+ String str;
+ boolean isNeglect = true;
+ int i = 0;
+ do {
+ str = outReader.readLine();
+ if (str==null) {
+ return null;
+ }
+ str = trim(str, " \t");
+ if(str.length()>0) {
+ 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; i<toToConvert.size(); i++) {
+ objs[i] =getObjString(toToConvert.elementAt(i));
+ }
+ return(objs);
+ }
+
+ public static String getObjString(Object nObj) {
+ if(nObj instanceof String) return (String)nObj;
+ return nObj.toString();
+ }
+
+ static public int toInteger(Object oVal) throws Exception {
+ if(oVal==null) throw new Exception("Null string");
+ return new Integer(oVal.toString()).intValue();
+ }
+
+ static public double toDouble(Object oVal) throws Exception {
+ if(oVal==null) throw new Exception("Null string");
+ return new Double(oVal.toString()).doubleValue();
+ }
+
+ public static Object toObject(String key) throws Exception{
+ Class cls = Class.forName(key);
+ return cls.newInstance();
+ }
+} \ No newline at end of file
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 100755
index 000000000000..18e9832e31bc
--- /dev/null
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/IUpdateCycleEngine.java
@@ -0,0 +1,24 @@
+/**
+ * Description: provide the inteface 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 {
+ public void updateCycle(int t);
+} \ No newline at end of file
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/OutputMethods.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/OutputMethods.java
new file mode 100755
index 000000000000..b2177b8dfdb8
--- /dev/null
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/OutputMethods.java
@@ -0,0 +1,50 @@
+/**
+ * Description: Output methods for Array
+ *
+ * @ 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;
+
+
+public class OutputMethods {
+
+ public OutputMethods() {
+ }
+
+ public static String outputVectorAsStr(double[] vector){
+ if(vector==null) return "NULL";
+ String totalStr = "";
+ for(int i=0;i<vector.length;i++){
+ totalStr += vector[i];
+ if(i!=vector.length-1) {
+ totalStr += "\t";
+ }
+ }
+ totalStr+="\r\n";
+ return totalStr;
+ }
+
+ public static void outputVector(double[] vector){
+ for(int i=0;i<vector.length;i++){
+ System.out.print(vector[i]+" \t");
+ }
+ System.out.println("");
+ }
+} \ 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 100755
index 000000000000..b9f17ce4e045
--- /dev/null
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java
@@ -0,0 +1,162 @@
+/**
+ * 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.*;
+
+public class RandomGenerator {
+
+/**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 = (int)Math.rint(doubleRangeRandom(lowLimit,upLimit));
+ int num = (int)Math.floor(doubleRangeRandom(lowLimit,upLimit+1)-1E-10);
+ 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 + Math.random()*(upLimit-lowLimit);
+ return(num);
+}
+
+/**This function returns true or false with a random probability.
+ * @return int return value
+ */
+ public static boolean booleanRandom(){
+ boolean value = true;
+ double temp=Math.random();
+ if (temp<0.5) value=false;
+ return value;
+ }
+
+ public static int[] randomSelection(boolean[] types, int times) {
+ int validNum = 0;
+ for(int i=0; i<types.length; i++) {
+ if(!types[i]) {
+ validNum++;
+ }
+ }
+ int[] totalIndices = new int[validNum];
+ validNum = 0;
+ for(int i=0; i<types.length; i++) {
+ if(!types[i]) {
+ totalIndices[validNum] = i;
+ validNum++;
+ if(validNum==totalIndices.length) break;
+ }
+ }
+ return randomSelection(totalIndices, times);
+ }
+
+// public static int[] randomSelection(boolean[] types, int times) {
+// int realTimes = times;
+// if(realTimes>types.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<indices.length; i++) {
+// indices[i] = i;
+// }
+// return indices;
+// }
+// int i = 0;
+// while(i<realTimes) {
+// indices[i] = intRangeRandom(0, upper);
+// if(!internalTypes[indices[i]]) {
+// internalTypes[indices[i]] = true;
+// i++;
+// }
+// }
+// return indices;
+// }
+
+ public static int[] randomSelection(int low, int up, int times){
+ int[] totalIndices = new int[up-low];
+ for (int i=low; i<up; i++) {
+ totalIndices[i] = i;
+ }
+ return randomSelection(totalIndices, times);
+ }
+
+ public static int getRealV(double randTypeV) {
+ if(randTypeV<=0) return 0;
+ int realV = (int)Math.ceil(randTypeV);
+ if(Math.random()<(randTypeV-realV)) realV++;
+ return realV;
+ }
+
+ public static int[] randomSelection(int[] totalIndices, int times) {
+ if (times>=totalIndices.length) {
+ return totalIndices;
+ }
+ int[] indices = randomSelection(totalIndices.length, times);
+ for(int i=0; i<indices.length; i++) {
+ indices[i] = totalIndices[indices[i]];
+ }
+ return indices;
+ }
+
+ public static int[] randomSelection(int maxNum, int times) {
+ if(times<=0) return new int[0];
+ int realTimes = Math.min(maxNum, times);
+ boolean[] flags = new boolean[maxNum];
+// Arrays.fill(flags, false);
+ boolean isBelowHalf = times<maxNum*0.5;
+ int virtualTimes = realTimes;
+ if(!isBelowHalf) {
+ virtualTimes = maxNum-realTimes;
+ }
+ int i = 0;
+ int upper = maxNum-1;
+ int[] indices = new int[realTimes];
+
+ while(i<virtualTimes) {
+ indices[i] = intRangeRandom(0, upper);
+ if(!flags[indices[i]]) {
+ flags[indices[i]] = true;
+ i++;
+ }
+ }
+ if(!isBelowHalf) {
+ int j=0;
+ for(i=0; i<maxNum; i++) {
+ if(flags[i]==isBelowHalf) {
+ indices[j] = i;
+ j++;
+ if(j==realTimes) break;
+ }
+ }
+ }
+ return indices;
+ }
+} \ No newline at end of file