Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Genetic Prorgaming

Genetic Prorgaming

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicsgame-devdata-structureshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bluatigro
    wrote on last edited by
    #1

    this is a try at GP in C++ whit strings GP what : from array or grafic to formula GP how : 1 : write random formula's 2 : sort formula's on error 3 : best fumula's mix to kid's 4 : some kid's are mutated 5 : if genration < max and error > whised goto 2 version 0.1.1 building function run get "list" outof formula

    bluatigro 9 okt 2017
    // genetic programing whit strings
    // version 0.1

    #include #include #include #include #include using namespace std ;

    typedef VSTR vector ;

    VSTR split( string in , char cut = ' ' )
    {
    VSTR uit ;
    size_type i = 0 ;
    size_type j = in.find( cut ) ;
    while ( j != string::npos )
    {
    uit.push_back( in.substr( i , j - i ) ) ;
    i = ++j ;
    j = in.find( cut , j ) ;
    if ( j == string::npos )
    in.push_back( in.substr( i , in.lenght() ) ) ;
    }
    return uit ;
    }

    string dbl2str( double x )
    {
    stringsream ss ;
    ss << x ;
    return ss.str() ;
    }

    double str2dbl( string x )
    {
    // how ?
    }

    class GeneProg
    {
    private :
    int numberMode ;
    VSTR genes ;
    double in[ 10 ] ;
    int inmax ;
    public :
    GeneProg()
    {
    numberMode = 0 ;
    inmax = 0 ;
    }
    string run( string prog )
    {
    int einde = prog.find( ']' ) ;
    int begin = einde ;
    while ( prog[ begin ] != '[' ) ;
    begin-- ;
    return prog.substr( begin , einde - begin ) ;
    }
    } ;

    int main()
    {
    GeneProg GP ;
    string a = "[ + 7 [ - 2 3 ] ]" ;
    string b = "[ * 9 [ / 8 6 ] ]" ;
    cout << "[ test run ]" << endl ;
    cout << "prog a = " << a << endl ;
    //gp.run shoot give "[ - 2 3 ]"
    cout << "run a = " << GP.run( a ) << endl ;
    cout << "check a = " << 7 + ( 2 - 3 ) << endl ;
    cout << "prog b = " << b << endl ;
    //gp.run shoot give "[ / 8 6 ]"
    cout << "run b = " << GP.run( b ) << endl ;
    cout << "check b = " << 9 * ( 8 / 6 ) << endl ;
    cout << "[ game over ]" << endl ;
    cin.get() ;
    }

    D 1 Reply Last reply
    0
    • B bluatigro

      this is a try at GP in C++ whit strings GP what : from array or grafic to formula GP how : 1 : write random formula's 2 : sort formula's on error 3 : best fumula's mix to kid's 4 : some kid's are mutated 5 : if genration < max and error > whised goto 2 version 0.1.1 building function run get "list" outof formula

      bluatigro 9 okt 2017
      // genetic programing whit strings
      // version 0.1

      #include #include #include #include #include using namespace std ;

      typedef VSTR vector ;

      VSTR split( string in , char cut = ' ' )
      {
      VSTR uit ;
      size_type i = 0 ;
      size_type j = in.find( cut ) ;
      while ( j != string::npos )
      {
      uit.push_back( in.substr( i , j - i ) ) ;
      i = ++j ;
      j = in.find( cut , j ) ;
      if ( j == string::npos )
      in.push_back( in.substr( i , in.lenght() ) ) ;
      }
      return uit ;
      }

      string dbl2str( double x )
      {
      stringsream ss ;
      ss << x ;
      return ss.str() ;
      }

      double str2dbl( string x )
      {
      // how ?
      }

      class GeneProg
      {
      private :
      int numberMode ;
      VSTR genes ;
      double in[ 10 ] ;
      int inmax ;
      public :
      GeneProg()
      {
      numberMode = 0 ;
      inmax = 0 ;
      }
      string run( string prog )
      {
      int einde = prog.find( ']' ) ;
      int begin = einde ;
      while ( prog[ begin ] != '[' ) ;
      begin-- ;
      return prog.substr( begin , einde - begin ) ;
      }
      } ;

      int main()
      {
      GeneProg GP ;
      string a = "[ + 7 [ - 2 3 ] ]" ;
      string b = "[ * 9 [ / 8 6 ] ]" ;
      cout << "[ test run ]" << endl ;
      cout << "prog a = " << a << endl ;
      //gp.run shoot give "[ - 2 3 ]"
      cout << "run a = " << GP.run( a ) << endl ;
      cout << "check a = " << 7 + ( 2 - 3 ) << endl ;
      cout << "prog b = " << b << endl ;
      //gp.run shoot give "[ / 8 6 ]"
      cout << "run b = " << GP.run( b ) << endl ;
      cout << "check b = " << 9 * ( 8 / 6 ) << endl ;
      cout << "[ game over ]" << endl ;
      cin.get() ;
      }

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      See here for the answers to all of your questions. Yes, I know you did not actually ask any questions, but if you did, the link would still be considered valuable.

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups