genetic_engine 0.3.0
genetic_engine: ^0.3.0 copied to clipboard
A pure Dart genetic algorithm framework with extensible genomes, selection, crossover and mutation for Flutter apps and Dart services.
genetic_engine #
A pure Dart genetic algorithm framework for Flutter apps and Dart APIs. Compose typed strategies for your problem without modifying the evolution loop. No runtime dependencies, Flutter imports, or connection to a fuzzy engine.
Status: pre-release 0.3.0. GitHub source is available; pub.dev publication is pending. Badges describe CI, SDK requirements, license and tags; there is no claim of pub.dev availability or a package score before publication.
Install from source #
dependencies:
genetic_engine:
git:
url: https://github.com/kleberandrade/genetic-engine.git
ref: v0.3.0
For local development, use path: ../genetic_engine instead. After publication,
this dependency can be replaced with the corresponding hosted version.
Your first optimization #
A genetic algorithm creates candidate solutions, evaluates them, selects parents, and generates new candidates using crossover and mutation. It repeats this process until a stopping condition holds. Higher fitness is better by default.
This example asks for 32 binary genes all equal to true:
import 'package:genetic_engine/genetic_engine.dart';
void main() {
final engine = GeneticAlgorithm<List<bool>>(
factory: CallbackGenomeFactory((r) =>
List.unmodifiable(List.generate(32, (_) => r.nextBool()))),
evaluator: CallbackFitnessEvaluator(
(g) => g.where((bit) => bit).length.toDouble()),
selection: TournamentSelection(),
crossover: SinglePointCrossover(),
mutation: const BitFlipMutation(),
mutationRate: 0.3,
maxGenerations: 200,
targetFitness: 32,
seed: 42,
);
final result = engine.run();
print(result.best.fitness);
}
Use Objective.minimize to optimize costs or distances. A genetic algorithm is a
stochastic heuristic: it does not guarantee the global optimum.
Choose strategies #
| Representation | Crossover | Mutation |
|---|---|---|
| Binary list | SinglePointCrossover, UniformCrossover |
BitFlipMutation |
| Integer list | SinglePointCrossover, UniformCrossover |
Your Mutation<List<int>> |
| Real list | SinglePointCrossover, UniformCrossover |
RealResetMutation |
| Permutation | OrderCrossover |
SwapMutation |
| Custom immutable object | Your Crossover<T> |
Your Mutation<T> |
TournamentSelection<T> supports either objective, including negative fitness.
The main problem extension points are interfaces: GenomeFactory, FitnessEvaluator,
Selection, Crossover, and Mutation. Functions can be wrapped using the
Callback... adapters or passed to GeneticAlgorithm.withCallbacks.
New in 0.3: fixed/fractional elite policies; elite, rank, truncation and roulette selection; two-point, CX and PMX crossover; insertion, reverse and partial shuffle mutation; AND/OR, elapsed-time and other stopping policies. See the catalogue for exact semantics. The travelling salesman example combines permutation operators with fractional elitism.
Learn and contribute #
- Operator catalogue, elitism and composable stopping
- Papers, implementation references and provenance
- Getting started, terminology and parameter guide
- Architecture and dependency rules
- Custom operators and problem constraints
- Flutter and Dart service integration
- Migration from pre-release 0.1
- Contributing, changelog
- Engineering log and verification limits
Executable examples: binary search, numerical minimization, and custom integer mutation.
Development #
dart pub get
dart format --output=none --set-exit-if-changed lib test example
dart analyze --fatal-infos
dart test
dart run example/genetic_engine_example.dart
dart run example/minimize.dart
dart run example/custom_mutation.dart
dart pub publish --dry-run
MIT © 2026 Kleber Andrade.