Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/bbsr.go @ 16191

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

#2929: Added current DLL to PGE dir that needs to be placed in bin path

File size: 2.0 KB
Line 
1package pge
2
3import (
4  "fmt"
5  // "sort"
6
7  probs "github.com/verdverm/go-pge/problems"
8  expr "github.com/verdverm/go-symexpr"
9)
10
11func (PS *PgeSearch) GenInitExpr() *probs.ReportQueue {
12
13  fmt.Println("Call gen method")
14
15
16  switch PS.cnfg.initMethod {
17  case "method1":
18    return PS.GenInitExprMethod1()
19  case "method2":
20    return PS.GenInitExprMethod2()
21  case "method3":
22    return PS.GenInitExprMethod3()
23  default:
24    fmt.Println("Unknown init method")
25  }
26  return nil
27}
28
29func (PS *PgeSearch) Expand(O expr.Expr) (ret []expr.Expr) {
30  var exprs []expr.Expr
31
32  switch PS.cnfg.growMethod {
33  case "method1":
34    exprs = PS.ExpandMethod1(O)
35  case "method2":
36    exprs = PS.ExpandMethod2(O)
37  case "method3":
38    exprs = PS.ExpandMethod3(O)
39  default:
40    fmt.Println("Unknown expand method")
41  }
42
43  // convert and simplify
44  for i, e := range exprs {
45    if e == nil {
46      continue
47    }
48    defer func() {
49      if r := recover(); r != nil {
50        fmt.Printf("Recovered in Expand %v   %d %v", r, i, e)
51        exprs[i] = nil
52      }
53    }()
54    c := make([]float64, 0)
55    // fmt.Printf("Preconv   %v\n", e)
56    c, eqn := e.ConvertToConstants(c)
57    e.CalcExprStats()
58    // fmt.Printf("Postconv  %v\n", eqn)
59
60    // fmt.Printf("Presimp  %v\n", eqn)
61    exprs[i] = eqn.Simplify(PS.cnfg.simprules)
62    // fmt.Printf("Postsimp  %v\n\n", exprs[i])
63    // serial := make([]int, 0, 64)
64    // serial = exprs[i].Serial(serial)
65    // fmt.Printf("Postsimp  %v   %v\n\n", exprs[i], serial)
66  }
67
68  // sort.Sort(expr.ExprArray(exprs))
69
70  // remove duplicates
71
72  // last := 0
73  // for last < len(exprs) && exprs[last] == nil {
74  //  last++
75  // }
76  // for i := last + 1; i < len(exprs); i++ {
77  //  if exprs[i] == nil {
78  //    continue
79  //  }
80  //  if exprs[i].AmIAlmostSame(exprs[last]) {
81  //    exprs[i] = nil
82  //  } else {
83  //    last = i
84  //  }
85  // }
86
87  // copy to ret, ignoring nil & bad expressions ...
88  for _, e := range exprs {
89    if e == nil {
90      continue
91    }
92    // if !PS.cnfg.treecfg.CheckExpr(e) {
93    //  continue
94    // }
95    ret = append(ret, e)
96  }
97  return ret
98}
Note: See TracBrowser for help on using the repository browser.