Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/problem.go @ 16231

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

#2929: Fixed result error

File size: 3.1 KB
Line 
1package problems
2
3import (
4  "log"
5  "sort"
6  "strconv"
7  "strings"
8
9  expr "github.com_del/verdverm/go-symexpr"
10)
11
12type ExprProblemType int
13
14const (
15  UnknownPType ExprProblemType = iota
16  ExprBenchmark
17  ExprDiffeq
18  ExprRealData
19)
20
21func (ept ExprProblemType) String() string {
22  switch ept {
23  case ExprBenchmark:
24    return "benchmark"
25  case ExprDiffeq:
26    return "diffeq"
27  case ExprRealData:
28    return "real"
29  default:
30    return "UnknownPType"
31  }
32  return ""
33}
34
35func ProblemTypeFromString(ptype string) ExprProblemType {
36  switch ptype {
37  case "benchmark":
38    return ExprBenchmark
39  case "diffeq":
40    return ExprDiffeq
41  case "real":
42    return ExprRealData
43  default:
44    return UnknownPType
45  }
46  return UnknownPType
47}
48
49type ExprProblem struct {
50  Name     string
51  VarNames []string
52  FuncTree expr.Expr // function as tree
53  MaxIter  int
54
55  // type of evaluation / data
56  SearchType ExprProblemType
57
58  // data
59  TrainFns []string
60  TestFns  []string
61  Train    []*PointSet
62  Test     []*PointSet
63  HitRatio float64
64
65  // variable information
66  SearchVar  int
67  UsableVars []int
68  IndepNames []string
69  DepndNames []string
70  SysNames   []string
71
72  // tree gen/restrict information
73  TreeCfg *TreeParams
74}
75
76type ExprProblemComm struct {
77  // incoming channels
78  Cmds chan int
79
80  // outgoing channels
81  Rpts chan *ExprReportArray
82  Gen  chan [2]int
83}
84
85func ProbConfigParser(field, value string, config interface{}) (err error) {
86
87  EP := config.(*ExprProblem)
88  if EP.TreeCfg == nil {
89    EP.TreeCfg = new(TreeParams)
90  }
91
92  switch strings.ToUpper(field) {
93  case "NAME":
94    EP.Name = value
95  case "PROBLEMTYPE":
96    typ := ProblemTypeFromString(strings.ToLower(value))
97    if typ == UnknownPType {
98      log.Fatalf("Unknown ProblemType in Problem config file\n")
99    } else {
100      EP.SearchType = typ
101    }
102  case "MAXITER":
103    EP.MaxIter, err = strconv.Atoi(value)
104
105  case "HITRATIO":
106    fval, cerr := strconv.ParseFloat(value, 64)
107    if cerr != nil {
108      log.Printf("Expected float64 for HitRatio\n")
109      return cerr
110    }
111    EP.HitRatio = fval
112
113  case "TRAINDATA":
114    EP.TrainFns = strings.Fields(value)
115  case "TESTDATA":
116    EP.TestFns = strings.Fields(value)
117
118  case "USABLEVARS":
119    usable := strings.Fields(value)
120    for _, v := range usable {
121      ival, cerr := strconv.Atoi(v)
122      if cerr != nil {
123        log.Printf("Expected integer for UsableDim\n")
124        return cerr
125      }
126      EP.UsableVars = append(EP.UsableVars, ival)
127    }
128    EP.UsableVars = unique(EP.UsableVars)
129    EP.TreeCfg.UsableVars = EP.UsableVars[:]
130    EP.TreeCfg.UsableVars = unique(EP.TreeCfg.UsableVars)
131
132  case "SEARCHVAR":
133    ival, cerr := strconv.Atoi(value)
134    if cerr != nil {
135      log.Printf("Expected integer for UsableDim\n")
136      return cerr
137    }
138    EP.SearchVar = ival
139
140  default:
141    // check augillary parsable structures [only TreeParams for now]
142    found, ferr := ParseTreeParams(field, value, EP.TreeCfg)
143    if ferr != nil {
144      log.Fatalf("error parsing Problem Config\n")
145      return ferr
146    }
147    if !found {
148      log.Printf("Problem Config Not Implemented: %s, %s\n\n", field, value)
149    }
150
151  }
152  return
153}
154
155func unique(list []int) []int {
156  sort.Ints(list)
157  var last int
158  i := 0
159  for _, x := range list {
160    if i == 0 || x != last {
161      last = x
162      list[i] = x
163      i++
164    }
165  }
166  return list[0:i]
167}
Note: See TracBrowser for help on using the repository browser.