Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit c5a15a3

Browse files
committed
Updated the sandbox strategy to update CR and F at every trial
1 parent 4cfe28c commit c5a15a3

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/main/java/com/vsthost/rnd/jdeoptim/evolution/strategies/SandboxStrategy.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -108,31 +108,32 @@ public void regenerate(Population population, Problem problem, Objective objecti
108108
// Get the best member of the population:
109109
final double[] bestMember = population.getBestMember();
110110

111-
// Are we going to adjust CR and F?
112-
if (this.c > 0) {
113-
// Yes. We will not adjust the CR first:
114-
this.cr = new NormalDistribution(this.randomGenerator, this.meanCR, 0.1).sample();
115-
116-
// Check and reset CR:
117-
this.cr = this.cr > 1 ? 1 : (this.cr < 0 ? 0 : this.cr);
118-
119-
// OK, now we will adjust F:
120-
do {
121-
// Get the new F:
122-
this.f = new CauchyDistribution(this.randomGenerator, this.meanF, 0.1).sample();
123-
124-
// Check and reset F if required:
125-
this.f = this.f > 1 ? 1 : this.f;
126-
} while (this.f <= 0);
111+
// Iterate over the current population:
112+
for (int c = 0; c < population.getSize(); c++) {
113+
// Are we going to adjust CR and F?
114+
if (this.c > 0) {
115+
// Yes. We will not adjust the CR first:
116+
this.cr = new NormalDistribution(this.randomGenerator, this.meanCR, 0.1).sample();
117+
118+
// Check and reset CR:
119+
this.cr = this.cr > 1 ? 1 : (this.cr < 0 ? 0 : this.cr);
120+
121+
// OK, now we will adjust F:
122+
do {
123+
// Get the new F:
124+
this.f = new CauchyDistribution(this.randomGenerator, this.meanF, 0.1).sample();
125+
126+
// Check and reset F if required:
127+
this.f = this.f > 1 ? 1 : this.f;
128+
} while (this.f <= 0);
127129
// System.err.print(this.meanF);
128130
// System.err.print(" ");
129131
// System.err.print(this.cr);
130132
// System.err.print(" ");
131133
// System.err.println(this.f);
132-
}
134+
}
135+
133136

134-
// Iterate over the current population:
135-
for (int c = 0; c < population.getSize(); c++) {
136137
// Get the candidate as the base of the next candidate (a.k.a. trial):
137138
final double[] trial = population.getMemberCopy(c);
138139

@@ -183,12 +184,11 @@ else if (trial[i] > problem.getUpper()[i]) {
183184
this.goodF2 += Math.pow(this.f, 2);
184185
}
185186

186-
}
187-
188-
// Re-compute mean CR and F if required:
189-
if (this.c > 0 && this.goodF != 0) {
190-
this.meanCR = (1 - this.c) * this.meanCR + this.c * this.goodCR;
191-
this.meanF = (1 - this.c) * this.meanF + this.c * this.goodF2 / this.goodF;
187+
// Re-compute mean CR and F if required:
188+
if (this.c > 0 && this.goodF != 0) {
189+
this.meanCR = (1 - this.c) * this.meanCR + this.c * this.goodCR;
190+
this.meanF = (1 - this.c) * this.meanF + this.c * this.goodF2 / this.goodF;
191+
}
192192
}
193193
}
194194
}

0 commit comments

Comments
 (0)