Skip to content

Commit a627e79

Browse files
committed
added list of available JSSP instances to JSSPInstance
1 parent edd679a commit a627e79

File tree

4 files changed

+83
-3
lines changed

4 files changed

+83
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ First, you need to add the following repository, which is a repository that can
4444
```
4545

4646
Than you can add the dependency on our `aitoa-code` repository into your `dependencies` section.
47-
Here, `0.8.72` is the current version of `aitoa-code`.
47+
Here, `0.8.73` is the current version of `aitoa-code`.
4848
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.
4949

5050
```xml
5151
<dependencies>
5252
<dependency>
5353
<groupId>com.github.thomasWeise</groupId>
5454
<artifactId>aitoa-code</artifactId>
55-
<version>0.8.72</version>
55+
<version>0.8.73</version>
5656
</dependency>
5757
</dependencies>
5858
```

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>aitoa</groupId>
77
<artifactId>aitoa-code</artifactId>
8-
<version>0.8.72</version>
8+
<version>0.8.73</version>
99
<packaging>jar</packaging>
1010
<name>aitoa-code</name>
1111
<description>Example Source Codes from the Book "Introduction to Optimization Algorithms"</description>

src/main/java/aitoa/examples/jssp/JSSPInstance.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import java.io.InputStream;
66
import java.io.InputStreamReader;
77
import java.math.BigInteger;
8+
import java.util.Arrays;
9+
import java.util.Collections;
10+
import java.util.HashSet;
11+
import java.util.List;
812

913
import aitoa.utils.math.BigMath;
1014

@@ -264,6 +268,64 @@ public final double getScale() {
264268
.pow(this.m)));
265269
}
266270

271+
/**
272+
* Get an unmodifiable list of the names of all JSSP instances.
273+
* This list does not contain the {@code demo} instance.
274+
*
275+
* @return an unmodifiable list of the names of all JSSP
276+
* instances
277+
*/
278+
public static final List<String> getAllInstances() {
279+
return Holder.NAMES;
280+
}
281+
282+
/** the internal holder class */
283+
private static final class Holder {
284+
/** the names of all instances */
285+
static final List<String> NAMES = Holder.loadNames();
286+
287+
/**
288+
* the internal names loader
289+
*
290+
* @return the array of strings
291+
*/
292+
private static final List<String> loadNames() {
293+
final HashSet<String> names = new HashSet<>();
294+
try (
295+
final InputStream is = JSSPInstance.class
296+
.getResourceAsStream("instance_data.txt"); //$NON-NLS-1$
297+
final InputStreamReader isr =
298+
new InputStreamReader(is);
299+
final BufferedReader br = new BufferedReader(isr)) {
300+
String line = null;
301+
302+
loop: while ((line = br.readLine()) != null) {
303+
line = line.trim();
304+
if (line.isEmpty()) {
305+
continue loop;
306+
}
307+
if (line.startsWith("instance ")) { //$NON-NLS-1$
308+
line = line.substring(9).trim();
309+
if (line.isEmpty()) {
310+
continue loop;
311+
}
312+
if (line.indexOf(' ') >= 0) {
313+
continue loop;
314+
}
315+
names.add(line);
316+
}
317+
}
318+
} catch (final Throwable error) {
319+
throw new IllegalStateException(
320+
"Could not load instances text.", //$NON-NLS-1$
321+
error);
322+
}
323+
final String[] all =
324+
names.toArray(new String[names.size()]);
325+
Arrays.sort(all);
326+
return Collections.unmodifiableList(Arrays.asList(all));
327+
}
328+
}
267329
// start relevant
268330
}
269331
// end relevant

src/test/java/aitoa/examples/jssp/TestJSSPInstance.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package aitoa.examples.jssp;
22

3+
import java.util.Collection;
4+
35
import org.junit.Assert;
46
import org.junit.Test;
57

@@ -370,4 +372,20 @@ public void testLoadAllInstances() {
370372
TestTools.assertGreater(f.lowerBound(), 0d);
371373
}
372374
}
375+
376+
/** test all instances */
377+
@SuppressWarnings({ "static-method", "unused" })
378+
@Test(timeout = 3600000)
379+
public void testAllInstances() {
380+
final Collection<String> all =
381+
JSSPInstance.getAllInstances();
382+
Assert.assertNotNull(all);
383+
int size = all.size();
384+
TestTools.assertGreater(size, 0);
385+
for (final String n : all) {
386+
new JSSPInstance(n);
387+
--size;
388+
}
389+
Assert.assertEquals(0, size);
390+
}
373391
}

0 commit comments

Comments
 (0)