genetic_evolution

Last updated:

0 purchases

genetic_evolution Image
genetic_evolution Images
Add to Cart

Description:

genetic evolution

genetic_evolution #
A package that simulates a Genetic Evolutionary Algorithm among its generations.
Table of Contents #

Basic Usage
Examples

Simple Word Example
Intermediate Color Contrast Example


File Parsing

Basic Usage #
First, you must define your own GeneService, describing the Genes within a DNA strand. Notice that we are defining a Gene to be of type <String>.
class MyGeneService extends GeneService<String> {
...
}
copied to clipboard
Then, you must define your own FitnessService, describing how well an Entity's DNA performs.
class MyFitnessService extends FitnessService<String> {
...
}
copied to clipboard
Next, you can initialize a GeneticEvolution object.
GeneticEvolution geneticEvolution = GeneticEvolution(
geneticEvolutionConfig: GeneticEvolutionConfig(
numGenes: 10,
mutationRate: 0.25
),
fitnessService: MyFitnessService(),
geneService: MyGeneService(),
);
copied to clipboard
And finally, you can get the next generation using nextGeneration().
Generation generation = await geneticEvolution.nextGeneration();
copied to clipboard
Examples #
Simple Word Example #
The code for this Word example can be found in the /example/word_example folder (here).

Intermediate Color Contrast Example #
The code for this Color Contrast example can be found in the /example/color_contrast_example folder (here).

File Parsing #
You can write specific generations to a file, and similarly read in specific generations stored on a file.
First, define your own JsonConverter. (This class describes how to convert objects of Type <T> to and from JSON)
// Type <T> is Type <String> in this example
class GeneJsonConverter extends JsonConverter<String, Map<String, dynamic>> {
@override
fromJson(Map<String, dynamic> json) {
return json['text'];
}

@override
toJson(String object) {
return {'text': object};
}
}
copied to clipboard
Next, define your FileParser object based on your above JsonConverter.
final fileParser = FileParser<String>(
geneJsonConverter: GeneJsonConverter(),
);
copied to clipboard
Include this fileParser within the GeneticEvolution constructor.
final geneticEvolution = GeneticEvolution(
fileParser: fileParser,
... // other params go here
)
copied to clipboard
Now, you can write the current Generation to a file.
geneticEvolution.writeGenerationToFile();
copied to clipboard
Lastly, you can load in a specific Generation read from a file.
geneticEvolution.loadGenerationFromFile(wave: 10);
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.