Geneties Prorgammeren

Status
Niet open voor verdere reacties.

blua tigro

Gebruiker
Lid geworden
21 apr 2009
Berichten
48
dit is een poging tot GP in C++

GP wat :
van n tabel of grafiek naar n furmule rekenen

GP hoe :
1 : schijf n set furmules
2 : bereken output of formules
3 : sorteer formules op fout
4 : neem de beste en mix ze tot kinderen
5 : muteer somige kinderen
6 : als generatie < max en beste fout > gewenst ganaar 2

code stap 0.1.1 :
bouw run functie :
neem n "list" uit de formule
Code:
// bluatigro 9 okt 2017
// genetic programing whit strings
// version 0.1

#include <math.h>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>

using namespace std ;

typedef VSTR vector<string> ;

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 now 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 now give "[ / 8 6 ]" 
  cout << "run b = " << GP.run( b ) << endl ;
  cout << "check b = " << 9 * ( 8 / 6 ) << endl ;
  cout << "[ game over ]" << endl ;
  cin.get() ;
}
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan