| 1 | package net.bmahe.genetics4j.core.evaluation; | |
| 2 | ||
| 3 | import java.util.List; | |
| 4 | import java.util.Objects; | |
| 5 | import java.util.concurrent.CompletableFuture; | |
| 6 | import java.util.concurrent.ExecutorService; | |
| 7 | ||
| 8 | import org.apache.commons.lang3.Validate; | |
| 9 | import org.apache.logging.log4j.LogManager; | |
| 10 | import org.apache.logging.log4j.Logger; | |
| 11 | ||
| 12 | import net.bmahe.genetics4j.core.FitnessBulkAsync; | |
| 13 | import net.bmahe.genetics4j.core.Genotype; | |
| 14 | import net.bmahe.genetics4j.core.spec.EAConfigurationBulkAsync; | |
| 15 | ||
| 16 | /** | |
| 17 | * Wrapper around {@link net.bmahe.genetics4j.core.FitnessBulkAsync} for computing the fitness of a population | |
| 18 | * | |
| 19 | * @param <T> | |
| 20 | */ | |
| 21 | public class FitnessEvaluatorBulkAsync<T extends Comparable<T>> implements FitnessEvaluator<T> { | |
| 22 | ||
| 23 | public static final Logger logger = LogManager.getLogger(FitnessEvaluatorBulkAsync.class); | |
| 24 | ||
| 25 | private final EAConfigurationBulkAsync<T> eaConfigurationBulkAsync; | |
| 26 | ||
| 27 | private final ExecutorService executorService; | |
| 28 | ||
| 29 | public FitnessEvaluatorBulkAsync(final EAConfigurationBulkAsync<T> _eaConfigurationBulkAsync, | |
| 30 | final ExecutorService _executorService) { | |
| 31 | Objects.requireNonNull(_eaConfigurationBulkAsync); | |
| 32 | Objects.requireNonNull(_executorService); | |
| 33 | ||
| 34 |
1
1. <init> : Removed assignment to member variable eaConfigurationBulkAsync → NO_COVERAGE |
this.eaConfigurationBulkAsync = _eaConfigurationBulkAsync; |
| 35 |
1
1. <init> : Removed assignment to member variable executorService → NO_COVERAGE |
this.executorService = _executorService; |
| 36 | } | |
| 37 | ||
| 38 | @Override | |
| 39 | public List<T> evaluate(final long generation, final List<Genotype> genotypes) { | |
| 40 | Validate.isTrue(generation >= 0); | |
| 41 | Objects.requireNonNull(genotypes); | |
| 42 | Validate.isTrue(genotypes.size() > 0); | |
| 43 | ||
| 44 |
1
1. evaluate : removed call to net/bmahe/genetics4j/core/spec/EAConfigurationBulkAsync::fitness → NO_COVERAGE |
final FitnessBulkAsync<T> fitnessBulkAsync = eaConfigurationBulkAsync.fitness(); |
| 45 | ||
| 46 | logger.trace("Submitting fitness computation task"); | |
| 47 |
1
1. evaluate : removed call to net/bmahe/genetics4j/core/FitnessBulkAsync::compute → NO_COVERAGE |
final CompletableFuture<List<T>> fitnessesCF = fitnessBulkAsync.compute(executorService, genotypes); |
| 48 | ||
| 49 |
2
1. evaluate : removed call to java/util/concurrent/CompletableFuture::join → NO_COVERAGE 2. evaluate : replaced return value with Collections.emptyList for net/bmahe/genetics4j/core/evaluation/FitnessEvaluatorBulkAsync::evaluate → NO_COVERAGE |
return fitnessesCF.join(); |
| 50 | } | |
| 51 | } | |
Mutations | ||
| 34 |
1.1 |
|
| 35 |
1.1 |
|
| 44 |
1.1 |
|
| 47 |
1.1 |
|
| 49 |
1.1 2.2 |