darwin 0.4.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 48

darwin

Build Status

A genetic/evolutionary algorithm library for Dart. Given a population of phenotypes, an evaluator (fitness function), and time, the algorithm will evolve the population until it crosses given fitness threshold.

Read more about genetic algorithms on Wikipedia.

Features of this library:

  • Generic approach (anything can be a gene, as long as it can mutate)
  • User can tune crossover probability, mutation rate, mutation strength, etc.
  • Niching via fitness sharing
  • Experimental support for multithreaded computation

For up-to-date example use, please see example/example.dart.

0.4.1

  • Upgrade to Dart 2

example/example.dart

import 'dart:async';
import 'dart:math';

import 'package:darwin/darwin.dart';

Future<Null> main() async {
  // Create first generation, either by random or by continuing with existing
  // progress.
  var firstGeneration =
      new Generation<MyPhenotype, bool, SingleObjectiveResult>()
        ..members
            .addAll(new List.generate(10, (_) => new MyPhenotype.Random()));

  // Evaluators take each phenotype and assign a fitness value to it according
  // to some fitness function.
  var evaluator = new MyEvaluator();

  // Breeders are in charge of creating new generations from previous ones (that
  // have been graded by the evaluator). Their only required argument is
  // a function that returns a blank phenotype.
  var breeder = new GenerationBreeder<MyPhenotype, bool, SingleObjectiveResult>(
      () => new MyPhenotype())
    ..crossoverPropability = 0.8;

  var algo = new GeneticAlgorithm<MyPhenotype, bool, SingleObjectiveResult>(
    firstGeneration,
    evaluator,
    breeder,
  );

  // Start the algorithm.
  await algo.runUntilDone();

  // Print all members of the last generation when done.
  algo.generations.last.members
      .forEach((Phenotype ph) => print("${ph.genesAsString}"));
}

Random random = new Random();

class MyEvaluator
    extends PhenotypeEvaluator<MyPhenotype, bool, SingleObjectiveResult> {
  Future<SingleObjectiveResult> evaluate(MyPhenotype phenotype) {
    // This implementation just counts false values - the more false values,
    // the worse outcome of the fitness function.
    final result = new SingleObjectiveResult();
    result.value =
        phenotype.genes.where((bool v) => v == false).length.toDouble();
    return new Future.value(result);
  }
}

class MyPhenotype extends Phenotype<bool, SingleObjectiveResult> {
  static int geneCount = 6;

  MyPhenotype();

  MyPhenotype.Random() {
    genes = new List<bool>(geneCount);
    for (int i = 0; i < geneCount; i++) {
      genes[i] = random.nextBool();
    }
  }

  bool mutateGene(bool gene, num strength) {
    return !gene;
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  darwin: ^0.4.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:darwin/darwin.dart';
  
Version Uploaded Documentation Archive
0.4.1 Jul 24, 2018 Go to the documentation of darwin 0.4.1 Download darwin 0.4.1 archive
0.4.0 Jan 27, 2018 Go to the documentation of darwin 0.4.0 Download darwin 0.4.0 archive
0.3.1 Nov 23, 2017 Go to the documentation of darwin 0.3.1 Download darwin 0.3.1 archive
0.2.5 Feb 3, 2016 Go to the documentation of darwin 0.2.5 Download darwin 0.2.5 archive
0.2.4 Jan 17, 2014 Go to the documentation of darwin 0.2.4 Download darwin 0.2.4 archive
0.2.3 Jan 17, 2014 Go to the documentation of darwin 0.2.3 Download darwin 0.2.3 archive
0.2.2 Jan 16, 2014 Go to the documentation of darwin 0.2.2 Download darwin 0.2.2 archive
0.2.1 Jan 14, 2014 Go to the documentation of darwin 0.2.1 Download darwin 0.2.1 archive
0.2.0 Jan 14, 2014 Go to the documentation of darwin 0.2.0 Download darwin 0.2.0 archive
0.1.1 Jan 14, 2014 Go to the documentation of darwin 0.1.1 Download darwin 0.1.1 archive

All 11 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Sep 18, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.3

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:darwin/darwin.dart.

Suggestions

The description is too long.

Search engines will display only the first part of the description. Try to keep it under 180 characters.

Format lib/src/phenotype.dart.

Run dartfmt to format lib/src/phenotype.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.0 <3.0.0
meta ^1.1.6 1.1.6
Dev dependencies
test >=0.12.30 <2.0.0