/Differential_Evolution

Differential Evolution algorithm and some of its variants.

Primary LanguageC++

README

About

The basic differential evolution algorithm, and some of its variants.

Build and Install

Dependencies:

  • CMake, with a minimum version of 3.2.1
  • Boost, minumum required: 1.57, and if you installed boost in a custom directory, you have to specify it by -DBOOST_ROOT=yore/boost/root

Below is an examle to install:

cmake -DBOOST_ROOT=~/.softwares/boost -DCMAKE_INSTALL_PREFIX=~/mysoft/de
make install

Features

Basic DE mutation strategies:

enum MutationStrategy
{
    Rand1 = 0,
    Rand2, 
    Best1,
    Best2,
    CurrentToRand1, 
    RandToBest1, 
    RandToBest2
};

Crossover strategies:

enum CrossoverStrategy
{
    Bin = 0,
    Exp
};

Selection strategies to handle constraints:

enum SelectionStrategy
{
    StaticPenalty = 0,
    FeasibilityRule,
    Epsilon
};

Two DE variants are implemented:

My recommendation:

  • DERandomF
  • Best1/Bin/FeasibilityRule
  • F ~ N(0.75, 0.25)
  • CR = 0.8

Example

#include "DifferentialEvolution.h"
#include <iostream>
#include <vector>
#include <utility>
#include <map>
using namespace std;
int main()
{
    Objective objf = [](const size_t, const vector<double>& xs)->Evaluated{
        double fom = 0.0; 
        for(auto v : xs)
            fom += v * v;
        vector<double> constr_vios = {}; // no constraints
        return {fom, constr_vios};
    };

    const vector<pair<double, double>> ranges{{-3, 3}, {-5, 5}};
    const MutationStrategy  ms = MutationStrategy::Best1;
    const CrossoverStrategy cs = CrossoverStrategy::Bin;
    const SelectionStrategy ss = SelectionStrategy::FeasibilityRule; // How to handle constraints
    const double F             = 0.8;
    const double CR            = 0.8;
    const size_t population    = 10;
    const size_t max_iter      = 100; // total evaluation: max_iter * population
    const map<string, double> extra_conf = {};

    DE de1(objf, ranges); // use default setting
    DE de2(objf, ranges, ms, cs, ss, F, CR, population, max_iter, extra_conf);
    Solution sol1 = de1.solver();
    Solution sol2 = de2.solver();

    return EXIT_SUCCESS;
}