Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/src/go-pge/main_post.go

Last change on this file was 16666, checked in by hmaislin, 6 years ago

#2929: Modified make / folder structure to build original app, added x86 dll

File size: 4.1 KB
Line 
1package main
2
3import (
4  "bufio"
5  "bytes"
6  "fmt"
7  "io/ioutil"
8  "os"
9  exec "os/exec"
10  "sort"
11  "text/template"
12)
13
14func post(DS *MainSearch) {
15
16  fmt.Printf("\n\nMain - Post Processing\n======================\n\n")
17
18  DC := DS.cnfg
19  // setup log dir and open main log files
20  basedir, _ := os.Open(DC.logDir)
21  subdirs, _ := basedir.Readdirnames(0)
22  sort.Strings(subdirs)
23
24  for _, sdir := range subdirs {
25    processProblemDir(sdir, DC.logDir+sdir)
26  }
27
28}
29
30func processProblemDir(probstr, dirstr string) {
31  outdir := "out/bench/" + probstr
32
33  pdir, _ := os.Open(dirstr)
34  rundirs, _ := pdir.Readdirnames(0)
35  sort.Strings(rundirs)
36  fmt.Printf("ProbDir %s\n", probstr)
37
38  var results []runResults
39  for r, rdir := range rundirs {
40    ret := processRunDir(r, dirstr+"/"+rdir)
41    results = append(results, ret)
42  }
43
44  var genErr []aveErr
45  for j := 1; j < len(results[0].genErr); j++ {
46    ave, best := 0.0, 0.0
47    for i := 0; i < len(results); i++ {
48      if results[i].genErr[j].gen < 1 {
49        continue
50      }
51      // fmt.Printf("%d %d %d\n", i, j, results[i].genErr[j].gen)
52      ave += results[i].genErr[j].err
53      best += results[i].genErr[j].best
54    }
55    gen := j * 10
56    ave /= float64(len(results))
57    best /= float64(len(results))
58    tmp := aveErr{gen, ave, best}
59    fmt.Printf("Gen: %v\n", tmp)
60
61    genErr = append(genErr, tmp)
62  }
63
64  makeGraph(probstr, outdir, genErr)
65
66  fmt.Println("\n\n\n")
67}
68
69type aveErr struct {
70  gen  int
71  err  float64
72  best float64
73}
74
75type bestEqn struct {
76  pos     int
77  eqn_str string
78  latex   string
79  size    int
80  err     float64
81}
82
83type runResults struct {
84  genErr []aveErr
85  eqns   []bestEqn
86}
87
88func processRunDir(run int, dirstr string) (ret runResults) {
89
90  fmt.Println("  run ", run, " ", dirstr)
91
92  ret.genErr = make([]aveErr, 101)
93
94  gpsr_eqn_data, _ := ioutil.ReadFile(dirstr + "/gpsr/gpsr:eqns.log")
95  lines := bytes.Split(gpsr_eqn_data, []byte("\n"))
96
97  var (
98    str, tmp         string
99    gen, cnt         int
100    pos, size        int
101    terr, tsum, tmin float64
102    latex, eqn_str   string
103  )
104
105  for l := 0; l < len(lines); l++ {
106    _, err := fmt.Sscanf(string(lines[l]), "%s %d %d", &str, &gen, &cnt)
107    if err != nil {
108      // fmt.Println("Err on GEN line: ", err)
109      break
110    }
111    // fmt.Println("    Gen: ", gen)
112    tsum = 0.0
113    tmin = 1000000.0
114    for i := 0; i < cnt; i++ {
115      l++
116      fmt.Sscanf(string(lines[l]), "%d", &pos)
117      latex = string(bytes.TrimSpace(lines[l][2:]))
118      l++
119      eqn_str = string(lines[l])
120      l++
121      fmt.Sscanf(string(lines[l]), "%s %d", &str, &size)
122      l += 5
123      fmt.Sscanf(string(lines[l]), "%s %s %f", &str, &tmp, &terr)
124      if terr < tmin {
125        tmin = terr
126      }
127      tsum += terr
128      l += 2
129      _ = latex
130      _ = eqn_str
131
132      if gen == 1000 {
133        var eqn bestEqn
134        eqn.pos = i
135        eqn.eqn_str = eqn_str
136        eqn.latex = latex
137        eqn.err = terr
138        eqn.size = size
139        ret.eqns = append(ret.eqns, eqn)
140        // if i < 12 {
141        //  fmt.Printf("    %d %s  %d %f\n", i, latex, size, terr)
142        // }
143      }
144    }
145    var gerr aveErr
146    gerr.gen = gen
147    gerr.err = terr
148    gerr.best = tmin
149    ret.genErr[gen/10] = gerr
150    // fmt.Printf("Gen: %d  %f  %f\n", gen, tsum/float64(cnt), tmin)
151
152  }
153  return
154}
155
156func makeGraph(prob, dir string, genErr []aveErr) {
157
158  dataFN := dir + "/errData.txt"
159  gnuFN := dir + "/plotData.gnu"
160  plotFN := dir + "/" + prob
161
162  dataFile, _ := os.Create(dataFN)
163  out := bufio.NewWriter(dataFile)
164
165  for _, pnt := range genErr {
166    fmt.Fprintln(out, pnt.gen, pnt.err, pnt.best)
167  }
168
169  out.Flush()
170  dataFile.Close()
171
172  pInfo := plotInfo{plotFN, dataFN, prob}
173
174  gnuFile, _ := os.Create(gnuFN)
175  gout := bufio.NewWriter(gnuFile)
176
177  tmpl, err := template.New("gnu").Parse(plot_file)
178  if err != nil {
179    panic(err)
180  }
181  err = tmpl.Execute(gout, pInfo)
182  if err != nil {
183    panic(err)
184  }
185
186  gout.Flush()
187  gnuFile.Close()
188
189  cmd := exec.Command("gnuplot", gnuFN)
190  err = cmd.Run()
191  if err != nil {
192    panic(err)
193  }
194}
195
196type plotInfo struct {
197  Outfn string
198  Infn  string
199  Prob  string
200}
201
202var plot_file = `
203set term postscript enhanced
204set output '{{.Outfn}}.png'
205
206set style line 1 lt 1 lc rgb "blue" lw 1
207set style line 2 lt 1 lc rgb "black" lw 1
208set style line 3 lt 1 lc rgb "red" lw 1
209set autoscale
210plot '{{.Infn}}' using 1:2 with lines ls 2, '' using 1:3 with lines ls 1
211
212`
213
214var eqn_tex_file = `
215\subsection*\{ {{}} \}
216
217`
Note: See TracBrowser for help on using the repository browser.