Interface FitnessBulkAsync<T extends Comparable<T>>

Type Parameters:
T - the type of fitness values produced, must be comparable for selection operations
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface FitnessBulkAsync<T extends Comparable<T>>
Functional interface for asynchronous batch fitness evaluation in evolutionary algorithms.

FitnessBulkAsync enables efficient evaluation of entire populations through asynchronous, batch-oriented fitness computation. This approach is particularly beneficial for expensive fitness functions that can be optimized through parallel processing, external service calls, or specialized hardware acceleration like GPUs.

Key advantages of bulk asynchronous evaluation:

  • Batch optimization: Process multiple individuals simultaneously for better resource utilization
  • External integration: Efficient interfacing with databases, web services, or simulation engines
  • Hardware acceleration: Leverage GPUs, TPUs, or distributed computing resources
  • I/O efficiency: Minimize network round-trips and database connections through batching
  • Non-blocking execution: Allow other operations to proceed while fitness computation occurs

Common use cases include:

  • Neural network evaluation: Batch processing through deep learning frameworks
  • Simulation-based fitness: Running multiple simulations in parallel or on clusters
  • Database queries: Efficient batch retrieval of fitness data from external sources
  • Web service calls: Minimize API calls through bulk evaluation requests
  • Scientific computing: Utilize high-performance computing resources

Implementation considerations:

  • Return order: Fitness values must correspond to input genotypes in the same order
  • Error handling: Handle individual evaluation failures gracefully within the batch
  • Resource management: Properly utilize the provided executor service for concurrent operations
  • Cancellation support: Consider supporting cancellation through CompletableFuture mechanisms

Example implementations:


 // GPU-accelerated batch evaluation
 FitnessBulkAsync<Double> gpuEvaluator = (executorService, genotypes) -> {
     return CompletableFuture.supplyAsync(() -> {
         // Convert genotypes to GPU-friendly format
         float[][] inputData = convertToGPUFormat(genotypes);
         
         // Execute batch computation on GPU
         float[] results = gpuKernel.evaluate(inputData);
         
         // Convert back to fitness values
         return Arrays.stream(results)
                 .boxed()
                 .map(Double::valueOf)
                 .collect(toList());
     }, executorService);
 };
 
 // External service batch evaluation
 FitnessBulkAsync<Double> serviceEvaluator = (executorService, genotypes) -> {
     return CompletableFuture.supplyAsync(() -> {
         // Prepare batch request
         BatchEvaluationRequest request = new BatchEvaluationRequest(genotypes);
         
         // Make single API call for entire batch
         BatchEvaluationResponse response = fitnessService.evaluateBatch(request);
         
         return response.getFitnessValues();
     }, executorService);
 };
 
 // Parallel simulation evaluation
 FitnessBulkAsync<Double> simulationEvaluator = (executorService, genotypes) -> {
     List<CompletableFuture<Double>> futures = genotypes.stream()
         .map(genotype -> CompletableFuture.supplyAsync(
             () -> runSimulation(genotype), executorService))
         .collect(toList());
     
     return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
         .thenApply(ignored -> futures.stream()
             .map(CompletableFuture::join)
             .collect(toList()));
 };
 

Integration with EA system:

  • Configuration: Used with EAConfigurationBulkAsync
  • Evaluation flow: Called by FitnessEvaluatorBulkAsync
  • Thread management: Receives configured executor service for optimal resource usage
  • Performance monitoring: Can be wrapped with metrics collection and caching strategies
See Also:
  • Method Details

    • compute

      CompletableFuture<List<T>> compute(ExecutorService executorService, List<Genotype> genotypes)
      Asynchronously computes fitness values for an entire population of genotypes.

      This method implements the core fitness evaluation logic for bulk asynchronous processing. Implementations should leverage the provided executor service for optimal concurrency and return a CompletableFuture that will complete with fitness values corresponding to each input genotype in the same order.

      Implementation requirements:

      • Order preservation: Return fitness values in the same order as input genotypes
      • Size consistency: Return exactly one fitness value per input genotype
      • Executor usage: Utilize the provided executor service for concurrent operations
      • Error handling: Handle evaluation failures gracefully or propagate through CompletableFuture

      Performance considerations:

      • Batch operations where possible to minimize overhead
      • Use the executor service for CPU-bound parallel operations
      • Consider async I/O for external service calls
      • Implement appropriate timeouts for long-running operations
      Parameters:
      executorService - the executor service configured in the EA system for parallel operations
      genotypes - the population of genotypes to evaluate
      Returns:
      a CompletableFuture that will complete with fitness values corresponding to each genotype
      Throws:
      IllegalArgumentException - if genotypes is null or empty (implementation-dependent)
      RuntimeException - if evaluation setup fails (propagated through CompletableFuture)