algo: add DoCEC2020SOMAT3A func
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-02-23 18:05:18 +01:00
parent 80a9cd5743
commit ead8c80e56
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ

View File

@ -582,3 +582,87 @@ funcCount := len(cec2020.Functions)
stats.SaveTable(algoName, algoStats)
m.Unlock()
}
// DoCEC2020SOMAT3A performs a search using the SOMA T3A method.
func DoCEC2020SOMAT3A(wg *sync.WaitGroup, m *sync.Mutex) {
defer wg.Done()
// funcCount is the number of bench functions available and tested.
funcCount := len(cec2020.Functions)
// stats for the current algo.
algoStats := make([][]stats.Stats, funcCount)
// ch serves as a way to get the actual computed output.
ch := make(chan []stats.Stats, funcCount)
chAlgoMeans := make(chan *stats.AlgoBenchMean, funcCount)
defer close(ch)
defer close(chAlgoMeans)
// somat3a params.
np := 50
k := 10
mSize := 10
n := 5
njumps := 7
for i := range algoStats {
somat3a := ga.NewSOMAT3A()
// params:
// Generations, minimum bench iterations, initial population size,
// leader candidates, migration candidates group size, number of
// migrants, number of jumps each migrant performs, dimensions, bench
// name and synchronisation channels.
//
// -1 to disable generation limits,
// n > 0 for minimum bench iterations,
// np >= k+mSize as initial population size,
// k, mSize, n and njumps >= 0.
err := somat3a.Init(-1, 30, np, k, mSize, n, njumps,
cec2020.Dimensions, cec2020.FuncNames[i],
ch, chAlgoMeans,
)
if err != nil {
log.Panicf("Failed to initialise SOMA T3A, error: %q", err)
}
go somat3a.Run()
}
// get results.
for i := range algoStats {
s := <-ch
aM := <-chAlgoMeans
algoStats[i] = s
saveAlgoMeans(*aM)
}
pCh := make(chan report.PicList, funcCount*len(cec2020.Dimensions))
pMeanCh := make(chan report.PicList, funcCount*len(cec2020.Dimensions))
for _, algoStat := range algoStats {
go plotAllDims(algoStat, "plot", ".pdf", pCh, pMeanCh)
}
pLs := []report.PicList{}
pLsMean := []report.PicList{}
for range algoStats {
pL := <-pCh
pLMean := <-pMeanCh
pLs = append(pLs, pL)
pLsMean = append(pLsMean, pLMean)
}
algoName := "SOMA T3A"
// protect access to shared data.
m.Lock()
report.SavePicsToFile(pLs, pLsMean, algoName)
stats.SaveTable(algoName, algoStats)
m.Unlock()
}