Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/main.go @ 16147

Last change on this file since 16147 was 16080, checked in by hmaislin, 6 years ago

#2929 initial commit of working PGE version

File size: 3.5 KB
Line 
1package main
2
3import (
4  "bufio"
5  "flag"
6  "fmt"
7  log "log"
8  rand "math/rand"
9  os "os"
10  rt "runtime"
11  pprof "runtime/pprof"
12  "strings"
13  "C"
14  probs "github.com/verdverm/go-pge/problems"
15  expr "github.com/verdverm/go-symexpr"
16  tmplt "text/template"
17)
18
19var debug = false
20var numProcs = 12
21
22var cpuprofile = flag.String("prof", "", "write cpu profile to file")
23
24var arg_cfg = flag.String("cfg", "config/main/main_default.cfg", cfg_help_str)
25var arg_pcfg = flag.String("pcfg", "", pcfg_help_str)
26var arg_scfg = flag.String("scfg", "", scfg_help_str)
27var arg_gen = flag.String("gen", "", gen_help_str)
28var arg_tmp = flag.Bool("tmp", false, "run tmp code and exit")
29var arg_post = flag.Bool("post", false, "run output processing code and exit")
30
31var arg_pge_iter = flag.Int("iter", -1, "iterations for PGE")
32var arg_pge_peel = flag.Int("peel", -1, "peel count for PGE")
33var arg_pge_init = flag.String("init", "", "initialize function for PGE")
34var arg_pge_grow = flag.String("grow", "", "expansion function for PGE")
35var arg_pge_evals = flag.Int("evals", 1, "number of evaluater routines")
36
37var cfg_help_str = "A main config file"
38var pcfg_help_str = "A Problem config file"
39var scfg_help_str = "A Search config file"
40var gen_help_str = "Generate Data [bench,diffeq]:[list,all,probname]"
41
42func main() {
43  runmain()
44}
45
46//export runmain
47func runmain() {
48
49  flag.Parse()
50
51  initGo()
52
53  expr.DumpExprTypes()
54
55  if *arg_tmp {
56    printBenchLatex()
57    // tmp()
58    return
59  }
60
61  if *cpuprofile != "" {
62    f, err := os.Create(*cpuprofile)
63    if err != nil {
64      log.Fatal(err)
65    }
66    pprof.StartCPUProfile(f)
67    defer pprof.StopCPUProfile()
68  }
69
70  // if arg_gen = something, then generate data and exit
71  if *arg_gen != "" {
72    if strings.HasPrefix(strings.ToLower(*arg_gen), "bench") {
73      genBenchmark(*arg_gen)
74    } else {
75      fmt.Printf("NOT generating %s data, mwahahaha\n", *arg_gen)
76    }
77    return
78  }
79
80  /*******************************
81        Main Code
82   *******************************/
83
84  var DS MainSearch
85
86  DS.ParseConfig(*arg_cfg)
87
88  if *arg_pcfg != "" {
89    DS.cnfg.probCfg = *arg_pcfg
90  }
91  if *arg_scfg != "" {
92    DS.cnfg.srchCfg = []string{*arg_scfg}
93  }
94
95  if *arg_post {
96    post(&DS)
97    return
98  }
99
100  initDone := make(chan int)
101
102  DS.Init(initDone, nil)
103  // fmt.Printf("initd: %v\n", DS)
104
105  DS.Run()
106
107}
108
109//export testPGE
110func testPGE() int {
111  return 1337
112}
113
114//export runPGE
115func runPGE() { //DS MainSearch, numProcs int) {
116  var DS MainSearch
117  rt.GOMAXPROCS(numProcs)
118  rand.Seed(rand.Int63())
119
120  //if *arg_pcfg != "" {
121  //  DS.cnfg.probCfg = *arg_pcfg
122  //}
123  //if *arg_scfg != "" {
124  //  DS.cnfg.srchCfg = []string{*arg_scfg}
125  //}
126
127  //if *arg_post {
128  //  post(&DS)
129  //  return
130  //}
131
132  initDone := make(chan int)
133
134  DS.Init(initDone, nil)
135  DS.Run()
136}
137
138//export initGo
139func initGo() {
140  fmt.Printf("Initializing Go System (%d threads)\n", numProcs)
141  if debug {
142    rt.GOMAXPROCS(2)
143    rand.Seed(0)
144  } else {
145    rt.GOMAXPROCS(numProcs)
146    rand.Seed(rand.Int63())
147  }
148}
149
150//export tmp
151func tmp() {
152
153  T, err := tmplt.ParseFiles("config/prob/prob_template.txt")
154  if err != nil {
155    log.Fatal("Error reading template file: ", err)
156  }
157
158  fmt.Println("T.name: ", T.Name())
159
160  for _, B := range probs.BenchmarkList {
161
162    ftotal, err2 := os.Create("config/prob/bench/" + B.Name + ".cfg")
163    if err2 != nil {
164      fmt.Printf("Error creating config file: %s  %v\n", B.Name, err)
165      return
166    }
167    file := bufio.NewWriter(ftotal)
168
169    err = T.Execute(os.Stdout, B)
170    err = T.Execute(file, B)
171
172    file.Flush()
173    ftotal.Close()
174  }
175}
Note: See TracBrowser for help on using the repository browser.