예제 #1
0
int scanner(char sourceFile[]){
FILE *source;
char ch;
int targetChar=0;
int mutantCount=97;
char newFile[20]="dominion";
char postFile[20]="dominion";
   source = fopen(sourceFile, "r");
   while( ( ch = fgetc(source) ) != EOF ){
      targetChar++;
      if (isdigit(ch)&&((rand()%10)==5)){
         printf("char count: %d\n",targetChar);
         strcpy(newFile,postFile);
         char targetCharArr[3];
         targetCharArr[0]=mutantCount;
         targetCharArr[1]='.';
         targetCharArr[2]='c';
         
         strcat(newFile,targetCharArr);
         mutator(sourceFile,newFile, targetChar);
         mutantCount++;
      }
      if(mutantCount>122)
      {
         fclose(source);
         return 0;
      }
   }
   fclose(source);
   return 0;
} 
예제 #2
0
GA1DArrayAlleleGenome<float>::
GA1DArrayAlleleGenome(unsigned int length, const GAAlleleSet<float> & s,
		      GAGenome::Evaluator f, void * u) :
GA1DArrayGenome<float>(length, f, u){
  naset = 1;
  aset = new GAAlleleSet<float>[1];
  aset[0] = s;

  initializer(DEFAULT_REAL_INITIALIZER);
  mutator(DEFAULT_REAL_MUTATOR);
  comparator(DEFAULT_REAL_COMPARATOR);
  crossover(DEFAULT_REAL_CROSSOVER);
}
GA1DArrayAlleleGenome<T>::
GA1DArrayAlleleGenome(unsigned int length, const GAAlleleSet<T> & s,
                      GAGenome::Evaluator f, void * u) :
    GA1DArrayGenome<T>(length, f, u) {
    naset = 1;
    aset = new GAAlleleSet<T>[1];
    aset[0] = s;

    initializer(GA1DArrayAlleleGenome<T>::DEFAULT_1DARRAY_ALLELE_INITIALIZER);
    mutator(GA1DArrayAlleleGenome<T>::DEFAULT_1DARRAY_ALLELE_MUTATOR);
    comparator(GA1DArrayAlleleGenome<T>::DEFAULT_1DARRAY_ALLELE_COMPARATOR);
    crossover(GA1DArrayAlleleGenome<T>::DEFAULT_1DARRAY_ALLELE_CROSSOVER);
}
template <> GA1DArrayAlleleGenome<char>::
GA1DArrayAlleleGenome(unsigned int length, const GAAlleleSet<char> & s,
		      GAGenome::Evaluator f, void * u) :
GA1DArrayGenome<char>(length, f, u){
  naset = 1;
  aset = new GAAlleleSet<char>[1];
  aset[0] = s;

  initializer(DEFAULT_STRING_INITIALIZER);
  mutator(DEFAULT_STRING_MUTATOR);
  comparator(DEFAULT_STRING_COMPARATOR);
  crossover(DEFAULT_STRING_CROSSOVER);
}
예제 #5
0
GA1DArrayAlleleGenome<float>::
GA1DArrayAlleleGenome(const GAAlleleSetArray<float> & sa,
		      GAGenome::Evaluator f, void * u) :
GA1DArrayGenome<float>(sa.size(), f, u){
  naset = sa.size();
  aset = new GAAlleleSet<float>[naset];
  for(int i=0; i<naset; i++)
    aset[i] = sa.set(i);

  initializer(DEFAULT_REAL_INITIALIZER);
  mutator(DEFAULT_REAL_MUTATOR);
  comparator(DEFAULT_REAL_COMPARATOR);
  crossover(DEFAULT_REAL_CROSSOVER);
}
예제 #6
0
GA3DArrayAlleleGenome<T>::
GA3DArrayAlleleGenome(unsigned int w, unsigned int h, unsigned int d,
		      const GAAlleleSetArray<T> & sa,
		      GAGenome::Evaluator f, void * u) :
GA3DArrayGenome<T>(w,h,d, f, u) {
  naset = sa.size();
  aset = new GAAlleleSet<T>[naset];
  for(int i=0; i<naset; i++)
    aset[i] = sa.set(i);

  initializer(DEFAULT_3DARRAY_ALLELE_INITIALIZER);
  mutator(DEFAULT_3DARRAY_ALLELE_MUTATOR);
  comparator(DEFAULT_3DARRAY_ALLELE_COMPARATOR);
  crossover(DEFAULT_3DARRAY_ALLELE_CROSSOVER);
}
예제 #7
0
void do_optimize(static_lattice_swarming_pattern&swp, ind_t&ind,
                 params_t&params, RNG_t&rng)
{ lattice_moves_generator<static_lattice_swarming_pattern::Dimension,RNG_t>
    mutator(rng);

  LatticeDisplayFarm<params_t> displayfarm;
  displayfarm.inheritParametersFrom(params);

  BoostDotGraphController<static_lattice_swarming_pattern::graph_t,
                          params_t,true>
    opt_animation;
  opt_animation.add_vertex_property("color",
    make_color_temperature(swp.lattice.graph));
  opt_animation.add_vertex_property("pos",
                                    //make_vertex_id(swp.lattice.graph,80));
//     vertex_location_map<static_lattice_swarming_pattern::Dimension,
//                         static_lattice_swarming_pattern::graph_t>
//                                     (swp.lattice.graph,80,2));
       place_vertex<static_lattice_swarming_pattern::Dimension,
                    static_lattice_swarming_pattern::graph_t>
                                    (swp.lattice.graph,80));

// this is silly for an undirected graph
//   opt_animation.add_edge_property("style",
//     make_bool_string_property("bold","",
//       belongs_to_a_2_loop<static_lattice_swarming_pattern::graph_t>,
//       swp.lattice.graph));

  if (swp.n_individuals() < 40)
  { displayfarm.installController(opt_animation);
    opt_animation.params.setdisplayToScreen(
      displayfarm.params.animate_optimization());
    //opt_animation.params.setdisplayEvery(50);
  }

  //hill_climb(swp,ind,mutator,&params,&displayfarm);
  swp.setannealing_rate_factor(swp.n_individuals());
  simulated_annealing(swp,ind,mutator,&params,rng,&displayfarm);
}