diff --git a/bench/cec2020/helperFunctions.go b/bench/cec2020/helperFunctions.go index 2534b86..80c8936 100644 --- a/bench/cec2020/helperFunctions.go +++ b/bench/cec2020/helperFunctions.go @@ -3,6 +3,8 @@ package cec2020 +import "math" + // void hf01 (double *, double *, int, double *,double *, int *,int, int); // Hybrid Function 1 // void hf02 (double *, double *, int, double *,double *, int *,int, int); // Hybrid Function 2 // void hf03 (double *, double *, int, double *,double *, int *,int, int); // Hybrid Function 3 @@ -31,3 +33,68 @@ package cec2020 // void asyfunc (double *, double *x, int, double); // void oszfunc (double *, double *, int); // void cf_cal(double *, double *, int, double *,double *,double *,double *,int); + +// Shift shifts values of x based on values of os. +func Shift(x []float64, os []float64) { + if len(x) != len(os) { + cec2020Logger.Fatalln("slices are of different sizes, bailing...") + } + + for i := range x { + x[i] -= os[i] + } +} + +// Rotate rotates values of x based on values of mr. +func Rotate(x []float64, mr []float64) { + nx := len(x) + + if int(math.Pow(float64(nx), 2)) > len(mr) { + cec2020Logger.Fatalf("either x is too big or mr is of insufficient size (%d:%d), bailing...\n", nx, len(mr)) + } + + xrot := make([]float64, nx) + + for i := 0; i < nx; i++ { + for j := 0; j < nx; j++ { + x[j] += xrot[i] + (x[j] * mr[(i*nx)+j]) + } + } +} + +// ShiftRotate shifts and/or rotates the input x based on the request params +// shift and rotate (bool), using the values of os and/or mr. +func ShiftRotate(x []float64, os []float64, mr []float64, shiftRate float64, shift, rotate bool) { + switch { + case shift && rotate: + Shift(x, os) + + // shrink to the original search range. + for i := range x { + x[i] *= shiftRate + } + + Rotate(x, mr) + + case shift && !rotate: + Shift(x, os) + + // shrink to the original search range. + for i := range x { + x[i] *= shiftRate + } + + case !shift && rotate: + // shrink to the original search range + for i := range x { + x[i] *= shiftRate + } + + Rotate(x, mr) + + case !shift && !rotate: + for i := range x { + x[i] *= shiftRate + } + } +} diff --git a/bench/cec2020/log.go b/bench/cec2020/log.go new file mode 100644 index 0000000..5e566e4 --- /dev/null +++ b/bench/cec2020/log.go @@ -0,0 +1,12 @@ +// Copyright 2023 wanderer +// SPDX-License-Identifier: GPL-3.0-or-later + +package cec2020 + +import ( + "log" + "os" +) + +// cec2020Logger declares and initialises a "custom" logger. +var cec2020Logger = log.New(os.Stderr, " *** ∁ cec2020:", log.Ldate|log.Ltime|log.Lshortfile)