Skip to content

Commit

Permalink
Added checkstyle filter for exceptional catch of RuntimeException.
Browse files Browse the repository at this point in the history
These catch occur in multi-start optimizers. The exceptions are caught
and stored, and if all restarts fail, then one of the stored
RuntimeException is rethrown. The purpose of multi-start is both to
allow some trials to fail and to avoid being trapped in a local
extremum. Catching RuntimeException is therefore mandatory here, and not
dangerous since we rethrow them as needed.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1179947 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Luc Maisonobe committed Oct 7, 2011
1 parent 0fcb15f commit ef69daf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@
<property name="onCommentFormat" value="CHECKSTYLE\: resume MultipleVariableDeclarations"/>
<property name="checkFormat" value="MultipleVariableDeclarations"/>
</module>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE\: stop IllegalCatch"/>
<property name="onCommentFormat" value="CHECKSTYLE\: resume IllegalCatch"/>
<property name="checkFormat" value="IllegalCatch"/>
</module>

</module>

Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,15 @@ public RealPointValuePair optimize(int maxEval, final FUNC f,

// Multi-start loop.
for (int i = 0; i < starts; ++i) {
// CHECKSTYLE: stop IllegalCatch
try {
optima[i] = optimizer.optimize(maxEval - totalEvaluations, f, goal,
i == 0 ? startPoint : generator.nextVector());
} catch (RuntimeException mue) {
lastException = mue;
optima[i] = null;
}
// CHECKSTYLE: resume IllegalCatch

totalEvaluations += optimizer.getEvaluations();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public VectorialPointValuePair optimize(int maxEval, final FUNC f,
// Multi-start loop.
for (int i = 0; i < starts; ++i) {

// CHECKSTYLE: stop IllegalCatch
try {
optima[i] = optimizer.optimize(maxEval - totalEvaluations, f, target, weights,
i == 0 ? startPoint : generator.nextVector());
Expand All @@ -160,6 +161,7 @@ public VectorialPointValuePair optimize(int maxEval, final FUNC f,
lastException = mue;
optima[i] = null;
}
// CHECKSTYLE: resume IllegalCatch

totalEvaluations += optimizer.getEvaluations();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,15 @@ public UnivariateRealPointValuePair optimize(int maxEval, final FUNC f,

// Multi-start loop.
for (int i = 0; i < starts; ++i) {
// CHECKSTYLE: stop IllegalCatch
try {
final double s = (i == 0) ? startValue : min + generator.nextDouble() * (max - min);
optima[i] = optimizer.optimize(maxEval - totalEvaluations, f, goal, min, max, s);
} catch (RuntimeException mue) {
lastException = mue;
optima[i] = null;
}
// CHECKSTYLE: resume IllegalCatch

totalEvaluations += optimizer.getEvaluations();
}
Expand Down

0 comments on commit ef69daf

Please sign in to comment.