diff --git a/algo/algo.go b/algo/algo.go index 5f24c01..adcff07 100644 --- a/algo/algo.go +++ b/algo/algo.go @@ -57,9 +57,9 @@ func DoRandomSearch(wg *sync.WaitGroup, m *sync.Mutex) { // protect access to shared data. m.Lock() report.SavePicsToFile(pLs, "Random Search") - m.Unlock() stats.SaveTable("Random Search", algoStats) + m.Unlock() } // DoStochasticHillClimbing performs a search using the 'Stochastic Hill @@ -104,9 +104,9 @@ func DoStochasticHillClimbing(wg *sync.WaitGroup, m *sync.Mutex) { // protect access to shared data. m.Lock() report.SavePicsToFile(pLs, "Stochastic Hill Climbing") - m.Unlock() stats.SaveTable("Stochastic Hill CLimbing", algoStats) + m.Unlock() } func newValues() *Values { diff --git a/main.go b/main.go index b93c740..5430f84 100644 --- a/main.go +++ b/main.go @@ -31,6 +31,7 @@ func main() { wg.Wait() report.SaveTexAllPics() + report.SaveTexAllTables() report.Print() log.Println("looks like we're done") diff --git a/report/allTables.go b/report/allTables.go new file mode 100644 index 0000000..62caac7 --- /dev/null +++ b/report/allTables.go @@ -0,0 +1,53 @@ +// Copyright 2022 wanderer +// SPDX-License-Identifier: GPL-3.0-or-later + +package report + +import ( + _ "embed" + "log" + "os" + "text/template" + "time" +) + +type tableTexFiles struct { + Algo string + FilePaths []string +} + +type allTheTables struct { + TexFiles []tableTexFiles +} + +var ( + allTables = &allTheTables{} + //go:embed alltables.tmpl + tmplAllTablesFile []byte +) + +func SaveTexAllTables() { + a := allTables + texAllTablesFile := GetTexDir() + "alltables" + ".tex" + + tmplAllTables := template.New("alltables") + tmplAllTables = template.Must(tmplAllTables.Parse(string(tmplAllTablesFile))) + + f, err := os.Create(texAllTablesFile) + if err != nil { + log.Println(err) + } + defer f.Close() + + err = tmplAllTables.Execute(f, struct { + AllTables allTheTables + Timestamp time.Time + }{ + AllTables: *a, + Timestamp: time.Now(), + }) + + if err != nil { + log.Println(err) + } +} diff --git a/report/alltables.tmpl b/report/alltables.tmpl new file mode 100644 index 0000000..f2e4bda --- /dev/null +++ b/report/alltables.tmpl @@ -0,0 +1,17 @@ +% Code generated by math-optim; DO NOT EDIT. +% +% This file was generated by robots at +% {{ .Timestamp }} +% source: git.dotya.ml/wanderer/math-optim/report/alltables.tmpl + +% This file is a part of the math-optim project. +% project homepage: https://git.dotya.ml/wanderer/math-optim/ + +\section{Per-algo benchmark comparison statistics} +{{ range $i, $v := .AllTables.TexFiles }} +{{- range $j, $u := $v.FilePaths }} +\include{ {{- $u -}} } +{{- end -}} +{{ end }} + +% vim: ft=gotexttmpl.tex ts=2 sts=2 sw=2 bs=2 expandtab diff --git a/report/table.go b/report/table.go index 62c00d3..15efe4d 100644 --- a/report/table.go +++ b/report/table.go @@ -49,6 +49,9 @@ func SaveTableToFile(t Table) { tmplTable := template.Must(template.ParseFiles(tmplTableFile)) + ttf := tableTexFiles{Algo: t.Algo, FilePaths: []string{texTableFile}} + allTables.TexFiles = append(allTables.TexFiles, ttf) + f, err := os.Create(texTableFile) if err != nil { log.Println(err)