Single-objective benchmark problems#

namespace problems

Implementations of some benchmark functions that can be used to test the genetic algorithms. There are some benchmark problems implemented for every encoding type, and the real-encoded problems can also be used for the binary-encoded GAs.

All of the problems are implemented for maximization.

class Sphere#

#include <problems/single_objective.hpp>
class Sphere : public gapp::problems::BenchmarkFunction<RealGene>#

Implementation of the function \( -f(\vec{x}) = \langle \vec{x}, \vec{x} \rangle \) for any number of variables. This is a simple single-objective benchmark function with a single global optimum that is easy to find, and no other local optima.

Evaluated on the hypercube \( x_i \in [-5.12, 5.12] \).

The global optimum is \( f(\vec{x}) = 0 \) at \( \vec{x} = (0, 0, ... , 0) \).

This benchmark function can be used for both the real- and binary-encoded GAs.

Public Functions

inline explicit Sphere(size_t num_vars, size_t bits_per_var = 32)#

Create a sphere function.

Parameters:
  • num_vars – The number of variables. Must be at least 1.

  • bits_per_var – The number of bits representing a variable when used with the binary-encoded GA.

class Rastrigin#

#include <problems/single_objective.hpp>
class Rastrigin : public gapp::problems::BenchmarkFunction<RealGene>#

Implementation of the Rastrigin function for any number of variables, modified for maximization. This function has many uniformly distributed local optima and a single global optimum.

\[ -f(\vec{x}) = 10d + \sum_{i=1}^d \left[ x_i^2 - 10\cos(2\pi x_i) \right] \]

Evaluated on the hypercube \( x_i \in [-5.12, 5.12] \).

The global optimum is \( f(\vec{x}) = 0 \) at \( \vec{x} = (0, 0, ... , 0) \).

This benchmark function can be used for both the real- and binary-encoded GAs.

See also

Rastrigin, L. A. “Systems of extremal control.” Nauka, Moscow (1974).

Public Functions

inline explicit Rastrigin(size_t num_vars, size_t bits_per_var = 32)#

Create a Rastrigin function.

Parameters:
  • num_vars – The number of variables. Must be at least 1.

  • bits_per_var – The number of bits representing a variable when used with the binary-encoded GA.

class Rosenbrock#

#include <problems/single_objective.hpp>
class Rosenbrock : public gapp::problems::BenchmarkFunction<RealGene>#

Implementation of the Rosenbrock function for any number of variables, modified for maximization. This single-objective benchmark function has no local optima, and only a single global optimum, but this optimum can be very difficult to find.

\[ -f(\vec{x}) = \sum_{i=1}^{d-1} \left[ 100( x_{i+1} - x_i^2 )^2 + (x_i - 1)^2 \right] \]

Evaluated on the hypercube \( x_i \in [-2.048, 2.048] \).

The global optimum is \( f(\vec{x}) = 0 \) at \( \vec{x} = (0, 0, ... , 0) \).

This benchmark function can be used for both the real- and binary-encoded GAs.

See also

Rosenbrock, H. H. “An automatic method for finding the greatest or least value of a function.” The computer journal 3, no. 3 (1960): 175-184.

Public Functions

inline explicit Rosenbrock(size_t num_vars, size_t bits_per_var = 32)#

Create a Rosenbrock function.

Parameters:
  • num_vars – The number of variables. Must be at least 1.

  • bits_per_var – The number of bits representing a variable when used with the binary-encoded GA.

class Schwefel#

#include <problems/single_objective.hpp>
class Schwefel : public gapp::problems::BenchmarkFunction<RealGene>#

Implementation of the Schwefel function for any number of variables, modified for maximization. This single-objective benchmark function has many local optima, and a global optimum that is far away from the next best local optima.

\[ -f(\vec{x}) = 418.98d - \sum_{i=1}^d x_i \sin\left( \sqrt{|x_i|} \right) \]

Evaluated on the hypercube \( x_i \in [-500.0, 500.0] \).

The global optimum is \( f(\vec{x}) = 0 \) at \( \vec{x} = (420.9687, 420.9687, ... , 420.9687) \).

