All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.debacharya.nsgaii.plugin.FitnessCalculatorProvider Maven / Gradle / Ivy

Go to download

A NSGA-II implementation using Java. This implementation of NSGA-II algorithm is in pure reference to the original published paper. This is not an effort to convert the originally implemented C code in Java. The original C code by the authors has not be referred to while writing this implementation. This is a fully customizable implementation of the NSGA-II algorithm, made as generic as possible. This documentation assumes you have basic understanding of the NSGA-II algorithm. Apart from the core concepts of the algorithm, everything else in this package can be implemented as per the user's choice and plugged into the algorithm dynamically. Since NSGA-II is more like a set of protocols to follow as an algorithm rather than a concrete implementation of every aspect, this package has been re-written from scratch keeping complete customizability in mind. Apart from the core concepts of the algorithm, everything is considered to be a plugin external to the algorithm that can be implemented by the user and dynamically plugged into the algorithm during runtime as needed. This opens up the possibility of the package to be used simply as a PoC or be converted into something much more complex according to the users needs.

There is a newer version: 3.2.0
Show newest version
package com.debacharya.nsgaii.plugin;

import com.debacharya.nsgaii.Service;
import com.debacharya.nsgaii.datastructure.BooleanAllele;

import java.util.stream.Collectors;

public class FitnessCalculatorProvider {

	private static final String NON_BOOLEAN_ALLELE_UNSUPPORTED = "FitnessCalculator.normalizedGeneticCodeValue does not work with AbstractAllele type "			+
																" other than BooleanAllele. If you are implementing a different type of AbstractAllele object " +
																" use your own implementation of FitnessCalculator.";

	public static FitnessCalculator normalizedGeneticCodeValue(double actualMin, double actualMax, double normalizedMin, double normalizedMax) {
		return chromosome -> {

			if(!(chromosome.getGeneticCode().get(0) instanceof BooleanAllele))
				throw new UnsupportedOperationException(FitnessCalculatorProvider.NON_BOOLEAN_ALLELE_UNSUPPORTED);

			return Service.getNormalizedGeneticCodeValue(
					chromosome.getGeneticCode().stream().map(e -> (BooleanAllele) e).collect(Collectors.toList()),
					actualMin,
					actualMax,
					normalizedMin,
					normalizedMax
			);
		};
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy