summaryrefslogtreecommitdiffstats
path: root/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global
parentInitial commit. (diff)
downloadlibreoffice-upstream/4%7.4.7.tar.xz
libreoffice-upstream/4%7.4.7.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global')
-rw-r--r--nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/BasicBound.java64
-rw-r--r--nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/IUpdateCycleEngine.java24
-rw-r--r--nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java108
3 files changed, 196 insertions, 0 deletions
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 000000000..6ed1089d9
--- /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 000000000..0b4db684f
--- /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 000000000..245149e87
--- /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;
+ }
+}