Skip to content

Commit 0238d55

Browse files
committed
BugFix for Greedy2p1GAmod, new Main Program, Version stepping
1 parent 4a392a9 commit 0238d55

File tree

5 files changed

+110
-36
lines changed

5 files changed

+110
-36
lines changed

README.md

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

4545
Than you can add the dependency on our `aitoa-code` repository into your `dependencies` section.
46-
Here, `0.8.21` is the current version of `aitoa-code`.
46+
Here, `0.8.22` is the current version of `aitoa-code`.
4747
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.
4848

4949
```xml
5050
<dependencies>
5151
<dependency>
5252
<groupId>com.github.thomasWeise</groupId>
5353
<artifactId>aitoa-code</artifactId>
54-
<version>0.8.21</version>
54+
<version>0.8.22</version>
5555
</dependency>
5656
</dependencies>
5757
```

pom.xml

Lines changed: 2 additions & 2 deletions
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.21</version>
8+
<version>0.8.22</version>
99
<packaging>jar</packaging>
1010
<name>aitoa-code</name>
1111
<description>Example Source Codes from the Book "Introduction to Optimization Algorithms"</description>
@@ -46,7 +46,7 @@
4646
<junit.version>4.13</junit.version>
4747
<oshi.version>4.3.0</oshi.version>
4848
<slf4j.version>1.7.30</slf4j.version>
49-
<project.mainClass>aitoa.examples.jssp.JSSPExperiment</project.mainClass>
49+
<project.mainClass>aitoa.utils.logs.PostProcessor</project.mainClass>
5050
</properties>
5151

5252
<licenses>

