Skip to content

Commit

Permalink
Renamed test_run_pop to command line tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncan Blythe committed May 21, 2010
1 parent 230b83d commit ddaa00b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

iterations = 0

a = int(raw_input('to try mutations press 1, to try ficken press 0:- '))
a = int(raw_input('To run a population press 2, to try mutations press 1, to try ficken press 0:- '))

if a:
if a==1:
P = Population(4, Instrument, {'const_prob':0.7, 'max_children':3})
while not raw_input('press return to continue or x to quit mutate:- '):
for i in P.individuals:
Expand All @@ -33,7 +33,7 @@
i.Fitness = 0
print 'This is iteration number',iterations

else:
elif a==0:
P = Population(3, Instrument, {'const_prob':0.7, 'max_children':3})
while not raw_input('press return to continue or x to quit ficken:- '):
for i in P.individuals:
Expand Down Expand Up @@ -62,3 +62,47 @@
i.Fitness = 0
print "assigning fitnesses"
print 'This is iteration number',iterations,'length is',len(P.individuals)
else:
P = Population(3, Instrument, {'const_prob':0.7, 'max_children':3})
while not raw_input('press return to continue or x to quit Population run:- '):
for i in P.individuals:
try:
csd = csound_adapter.CSD()
csd.orchestra(i)
csd.score('i 1 0 5')
csd.play()
print i.to_json()
print i.to_instr()
except OSError:
print 'skipping this iteration:- Csound crashed'
n = int(raw_input('which did you like best: 1,2,3 or 4?:- '))-1
m = int(raw_input('which did you like 2nd best: 1,2,3 or 4?:- '))-1
P.individuals[n].Fitness = 1
P.individuals[m].Fitness = 1
a = P.individuals[n]
c = P.individuals[m]

print "updated fitnesses"
P.natural_selection(no_surviving=2)
print "kill shitty 2"
try:
d = a.ficken(c)
except:
d = a.mutate()
P.append_individual(d)
print "There is lovin' goin' on"
print "There are now"+str((P.size))+" individuals"
b = a.mutate()
P.append_individual(b)
print "The fittest has mutated"
print "There are now" + str(P.size)+" individuals"
iterations = iterations+1
print "updating iterations"
for i in P.individuals:
i.Fitness = 0
print "assigning fitnesses"
print 'This is iteration number',iterations,'length is',len(P.individuals)




1 change: 1 addition & 0 deletions sound_evolution/genetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, size, cls, params):
def __kill(self, index):
"""kill index'th element off from the population"""
del self.individuals[index]
self.size = self.size - 1

def append_individual(self, individ):
self.individuals.append(individ)
Expand Down

0 comments on commit ddaa00b

Please sign in to comment.