Skip to content

Commit

Permalink
fixed umda eda for jssp
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasWeise committed May 14, 2020
1 parent c8f4a1d commit 6c4b90f
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 96 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.56` is the current version of `aitoa-code`.
Here, `0.8.57` 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.56</version>
<version>0.8.57</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion 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.56</version>
<version>0.8.57</version>
<packaging>jar</packaging>
<name>aitoa-code</name>
<description>Example Source Codes from the Book "Introduction to Optimization Algorithms"</description>
Expand Down
4 changes: 3 additions & 1 deletion 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, 10 }) {
for (final int mu : new int[] { 2, 3, 4, 10, 1000 }) {
list.add(() -> new EDA<>(mu, 32768, //
new JSSPUMDAModel(problem.instance)));
list.add(() -> new EDA<>(mu, 4096, //
Expand All @@ -534,6 +534,8 @@ public void configureBuilderForProblem(
if (mu < lambda) {
list.add(() -> new EDAWithClearing<>(mu, lambda, //
new JSSPUMDAModel(problem.instance)));
list.add(() -> new EDA<>(mu, lambda, //
new JSSPUMDAModel(problem.instance)));
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/aitoa/examples/jssp/JSSPUMDAModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,16 @@ public String toString() {
*/
static final int find(final long value, final long[] array,
final int length) {
int i = Math.abs(//
final int i = Math.abs(//
Arrays.binarySearch(array, 0, length, value) + 1);
while (array[i] == value) {
++i;
}
// The code below would be needed if there could be two elements
// in array with the same value. This can only happen if one
// index would have probability 0.
// This is not possible in the current configuration, so it is
// commented out.
// while (array[i] == value) {
// ++i;
// }
return i;
}
}
179 changes: 91 additions & 88 deletions src/test/java/aitoa/examples/jssp/TestJSSPUMDAModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,92 +127,95 @@ public final void testFind() {
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));
}
// The tests below are only relevant in cases where an index
// could have zero probability. This is not possible in the
// current implementation.
// /**
// * 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 6c4b90f

Please sign in to comment.