diff --git a/algo/stochasticHillClimbing.go b/algo/stochasticHillClimbing.go index 7746bf5..e553a2f 100644 --- a/algo/stochasticHillClimbing.go +++ b/algo/stochasticHillClimbing.go @@ -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))