onilink_

Generic GA skeletton

Nov 9th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. struct Gene
  4. {
  5.     virtual void mutate(float factor) = 0;
  6.     virtual void reset() = 0;
  7.     virtual void randomize() = 0;
  8. };
  9.  
  10. struct Creature
  11. {
  12.     std::vector< std::unique_ptr<Gene> > dna;
  13.    
  14.     void mutate(float factor) {
  15.         for(auto& gene: dna)
  16.             gene->mutate(factor);
  17.     }
  18.     void reset() {
  19.         for(auto& gene: dna)
  20.             gene->reset();
  21.     }
  22.     void randomize() {
  23.         for(auto& gene: dna)
  24.             gene->randomize();
  25.     }
  26.     virtual float fitness() const = 0;
  27. };
  28.  
  29. struct World
  30. {
  31.     std::vector< std::unique_ptr<Creature> > creatures;
  32. };
  33.  
  34. int main()
  35. {
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment