Skip to content

Commit

Permalink
Fixed bug in JSSP UMDA Model (argh!) and now using newest OSHI version
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasWeise committed May 12, 2020
1 parent ba2ec63 commit 99e38f7
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ 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
<dependencies>
<dependency>
<groupId>com.github.thomasWeise</groupId>
<artifactId>aitoa-code</artifactId>
<version>0.8.55</version>
<version>0.8.56</version>
</dependency>
</dependencies>
```
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>aitoa</groupId>
<artifactId>aitoa-code</artifactId>
<version>0.8.55</version>
<version>0.8.56</version>
<packaging>jar</packaging>
<name>aitoa-code</name>
<description>Example Source Codes from the Book "Introduction to Optimization Algorithms"</description>
Expand Down Expand Up @@ -44,7 +44,7 @@
<project.reporting.outputEncoding>${encoding}</project.reporting.outputEncoding>
<java.source.version>1.8</java.source.version>
<junit.version>4.13</junit.version>
<oshi.version>4.4.2</oshi.version>
<oshi.version>5.0.1</oshi.version>
<slf4j.version>1.7.30</slf4j.version>
<project.mainClass>aitoa.utils.logs.PostProcessor</project.mainClass>
</properties>
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/aitoa/examples/jssp/EJSSPExperimentStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public void configureBuilderForProblem(
IMetaheuristic<int[], JSSPCandidateSolution>>> 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, //
Expand All @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/aitoa/examples/jssp/JSSPUMDAModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
89 changes: 89 additions & 0 deletions src/test/java/aitoa/examples/jssp/TestJSSPUMDAModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 99e38f7

Please sign in to comment.