Update of /cvsroot/pure-data/externals/grh/GApop/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30129
Modified Files: GApop.cpp Log Message: some bug fixes ...
Index: GApop.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grh/GApop/src/GApop.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GApop.cpp 12 Jul 2005 14:20:39 -0000 1.1 --- GApop.cpp 1 Aug 2005 15:07:37 -0000 1.2 *************** *** 5,9 **** // how to use it // ! // Copyright (c) 2004 Georg Holzmann grh@gmx.at // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "license.txt," in this distribution. --- 5,9 ---- // how to use it // ! // Copyright (c) 2004 Georg Holzmann grh@mur.at // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "license.txt," in this distribution. *************** *** 41,44 **** --- 41,47 ---- // constructor with a variable argument list GApop(int argc,const t_atom *argv); + + //destructor + ~GApop();
protected: *************** *** 53,56 **** --- 56,60 ---- // the fitness order int *tempfit; + float *tempfit1;
// the other parameters: *************** *** 178,182 **** post("1 - set all parameters:"); post("popbuf contains the population (array with numbers"); ! post(" between 0 and 1, max size is 200)"); post("fitbuf contains the fitness function (numbers between"); post(" 0 and 1, size should be 101: 0 = fitness(0),"); --- 182,186 ---- post("1 - set all parameters:"); post("popbuf contains the population (array with numbers"); ! post(" between 0 and 1)"); post("fitbuf contains the fitness function (numbers between"); post(" 0 and 1, size should be 101: 0 = fitness(0),"); *************** *** 187,193 **** post("2 - get the data:"); post("cross makes fitscaling, crossover and mutation"); ! post("numbers in inlet 0 get the values: 0 means the value"); post(" of the fittest, 1 the value of the next..."); ! post("have fun - Georg Holzmann grh@gmx.at\n"); }
--- 191,197 ---- post("2 - get the data:"); post("cross makes fitscaling, crossover and mutation"); ! post("numbers in inlet 0 get the values: 0 means the value"); post(" of the fittest, 1 the value of the next..."); ! post("have fun - Georg Holzmann grh@mur.at\n"); }
*************** *** 203,206 **** --- 207,211 ---- popbuf=NULL; popname=NULL; tempfit=NULL; + tempfit1=NULL; buffsize=0; pairs = 0; *************** *** 217,222 **** // set buffer according to creation arguments if(argc == 1 && IsSymbol(argv[0])) ! { m_set(argc,argv); } ! }
--- 222,236 ---- // set buffer according to creation arguments if(argc == 1 && IsSymbol(argv[0])) ! m_set(argc,argv); ! } ! ! GApop::~GApop() ! { ! if(popbuf) delete popbuf; ! if(fitbuf) delete fitbuf; ! if(tempfit) delete[] tempfit; ! if(tempfit1) delete[] tempfit1; ! ! }
*************** *** 317,321 **** // clear existing buffer if(popbuf) delete popbuf; ! if(tempfit) delete tempfit;
// save buffer name --- 331,336 ---- // clear existing buffer if(popbuf) delete popbuf; ! if(tempfit) delete[] tempfit; ! if(tempfit1) delete[] tempfit1;
// save buffer name *************** *** 325,330 **** buffsize = popbuf->Frames();
! // make new tempfit buffer tempfit = new int[buffsize];
if(!popbuf->Ok()) { --- 340,346 ---- buffsize = popbuf->Frames();
! // make new tempfit buffers tempfit = new int[buffsize]; + tempfit1 = new float[buffsize];
if(!popbuf->Ok()) { *************** *** 391,411 **** void GApop::m_cross() { ! if(Checkpopbuf() && Checkfitbuf() && pairs<(buffsize/2-1)) ! {
! // 1. step: // every parameter get's a fitness from the // given fitness function // this fitness is saved into the temporary array tempfit1[]
- // make temporary array - float *tempfit1 = new float[200]; - // write the fitness for(int i=0; i < buffsize; i++) - { tempfit1[i] = cutse(fitbuf->Data()[int(popbuf->Data()[i]*100+0.5)]); - }
--- 407,429 ---- void GApop::m_cross() { ! if(!Checkpopbuf() || !Checkfitbuf()) ! return; ! ! if(pairs>=(buffsize/2)) ! { ! post("GApop - pairs must be smaller then (buffsize/2)-1!"); ! post(" currently %d pairs with a buffsize of %d!", pairs, buffsize); ! return; ! }
! // 1. step: // every parameter get's a fitness from the // given fitness function // this fitness is saved into the temporary array tempfit1[]
// write the fitness for(int i=0; i < buffsize; i++) tempfit1[i] = cutse(fitbuf->Data()[int(popbuf->Data()[i]*100+0.5)]);
*************** *** 464,478 **** } } - - // delete the temporary array - delete []tempfit1; - } - - - else - { - // invalid buffers - post("GApop - entered buffers are invalid!"); - } }
--- 482,485 ---- *************** *** 480,484 **** // takes the incomig ints and gives out the specific individuum: // 0 ... fittest individuum ! // 1 ... next individuum // ... void GApop::m_trigger(int i) --- 487,491 ---- // takes the incomig ints and gives out the specific individuum: // 0 ... fittest individuum ! // 1 ... next fit individuum // ... void GApop::m_trigger(int i) *************** *** 488,493 **** // make the boundaries for i: ! if(i<0) {i=0;} ! if(i>200) {i=200;} // correct syntax, output value --- 495,500 ---- // make the boundaries for i: ! if(i<0) i=0; ! if(i>buffsize) i=buffsize; // correct syntax, output value