Skip to content

Commit

Permalink
cleanup of comments (e.g., removal of unnecessary "relevant" tags)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasWeise committed Apr 22, 2020
1 parent c1ce4d2 commit 205890c
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 79 deletions.
11 changes: 3 additions & 8 deletions src/main/java/aitoa/algorithms/EA1p1.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,26 @@
* @param <Y>
* the solution space
*/
// start relevant
public final class EA1p1<X, Y> implements IMetaheuristic<X, Y> {
// end relevant

/** create */
public EA1p1() {
super();
}

/** {@inheritDoc} */
@Override
// start relevant
public final void solve(final IBlackBoxProcess<X, Y> process) {
// init local variables x_cur, x_best, nullary, unary, random
// end relevant

final X x_cur = process.getSearchSpace().create();
final X x_best = process.getSearchSpace().create();
final INullarySearchOperator<X> nullary =
process.getNullarySearchOperator(); // get nullary op
final IUnarySearchOperator<X> unary =
process.getUnarySearchOperator(); // get unary op
final Random random = process.getRandom();// get random gen
// start relevant

// create starting point: a random point in the search space
nullary.apply(x_best, random); // put random point in x_best
double f_best = process.evaluate(x_best); // map & evaluate
Expand All @@ -66,7 +64,6 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
} // otherwise, i.e., f_cur > f_best: just forget x_cur
} // until time is up
} // process will have remembered the best candidate solution
// end relevant

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -101,6 +98,4 @@ public final void printSetup(final Writer output)
return IMetaheuristic.getSetupNameWithUnaryOperator(this,
builder);
}
// start relevant
}
// end relevant
3 changes: 0 additions & 3 deletions src/main/java/aitoa/algorithms/EA1p1WithFitness.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@
* @param <Y>
* the solution space
*/
// start relevant
public final class EA1p1WithFitness<X, Y>
implements IMetaheuristic<X, Y> {
/** the fitness assignment process */
public final FitnessAssignmentProcess<? super X> fitness;

// end relevant
/**
* create
*
Expand All @@ -51,7 +49,6 @@ public EA1p1WithFitness(
/** {@inheritDoc} */
@Override
@SuppressWarnings("unchecked")
// start relevant
public final void solve(final IBlackBoxProcess<X, Y> process) {
// init local variables pop, nullary, unary, random
// end relevant
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/aitoa/algorithms/EAWithRestarts.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
final X x = searchSpace.create();
nullary.apply(x, random);
population[i] = new Individual<>(x, process.evaluate(x));
// end relevant
if (process.shouldTerminate()) {
return;
}
// start relevant
}

while (nonImprovedGen < this.generationsUntilRestart) {
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/aitoa/algorithms/EDAWithFitness.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
* @param <Y>
* the solution space
*/
// start relevant
public final class EDAWithFitness<X, Y>
implements IMetaheuristic<X, Y> {
// end relevant

/** the number of solution to be selected */
public final int mu;
Expand Down Expand Up @@ -100,9 +98,7 @@ public final String toString() {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
// start relevant
public final void solve(final IBlackBoxProcess<X, Y> process) {
// end relevant
// create local variables
final Random random = process.getRandom();
final ISpace<X> searchSpace = process.getSearchSpace();
Expand All @@ -113,7 +109,7 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
final FitnessIndividual<X>[] P =
new FitnessIndividual[this.lambda];
this.fitness.initialize();
// start relevant

// local variable initialization omitted for brevity
Model.initialize(); // initialize model=uniform distribution

Expand All @@ -122,11 +118,9 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
final X x = searchSpace.create();
nullary.apply(x, random);
P[i] = new FitnessIndividual<>(x, process.evaluate(x));
// end relevant
if (process.shouldTerminate()) { // we return
return; // best solution is stored in process
}
// start relevant
}

for (;;) {// each iteration: update model, sample model
Expand All @@ -146,4 +140,3 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
} // the end of the main loop
}
}
// end relevant
9 changes: 1 addition & 8 deletions src/main/java/aitoa/algorithms/HillClimber2.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,19 @@
* @param <Y>
* the solution space
*/
// start relevant
public final class HillClimber2<X, Y>
implements IMetaheuristic<X, Y> {

// end relevant
/** create */
public HillClimber2() {
super();
}

/** {@inheritDoc} */
@Override
// start relevant
public final void solve(final IBlackBoxProcess<X, Y> process) {
// init local variables x_cur, x_best, nullary, unary, random,
// f_best, improved: omitted here for brevity
// end relevant
final X x_cur = process.getSearchSpace().create();
final X x_best = process.getSearchSpace().create();
final INullarySearchOperator<X> nullary =
Expand All @@ -54,7 +50,7 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
process.getUnarySearchOperator(); // get unary op
final Random random = process.getRandom();// get random gen
boolean improved = true;
// start relevant

// create starting point: a random point in the search space
nullary.apply(x_best, random); // put random point in x_best
final double[] f_best = { process.evaluate(x_best) }; // evaluate
Expand All @@ -79,7 +75,6 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
}

} // process will have remembered the best candidate solution
// end relevant

/** {@inheritDoc} */
@Override
Expand All @@ -94,6 +89,4 @@ public final String toString() {
return IMetaheuristic.getSetupNameWithUnaryOperator(this,
builder);
}
// start relevant
}
// end relevant
8 changes: 0 additions & 8 deletions src/main/java/aitoa/algorithms/HybridEDA.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
* @param <Y>
* the solution space
*/
// start relevant
public final class HybridEDA<X, Y>
implements IMetaheuristic<X, Y> {
// end relevant

/** the number of solution to be selected */
public final int mu;
Expand Down Expand Up @@ -120,9 +118,7 @@ public final String toString() {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
// start relevant
public final void solve(final IBlackBoxProcess<X, Y> process) {
// end relevant
// create local variables
final Random random = process.getRandom();
final ISpace<X> searchSpace = process.getSearchSpace();
Expand All @@ -135,7 +131,6 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
final Individual<X>[] P = new Individual[this.lambda];
final X temp = searchSpace.create();

// start relevant
// the initialization of local variables is omitted for brevity
Model.initialize(); // initialize model=uniform distribution

Expand All @@ -144,11 +139,9 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
final X x = searchSpace.create();
nullary.apply(x, random);
P[i] = new Individual<>(x, process.evaluate(x));
// end relevant
if (process.shouldTerminate()) { // we return
return; // best solution is stored in process
}
// start relevant
}

for (;;) {// each iteration: LS, update model, then sample
Expand Down Expand Up @@ -187,4 +180,3 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
} // the end of the main loop
}
}
// end relevant
10 changes: 0 additions & 10 deletions src/main/java/aitoa/algorithms/HybridEDAWithFitness.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
* @param <Y>
* the solution space
*/
// start relevant
public final class HybridEDAWithFitness<X, Y>
implements IMetaheuristic<X, Y> {
// end relevant

/** the number of solution to be selected */
public final int mu;
Expand Down Expand Up @@ -127,9 +125,7 @@ public final String toString() {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
// start relevant
public final void solve(final IBlackBoxProcess<X, Y> process) {
// end relevant
// create local variables
final Random random = process.getRandom();
final ISpace<X> searchSpace = process.getSearchSpace();
Expand All @@ -144,7 +140,6 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
final X temp = searchSpace.create();
this.fitness.initialize();

// start relevant
// the initialization of local variables is omitted for brevity
Model.initialize(); // initialize model=uniform distribution

Expand All @@ -153,11 +148,9 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
final X x = searchSpace.create();
nullary.apply(x, random);
P[i] = new FitnessIndividual<>(x, process.evaluate(x));
// end relevant
if (process.shouldTerminate()) { // we return
return; // best solution is stored in process
}
// start relevant
}

for (;;) {// each iteration: LS, update model, then sample
Expand Down Expand Up @@ -194,12 +187,9 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
Model.sample(dest.x, random);
dest.quality = process.evaluate(dest.x);
} // the end of the new points generation
// end relevant
if (process.shouldTerminate()) { // we return
return; // best solution is stored in process
}
// start relevant
} // the end of the main loop
}
}
// end relevant
10 changes: 6 additions & 4 deletions src/main/java/aitoa/algorithms/MA.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,13 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {

while (!process.shouldTerminate()) { // main loop
for (final LSIndividual<X> ind : P) {
// If ind is not known to be local optimum, refine it with local
// search à la HillClimber2 for a given number of maximum steps
// (code omitted for brevity).
// end relevant
if (ind.isOptimum) {
continue;
}
// refine ind with local search à la HillClimber2 (code omitted)
// for a given number of maximum steps
// end relevant
int steps = this.maxLSSteps;
do { // local search in style of HillClimber2
improved = unary.enumerate(random, ind.x, temp, //
Expand Down Expand Up @@ -189,9 +190,10 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
} while (p2 == p1);
// perform recombination of the two selected individuals
binary.apply(sel.x, P[p2].x, dest.x, random);
// map to solution/schedule and evaluate quality
dest.quality = process.evaluate(dest.x);
// end relevant
dest.isOptimum = false;
// start relevant
} // the end of the offspring generation
} // the end of the main loop
}
Expand Down
14 changes: 1 addition & 13 deletions src/main/java/aitoa/algorithms/MAWithClearing.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@
* @param <Y>
* the solution space
*/
// start relevant
public final class MAWithClearing<X, Y>
implements IMetaheuristic<X, Y> {
// end relevant

/** the number of selected parents */
public final int mu;
Expand Down Expand Up @@ -128,12 +126,7 @@ public final String toString() {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
// start relevant
public final void solve(final IBlackBoxProcess<X, Y> process) {
// omitted: initialize local variables random, searchSpace,
// nullary, unary, binary, and arrays P and P2 of length
// mu+lambda, and array T to null
// end relevant
// create local variables
final Random random = process.getRandom();
final ISpace<X> searchSpace = process.getSearchSpace();
Expand All @@ -149,18 +142,16 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
P2 = new LSIndividual[P.length];
boolean improved = false;
int p2 = -1;
// start relevant

restart: while (!process.shouldTerminate()) {
// first generation: fill population with random individuals
for (int i = P.length; (--i) >= 0;) {
final X x = searchSpace.create();
nullary.apply(x, random);
P[i] = new LSIndividual<>(x, process.evaluate(x));
// end relevant
if (process.shouldTerminate()) {
return;
}
// start relevant
}

while (!process.shouldTerminate()) { // main loop
Expand Down Expand Up @@ -236,7 +227,6 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
} // the end of the main loop
} // end of the restart loop
}
// end relevant

/** {@inheritDoc} */
@Override
Expand All @@ -245,6 +235,4 @@ public final void solve(final IBlackBoxProcess<X, Y> process) {
return IMetaheuristic.getSetupNameWithUnaryAndBinaryOperator(//
this, builder);
}
// start relevant
}
// end relevant
Loading

0 comments on commit 205890c

Please sign in to comment.