Skip to content

Commit

Permalink
Merge pull request #39 from aarongarrett/feat-ppft
Browse files Browse the repository at this point in the history
feat: replace pp with ppft
  • Loading branch information
sanjayankur31 authored Oct 24, 2024
2 parents 84f1935 + 142bd39 commit ecb244b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Requirements
* Requires Python 3+.
* Numpy and Pylab are required for several functions in ``ec.observers``.
* Pylab and Matplotlib are required for several functions in ``ec.analysis``.
* Parallel Python (pp) is required if ``ec.evaluators.parallel_evaluation_pp`` is used.
* Parallel Python (ppft) is required if ``ec.evaluators.parallel_evaluation_pp`` is used.


License
Expand Down
28 changes: 14 additions & 14 deletions examples/advanced/parallel_evaluation_pp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import math

# Define an additional "necessary" function for the evaluator
# to see how it must be handled when using pp.
# to see how it must be handled when using ppft.
def my_squaring_function(x):
return x**2

Expand All @@ -15,36 +15,36 @@ def generate_rastrigin(random, args):
def evaluate_rastrigin(candidates, args):
fitness = []
for cs in candidates:
fit = 10 * len(cs) + sum([(my_squaring_function(x - 1) -
10 * math.cos(2 * math.pi * (x - 1)))
fit = 10 * len(cs) + sum([(my_squaring_function(x - 1) -
10 * math.cos(2 * math.pi * (x - 1)))
for x in cs])
fitness.append(fit)
return fitness
def main(prng=None, display=False):

def main(prng=None, display=False):
if prng is None:
prng = Random()
prng.seed(time())
prng.seed(time())

ea = inspyred.ec.DEA(prng)
if display:
ea.observer = inspyred.ec.observers.stats_observer
ea.observer = inspyred.ec.observers.stats_observer
ea.terminator = inspyred.ec.terminators.evaluation_termination
final_pop = ea.evolve(generator=generate_rastrigin,
final_pop = ea.evolve(generator=generate_rastrigin,
evaluator=inspyred.ec.evaluators.parallel_evaluation_pp,
pp_evaluator=evaluate_rastrigin,
pp_evaluator=evaluate_rastrigin,
pp_dependencies=(my_squaring_function,),
pp_modules=("math",),
pop_size=8,
pop_size=8,
bounder=inspyred.ec.Bounder(-5.12, 5.12),
maximize=False,
max_evaluations=256,
num_inputs=3)

if display:
best = max(final_pop)
best = max(final_pop)
print('Best Solution: \n{0}'.format(str(best)))
return ea

if __name__ == '__main__':
main(display=True)
2 changes: 1 addition & 1 deletion inspyred/ec/evaluators.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def parallel_evaluation_pp(candidates, args):
documentation for `Parallel Python <http://www.parallelpython.com>`_.
"""
import pp
import ppft as pp
logger = args['_ec'].logger

try:
Expand Down

0 comments on commit ecb244b

Please sign in to comment.