This benchmark function can be used for both the real- and binary-encoded GAs.

Public Functions

inline explicit Schwefel(size_t num_vars, size_t bits_per_var = 32)#

Create a Schwefel function.

Parameters:
  • num_vars – The number of variables. Must be at least 1.

  • bits_per_var – The number of bits representing a variable when used with the binary-encoded GA.

class Griewank#

#include <problems/single_objective.hpp>
class Griewank : public gapp::problems::BenchmarkFunction<RealGene>#

Implementation of the Griewank function for any number of variables, modified for maximization. This single-objective benchmark function has many uniformly distributed local optima and a single global optimum. While it can be used with any number of variables, the difficulty of finding the global optimum does not increase significantly for variable counts above ~10.

\[ -f(\vec{x}) = 1 + \sum_{i=1}^d\frac{x_i^2}{4000} - \prod_{i=1}^d\cos\left( \frac{x_i}{\sqrt{i}} \right) \]

Evaluated on the hypercube \( x_i \in [-600.0, 600.0] \).

The global optimum is \( f(\vec{x}) = 0 \) at \( \vec{x} = (0, 0, ... , 0) \).

This benchmark function can be used for both the real- and binary-encoded GAs.

See also

Locatelli, M. “A note on the Griewank test function.” Journal of global optimization 25, no. 2 (2003): 169-174.

See also

Huang, Y., et al. “Unusual phenomenon of optimizing the Griewank function with the increase of dimension.” Frontiers of Information Technology & Electronic Engineering 20, no. 10 (2019): 1344-1360.

Public Functions

inline explicit Griewank(size_t num_vars, size_t bits_per_var = 32)#

Create a Griewank function.

Parameters:
  • num_vars – The number of variables. Must be at least 1.

  • bits_per_var – The number of bits representing a variable when used with the binary-encoded GA.

class Ackley#

#include <problems/single_objective.hpp>
class Ackley : public gapp::problems::BenchmarkFunction<RealGene>#

Implementation of the Ackley function for any number of variables, modified for maximization. This single-objective benchmark function has a single global optimum, and many local optima. The regions further away from the optimum are nearly flat.

\[ -f(\vec{x}) = 20 + e - 20e^{\left( -0.2\sqrt{ \frac{1}{d}\sum_{i=1}^d x_i^2 } \right)} - e^{\left( \frac{1}{d}\sum_{i=1}^d\cos(2\pi x_i) \right)} \]

Evaluated on the hypercube \( x_i \in [-32.768, 32.768] \).

The global optimum is \( f(\vec{x}) = 0 \) at \( \vec{x} = (0, 0, ... , 0) \).

This benchmark function can be used for both the real- and binary-encoded GAs.

See also

Ackley, D H. “A connectionist machine for genetic hillclimbing.” (1987).

Public Functions

inline explicit Ackley(size_t num_vars, size_t bits_per_var = 32)#

Create an Ackley function.

Parameters:
  • num_vars – The number of variables. Must be at least 1.

  • bits_per_var – The number of bits representing a variable when used with the binary-encoded GA.

class Levy#

#include <problems/single_objective.hpp>
class Levy : public gapp::problems::BenchmarkFunction<RealGene>#

Implementation of the Lévy function for any number of variables, modified for maximization.

\[ -f(\vec{x}) = \sin^2(\pi w_1) + (w_d - 1)^2( 1 + \sin^2(2\pi w_d) ) + \sum_{i=1}^d (w_i - 1)^2 (1 + 10\sin^2(\pi w_i + 1)) \]
\[ \textrm{where } w_i = 1 + \frac{x_i - 1}{4} \]

Evaluated on the hypercube \( x_i \in [-10.0, 10.0] \).

The global optimum is \( f(\vec{x}) = 0 \) at \( \vec{x} = (1, 1, ... , 1) \).

This benchmark function can be used for both the real- and binary-encoded GAs.

Public Functions

inline explicit Levy(size_t num_vars, size_t bits_per_var = 32)#

Create a Lévy function.

Parameters:
  • num_vars – The number of variables. Must be at least 1.

  • bits_per_var – The number of bits representing a variable when used with the binary-encoded GA.