예제 #1
0
 @SuppressWarnings("unchecked")
 public void configure(Configuration settings) {
   // Number of mutator components
   int numberOfComponents = settings.getList("component[@type]").size();
   // Allocate space for components
   IMutator[] components = new IMutator[numberOfComponents];
   for (int i = 0; i < numberOfComponents; i++) {
     // Header
     String header = "component(" + i + ")";
     try {
       // Component classname
       String componentClassname = settings.getString(header + "[@type");
       // Component class
       Class<IMutator> componentClass = (Class<IMutator>) Class.forName(componentClassname);
       // Component instance
       IMutator component = componentClass.newInstance();
       // Configure component (if necessary)
       if (component instanceof IConfigure) {
         ((IConfigure) component).configure(settings.subset(header));
       }
     } catch (ClassNotFoundException e) {
       e.printStackTrace();
     } catch (InstantiationException e) {
       e.printStackTrace();
     } catch (IllegalAccessException e) {
       e.printStackTrace();
     }
   }
   // Set components
   setComponents(components);
 }
예제 #2
0
파일: MGG.java 프로젝트: jahguide89/JClec4
 /**
  * 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);
   }
 }