Example #1
0
functions::RealVector CRGenetics::geneToVector(const GARealGenome& gen)
{
  functions::RealVector v(gen.size());
  for (unsigned int i = 0; i < gen.size(); i++) {
    v[i] = gen.gene(i);
  }
  return v;
}
Example #2
0
void CRGenetics::setGeneticOperators(GARealGenome &genome)
{
  GeneticConfig &config = dynamic_cast<GeneticConfig&>(* (this->config));
  if (config.initializer_type == "Random") {
      cout << "CRGenetics::run --> Random initialization\n";
      genome.initializer(GAGenomeRandomInitializer);
    } else {
      if (config.debug) {
	cout << "CRGenetics::setGeneticOperators --> Deterministic initialization\n";
      }
    }
    
    cout << "CRGenetics::run --> Crossover type: ";
    if (config.crossover_type == "Mixer") {
      cout << "Waypoint mixer\n";
      genome.crossover(GAGenomeUniformWaypointMixer); 
    } else if (config.crossover_type == "Uniform") {
      genome.crossover(GARealUniformCrossoverCheck);
      cout << "Uniform\n";
    } else if (config.crossover_type == "TwoPoints" ||
      config.crossover_type == "TwoPoint"
    ) {
      genome.crossover(GARealGenome::TwoPointCrossover);
      cout << "Two point\n";
    } else if (config.crossover_type == "OnePoint") {
      genome.crossover(GARealGenome::OnePointCrossover);
      cout << "One point\n";
    } else {
      // Default crossover operator
      config.crossover_type = "Uniform";
      genome.crossover(GARealUniformCrossoverCheck);
      cout << "Uniform\n";
    }
    
    cout << "CRGenetics::run --> Mutator type: ";
    if (config.mutator_type == "MaMutator") {
      cout << "MaMutator\n";
      genome.mutator(GARealGaussianMaMutator);
    } else if (config.mutator_type == "Gaussian") {
      cout << "Gaussian\n";
      genome.mutator(GARealGaussianMutatorCheck);
    } else {
      // Default mutator
      config.mutator_type = "Gaussian";
      cout << "Gaussian\n";
      genome.mutator(GARealGaussianMutatorCheck);
    }
    
    // The same process has to be applied to the population
//     GAPopulation population(genome, config.population);
//     if (config.initializer_type == "Deterministic") {
//       population.initializer(GAPopulationInitializer);
//     }
}
Example #3
0
void GARealGenome::copy(GARealGenome b){
this->y_factor=b.y_factor;
this->genome.resize(b.size());
vector<double>::iterator pgene=this->genome.begin();
vector<double>::iterator pgeneb=b.genome.begin();
while(pgene != this->genome.end()) {
	*pgene++ =fabs(fmod(*pgeneb++ +dgene,dgene2)-dgene);
	}
	/*
this->gene_min=b.gene_min;
this->gene_max=b.gene_max;
this->dgene=b.dgene;
*/
}