def f14(domain=(-65.54, 65.54), dimensions=2): """ M. Shekel's Foxholes Function Dimensions: 2 Domain: -65.54 -> 65.54 Minimum value: f(31.95) = 0.998 (~1) :param domain: :param dimensions: :return: """ def function(x): sum = 0 for j in range(24): secondsum = 0 for i in range(2): secondsum += (x[i] - ComparativeBenchmarks.a_matrix[i][j])**6 sum += (j + 1 + secondsum)**-1 total = ((1 / 500) + sum)**-1 return total return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0.998, name="14")
def f12(domain=(-50, 50), dimensions=30): """ Generalised Penalised Function Domain: -50 -> 50 Minimum value: f(-1) = 0 :param domain: :param dimensions: :return: """ def function(x): n = len(x) sum = 0 secondsum = 0 for i in range(n): if i < n - 1: sum += ( (((ComparativeBenchmarks.y(x[i]) - 1)**2) * (1 + 10 * (math.sin(math.pi * ComparativeBenchmarks.y(x[i + 1])))**2)) + (ComparativeBenchmarks.y(x[n - 1]) - 1)**2) secondsum += ComparativeBenchmarks.u(x[i], 10, 100, 4) total = (math.pi / n) * ( (10 * math.sin(math.pi * ComparativeBenchmarks.y(x[1])))**2 + sum) + secondsum return total return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0, name="12")
def f13(domain=(-50, 50), dimensions=30): """ TODO CHECK AGAIN Generalised Penalised Function Domain: -50 -> 50 Minimum value: f(1,...,1) = 0 :param domain: :param dimensions: :return: """ def function(x): n = len(x) sum = 0 secondsum = 0 for i in range(n - 2): sum += (x[i] - 1)**2 * (1 + np.sin( 3 * np.pi * x[i + 1])**2) + (x[n - 1] - 1)**2 * ( 1 + np.sin(2 * np.pi * x[n - 1])**2) for i in range(n - 1): secondsum += ComparativeBenchmarks.u(x[i], 5, 100, 4) total = 0.1 * (np.sin(np.pi * 3 * x[0])**2 + sum) + secondsum return total return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0, name="13")
def f10(domain=(-32, 32), dimensions=30): """ Ackley's Function Domain: -32 -> 32 Minimum value: f(0) = 0 :param domain: :param dimensions: :return: """ def function(x): sum = 0 n = len(x) a = 0 b = 0 for i in range(n): a += x[i]**2 b += np.cos(2 * np.pi * x[i]) sum = -20 * np.exp(-0.2 * ((1 / n) * a**0.5)) - np.exp( (1 / n) * b) + 20 + np.e return sum return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0, name="10")
def f20(domain=(0, 1), dimensions=6): """ R. Hartman's Family Dimensions: 6 Domain: 0 -> 1 Minimum value: f(0.201,0.150,0.477,0.275,0.311,0.657) = -3.32 :param domain: :param dimensions: :return: """ def function(x): sum = 0 for i in range(4): secondsum = 0 for j in range(6): secondsum += ComparativeBenchmarks.a_hartman20[i][j] * \ ((x[j]-ComparativeBenchmarks.p_hartman20[i][j])**2) sum += ComparativeBenchmarks.c_hartman[i] * math.exp( -secondsum) return -sum return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=-3.32, name="20")
def f19(domain=(0, 1), dimensions=3): """ R. Hartman's Family Dimensions: 3 Domain: 0 -> 1 Minimum value: f(0.114,0.556,0.852) = -3.86 :param domain: :param dimensions: :return: """ def function(x): sum = 0 for i in range(4): secondsum = 0 for j in range(3): secondsum += ComparativeBenchmarks.a_hartman19[i][j] * \ ((x[j]-ComparativeBenchmarks.p_hartman19[i][j])**2) sum += ComparativeBenchmarks.c_hartman[i] * math.exp( -secondsum) return -sum return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=-3.86, name="19")
def f15(domain=(-5, 5), dimensions=4): """ N. Kowalik's Function Dimensions: 4 Domain: -5 -> 5 Minimum value: f(0.19,0.19,0.12,0.14) = 0.0003075 :param domain: :param dimensions: :return: """ def function(x): sum = 0 for i in range(10): sum += (ComparativeBenchmarks.a_vector[i] - ((x[0] * ((ComparativeBenchmarks.b_vector[i]**2) + ComparativeBenchmarks.b_vector[i] * x[1])) / ((ComparativeBenchmarks.b_vector[i]**2) + ComparativeBenchmarks.b_vector[i] * x[2] + x[3])))**2 return sum return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=-1.1428, name="15")
def f23(domain=(0, 10), dimensions=4): """ S. Shekel's Family Dimensions: 4 Domain: 0 -> 10 Minimum value: f(~4) = -10.5 :param domain: :param dimensions: :return: """ def function(x): sum = 0 for i in range(9): vector_1 = ComparativeBenchmarks.subtract_vectors( x, ComparativeBenchmarks.a_shekel[i]) vector_2 = ComparativeBenchmarks.subtract_vectors( x, ComparativeBenchmarks.a_shekel[i]) sum += (ComparativeBenchmarks.dot_product(vector_1, vector_2) + ComparativeBenchmarks.c_shekel[i])**-1 return -sum return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=-10.5, name="23")
def f16(domain=(-5, 5), dimensions=2): """ O. Six-Hump Camel-Back Function Dimensions: 2 Domain: -5 -> 5 Minimum value: f(-0.09,0.71) = -1.0316 :param domain: :param dimensions: :return: """ def function(x): return 4 * x[0]**2 - 2.1 * x[0]**4 + ( 1 / 3) * x[0]**6 + x[0] * x[1] - 4 * x[1]**2 + 4 * x[1]**4 return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=-1.0316, name="16")
def f17(domain=(-5, 15), dimensions=2): """ P. Branin Function Dimensions: 2 Domain: -5 -> 15 Minimum value: f(9.42,2.47) = 0.398 :param domain: :param dimensions: :return: """ def function(x): return ((x[1] - (5.1 / (4*(math.pi**2))) * (x[0]**2) + (5/math.pi)*x[0] - 6)**2) + 10*(1 - (1/(8*math.pi))) * \ math.cos(x[0])+10 return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0.398, name="17")
def f9(domain=(-5.12, 5.12), dimensions=30): """ Generalised Rastrigin's Function Domain: -5.12 -> 5.12 Minimum value: f(0) = 0 :param domain: :param dimensions: :return: """ def function(x): sum = 0 for i in range(len(x)): sum += (x[i]**2) - 10 * math.cos(2 * math.pi * x[i]) + 10 return sum return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0, name="9")
def f6(domain=(-100, 100), dimensions=30): """ Step Function Domain: -100 -> 100 Minimum value: f(p) = 0, -0.5 <= p <= 0.5 :param domain: :param dimensions: :return: """ def function(x): sum = 0 for i in range(len(x)): sum += (abs(x[i] + 0.5))**2 return sum return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0, name="6")
def f5(domain=(-30, 30), dimensions=30): """ Generalised Rosenbrock's Function Domain: -30 -> 30 Minimum value: f(1) = 0 :param domain: :param dimensions: :return: """ def function(x): sum = 0 for i in range(len(x) - 1): sum += 100 * (x[i + 1] - (x[i]**2))**2 + (x[i] - 1)**2 return sum return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0, name="5")
def f4(domain=(-100, 100), dimensions=30): """ Domain: -100 -> 100 Minimum value: f(0) = 0 :param domain: :param dimensions: :return: """ def function(x): max = None for i in range(len(x)): if max is None or abs(x[i]) > max: max = abs(x[i]) return max return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0, name="4")
def f1(domain=(-5.12, 5.12), dimensions=30): """ Sphere Model Domain: -5.12 -> 5.12 Minimum Value: f(0) = 0 :param domain: :param dimensions: :return: """ def function(x): sum = 0 for i in range(len(x)): sum += x[i]**2 return sum return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0, name="1")
def f7(domain=(-1.28, 1.28), dimensions=30): """ Quartic Function i.e. Noise Domain: -1.28 -> 1.28 Minimum value: f(0) = 0 :param domain: :param dimensions: :return: """ def function(x): sum = 0 for i in range(len(x)): sum += (i + 1) * x[i]**4 sum += random.uniform(0, 1) return sum return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0, name="7")
def f8(domain=(-500, 500), dimensions=30): """ Generalised Schwefel's Problem 2.26 Domain: -500 -> 500 Minimum value: f(420.97) = -12569.5(30)/41898.3(100) :param domain: :param dimensions: :return: """ def function(x): sum = 0 n = len(x) for i in range(n): sum += -x[i] * math.sin(math.sqrt(abs(x[i]))) return sum min_value = -418.9829 * dimensions return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=min_value, name="8")
def f11(domain=(-600, 600), dimensions=30): """ Generalised Griewank Function Domain: -600 -> 600 Minimum value: f(0) = 0 :param domain: :param dimensions: :return: """ def function(x): sum = 0 prod = 0 for i in range(len(x)): sum += x[i]**2 prod *= math.cos(x[i] / (math.sqrt(i + 1))) total = (1 / 4000) * sum + prod return total return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0, name="11")
def f3(domain=(-100, 100), dimensions=30): """ Schwefel's Problem 1.2 Domain: -100 -> 100 Minimum value: f(0) = 0 :param domain: :param dimensions: :return: """ def function(x): sum = 0 for i in range(len(x)): secondsum = 0 for j in range(i): secondsum += x[j] sum += secondsum**2 return sum return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0, name="3")
def f18(domain=(-2, 2), dimensions=2): """ Q. Goldstein-Price Function Dimensions: 2 Domain: -2 -> 2 Minimum value: f(0,-1) = 3 :param domain: :param dimensions: :return: """ def function(x): return ((1 + ((x[0] + x[1] + 1)**2) * (19 - (14 * x[0]) + ((3 * x[0])**2) - (14 * x[1]) + (6 * x[0] * x[1]) + ((3 * x[1])**2))) * (30 + (((2 * x[0]) - (3 * x[1]))**2) * (18 - (32 * x[0]) + (12 * (x[0]**2)) + (48 * x[1]) - (36 * x[0] * x[1]) + (27 * (x[1]**2))))) return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=3, name="18")
def f2(domain=(-10, 10), dimensions=30): """ Schwefel's Problem 2.22 Domain: -10 -> 10 Minimum value: f(0) = 0 :param domain: :param dimensions: :return: """ def function(x): sum = 0 prod = 0 for i in range(len(x)): sum += abs(x[i]) prod *= abs(x[i]) total = sum + prod return total return Benchmark(function=function, domain=domain, dimensions=dimensions, min_value=0, name="2")