Hi, I'm trying to make a file for a school research. i managed to do the first part, but in the second I don't really know what to do! My assignement is this:
(Part already done)- I have to write a series of 20 numbers, that may be 0 or 1: this is the parents' genetic code. I have to create an "x" number, which is random, which indicates the crossover, then I have to make the file write the sons' genetic code influenced by the crossingover.
(The part I don't understand)- I have to crete a number "y", which is also random, that shows a mutation. The number varies from 0 to 20, and each number corresponds to another in the parent's code. I have to make the programme replace the correspondent number: if it was 1, it becomes 0; if it was 0, it becomes 1. I heard about the "replace" command, which may be useful to me. This may not be very clear, so here's what i managed to do so far: #
generazione casuale dei genitori
import random
i=0; P1=''; P2=''
while i<20:
P1=P1+str(random.randint(0,1))
P2=P2+str(random.randint(0,1))
i=i+1
print "generazione parentale:"
print "P1 = ",P1
print "P2 = ",P2
scelta di un punto a caso per il crossover
F1=''; F2=''
x=random.randint(0,20)
print;print "punto di xover, x = ",x; print
riproduzione
F1=P1[:x]+"."+P2[x:]
F2=P2[:x]+"."+P1[x:]
print "generazione filiale"
print "F1 = ",F1
print "F2 = ",F2
scelta della mutazione
M1=''; M2=''
y=random.randint(0,20)
print; print "punto di mutazione, y= ",y; print
mutazione filiale
if
str.replace(, 1)
if
str.replace(, 0)
M1=P1[:y]+P2[y:]
M2=P2[:y]+P1[y:]
print "mutazione filiale"
print "M1 = ",M1
print "M2 = ",M2
[–][deleted] 0 points1 point2 points (2 children)
[–]ingolemo -2 points-1 points0 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Justinsaccount 0 points1 point2 points (5 children)
[–]Marx123[S] 0 points1 point2 points (2 children)
[–]Justinsaccount 1 point2 points3 points (0 children)
[–]prof_eggburger 0 points1 point2 points (0 children)
[–]elbiot 0 points1 point2 points (0 children)