From 99e38f71da761fb9b80ba8968a22682cdbe723cd Mon Sep 17 00:00:00 2001 From: tweise Date: Wed, 13 May 2020 07:23:51 +0800 Subject: [PATCH] Fixed bug in JSSP UMDA Model (argh!) and now using newest OSHI version --- README.md | 4 +- pom.xml | 4 +- .../examples/jssp/EJSSPExperimentStage.java | 8 +- .../aitoa/examples/jssp/JSSPUMDAModel.java | 8 +- .../examples/jssp/TestJSSPUMDAModel.java | 89 +++++++++++++++++++ 5 files changed, 104 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6603f47..c6d74fd 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ First, you need to add the following repository, which is a repository that can ``` Than you can add the dependency on our `aitoa-code` repository into your `dependencies` section. -Here, `0.8.55` is the current version of `aitoa-code`. +Here, `0.8.56` is the current version of `aitoa-code`. Notice that you may have more dependencies in your `dependencies` section, say on `junit`, but here I just put the one for `aitoa-code` as example. ```xml @@ -52,7 +52,7 @@ Notice that you may have more dependencies in your `dependencies` section, say o com.github.thomasWeise aitoa-code - 0.8.55 + 0.8.56 ``` diff --git a/pom.xml b/pom.xml index fb0d0bf..2e4c414 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ aitoa aitoa-code - 0.8.55 + 0.8.56 jar aitoa-code Example Source Codes from the Book "Introduction to Optimization Algorithms" @@ -44,7 +44,7 @@ ${encoding} 1.8 4.13 - 4.4.2 + 5.0.1 1.7.30 aitoa.utils.logs.PostProcessor diff --git a/src/main/java/aitoa/examples/jssp/EJSSPExperimentStage.java b/src/main/java/aitoa/examples/jssp/EJSSPExperimentStage.java index 9e965e6..5f291a0 100644 --- a/src/main/java/aitoa/examples/jssp/EJSSPExperimentStage.java +++ b/src/main/java/aitoa/examples/jssp/EJSSPExperimentStage.java @@ -518,7 +518,7 @@ public void configureBuilderForProblem( IMetaheuristic>> list = new ArrayList<>(); - for (final int mu : new int[] { 2, 3, 4 }) { + for (final int mu : new int[] { 2, 3, 4, 10 }) { list.add(() -> new EDA<>(mu, 32768, // new JSSPUMDAModel(problem.instance))); list.add(() -> new EDA<>(mu, 4096, // @@ -531,8 +531,10 @@ public void configureBuilderForProblem( for (final int lambdaShift : new int[] { 4, 5, 6, 7, 8 }) { final int lambda = 1 << lambdaShift; - list.add(() -> new EDAWithClearing<>(mu, lambda, // - new JSSPUMDAModel(problem.instance))); + if (mu < lambda) { + list.add(() -> new EDAWithClearing<>(mu, lambda, // + new JSSPUMDAModel(problem.instance))); + } } } return list.stream(); diff --git a/src/main/java/aitoa/examples/jssp/JSSPUMDAModel.java b/src/main/java/aitoa/examples/jssp/JSSPUMDAModel.java index 9218724..5b60eae 100644 --- a/src/main/java/aitoa/examples/jssp/JSSPUMDAModel.java +++ b/src/main/java/aitoa/examples/jssp/JSSPUMDAModel.java @@ -235,7 +235,11 @@ public String toString() { */ static final int find(final long value, final long[] array, final int length) { - return (Math.abs(// - Arrays.binarySearch(array, 0, length, value) + 1)); + int i = Math.abs(// + Arrays.binarySearch(array, 0, length, value) + 1); + while (array[i] == value) { + ++i; + } + return i; } } diff --git a/src/test/java/aitoa/examples/jssp/TestJSSPUMDAModel.java b/src/test/java/aitoa/examples/jssp/TestJSSPUMDAModel.java index 38dba05..5aa3935 100644 --- a/src/test/java/aitoa/examples/jssp/TestJSSPUMDAModel.java +++ b/src/test/java/aitoa/examples/jssp/TestJSSPUMDAModel.java @@ -126,4 +126,93 @@ public final void testFind() { Assert.assertEquals(3, JSSPUMDAModel.find(6, array, 4)); Assert.assertEquals(3, JSSPUMDAModel.find(7, array, 4)); } + + /** + * Test whether the internal find function works correct with + * 0s + */ + @SuppressWarnings("static-method") + @Test(timeout = 3600000) + public final void testFind2() { + final long[] data = { 0, 0, 1, 2, 3 }; + final long[] array = new long[data.length]; + + long sum = 0L; + for (int i = 0; i < array.length; i++) { + sum += data[i]; + array[i] = sum; + } + Assert.assertEquals(6, sum); + + Assert.assertEquals(2, + JSSPUMDAModel.find(0, array, array.length)); + Assert.assertEquals(3, + JSSPUMDAModel.find(1, array, array.length)); + Assert.assertEquals(3, + JSSPUMDAModel.find(2, array, array.length)); + Assert.assertEquals(4, + JSSPUMDAModel.find(3, array, array.length)); + Assert.assertEquals(4, + JSSPUMDAModel.find(4, array, array.length)); + Assert.assertEquals(4, + JSSPUMDAModel.find(5, array, array.length)); + } + + /** + * Test whether the internal find function works correct with + * 0s + */ + @SuppressWarnings("static-method") + @Test(timeout = 3600000) + public final void testFind3() { + final long[] data = { 0, 0, 1, 0, 1, 0, 1 }; + final long[] array = new long[data.length]; + + long sum = 0L; + for (int i = 0; i < array.length; i++) { + sum += data[i]; + array[i] = sum; + } + Assert.assertEquals(3, sum); + + Assert.assertEquals(2, + JSSPUMDAModel.find(0, array, array.length)); + Assert.assertEquals(4, + JSSPUMDAModel.find(1, array, array.length)); + Assert.assertEquals(6, + JSSPUMDAModel.find(2, array, array.length)); + } + + /** + * Test whether the internal find function works correct with + * 0s + */ + @SuppressWarnings("static-method") + @Test(timeout = 3600000) + public final void testFind4() { + final long[] data = { 0, 0, 1, 0, 0, 0, 3, 0, 1, 0, 2, 0 }; + final long[] array = new long[data.length]; + + long sum = 0L; + for (int i = 0; i < array.length; i++) { + sum += data[i]; + array[i] = sum; + } + Assert.assertEquals(7, sum); + + Assert.assertEquals(2, + JSSPUMDAModel.find(0, array, array.length)); + Assert.assertEquals(6, + JSSPUMDAModel.find(1, array, array.length)); + Assert.assertEquals(6, + JSSPUMDAModel.find(2, array, array.length)); + Assert.assertEquals(6, + JSSPUMDAModel.find(3, array, array.length)); + Assert.assertEquals(8, + JSSPUMDAModel.find(4, array, array.length)); + Assert.assertEquals(10, + JSSPUMDAModel.find(5, array, array.length)); + Assert.assertEquals(10, + JSSPUMDAModel.find(6, array, array.length)); + } }