[EvA] Question on EVA2 - Initialize populations in a GA

Marcel Kronfeld marcel.kronfeld at uni-tuebingen.de
Mon May 31 12:00:15 CEST 2010


Vitins Basil wrote:
> I've applied EVA2 in my current research and appreciate the diverse
> possibilities. Thank you very much!
> 
> One open question is now occuring applying the GA (binary genome):
> 
> To access the population after optimization and input the same or a
> manipulated population again for a new optimization run, I used the
> commands:
> 
> ga.getPopulation(); ga.setPopulation(popInput); or
> ga.initByPopulation(popInput, true);
> 
> unfortunately without success.
> 
> 
> Am I right that I have no access to the documentation of the
> GeneticAlgorithm class to get help there?
> 
> 
> Sorry for any inconvenience caused by this quesions!
> 
> Thanks in advance for a short answer!
> 
> Have a nice weekend and best regards,

Dear Basil,

to explicitely set the initial population using the OptimizerFactory,
you need to access the OptimizerRunnable instance and set the restart
flag. Note that the termination criterion depends on the GA population,
so you will need to reset the evaluation counter before recycling an
"old" population (depending on the terminator type). Ill paste the
analogous example code at the bottom.

Also note that there is API documentation within the source code
package, though we know its partially incomplete. Our bad, but
unfortunately we currently dont have the manpower to revise it.

However please dont hesitate to pose further questions.

Best regards,
 Marcel Kronfeld

--
	public static void mainTestB1(String[] args) {
		
		int populationSize = 2;
		int evaluationTerminator = 8;

		// set a problem instance
		
		B1Problem b1 = new B1Problem();
		
		BitSet solution;
		
		// default ga.parameter instance with a GA
		GOParameters gaParams = OptimizerFactory.standardGA(b1);
		gaParams.setTerminator(new EvaluationTerminator(evaluationTerminator));
		Population popInput = new Population(populationSize);
		
		AbstractEAIndividual.setOperators(
				b1.getIndividualTemplate(), new MutateGANBit(), 0.5,new
CrossoverGANPoint(),0.5);
		
		// set a specific random seed
//		gaParams.setSeed (2342) ;
		
		// access the GA
		GeneticAlgorithm ga = (GeneticAlgorithm)gaParams.getOptimizer();
		
		// set elitism
		ga.setElitism (true);
		
		// set population size
		
		ga.setPopulation(new Population(populationSize));
		
		// start GA		
	
		//old: solution = OptimizerFactory.optimizeToBinary(gaParams,
"Ga-Solution");
		//new:
		OptimizerRunnable rnbl = OptimizerFactory.optimize(new
OptimizerRunnable(gaParams, "Ga-Solution"));
		solution = rnbl.getBinarySolution();
		
		// get the final population
		
		popInput = ga.getPopulation();
		

		for (int j = 1; j < 10; j++)
		{			
			
//			ga.setPopulation(popInput);
			
			//old: ga.initByPopulation(popInput, true);
			//old: solution = OptimizerFactory.optimizeToBinary(gaParams,
"Ga-Solution");
			// new:
			popInput.SetFunctionCalls(0); // to reset the evaluation counter -
necessary depending on which terminator is in use
			ga.initByPopulation(popInput, false); // set the population to the GA
(no reset)
			rnbl = new OptimizerRunnable(gaParams, "Ga-Solution", true); //
create a new runnable and flag it as a restart run
			OptimizerFactory.optimize(rnbl);
			solution = rnbl.getBinarySolution();
						
			popInput = ga.getPopulation();
			
			for (int i = 0; i < populationSize; i++) System.out.println("IndyID:
"+popInput.getEAIndividual(i).getIndyID());
			
			System.out.println ("Best solution at iteration "+j+": ");
			
			System.out.println("GetIndy of best Indi:
"+popInput.getBestEAIndividual().getIndyID());
			System.out.println("BestIndividual String Rep:
"+popInput.getBestEAIndividual().getStringRepresentation());
			System.out.println("BestIndi.:
"+AbstractEAIndividual.getDefaultStringRepresentation(popInput.getBestEAIndividual()));
		}
	}
-- 
 Dipl.-Inform. Marcel Kronfeld
 Wilhelm-Schickard-Institute for Computer Science
 University of Tuebingen
 Sand 1 - A305, 72076 Tuebingen, Germany

 Phone: (+49/0)-7071-29-78987, Fax: (+49/0)-7071-29-5091
 EMail: marcel.kronfeld at uni-tuebingen.de


More information about the EvA mailing list