Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 16620 was 16620, checked in by hmaislin, 5 years ago

#2929: Reorganized folder structure for make script, removed explicit marshalling, erased go-side logging

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