# -*- coding: utf-8 -*- import numpy as np from numpy import (abs, asarray, cos, exp, floor, pi, sign, sin, sqrt, sum, size, tril, isnan, atleast_2d, repeat) from numpy.testing import assert_almost_equal from .go_benchmark import Benchmark class CarromTable(Benchmark): r""" CarromTable objective function. The CarromTable [1]_ global optimization problem is a multimodal minimization problem defined as follows: .. math:: f_{\text{CarromTable}}(x) = - \frac{1}{30}\left(\cos(x_1) cos(x_2) e^{\left|1 - \frac{\sqrt{x_1^2 + x_2^2}}{\pi}\right|}\right)^2 with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. *Global optimum*: :math:`f(x) = -24.15681551650653` for :math:`x_i = \pm 9.646157266348881` for :math:`i = 1, 2` .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions For Global Optimization Problems Int. Journal of Mathematical Modelling and Numerical Optimisation, 2013, 4, 150-194. """ def __init__(self, dimensions=2): Benchmark.__init__(self, dimensions) self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) self.global_optimum = [(9.646157266348881, 9.646134286497169), (-9.646157266348881, 9.646134286497169), (9.646157266348881, -9.646134286497169), (-9.646157266348881, -9.646134286497169)] self.fglob = -24.15681551650653 def fun(self, x, *args): self.nfev += 1 u = cos(x[0]) * cos(x[1]) v = sqrt(x[0] ** 2 + x[1] ** 2) return -((u * exp(abs(1 - v / pi))) ** 2) / 30. class Chichinadze(Benchmark): r""" Chichinadze objective function. This class defines the Chichinadze [1]_ global optimization problem. This is a multimodal minimization problem defined as follows: .. math:: f_{\text{Chichinadze}}(x) = x_{1}^{2} - 12 x_{1} + 8 \sin\left(\frac{5}{2} \pi x_{1}\right) + 10 \cos\left(\frac{1}{2} \pi x_{1}\right) + 11 - 0.2 \frac{\sqrt{5}}{e^{\frac{1}{2} \left(x_{2} -0.5 \right)^{2}}} with :math:`x_i \in [-30, 30]` for :math:`i = 1, 2`. *Global optimum*: :math:`f(x) = -42.94438701899098` for :math:`x = [6.189866586965680, 0.5]` .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 TODO: Jamil#33 has a dividing factor of 2 in the sin term. However, f(x) for the given solution does not give the global minimum. i.e. the equation is at odds with the solution. Only by removing the dividing factor of 2, i.e. `8 * sin(5 * pi * x[0])` does the given solution result in the given global minimum. Do we keep the result or equation? """ def __init__(self, dimensions=2): Benchmark.__init__(self, dimensions) self._bounds = list(zip([-30.0] * self.N, [30.0] * self.N)) self.custom_bounds = [(-10, 10), (-10, 10)] self.global_optimum = [[6.189866586965680, 0.5]] self.fglob = -42.94438701899098 def fun(self, x, *args): self.nfev += 1 return (x[0] ** 2 - 12 * x[0] + 11 + 10 * cos(pi * x[0] / 2) + 8 * sin(5 * pi * x[0] / 2) - 1.0 / sqrt(5) * exp(-((x[1] - 0.5) ** 2) / 2)) class Cigar(Benchmark): r""" Cigar objective function. This class defines the Cigar [1]_ global optimization problem. This is a multimodal minimization problem defined as follows: .. math:: f_{\text{Cigar}}(x) = x_1^2 + 10^6\sum_{i=2}^{n} x_i^2 Here, :math:`n` represents the number of dimensions and :math:`x_i \in [-100, 100]` for :math:`i = 1, ..., n`. *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for :math:`i = 1, ..., n` .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 """ def __init__(self, dimensions=2): Benchmark.__init__(self, dimensions) self._bounds = list(zip([-100.0] * self.N, [100.0] * self.N)) self.custom_bounds = [(-5, 5), (-5, 5)] self.global_optimum = [[0 for _ in range(self.N)]] self.fglob = 0.0 self.change_dimensionality = True def fun(self, x, *args): self.nfev += 1 return x[0] ** 2 + 1e6 * sum(x[1:] ** 2) class Cola(Benchmark): r""" Cola objective function. This class defines the Cola global optimization problem. The 17-dimensional function computes indirectly the formula :math:`f(n, u)` by setting :math:`x_0 = y_0, x_1 = u_0, x_i = u_{2(i2)}, y_i = u_{2(i2)+1}` : .. math:: f_{\text{Cola}}(x) = \sum_{i