Difference between revisions of "Simulated Annealing - Configuring and Running"

From jecoliwiki
Jump to: navigation, search
(Created page with "Category:Howtos __TOC__ ==== Example ==== An example of simulated annealing algorithm applied to the motifs evaluation problem: - * size of a solution: int isize ...")
 

Latest revision as of 16:31, 5 March 2013


Contents


[edit] Example

An example of simulated annealing algorithm applied to the motifs evaluation problem:

/** size of a solution */
int isize = sequences.getNumSequences();
		
/** max value of a gene */
int maxgene = sequences.getSeqSize()-sequences.getMotifSize()+1;
		
SimulatedAnnealingConfiguration<ILinearRepresentation<Integer>,IntegerRepresentationFactory> configuration = 
    new SimulatedAnnealingConfiguration<ILinearRepresentation<Integer>,IntegerRepresentationFactory>();
configuration.setEvaluationFunction( new MotifsEvaluationFunction(sequences) );
IntegerRepresentationFactory solutionFactory = new IntegerRepresentationFactory(isize,maxgene);
configuration.setSolutionFactory(solutionFactory); 

configuration.setRandomNumberGenerator(new DefaultRandomNumberGenerator());
configuration.setProblemBaseDirectory("nullDirectory");
configuration.setAlgorithmStateFile("nullFile");
configuration.setSaveAlgorithmStateDirectoryPath("nullDirectory");
configuration.setAlgorithmResultWriterList(new ArrayList<IAlgorithmResultWriter<ILinearRepresentation<Integer>>>());
configuration.setStatisticsConfiguration(new StatisticsConfiguration());
		 
IAnnealingSchedule annealingSchedule = new  AnnealingSchedule(100,0.99,5.0);
configuration.setAnnealingSchedule(annealingSchedule);

ITerminationCriteria terminationCriteria = new IterationTerminationCriteria(numberGenerations);
configuration.setTerminationCriteria(terminationCriteria);
		
ReproductionOperatorContainer operatorContainer = new ReproductionOperatorContainer();
operatorContainer.addOperator(0.5,	new LinearGenomeRandomMutation<Integer>(3));	
operatorContainer.addOperator(0.5,	new IntegerAddMutation(3) );
configuration.setMutationOperatorContainer(operatorContainer);

[edit] Executing the Algorithm

As previously stated, the specific algorithm should be instantiated and the method run executed.

IAlgorithm<ILinearRepresentation<Integer>> algorithm = new SimulatedAnnealing<ILinearRepresentation<Integer>,IntegerRepresentationFactory>(configuration);
IAlgorithmResult<ILinearRepresentation<Integer>> result = algorithm.run();
Personal tools