Difference between revisions of "Multiobjective example"

From jecoliwiki
Jump to: navigation, search
(Created page with "__TOC__ 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_-_C...")
 

Latest revision as of 16:01, 5 March 2013

Contents


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]


http://www.storetadalafilonline.com/ buy cialis online no prescription - order cialis http://www.diazepamshoponline.com/ buy cheap valium - cheap valium

[edit] 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.


[edit] 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:

File:Obj1.png

File:Obj2.png

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) {
		super(isMaximization);
	}

	@Override
	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)));
 	    } 
 	        
	    fitnesses[0]=f0;
 	    fitnesses[1]=f1;
	    
		return fitnesses;		
	}

 	@Override
	public void verifyInputData()
			throws InvalidEvaluationFunctionInputDataException {
		
		
	}

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

 }

[edit] 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
                              SPEA2Configuration<ILinearRepresentation<Double>,RealValueRepresentationFactory>();

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

			
			int numberGenerations = 100;
			ITerminationCriteria terminationCriteria;
			terminationCriteria = new IterationTerminationCriteria(numberGenerations);
			configuration.setTerminationCriteria(terminationCriteria);
			
			RecombinationParameters recombinationParameters = new RecombinationParameters(0,populationSize,0,true);
			configuration.setRecombinationParameters(recombinationParameters);
			
			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));
			configuration.setReproductionOperatorContainer(reproductionOperatorContainer);
			
			IAlgorithm<ILinearRepresentation<Double>> algorithm = 
                             new SPEA2<ILinearRepresentation<Double>,RealValueRepresentationFactory>(configuration);

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

			
			
		} catch (InvalidNumberOfIterationsException e) {
			e.printStackTrace();
		} catch (InvalidConfigurationException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

 }

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

File:Kursawe.png

Personal tools