Exemplo n.º 1
0
 /** Constructor: Create a crossover operator with the given selection parent strategy */
 public ArityTwo(Environment _environment, Selection _selection) {
   super(_environment);
   selection = _selection;
   if (selection != null) {
     selection.setSize(2);
   }
 }
Exemplo n.º 2
0
 /**
  * Apply the operator over the given individuals
  *
  * @param population Source population
  * @param x Individual used as first parent
  * @return A collection of individuals generated by the operator
  */
 public Vector apply(Population population, int x) {
   Vector children = null;
   if (population != null && selection != null) {
     Vector parents = selection.choose(population, x);
     Individual child1 = (Individual) (Cloner.clone(parents.elementAt(0)));
     Individual child2 = (Individual) (Cloner.clone(parents.elementAt(1)));
     // only for two children
     apply(child1, child2);
     children = new Vector();
     children.add(child1);
     children.add(child2);
   }
   return children;
 }
Exemplo n.º 3
0
 public void setEnvironment(Environment _environment) {
   super.setEnvironment(_environment);
   selection.setEnvironment(environment);
 }