Commit b15c0195 authored by David A.. Werner's avatar David A.. Werner
Browse files

Bugfixes to mate and mutate and change_muscle_value

parent 55c7cdcd
......@@ -138,12 +138,12 @@ class Manduca(object):
# - flip a random muscle-on
# - do the secret-sauce mutation if desired.
def mutate (self, rng=np.random, max_mutations = 20):
n_mutations = rng.randing(1,MAX_MUTATIONS)
for _ in num_mutations:
num_mutations = rng.randint(1, max_mutations)
for _ in range(num_mutations):
mutation_type = rng.randint(2)
if mutation_type == 0:
time_step = rng.randint(self.num_time_steps)
leg_idx = np.randint(self.num_legs)
leg_idx = rng.randint(self.num_legs)
value = self.legs[time_step][leg_idx]
self.legs[time_step][leg_idx] = int(value) ^ 1
elif mutation_type == 1:
......@@ -160,11 +160,11 @@ class Manduca(object):
# Pick entire rows from one parent or the other. Each row of the child comes
# from the first parent or the second (with equal likelihood).
# This is the final function that you write yourself.
def mate (self, parent2, rng=np.random):
child = self.copy()
def mate(self, parent2, rng=np.random):
child = self.clone()
num_time_steps = child.num_time_steps
for time_step in range(num_time_steps):
dna_src = rng.randint(1)
dna_src = rng.randint(2)
if dna_src == 0:
continue
else:
......@@ -382,5 +382,5 @@ class SimpleManduca(Manduca):
size=(time_segments, num_legs-1))
return SimpleManduca(legs, muscles, time_step, **kwargs)
def change_muscle_value(self, current_value):
def change_muscle_value(self, current_value, rng=np.random):
return current_value^self.body_properties.muscle_strength
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment