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

fitness_function is now a string, for multithreading support

parent c0d2f548
......@@ -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
......
......@@ -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]
......
......@@ -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
......
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