Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Alexander R. Hankin
EE194_Manduca_Simulator
Commits
b15c0195
Commit
b15c0195
authored
May 02, 2018
by
David A.. Werner
Browse files
Bugfixes to mate and mutate and change_muscle_value
parent
55c7cdcd
Changes
1
Hide whitespace changes
Inline
Side-by-side
manduca/Manducas.py
View file @
b15c0195
...
...
@@ -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
.
randin
g
(
1
,
MAX_MUTATIONS
)
for
_
in
num_mutations
:
n
um
_mutations
=
rng
.
randin
t
(
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
.
c
opy
()
def
mate
(
self
,
parent2
,
rng
=
np
.
random
):
child
=
self
.
c
lone
()
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment