From d2c4f2b1db6ab9af5b394848fa868b97c8cb692a Mon Sep 17 00:00:00 2001 From: surtur Date: Fri, 24 Jun 2022 00:56:10 +0200 Subject: [PATCH] go: add a way to iterate over func names for stats --- algo/algo.go | 8 ++++---- bench/functions.go | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/algo/algo.go b/algo/algo.go index 50fa8ef..7cbf605 100644 --- a/algo/algo.go +++ b/algo/algo.go @@ -27,10 +27,10 @@ func DoRandomSearch(wg *sync.WaitGroup) { // stats for the current algo (RandomSearch). algoStats := make([][]stats.Stats, funcCount) - // ng y'all. - algoStats[0] = RandomSearchNG(10000, 30, []int{5, 10, 20}, "Schwefel") - algoStats[1] = RandomSearchNG(10000, 30, []int{5, 10, 20}, "De Jong 1st") - algoStats[2] = RandomSearchNG(10000, 30, []int{5, 10, 20}, "De Jong 2nd") + for i := range algoStats { + // ng y'all. + algoStats[i] = RandomSearchNG(10000, 30, []int{5, 10, 20}, bench.FuncNames[i]) + } for i := range algoStats { plotAllDims(algoStats[i], "plot", ".svg") diff --git a/bench/functions.go b/bench/functions.go index 1228e78..7198dba 100644 --- a/bench/functions.go +++ b/bench/functions.go @@ -13,6 +13,12 @@ var Functions = map[string]func([]float64) float64{ "De Jong 2nd": DeJong2nd, } +var FuncNames = map[int]string{ + 0: "Schwefel", + 1: "De Jong 1st", + 2: "De Jong 2nd", +} + // Function params maps function names to their funcParams for easier iterable // access. var FunctionParams = map[string]funcParams{