Skip to content

Commit

Permalink
added list of available JSSP instances to JSSPInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasWeise committed Oct 31, 2020
1 parent edd679a commit a627e79
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 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.72` is the current version of `aitoa-code`.
Here, `0.8.73` 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.72</version>
<version>0.8.73</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.72</version>
<version>0.8.73</version>
<packaging>jar</packaging>
<name>aitoa-code</name>
<description>Example Source Codes from the Book "Introduction to Optimization Algorithms"</description>
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/aitoa/examples/jssp/JSSPInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;

import aitoa.utils.math.BigMath;

Expand Down Expand Up @@ -264,6 +268,64 @@ public final double getScale() {
.pow(this.m)));
}

/**
* Get an unmodifiable list of the names of all JSSP instances.
* This list does not contain the {@code demo} instance.
*
* @return an unmodifiable list of the names of all JSSP
* instances
*/
public static final List<String> getAllInstances() {
return Holder.NAMES;
}

/** the internal holder class */
private static final class Holder {
/** the names of all instances */
static final List<String> NAMES = Holder.loadNames();

/**
* the internal names loader
*
* @return the array of strings
*/
private static final List<String> loadNames() {
final HashSet<String> names = new HashSet<>();
try (
final InputStream is = JSSPInstance.class
.getResourceAsStream("instance_data.txt"); //$NON-NLS-1$
final InputStreamReader isr =
new InputStreamReader(is);
final BufferedReader br = new BufferedReader(isr)) {
String line = null;

loop: while ((line = br.readLine()) != null) {
line = line.trim();
if (line.isEmpty()) {
continue loop;
}
if (line.startsWith("instance ")) { //$NON-NLS-1$
line = line.substring(9).trim();
if (line.isEmpty()) {
continue loop;
}
if (line.indexOf(' ') >= 0) {
continue loop;
}
names.add(line);
}
}
} catch (final Throwable error) {
throw new IllegalStateException(
"Could not load instances text.", //$NON-NLS-1$
error);
}
final String[] all =
names.toArray(new String[names.size()]);
Arrays.sort(all);
return Collections.unmodifiableList(Arrays.asList(all));
}
}
// start relevant
}
// end relevant
18 changes: 18 additions & 0 deletions src/test/java/aitoa/examples/jssp/TestJSSPInstance.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package aitoa.examples.jssp;

import java.util.Collection;

import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -370,4 +372,20 @@ public void testLoadAllInstances() {
TestTools.assertGreater(f.lowerBound(), 0d);
}
}

/** test all instances */
@SuppressWarnings({ "static-method", "unused" })
@Test(timeout = 3600000)
public void testAllInstances() {
final Collection<String> all =
JSSPInstance.getAllInstances();
Assert.assertNotNull(all);
int size = all.size();
TestTools.assertGreater(size, 0);
for (final String n : all) {
new JSSPInstance(n);
--size;
}
Assert.assertEquals(0, size);
}
}

0 comments on commit a627e79

Please sign in to comment.