Add HillClimb
selector evaluate methods
#119
Merged
+48
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a new
evaluate
method to theHillClimb
selector.The
HillClimb
selector is a composition of a selector and a mutator that simply returns the best individual within a set of iterations. The implementation relies on the mutated individuals being correctly evaluated so that the best fitness individual can be chosen. This requires users to callevaluate
on the mutator passed in. It may also require users to callevaluate
on the selected individual but this depends on whether the selected individual has previously been evaluated. Callingevaluate
on theHillClimb
type itself is almost never what you want as it would result in the selected individual being evaluated which should already happen within the selector.This change introduces new
evaluate_iterations
andevaluate_mutations
methods on theHillClimb
selector that transform the inner operators. The former adapts both the selector and mutator with the given evaluator, requiring theClone
bound, whereas the latter adapts just the inner mutator with the given evaluator.These methods are an alternative to chaining on the selector and/or mutator directly but otherwise provide no new functionality. The original plan was to override the
evaluate
method but it is possible that users will want to hill climb with a separate evaluator and then evaluate again. Theevaluate_iterations
method ensures that both the selected and mutated individuals are evaluated consistently whereas theevaluate_mutations
method assumes that the selected individual has already been evaluated.