src/main/java/aitoa/algorithms/bitstrings/Greedy2p1GAmod.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ public Greedy2p1GAmod(final int _m) {
7474

7575
// allocate necessary data structures
7676
final BinomialDistribution binDist =
77-
new BinomialDistribution(x.length,
78-
((double) (this.m)) / n);
77+
new BinomialDistribution(n, ((double) (this.m)) / n);
7978
final DiscreteGreaterThanZero dgtzDist =
8079
new DiscreteGreaterThanZero(binDist);
8180

@@ -118,7 +117,7 @@ public Greedy2p1GAmod(final int _m) {
118117
if (random.nextBoolean()) {
119118
// if we copy zprime from x, then zprime != y if, well, at least
120119
// one zprime[i] != y[i]
121-
zIsNew = zIsNew | (zprime[i] != y[i]);
120+
zIsNew = zIsNew || (zprime[i] != y[i]);
122121
} else {
123122
// if we copy zprime from y, then zprime != x if, well, at least
124123
// one zprime[i] != x[i] (which means it must be different from
@@ -196,25 +195,29 @@ public Greedy2p1GAmod(final int _m) {
196195
// No, we are unlucky: The bit sequences toggled now equal either
197196
// those in x or y, so we need to do a full compare.
198197
check: {
199-
if (!zNEQx) { // maybe (element-wise) z==x, so
200-
// compare
201-
for (int i = n; (--i) >= 0;) {
202-
if (z[i] != x[i]) {
203-
break; // found mismatch
198+
checkX: {
199+
if (!zNEQx) {
200+
// maybe (element-wise) z==x, so compare
201+
for (int i = n; (--i) >= 0;) {
202+
if (z[i] != x[i]) {
203+
break checkX; // found mismatch
204+
}
204205
}
205-
}
206206
// no mismatch, i.e., (element-wise) z==x, so we can stop here
207-
break check;
207+
break check;
208+
}
208209
}
209210
// if we get here, z!=x (otherwise we would have done break)
210-
if (!zNEQy) { // maybe z==y
211-
for (int i = n; (--i) >= 0;) {
212-
if (z[i] != y[i]) {
213-
break; // found mismatch
211+
checkY: {
212+
if (!zNEQy) { // maybe z==y
213+
for (int i = n; (--i) >= 0;) {
214+
if (z[i] != y[i]) {
215+
break checkY; // found mismatch
216+
}
214217
}
215-
}
216218
// no mismatch, i.e., (element-wise) z==y, so we can stop here
217-
break check;
219+
break check;
220+
}
218221
}
219222
// if we get here, z!=x and z!=y (element-wise)
220223
zIsNew = true;

src/main/java/aitoa/algorithms/bitstrings/Greedy2p1GAmodFFA.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ public Greedy2p1GAmodFFA(final int _m, final int _UB) {
9090

9191
// allocate necessary data structures
9292
final BinomialDistribution binDist =
93-
new BinomialDistribution(x.length,
94-
((double) (this.m)) / n);
93+
new BinomialDistribution(n, ((double) (this.m)) / n);
9594
final DiscreteGreaterThanZero dgtzDist =
9695
new DiscreteGreaterThanZero(binDist);
9796

@@ -136,7 +135,7 @@ public Greedy2p1GAmodFFA(final int _m, final int _UB) {
136135
if (random.nextBoolean()) {
137136
// if we copy zprime from x, then zprime != y if, well, at least
138137
// one zprime[i] != y[i]
139-
zIsNew = zIsNew | (zprime[i] != y[i]);
138+
zIsNew = zIsNew || (zprime[i] != y[i]);
140139
} else {
141140
// if we copy zprime from y, then zprime != x if, well, at least
142141
// one zprime[i] != x[i] (which means it must be different from
@@ -214,25 +213,29 @@ public Greedy2p1GAmodFFA(final int _m, final int _UB) {
214213
// No, we are unlucky: The bit sequences toggled now equal either
215214
// those in x or y, so we need to do a full compare.
216215
check: {
217-
if (!zNEQx) { // maybe (element-wise) z==x, so
218-
// compare
219-
for (int i = n; (--i) >= 0;) {
220-
if (z[i] != x[i]) {
221-
break; // found mismatch
216+
checkX: {
217+
if (!zNEQx) {
218+
// maybe (element-wise) z==x, so compare
219+
for (int i = n; (--i) >= 0;) {
220+
if (z[i] != x[i]) {
221+
break checkX; // found mismatch
222+
}
222223
}
223-
}
224224
// no mismatch, i.e., (element-wise) z==x, so we can stop here
225-
break check;
225+
break check;
226+
}
226227
}
227228
// if we get here, z!=x (otherwise we would have done break)
228-
if (!zNEQy) { // maybe z==y
229-
for (int i = n; (--i) >= 0;) {
230-
if (z[i] != y[i]) {
231-
break; // found mismatch
229+
checkY: {
230+
if (!zNEQy) { // maybe z==y
231+
for (int i = n; (--i) >= 0;) {
232+
if (z[i] != y[i]) {
233+
break checkY; // found mismatch
234+
}
232235
}
233-
}
234236
// no mismatch, i.e., (element-wise) z==y, so we can stop here
235-
break check;
237+
break check;
238+
}
236239
}
237240
// if we get here, z!=x and z!=y (element-wise)
238241
zIsNew = true;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package aitoa.utils.logs;
2+
3+
import aitoa.utils.Configuration;
4+
import aitoa.utils.ConsoleIO;
5+
6+
/** The entry point for post-processing the data */
7+
public class PostProcessor {
8+
9+
/**
10+
* The main routine
11+
*
12+
* @param args
13+
* the command line arguments
14+
*/
15+
public static final void main(final String[] args) {
16+
final Class<?>[] classes = { //
17+
EndResults.class, //
18+
EndResultStatistics.class, //
19+
ErtEcdf.class, //
20+
IOHProfiler.class,//
21+
};
22+
23+
final String[] choices = new String[classes.length];
24+
for (int i = classes.length; (--i) >= 0;) {
25+
choices[i] = classes[i].getSimpleName();
26+
}
27+
28+
final String choice = "choice";//$NON-NLS-1$
29+
30+
ConsoleIO.stdout((s) -> {
31+
s.println("Welcome to the AITOA Result Post-Processor"); //$NON-NLS-1$
32+
for (final String c : choices) {
33+
s.print(" -choice=");//$NON-NLS-1$
34+
s.print(c);
35+
s.print(": execute the ");//$NON-NLS-1$
36+
s.print(c);
37+
s.println(" utility.");//$NON-NLS-1$
38+
}
39+
});
40+
41+
Configuration.putCommandLine(args);
42+
final String selected = Configuration.getString(choice);
43+
if (selected != null) {
44+
Class<?> taken = null;
45+
for (int i = choices.length; (--i) >= 0;) {
46+
if (choices[i].equalsIgnoreCase(selected)) {
47+
taken = classes[i];
48+
break;
49+
}
50+
}
51+
52+
if (taken == null) {
53+
ConsoleIO.stdout(
54+
'\'' + selected + "' is not a valid choice.");//$NON-NLS-1$
55+
return;
56+
}
57+
58+
try {
59+
taken.getMethod("main", String[].class)//$NON-NLS-1$
60+
.invoke(null, ((Object) (args)));
61+
} catch (final Throwable error) {
62+
ConsoleIO.stderr("Error when invoking the '"//$NON-NLS-1$
63+
+ selected + "' tool.", //$NON-NLS-1$
64+
error);
65+
}
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)