cpu_tour.html

来自「有趣的模拟进化的程序 由国外一生物学家开发 十分有趣」· HTML 代码 · 共 359 行 · 第 1/2 页

HTML
359
字号
    <td>Calculate the BX minus CX; put the result in ?BX?</tr><tr><th>(p) <td><tt>nand</tt>    <td>Perform a bitwise NAND on BX and CX; put the result in ?BX?</tr><tr><th>(q) <td><tt>IO</tt>    <td>Output the value ?BX? and replace it with a new input</tr><tr><th>(r) <td><tt>h-alloc</tt>    <td>Allocate memory for an offspring</tr><tr><th>(s) <td><tt>h-divide</tt>    <td>Divide off an offspring located between the Read-Head and Write-Head.</tr><tr><th>(t) <td><tt>h-copy</tt>    <td>Copy an instruction from the Read-Head to the Write-Head and advance both.</tr><tr><th>(u) <td><tt>h-search</tt>    <td>Find a complement template and place the Flow-Head after it.</tr><tr><th>(v) <td><tt>mov-head</tt>    <td>Move the ?IP? to the same position as the Flow-Head</tr><tr><th>(w) <td><tt>jmp-head</tt>    <td>Move the ?IP? by a fixed amount found in CX</tr><tr><th>(x) <td><tt>get-head</tt>    <td>Write the position of the ?IP? into CX</tr><tr><th>(y) <td><tt>if-label</tt>    <td>Execute the next instruction only if the given template complement was just copied</tr><tr><th>(z) <td><tt>set-flow</tt>    <td>Move the Flow-Head to the memory position specified by ?CX?</tr></table><h3>An example Ancestor</h3>The following organism is stored in the file <tt>organism.heads.15</tt>,which you should find in the source/support/config/ directory.  This is asimplified version of <tt>organism.default</tt> and<tt>organism.heads.100</tt>, of lengths 50 and 100 respectively (each hasadditional instructions placed before the copy loop)<p><table><tr><td colspan=2><font color="#886600"># ---  Setup  ---</font><br><tr><td><b><tt>h-alloc</tt></b>    <td><font color="#886600"># Allocate extra space at the end of the genome to copy the offspring into.</font><br><tr><td><b><tt>h-search&nbsp;</tt></b>   <td><font color="#886600"># Locate an    <tt>A:B</tt> template (at the end of the organism) and    place the Flow-Head after it</font><br><tr><td><b><tt>nop-C</tt></b>      <td><font color="#886600">#</font><br><tr><td><b><tt>nop-A</tt></b>      <td><font color="#886600">#</font><br><tr><td><b><tt>mov-head</tt></b>   <td><font color="#886600"># Place the    Write-Head at the Flow-Head (which is at beginning of    offspring-to-be).</font><br><tr><td><b><tt>nop-C</tt></b>      <td><font color="#886600"># [ Extra    <tt>nop-C</tt> commands can be placed here w/o harming the    organism! ]</font><br><tr><td>&nbsp;<tr><td colspan=2><font color="#886600"># ---  Copy Loop  ---</font><br><tr><td><b><tt>h-search</tt></b>   <td><font color="#886600"># No template,    so place the Flow-Head on the next line (to mark the beginning of the copy    loop)</font><br><tr><td><b><tt>h-copy</tt></b>     <td><font color="#886600"># Copy a single    instruction from the read head to the write head (and advance both    heads!)</font><br><tr><td><b><tt>if-label</tt></b>   <td><font color="#886600"># Execute the    line following this template <i>only if</i> we have just copied an    <tt>A:B</tt> template.</font><br><tr><td><b><tt>nop-C</tt></b>      <td><font color="#886600">#</font><br><tr><td><b><tt>nop-A</tt></b>      <td><font color="#886600">#</font><br><tr><td><b><tt>h-divide</tt></b>   <td><font color="#886600">#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...Divide off offspring! (note if-statement above!)</font><br><tr><td><b><tt>mov-head</tt></b>   <td><font color="#886600"># Otherwise,    move the IP back to the Flow-Head at the beginning of the copy    loop.</font><br><tr><td><b><tt>nop-A</tt></b>      <td><font color="#886600"># End label.</font><br><tr><td><b><tt>nop-B</tt></b>      <td><font color="#886600"># End label.</font><br></table><p>This program begins by allocating extra space for its offspring.  Theexact amount of space does not need to be specified -- it will allocate asmuch as it is allowed to.  The organism will then do a search for the endof its genome (where this new space was just placed) so that it will knowwhere to start copying.  First the Flow-Head is placed there, and then theWrite-Head is moved to the same point.<p>It is after this initial setup and before the actual copying processcommences that extra <tt>nop</tt> instructions can be included.  The onlycaveat is that you need to make sure that you don't duplicate any templatesthat the program will be searching for, or else it will no longer functionproperly.  The easiest thing to do is insert a long sequence of <tt>nop-C</tt>instructions.<p>Next we have the beginning of the "copy loop".  This segement of code startsoff with an <tt>h-search</tt> command with no template following it.  Insuch as case, the Flow-Head is placed on the line immediately following thesearch.  This head will be used to designate the place that the IP keepsreturning to with each cycle of the loop.<p>The <tt>h-copy</tt> command will copy a single instruction from the Read-Head(still at the very start of the genome, where it begins) to the Write-Head(which we placed at the beginning of the offspring).  With any copy commandthere is a user-specified chance of a copy mutation.  If one occurs, theWrite-Head will place a random instruction rather than the one that itgathered from the Read-Head.  After the copy occurs (for better or worse),both the Read-Head and the Write-Head are advanced to the next instructionin the genome.  It is for this reason that a common mutation we see happeningwill place a long string of h-copy instruction one after another.<p>The next command, <tt>if-label</tt> (followed by a <tt>nop-C</tt> and a<tt>nop-A</tt>) tests to see if the complement of <tt>C:A</tt> is the mostthing copied.  That is, if the two mostrecent instructions copied were a <tt>nop-A</tt> followed by a <tt>nop-B</tt>as is found at the end of the organism.  If so, we are done!  Execute thenext instruction which is <tt>h-divide</tt> (when this occurs, the read andwrite heads will surround the portion of memory to be split off as theoffspring's genome).  If not, then we need to keepgoing.  Skip the next instruction and move on to the <tt>mov-head</tt> whichwill move the head specified by the <tt>nop</tt> that follows (in this case<tt>nop-A</tt> which is the Instruction Pointer) to the Flow-Head at thebeginning of the copy loop.<p>This process will continue until all of the lines of code have been copies,and an offspring is born.<h3>An example logic gene</h3><p>Here is a short example program to demonstrate one way for an organism toperform the "OR" logic operation.  This time I'm only going to show thecontents of the registers after each command because the functionality ofthe individual instructions should be clear, and the logic itself won'tbe helped much by a line-by-line explanation in English.<p><center><table width=75%><tr><th bgcolor="#CCCCFF" width=11%>Line #    <th bgcolor="#CCCCFF" width=34%>Instruction    <td bgcolor="#CCCCFF" width=11%><b>AX</b>    <td bgcolor="#CCCCFF" width=11%><b>BX</b>    <td bgcolor="#CCCCFF" width=11%><b>CX</b>    <td bgcolor="#CCCCFF" width=11%><b>Stack</b>    <td bgcolor="#CCCCFF" width=11%><b>Output</b><tr><th bgcolor="#FF88FF"> 1 <th bgcolor="#88FFFF">IO    <td bgcolor="#FFBBBB">?  <td bgcolor="#FFBBBB">X  <td bgcolor="#FFBBBB">?      <td bgcolor="#AAFFAA">? <td bgcolor="#FFFF88"> ?<tr><th bgcolor="#FF88FF"> 2 <th bgcolor="#88FFFF">push      <td bgcolor="#FFBBBB">?  <td bgcolor="#FFBBBB">X  <td bgcolor="#FFBBBB">?      <td bgcolor="#AAFFAA">X, ?       <td bgcolor="#FFFF88">&nbsp;<tr><th bgcolor="#FF88FF"> 3 <th bgcolor="#88FFFF">pop       <td bgcolor="#FFBBBB">?  <td bgcolor="#FFBBBB">X  <td bgcolor="#FFBBBB">X      <td bgcolor="#AAFFAA">? <td bgcolor="#FFFF88">&nbsp;<tr><th bgcolor="#FF88FF"> 4<th bgcolor="#88FFFF">nop-C <td colspan=5>&nbsp;<tr><th bgcolor="#FF88FF"> 5 <th bgcolor="#88FFFF">nand      <td bgcolor="#FFBBBB">~X <td bgcolor="#FFBBBB">X  <td bgcolor="#FFBBBB">X      <td bgcolor="#AAFFAA">? <td bgcolor="#FFFF88">&nbsp;<tr><th bgcolor="#FF88FF"> 6<th bgcolor="#88FFFF">nop-A <td colspan=5>&nbsp;<tr><th bgcolor="#FF88FF"> 7 <th bgcolor="#88FFFF">IO        <td bgcolor="#FFBBBB">~X <td bgcolor="#FFBBBB">Y  <td bgcolor="#FFBBBB">X      <td bgcolor="#AAFFAA">? <td bgcolor="#FFFF88"> X<tr><th bgcolor="#FF88FF"> 8 <th bgcolor="#88FFFF">push      <td bgcolor="#FFBBBB">~X <td bgcolor="#FFBBBB">Y  <td bgcolor="#FFBBBB">X      <td bgcolor="#AAFFAA">Y, ?       <td bgcolor="#FFFF88">&nbsp;<tr><th bgcolor="#FF88FF"> 9 <th bgcolor="#88FFFF">pop       <td bgcolor="#FFBBBB">~X <td bgcolor="#FFBBBB">Y  <td bgcolor="#FFBBBB">Y      <td bgcolor="#AAFFAA">? <td bgcolor="#FFFF88">&nbsp;<tr><th bgcolor="#FF88FF">10<th bgcolor="#88FFFF">nop-C <td colspan=5>&nbsp;<tr><th bgcolor="#FF88FF">11 <th bgcolor="#88FFFF">nand      <td bgcolor="#FFBBBB">~X <td bgcolor="#FFBBBB">~Y <td bgcolor="#FFBBBB">Y      <td bgcolor="#AAFFAA">? <td bgcolor="#FFFF88">&nbsp;<tr><th bgcolor="#FF88FF">12 <th bgcolor="#88FFFF">swap      <td bgcolor="#FFBBBB">Y  <td bgcolor="#FFBBBB">~Y <td bgcolor="#FFBBBB">~X     <td bgcolor="#AAFFAA">? <td bgcolor="#FFFF88">&nbsp;<tr><th bgcolor="#FF88FF">13<th bgcolor="#88FFFF">nop-C <td colspan=5>&nbsp;<tr><th bgcolor="#FF88FF">14 <th bgcolor="#88FFFF">nand      <td bgcolor="#FFBBBB">Y  <td bgcolor="#FFBBBB">X or Y <td bgcolor="#FFBBBB">~X      <td bgcolor="#AAFFAA">? <td bgcolor="#FFFF88">&nbsp;<tr><th bgcolor="#FF88FF">15 <th bgcolor="#88FFFF">IO        <td bgcolor="#FFBBBB">Y  <td bgcolor="#FFBBBB">Z      <td bgcolor="#FFBBBB">~X      <td bgcolor="#AAFFAA">? <td bgcolor="#FFFF88"> X or Y</table></center>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?