go(plot): enable concurrent plotting
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-07-08 22:51:31 +02:00
parent bf08d22549
commit 1c5dfa9818
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 18 additions and 4 deletions

@ -16,6 +16,8 @@ type Values []float64
var picPath = "res/"
var plotWg sync.WaitGroup
// DoRandomSearch executes a search using the 'Random search' method.
func DoRandomSearch(wg *sync.WaitGroup) {
defer wg.Done()
@ -33,10 +35,14 @@ func DoRandomSearch(wg *sync.WaitGroup) {
}
for i := range algoStats {
plotAllDims(algoStats[i], "plot", ".svg")
plotWg.Add(1)
go plotAllDims(algoStats[i], "plot", ".svg", &plotWg)
}
stats.PrintStatisticTable(algoStats)
plotWg.Wait()
}
// DoStochasticHillClimbing performs a search using the 'Stochastic Hill
@ -56,10 +62,14 @@ func DoStochasticHillClimbing(wg *sync.WaitGroup) {
}
for _, algoStat := range algoStats {
plotAllDims(algoStat, "plot", ".svg")
plotWg.Add(1)
go plotAllDims(algoStat, "plot", ".svg", &plotWg)
}
stats.PrintStatisticTable(algoStats)
plotWg.Wait()
}
func newValues() *Values {

@ -6,6 +6,7 @@ package algo
import (
"fmt"
"log"
"sync"
"time"
"git.dotya.ml/wanderer/math-optim/stats"
@ -20,7 +21,9 @@ const preferredFontStyle = "Mono"
// violating the limit of 30, TODO(me): split this up.
// nolint: gocognit
func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string) {
func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string, wg *sync.WaitGroup) {
defer wg.Done() // does this work with panic in the mix? TODO(me): find out.
start := time.Now()
pWidth := 13 * vg.Centimeter
pHeight := 13 * vg.Centimeter
@ -81,7 +84,8 @@ func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string) {
lines...,
)
if err != nil {
log.Fatal(err)
// panic (don't panic, I know) instead of a hard exit.
log.Panic(err)
}
if err := createPath(picPath); err != nil {