Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

geno_fx.cpp

00001 #include <ctype.h> // isupper()
00002 #include "geno_fx.h"
00003 #include "framsg.h"
00004 
00005 int Geno_fx::roulette(const double *probtab,int count)
00006 {
00007    double sum=0;
00008    int i;
00009         for (i=0;i<count;i++) sum+=probtab[i];
00010    double sel=rnd01*sum;
00011    for (sum=0,i=0;i<count;i++) {sum+=probtab[i]; if (sel<sum) return i;}
00012    return -1;
00013 }
00014 
00015 int Geno_fx::getRandomNeuroClass()
00016 {
00017    int ileakt=0;
00018    for(int i=0;i<Neuro::getClassCount();i++) ileakt+=(Neuro::getClass(i)->active==true);
00019    if (ileakt==0) return -1;
00020    int los=randomN(ileakt)+1;
00021    ileakt=0;
00022    for(int i=0;i<Neuro::getClassCount();i++)
00023       {ileakt+=(Neuro::getClass(i)->active==true); if (ileakt==los) return i;}
00024    return -1; //never happens   
00025 }
00026 
00027 int Geno_fx::parseNeuroClass(char*& s)
00028 {
00029    int len=strlen(s);
00030    int Len=0,I=-1;
00031    for(int i=0;i<Neuro::getClassCount();i++)
00032    {
00033       const char *n=Neuro::getClass(i)->name;
00034       int l=strlen(n);
00035       if (len>=l && l>Len && (strncmp(s,n,l)==0)) {I=i; Len=l;}
00036    }
00037    s+=Len;
00038    return I;
00039 }
00040 
00041 int Geno_fx::getNeuroClass(const char* s)
00042 {
00043    char *p=(char*)s;
00044    return parseNeuroClass(p);
00045 }
00046 
00047 int Geno_fx::neuroClassProp(char*& s,int neuroclass,bool also_v1_N_props)
00048 {
00049    int len=strlen(s);
00050    int Len=0,I=-1;
00051    Param p=Neuro::getClass(neuroclass)->getProperties();
00052 /*      if (p.type(i)[0]=='f') do mutowania...
00053       {
00054          double mn=0,mx=1,df=0.5,c=p.getDouble(i);
00055          p.getMinMax(i,mn,mx,df);
00056          p.setDouble(i,RandMutValue(c,mn,mx));
00057          changed++;
00058          break;
00059       }*/
00060    for(int i=0;i<p.getPropCount();i++)
00061    {
00062       const char *n=p.id(i);
00063       int l=strlen(n);
00064       if (len>=l && l>Len && (strncmp(s,n,l)==0)) {I=i; Len=l;}
00065       if (also_v1_N_props) //recognize old properties symbols /=!
00066       {
00067          if (strcmp(n,"si")==0) n="/"; else
00068          if (strcmp(n,"in")==0) n="="; else
00069          if (strcmp(n,"fo")==0) n="!";
00070          l=strlen(n);
00071          if (len>=l && l>Len && (strncmp(s,n,l)==0)) {I=i; Len=l;}
00072       }
00073    }
00074    s+=Len;
00075    return I;
00076 }
00077 
00078 bool Geno_fx::isWS(const char c)
00079 {return c==' ' || c=='\n' || c=='\t' || c=='\r';}
00080 
00081 void Geno_fx::skipWS(char *&s)
00082 { if (!s) FramMessage("Geno_fx","skipWS","NULL reference!",1); else
00083      while (isWS(*s)) s++;
00084 }
00085 
00086 char* Geno_fx::strchrn0(const char *str,char ch)
00087 { return ch==0?NULL:strchr((char*)str,ch); }
00088 
00089 bool Geno_fx::isNeuroClassName(const char firstchar)
00090 {
00091    return isupper(firstchar) || firstchar=='|' || firstchar=='@';
00092 }
00093 
00094 //class TGeno_f2 : public Geno_fx {}; //przyklad
00095 

Generated on Tue Jul 30 23:21:19 2002 for Framsticks GenoFX by doxygen1.2.17