示例#1
0
 public void doInit() {
   // Call super method
   super.doInit();
   // Set number of recombinator repetitions
   setNumberOfRecombinatorRepetitions();
   // Initialize selectors used in algorithm
   bettersSelector = new BettersSelector(this);
   parentsSelector = new RandomSelector(this);
   updateSelector = new RouletteSelector(this);
 }
示例#2
0
 /**
  * Configuration method.
  *
  * <p>Configuration parameters for BaseAlgorithm class are:
  *
  * <ul>
  *   <li><code>species: ISpecies (complex)</code> Individual species
  *   <li><code>evaluator: IEvaluator (complex)</code> Individuals evaluator
  *   <li><code>population-size: int</code> Population size
  *   <li><code>max-of-generations: int</code> Maximum number of generations
  *   <li><code>provider: IProvider (complex)</code> Individuals provider
  *   <li><code>mu: int</code> Number of parents to select
  *   <li><code>lambda: int</code> Number of son to obtain by recombination
  *   <li><code>recombinator: IRecombinator (complex)</code> Recombination operator
  * </ul>
  */
 @SuppressWarnings("unchecked")
 public void configure(Configuration configuration) {
   // Call super.configure() method
   super.configure(configuration);
   // Mu parameter
   int mu = configuration.getInt("mu");
   setMu(mu);
   // Lambda parameter
   int lambda = configuration.getInt("lambda");
   setLambda(lambda);
   // Recombinator
   try {
     // Recombinator classname
     String recombinatorClassname = configuration.getString("recombinator[@type]");
     // Recombinator class
     Class<? extends IRecombinator> recombinatorClass =
         (Class<? extends IRecombinator>) Class.forName(recombinatorClassname);
     // Recombinator instance
     IRecombinator recombinator = recombinatorClass.newInstance();
     // Configure recombinator if necessary
     if (recombinator instanceof IConfigure) {
       // Extract recombinator configuration
       Configuration recombinatorConfiguration = configuration.subset("recombinator");
       // Configure species
       ((IConfigure) recombinator).configure(recombinatorConfiguration);
     }
     // Set species
     setRecombinator(recombinator);
   } catch (ClassNotFoundException e) {
     throw new ConfigurationRuntimeException("Illegal recombinator classname");
   } catch (InstantiationException e) {
     throw new ConfigurationRuntimeException("Problems creating an instance of recombinator", e);
   } catch (IllegalAccessException e) {
     throw new ConfigurationRuntimeException("Problems creating an instance of recombinator", e);
   }
 }