You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kylin.apache.org by "Zhong Yanghong (JIRA)" <ji...@apache.org> on 2018/03/21 05:39:00 UTC
[jira] [Updated] (KYLIN-3306) Fix the rarely happened unit test
exception of generic algorithm
[ https://issues.apache.org/jira/browse/KYLIN-3306?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Zhong Yanghong updated KYLIN-3306:
----------------------------------
Fix Version/s: v2.3.1
> Fix the rarely happened unit test exception of generic algorithm
> ----------------------------------------------------------------
>
> Key: KYLIN-3306
> URL: https://issues.apache.org/jira/browse/KYLIN-3306
> Project: Kylin
> Issue Type: Bug
> Reporter: Zhong Yanghong
> Assignee: Zhong Yanghong
> Priority: Major
> Fix For: v2.3.1
>
>
> There's a bug in the following code:
> {code}
> private Chromosome rouletteWheel(final List<Chromosome> chromosomes, final double totalFitness) {
> float rnd = (float) (GeneticAlgorithm.getRandomGenerator().nextDouble() * totalFitness);
> float runningScore = 0;
> for (Chromosome o : chromosomes) {
> if (rnd >= runningScore && rnd <= runningScore + o.getFitness()) {
> return o;
> }
> runningScore += o.getFitness();
> }
> return null;
> }
> {code}
> We should use double instead of float.
> For example, (float) (0.9999999988948809 * 40.510999999999996) = 40.511 > 40.510999999999996
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)