go(algo): add neighbour type
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-08-21 14:26:58 +02:00
parent 1ce3a6d04f
commit 6624d0e9dc
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

View File

@ -17,6 +17,10 @@
"gonum.org/v1/gonum/stat/distuv"
)
// neighbour is an alias for a float64 slice used for more natural handling of
// the underlying data.
type neighbour []float64
func getSHCLogPrefix() string {
return " ***  stochastic hill climbing:"
}
@ -45,7 +49,7 @@ func initValsSHC(dimens uint, vals []float64, uniform *distuv.Uniform) {
// selectBestNeighbour evaluates the randomly generated neighbours passed to it
// as a parameter and points to the best one (the one yielding the greatest
// progress in a favourable way).
func selectBestNeighbour(neighbours [][]float64, benchFuncName string) ([]float64, float64) {
func selectBestNeighbour(neighbours []neighbour, benchFuncName string) ([]float64, float64) {
// bestNeighbour is selected based on the value of the bench function it yields.
var bestNeighbour []float64
@ -91,7 +95,7 @@ func getAllowedTweak(searchSpaceSize float64) float64 {
return bench.MaxNeighbourVariancePercent * (searchSpaceSize * 0.01)
}
func genNeighbours(n, dimens int, benchName string, origin []float64, neighbVals [][]float64) {
func genNeighbours(n, dimens int, benchName string, origin []float64, neighbVals []neighbour) {
if dimens < 1 {
log.Fatalf("error: neighbour count set to: %d; want len(neighbVals) > 0, bailing\n", n)
}
@ -139,7 +143,7 @@ func singleHillClimb(
benchName string,
oldVals []float64,
) ([]float64, float64) {
neighbours := make([][]float64, dimens)
neighbours := make([]neighbour, dimens)
// prealloc the slice the size of dimens (and oldVals, should be the same).
vals := make([]float64, len(oldVals))