optima 0.1.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

Optima #

A collection of test functions for optimization useful to evaluate characteristics of optimization algorithms, such as convergence rate, precision, robustness, general performance.

Getting started #

Add this dependency to your pubspec.yaml file:

dependencies:
  optima: #latest version
  # And optionally:
  evolution: #latest version

Add this import statement to your source files:

import 'package:optima/optima.dart';
// and optionally:
import 'package:evolution/evolution.dart';

To give it a try, simply run the example.

dart ./example/main.dart 

This example optimizes versions of the sphere function and the Ackley function.

  • Sphere100 is version of the sphere function with a global minimum at (100.0, ..., 100.0).
  • Sphere100 (restricted) is the same problem to be solved within a restricted search space.
  • Ackley10 is a version of the ackley function with a global minimum at (10.0, ..., 10.0).
  • Ackley100 is a version of the ackley function with a global minimum at (100.0, ..., 100.0).
  • Ackley100 (restricted) is the same problem to be solved within a restricted search space.

Example #

Use optima to benchmark a version of the Differential Evolution algorithm provided by package:evolution.

import 'package:optima/optima.dart';
import 'package:evolution/evolution.dart';

void main() {
  //var seed = DateTime.now().millisecond;

  print("Optimize a version of the sphere function centered at (100.0, ... , 100.0) on the unrestricted version of the problem.");
  10.times((int i) {
    var ret = diff(4, 25, 10, 10, 25, i, 500, 10.0, sphere100);
    print("Sphere100 - Trial Nr.: ${i} - f: ${ret.fitness()} - ag: ${ret}");
    return ret;
  });

  print("Use the version confined within (50, 150) in each dimension.");
  10.times((int i) {
    var ret = diff2(4, 25, 10, 10, 25, i, 500, 10.0, sphere100, 50, 150);
    print("Sphere100 (restricted) - Trial Nr.: ${i} - f: ${ret.fitness()} - ag: ${ret}");
    return ret;
  });

  print("Optimize a version of the Ackley function centered at (10.0, ... , 10.0) on the unrestricted version of the problem.");
  10.times((int i) {
    var ret = diff(4, 25, 10, 10, 25, i, 1000, 10.0, ackley10);
    print("Ackley10 - Trial Nr.: ${i} - f: ${ret.fitness()} - ag: ${ret}   ");
    return ret;
  });

  print("Optimize a version of the Ackley function centered at (100.0, ... , 100.0) on the unrestricted version of the problem.");
  print("This will not find a solution to the problem.");

  10.times((int i) {
    var ret = diff(4, 25, 10, 10, 25, i, 1000, 10.0, ackley100);
    print("Ackley100 - Trial Nr.: ${i} - f: ${ret.fitness()} - ag: ${ret}");
    return ret;
  });

  print("Use the version of the Ackley function centered at (100.0, ... , 100.0) confined within (50, 150) in each dimension.");
  10.times((int i) {
    var ret = diff2(4, 25, 10, 10, 25, i, 1000, 10.0, ackley100, 50, 150);
    print(
        "Ackley100 (restricted) - Trial Nr.: ${i} - f: ${ret.fitness()} - ag: ${ret}");
    return ret;
  });
}

Changelog #

0.1.3 #

  • fix issues reported by pana

0.1.2 #

  • Improve description

0.1.1 #

  • Improve documentation

0.1.0 #

  • Fix Issues discovered by pana

0.0.1 #

  • Initial version

example/main.dart

import 'package:evolution/evolution.dart';
import 'package:optima/optima.dart';

void main() {
  //var seed = DateTime.now().millisecond;

  print(
      'Optimize a version of the sphere function centered at (100.0, ... , 100.0) on the unrestricted version of the problem.');
  10.times((int i) {
    var ret = diff(4, 25, 10, 10, 25, i, 500, 10.0, sphere100);
    print('Sphere100 - Trial Nr.: ${i} - f: ${ret.fitness()} - ag: ${ret}');
    return ret;
  });

  print('Use the version restricted on (50, 150) in each dimension.');
  10.times((int i) {
    var ret = diff2(4, 25, 10, 10, 25, i, 500, 10.0, sphere100, 50, 150);
    print(
        'Sphere100 (restricted) - Trial Nr.: ${i} - f: ${ret.fitness()} - ag: ${ret}');
    return ret;
  });

  print(
      'Optimize a version of the ackley function centered at (10.0, ... , 10.0) on the unrestricted version of the problem.');
  10.times((int i) {
    var ret = diff(4, 25, 10, 10, 25, i, 1000, 10.0, ackley10);
    print('Ackley10 - Trial Nr.: ${i} - f: ${ret.fitness()} - ag: ${ret}   ');
    return ret;
  });

  print(
      'Optimize a version of the ackley function centered at (100.0, ... , 100.0) on the unrestricted version of the problem.');
  print('This will not find a solution to the problem.');

  10.times((int i) {
    var ret = diff(4, 25, 10, 10, 25, i, 1000, 10.0, ackley100);
    print('Ackley100 - Trial Nr.: ${i} - f: ${ret.fitness()} - ag: ${ret}');
    return ret;
  });

  print('Use the version restricted on (50, 150) in each dimension.');
  10.times((int i) {
    var ret = diff2(4, 25, 10, 10, 25, i, 1000, 10.0, ackley100, 50, 150);
    print(
        'Ackley100 (restricted) - Trial Nr.: ${i} - f: ${ret.fitness()} - ag: ${ret}');
    return ret;
  });
}

Use this package as a library

1. Depend on it

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


dependencies:
  optima: ^0.1.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:optima/optima.dart';
  
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]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Jul 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
evolution ^0.1.7 0.1.11