<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">You might want your encoding-scheme to be a function, <div>and you want to evaluate that function inside generate-chromosome:<div><br></div><div><div>(define (generate-chromosome encoding-scheme number-of-genes)</div><div> (cond [(zero? number-of-genes) empty]</div><div> [else (cons (encoding-scheme)</div><div> (generate-chromosome encoding-scheme (sub1 number-of-genes)))]))</div><div><br></div><div>(define (binary-encoding-scheme)</div><div> (random 2))</div><div>(define (value-encoding-scheme)</div><div> (random))</div><div><br></div><div>(generate-chromosome binary-encoding-scheme 10)</div><div>(generate-chromosome value-encoding-scheme 10)</div><div><br></div><div><div>(0 1 1 1 1 1 0 1 1 0)</div><div>(0.17586764776624525</div><div> 0.13437314563189037</div><div> 0.585523111696543</div><div> 0.6533766686688987</div><div> 0.09071850144989983</div><div> 0.8804515074319006</div><div> 0.6998388642832832</div><div> 0.599233672637633</div><div> 0.5238661544779689</div><div> 0.72734166222789)</div><div>> </div></div><div><br></div><div><br></div><div>rac</div><div><br></div><div><br></div><div><br><div><div>On Dec 19, 2013, at 7:42 PM, Rian Shams wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hello All,<div><br></div><div>I am new to Racket and just started building an evolutionary computing module to supplement my research and learn more about Racket.</div><div><br></div><div>When it comes to representing a chromosome, there are many encoding schemes one can choose from. To start I would like to build a function that lets the user choose the encoding scheme they would like by being able to directly insert it into the function call. So far I have created this:</div>
<div><br></div><div><div>(define (generate-chromosome encoding-scheme number-of-genes)</div><div> (cond [(zero? number-of-genes) empty]</div><div> [else (cons encoding-scheme</div><div> (generate-chromosome encoding-scheme (sub1 number-of-genes)))]))</div>
<div><br></div><div>Two popular encoding schemes are the binary encoding scheme and the real value encoding scheme:</div><div><br></div><div>(define binary-encoding-scheme</div><div> (random 2))</div><div>(define value-encoding-scheme</div>
<div> (random))</div><div><br></div><div>So then calling this function using the binary encoding scheme:</div><div><br></div><div>(generate-chromosome binary-encoding-scheme 10)</div><div> </div><div>gives either a list of only ten 1's or a list of only ten 0's. Random only works once and whatever the first random value is stays and doesn't change.</div>
<div><br></div><div><div><b>How would I make random re-evaluate each time given that I want it to be included in the definition of an encoding scheme?</b></div></div><div><br></div><div>As an alternate, the function below works when I directly include (random 2) in for a value in the encoding scheme, but I prefer the structure of the above function.</div>
<div><br></div><div><div>(define (generate-chromosome-2 number-of-genes)</div><div> (cond [(zero? number-of-genes) empty]</div><div> [else (cons (random 2) ;binary-encoding-scheme</div><div> (generate-chromosome-2 (sub1 number-of-genes)))]))</div>
<div><br></div><div>So the function call</div><div>(generate-chromosome-2 10) gives the desired result, but doesn't fit the needed structure.</div></div><div><br></div><div>Any help would be much appreciated. </div><div>
<br></div><div>Best Regards,</div>-- <br>Rian Shams
</div></div>
____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></div></div></div></body></html>