source: cpp/geno_fx/html/geno__fx_8cpp-source.html @ 7

Last change on this file since 7 was 3, checked in by Maciej Komosinski, 16 years ago

added geno_fx, a base class for genetic operations on genotypes

File size: 8.9 KB
RevLine 
[3]1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3<title>geno_fx.cpp Source File</title>
4<link href="doxygen.css" rel="stylesheet" type="text/css">
5</head><body>
6<!-- Generated by Doxygen 1.2.17 -->
7<center>
8<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center>
9<hr><h1>geno_fx.cpp</h1><div class="fragment"><pre>00001 <span class="preprocessor">#include &lt;ctype.h&gt;</span> <span class="comment">// isupper()</span>
1000002 <span class="preprocessor">#include "<a class="code" href="geno__fx_8h.html">geno_fx.h</a>"</span>
1100003 <span class="preprocessor">#include "framsg.h"</span>
1200004
13<a name="l00005"></a><a class="code" href="classGeno__fx.html#z7_0">00005</a> <span class="keywordtype">int</span> <a class="code" href="classGeno__fx.html#z7_0">Geno_fx::roulette</a>(<span class="keyword">const</span> <span class="keywordtype">double</span> *probtab,<span class="keywordtype">int</span> count)
1400006 {
1500007    <span class="keywordtype">double</span> sum=0;
1600008    <span class="keywordtype">int</span> i;
1700009         <span class="keywordflow">for</span> (i=0;i&lt;count;i++) sum+=probtab[i];
1800010    <span class="keywordtype">double</span> sel=rnd01*sum;
1900011    <span class="keywordflow">for</span> (sum=0,i=0;i&lt;count;i++) {sum+=probtab[i]; <span class="keywordflow">if</span> (sel&lt;sum) <span class="keywordflow">return</span> i;}
2000012    <span class="keywordflow">return</span> -1;
2100013 }
2200014
23<a name="l00015"></a><a class="code" href="classGeno__fx.html#z7_1">00015</a> <span class="keywordtype">int</span> <a class="code" href="classGeno__fx.html#z7_1">Geno_fx::getRandomNeuroClass</a>()
2400016 {
2500017    <span class="keywordtype">int</span> ileakt=0;
2600018    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i&lt;Neuro::getClassCount();i++) ileakt+=(Neuro::getClass(i)-&gt;active==<span class="keyword">true</span>);
2700019    <span class="keywordflow">if</span> (ileakt==0) <span class="keywordflow">return</span> -1;
2800020    <span class="keywordtype">int</span> los=randomN(ileakt)+1;
2900021    ileakt=0;
3000022    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i&lt;Neuro::getClassCount();i++)
3100023       {ileakt+=(Neuro::getClass(i)-&gt;active==<span class="keyword">true</span>); <span class="keywordflow">if</span> (ileakt==los) <span class="keywordflow">return</span> i;}
3200024    <span class="keywordflow">return</span> -1; <span class="comment">//never happens   </span>
3300025 }
3400026
35<a name="l00027"></a><a class="code" href="classGeno__fx.html#z7_2">00027</a> <span class="keywordtype">int</span> <a class="code" href="classGeno__fx.html#z7_2">Geno_fx::parseNeuroClass</a>(<span class="keywordtype">char</span>*&amp; s)
3600028 {
3700029    <span class="keywordtype">int</span> len=strlen(s);
3800030    <span class="keywordtype">int</span> Len=0,I=-1;
3900031    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i&lt;Neuro::getClassCount();i++)
4000032    {
4100033       <span class="keyword">const</span> <span class="keywordtype">char</span> *n=Neuro::getClass(i)-&gt;name;
4200034       <span class="keywordtype">int</span> l=strlen(n);
4300035       <span class="keywordflow">if</span> (len&gt;=l &amp;&amp; l&gt;Len &amp;&amp; (strncmp(s,n,l)==0)) {I=i; Len=l;}
4400036    }
4500037    s+=Len;
4600038    <span class="keywordflow">return</span> I;
4700039 }
4800040
49<a name="l00041"></a><a class="code" href="classGeno__fx.html#z7_3">00041</a> <span class="keywordtype">int</span> <a class="code" href="classGeno__fx.html#z7_3">Geno_fx::getNeuroClass</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* s)
5000042 {
5100043    <span class="keywordtype">char</span> *p=(<span class="keywordtype">char</span>*)s;
5200044    <span class="keywordflow">return</span> <a class="code" href="classGeno__fx.html#z7_2">parseNeuroClass</a>(p);
5300045 }
5400046
55<a name="l00047"></a><a class="code" href="classGeno__fx.html#z7_4">00047</a> <span class="keywordtype">int</span> <a class="code" href="classGeno__fx.html#z7_4">Geno_fx::neuroClassProp</a>(<span class="keywordtype">char</span>*&amp; s,<span class="keywordtype">int</span> neuroclass,<span class="keywordtype">bool</span> also_v1_N_props)
5600048 {
5700049    <span class="keywordtype">int</span> len=strlen(s);
5800050    <span class="keywordtype">int</span> Len=0,I=-1;
5900051    Param p=Neuro::getClass(neuroclass)-&gt;getProperties();
6000052 <span class="comment">/*      if (p.type(i)[0]=='f') do mutowania...</span>
6100053 <span class="comment">      {</span>
6200054 <span class="comment">         double mn=0,mx=1,df=0.5,c=p.getDouble(i);</span>
6300055 <span class="comment">         p.getMinMax(i,mn,mx,df);</span>
6400056 <span class="comment">         p.setDouble(i,RandMutValue(c,mn,mx));</span>
6500057 <span class="comment">         changed++;</span>
6600058 <span class="comment">         break;</span>
6700059 <span class="comment">      }*/</span>
6800060    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i&lt;p.getPropCount();i++)
6900061    {
7000062       <span class="keyword">const</span> <span class="keywordtype">char</span> *n=p.id(i);
7100063       <span class="keywordtype">int</span> l=strlen(n);
7200064       <span class="keywordflow">if</span> (len&gt;=l &amp;&amp; l&gt;Len &amp;&amp; (strncmp(s,n,l)==0)) {I=i; Len=l;}
7300065       <span class="keywordflow">if</span> (also_v1_N_props) <span class="comment">//recognize old properties symbols /=!</span>
7400066       {
7500067          <span class="keywordflow">if</span> (strcmp(n,<span class="stringliteral">"si"</span>)==0) n=<span class="stringliteral">"/"</span>; <span class="keywordflow">else</span>
7600068          <span class="keywordflow">if</span> (strcmp(n,<span class="stringliteral">"in"</span>)==0) n=<span class="stringliteral">"="</span>; <span class="keywordflow">else</span>
7700069          <span class="keywordflow">if</span> (strcmp(n,<span class="stringliteral">"fo"</span>)==0) n=<span class="stringliteral">"!"</span>;
7800070          l=strlen(n);
7900071          <span class="keywordflow">if</span> (len&gt;=l &amp;&amp; l&gt;Len &amp;&amp; (strncmp(s,n,l)==0)) {I=i; Len=l;}
8000072       }
8100073    }
8200074    s+=Len;
8300075    <span class="keywordflow">return</span> I;
8400076 }
8500077
86<a name="l00078"></a><a class="code" href="classGeno__fx.html#z7_5">00078</a> <span class="keywordtype">bool</span> <a class="code" href="classGeno__fx.html#z7_5">Geno_fx::isWS</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> c)
8700079 {<span class="keywordflow">return</span> c==<span class="charliteral">' '</span> || c==<span class="charliteral">'\n'</span> || c==<span class="charliteral">'\t'</span> || c==<span class="charliteral">'\r'</span>;}
8800080
89<a name="l00081"></a><a class="code" href="classGeno__fx.html#z7_6">00081</a> <span class="keywordtype">void</span> <a class="code" href="classGeno__fx.html#z7_6">Geno_fx::skipWS</a>(<span class="keywordtype">char</span> *&amp;s)
9000082 { <span class="keywordflow">if</span> (!s) FramMessage(<span class="stringliteral">"Geno_fx"</span>,<span class="stringliteral">"skipWS"</span>,<span class="stringliteral">"NULL reference!"</span>,1); <span class="keywordflow">else</span>
9100083      <span class="keywordflow">while</span> (<a class="code" href="classGeno__fx.html#z7_5">isWS</a>(*s)) s++;
9200084 }
9300085
94<a name="l00086"></a><a class="code" href="classGeno__fx.html#z7_7">00086</a> <span class="keywordtype">char</span>* <a class="code" href="classGeno__fx.html#z7_7">Geno_fx::strchrn0</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *str,<span class="keywordtype">char</span> ch)
9500087 { <span class="keywordflow">return</span> ch==0?NULL:strchr((<span class="keywordtype">char</span>*)str,ch); }
9600088
97<a name="l00089"></a><a class="code" href="classGeno__fx.html#z7_8">00089</a> <span class="keywordtype">bool</span> <a class="code" href="classGeno__fx.html#z7_8">Geno_fx::isNeuroClassName</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> firstchar)
9800090 {
9900091    <span class="keywordflow">return</span> isupper(firstchar) || firstchar==<span class="charliteral">'|'</span> || firstchar==<span class="charliteral">'@'</span>;
10000092 }
10100093
10200094 <span class="comment">//class TGeno_f2 : public Geno_fx {}; //przyklad</span>
10300095
104</pre></div><hr><address style="align: right;"><small>Generated on Tue Jul 30 23:21:19 2002 for Framsticks GenoFX by
105<a href="http://www.doxygen.org/index.html">
106<img src="doxygen.png" alt="doxygen" align="middle" border=0
107width=110 height=53></a>1.2.17 </small></address>
108</body>
109</html>
Note: See TracBrowser for help on using the repository browser.