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
fe860006
Commit
fe860006
authored
May 02, 2018
by
David A.. Werner
Browse files
fitness_function is now a string, for multithreading support
parent
c0d2f548
Changes
3
Hide whitespace changes
Inline
Side-by-side
manduca/Manducas.py
View file @
fe860006
...
...
@@ -31,7 +31,7 @@ class Manduca(object):
self
.
_fitness
=
None
self
.
check_consistancy
()
if
fitness_function
==
None
:
self
.
_fitness_function
=
Manduca
.
distance_traveled
self
.
_fitness_function
=
'
distance_traveled
'
else
:
self
.
_fitness_function
=
fitness_function
if
body_properties
==
None
:
...
...
@@ -115,7 +115,11 @@ class Manduca(object):
@
property
def
fitness
(
self
):
if
(
self
.
_fitness
is
None
):
self
.
_fitness
=
self
.
_fitness_function
(
self
)
fn
=
getattr
(
self
,
self
.
_fitness_function
)
if
isinstance
(
fn
,
types
.
FunctionType
):
self
.
_fitness
=
getattr
(
self
,
self
.
_fitness_function
)(
self
)
else
:
self
.
_fitness
=
getattr
(
self
,
self
.
_fitness_function
)()
return
(
self
.
_fitness
)
@
property
...
...
tests/conftest.py
View file @
fe860006
...
...
@@ -2,7 +2,8 @@ from manduca import Manduca, ManducaBodyProperties
all_body_properties
=
[
None
,
Manduca
.
default_body_properties
,
Manduca
.
damped_body_properties
,
ManducaBodyProperties
(
10
,
4
,
6
,
2
,
10
)]
all_fitness_functions
=
[
Manduca
.
distance_traveled
,
lambda
m
:
1
/
sum
(
m
.
muscles
+
0.001
)]
#TODO (fn_name, fn_def or None if already a function)]
all_fitness_functions
=
[
'distance_traveled'
]
all_num_time_steps
=
[
2
,
3
,
5
,
10
]
all_num_legs
=
[
2
,
3
,
4
,
5
,
10
]
all_time_steps
=
[
0.01
,
1.0
,
10.0
,
1
]
...
...
tests/test_Manducas.py
View file @
fe860006
...
...
@@ -140,8 +140,11 @@ def test_fitness_reset():
# 3) Make sure it was reset
# 4) Make sure fitness evaluates to the correct value
# 5) Make sure _fitness is updated as well
def
neg_one
(
man
):
return
-
1
SimpleManduca
.
neg_one
=
neg_one
man
.
_fitness
=
1
man
.
fitness_function
=
lambda
m
:
-
1
man
.
fitness_function
=
'neg_one'
assert
man
.
_fitness
==
None
assert
man
.
fitness
==
-
1
assert
man
.
_fitness
==
-
1
...
...
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