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 @ 16231

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

#2929: Fixed result error

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