Merge Fitness
traits with Individual
#97
Merged
+201
−170
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 merges the
Fitness
andFitnessMut
traits withIndividual
.The original intent of having a separate
Fitness
trait is that some types, such as vectors and arrays, have no obvious fitness value without adding new restrictive trait bounds to infer it from the items. TheFitnessMut
trait was intended to allow the fitness to be mutated without requiring all individuals allow fitness mutation. However, after #94 the API was changed to return a reference and so by ruling out computed fitness values there is less need forFitnessMut
. The only concern there would be allowing the fitness of a primitive to be mutated as that would alter the individual itself and by extension the genome.This change merges the
Fitness
andFitnessMut
traits into theIndividual
trait and renames the associatedValue
toFitness
. This simplifies the API at the cost of allowing the scoring of a primitive such as an integer to alter the individual itself and not just the score.This includes a new
Nil
fitness value for individuals that do not have an actual fitness. This makes use of an empty array to construct a static reference to a value that works with both shared and exclusive references. This could be improved with unsafe or perhaps an external crate to construct a ZST but at the moment it only works for empty arrays and slices.