Multiobjective example

From jecoliwiki
Jump to: navigation, search


The use of the multiobjective algorithms provided is done by following the same steps as any other algorithm.

Follow these links to see how to configure NSGAII and SPEA2.

This example shows how to use the SPEA2 algorithm in the classical Kursawe problem.

You can find information about the Kursawe problem in:

  • F. Kursawe. A Variant of Evolution Strategies for Vector Optimization. In H.P. Schwefel and R. M¨nner, editors, Parallel Problem Solving for Nature, volume 496 of Lecture Notes in Computer Science, pages 193-197, Berlin, Germany, 1990. Springer-Verlag. [1] buy cialis online no prescription - order cialis buy cheap valium - cheap valium

Configuration of the algorithm:

  • Population Size: 1000
  • Maximum archive size: 1000 (will keep the 1000 best, non-dominated solutions)
  • Number of generations: 300
  • Representation: Real Valued solutions
  • Upper and Lower bounds of individuals: 5.0 , -5.0 respectively.

Defining the Evaluation Function:

To create a new Evaluation Function one must implement a Class that realises the interface IEvaluationFunction<T>. Read more about it here

In this particular case, the evaluation function will define two objective functions, just as follows:



where var is the variable of a given solution, n is the total number of variables in a solution.

When defining them in JECoLi compatible code, one gets the following class:

 * The Class KursaweEvaluationFunction.
public class KursaweEvaluationFunction<T extends IRepresentation> extends AbstractMultiobjectiveEvaluationFunction<ILinearRepresentation<Double>>{

	private static final long serialVersionUID = -9047419840577490750L;

	 * Instantiates a new kursawe evaluation function.
	 * @param isMaximization the is maximization
	public KursaweEvaluationFunction(boolean isMaximization) {

	public Double[] evaluateMO(ILinearRepresentation<Double> solutionRepresentation) throws Exception {
		Double[] fitnesses = new Double[2]; // two objectives
	    double aux, xi, xj;
	    //objective 1
 	    double f0 = 0.0;	    
 	    for (int var = 0; var < solutionRepresentation.getNumberOfElements() -1 ; var++) {
	    	xi = solutionRepresentation.getElement(var) * solutionRepresentation.getElement(var); 
	    	xj = solutionRepresentation.getElement(var+1) * solutionRepresentation.getElement(var+1);  
 	    	aux = (-0.2) * Math.sqrt(xi + xj);
	    	f0 += (-10.0) * Math.exp(aux);
	    //objective 2
	    double f1 = 0.0;	        
	    for (int var = 0; var < solutionRepresentation.getNumberOfElements() ; var++) {
	      f1 += (Math.pow(Math.abs(solutionRepresentation.getElement(var)),0.8) + 5.0 * Math.sin(Math.pow(solutionRepresentation.getElement(var),3.0)));
		return fitnesses;		

	public void verifyInputData()
			throws InvalidEvaluationFunctionInputDataException {

 	public IEvaluationFunction<ILinearRepresentation<Double>> deepCopy()
 			throws Exception {
		return null;


Configuring and Running the test class

One must also implement a main class where all the necessary parameters are correctly instantiated, including the previously defined evaluation function. The one defined for the Kursawe problem, looks something like this:

* The Class KursaweSPEA2Test.
public class KursaweSPEA2Test {

	 * The main method.
	 * @param args the args
	public static void main(String[] args) {
		try {
			SPEA2Configuration<ILinearRepresentation<Double>,RealValueRepresentationFactory> configuration = new

			configuration.setStatisticsConfiguration(new StatisticsConfiguration());
			configuration.setRandomNumberGenerator(new DefaultRandomNumberGenerator());
			IEvaluationFunction<ILinearRepresentation<Double>> evaluationFunction = 
                             new KursaweEvaluationFunction<ILinearRepresentation<Double>>(false);
			int solutionSize = 3;
			RealValueRepresentationFactory solutionFactory = new RealValueRepresentationFactory(solutionSize,-5.0,5.0,2);
			int populationSize = 200;
			int maximumArchiveSize = 200;

			int numberGenerations = 100;
			ITerminationCriteria terminationCriteria;
			terminationCriteria = new IterationTerminationCriteria(numberGenerations);
			RecombinationParameters recombinationParameters = new RecombinationParameters(0,populationSize,0,true);
			configuration.setSelectionOperator(new TournamentSelection<ILinearRepresentation<Double>>(1,2));
			configuration.setEnvironmentalSelectionOperator(new EnvironmentalSelection<ILinearRepresentation<Double>>());
			ReproductionOperatorContainer reproductionOperatorContainer = new ReproductionOperatorContainer();
			reproductionOperatorContainer.addOperator(0.5,new UniformCrossover<Double>());
			reproductionOperatorContainer.addOperator(0.5,new LinearGenomeRandomMutation<Double>(1));
			IAlgorithm<ILinearRepresentation<Double>> algorithm = 
                             new SPEA2<ILinearRepresentation<Double>,RealValueRepresentationFactory>(configuration);

			IAlgorithmResult<ILinearRepresentation<Double>> result =;
			IAlgorithmStatistics<ILinearRepresentation<Double>> stats = result.getAlgorithmStatistics();

		} catch (InvalidNumberOfIterationsException e) {
		} catch (InvalidConfigurationException e) {
		} catch (Exception e) {


If everything goes well you should get something like this, after plotting the results:


Personal tools