Added checkstyle filter for exceptional catch of RuntimeException.

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
This commit is contained in:
Luc Maisonobe 2011-10-07 07:25:51 +00:00
parent a339a751b9
commit 0251da64fd
4 changed files with 11 additions and 0 deletions

View File

@ -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>

View File

@ -149,6 +149,7 @@ public class BaseMultiStartMultivariateRealOptimizer<FUNC extends MultivariateRe
// 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());
@ -156,6 +157,7 @@ public class BaseMultiStartMultivariateRealOptimizer<FUNC extends MultivariateRe
lastException = mue;
optima[i] = null;
}
// CHECKSTYLE: resume IllegalCatch
totalEvaluations += optimizer.getEvaluations();
}

View File

@ -151,6 +151,7 @@ public class BaseMultiStartMultivariateVectorialOptimizer<FUNC extends Multivari
// 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());
@ -160,6 +161,7 @@ public class BaseMultiStartMultivariateVectorialOptimizer<FUNC extends Multivari
lastException = mue;
optima[i] = null;
}
// CHECKSTYLE: resume IllegalCatch
totalEvaluations += optimizer.getEvaluations();
}

View File

@ -161,6 +161,7 @@ public class MultiStartUnivariateRealOptimizer<FUNC extends UnivariateRealFuncti
// 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);
@ -168,6 +169,7 @@ public class MultiStartUnivariateRealOptimizer<FUNC extends UnivariateRealFuncti
lastException = mue;
optima[i] = null;
}
// CHECKSTYLE: resume IllegalCatch
totalEvaluations += optimizer.getEvaluations();
}