- Timestamp:
- 08/20/08 08:24:10 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Functions/BakedTreeEvaluator.cs
r483 r523 68 68 instr.symbol = EvaluatorSymbolTable.MapFunction(f.functionType); 69 69 switch(instr.symbol) { 70 case EvaluatorSymbolTable.DIFFERENTIAL: 70 case EvaluatorSymbolTable.DIFFERENTIAL: 71 71 case EvaluatorSymbolTable.VARIABLE: { 72 72 instr.i_arg0 = (int)f.data[0]; // var … … 87 87 this.sampleIndex = sampleIndex; 88 88 return EvaluateBakedCode(); 89 } 90 91 // skips a whole branch 92 private void SkipBakedCode() { 93 int i = 1; 94 while(i > 0) { 95 i+=codeArr[PC++].arity; 96 i--; 97 } 89 98 } 90 99 … … 179 188 } 180 189 case EvaluatorSymbolTable.AND: { // only defined for inputs 1 and 0 181 double result = 1.0;182 // have to evaluate all sub-trees, skipping would probably not lead to a big gain because183 // we have to iterate over the linear structure anyway184 for(int i = 0; i < currInstr.arity; i++){185 double x= EvaluateBakedCode();186 Debug.Assert(x == 0.0 || x == 1.0);187 result *= x;190 double result = EvaluateBakedCode(); 191 for(int i = 1; i < currInstr.arity; i++) { 192 if(result == 0.0) SkipBakedCode(); 193 else { 194 result = EvaluateBakedCode(); 195 } 196 Debug.Assert(result == 0.0 || result == 1.0); 188 197 } 189 198 return result; … … 203 212 double condition = EvaluateBakedCode(); 204 213 Debug.Assert(condition == 0.0 || condition == 1.0); 205 double x = EvaluateBakedCode(); 206 double y = EvaluateBakedCode(); 207 return condition * y - (condition - 1) * x; 214 double result; 215 if(condition == 0.0) { 216 result = EvaluateBakedCode(); SkipBakedCode(); 217 } else { 218 SkipBakedCode(); result = EvaluateBakedCode(); 219 } 220 return result; 208 221 } 209 222 case EvaluatorSymbolTable.LT: { … … 219 232 } 220 233 case EvaluatorSymbolTable.OR: { // only defined for inputs 0 or 1 221 double result = 0.0; // default is false 222 for(int i = 0; i < currInstr.arity; i++) { 223 double x = EvaluateBakedCode(); 224 Debug.Assert(x == 0.0 || x == 1.0); 225 result += x; 226 } 227 return Math.Sign(result); 234 double result = EvaluateBakedCode(); 235 for(int i = 1; i < currInstr.arity; i++) { 236 if(result > 0.0) SkipBakedCode(); 237 else { 238 result = EvaluateBakedCode(); 239 Debug.Assert(result == 0.0 || result == 1.0); 240 } 241 } 242 return result; 228 243 } 229 244 case EvaluatorSymbolTable.XOR: { // only defined for inputs 0 or 1 … … 232 247 return Math.Abs(x - y); 233 248 } 249 case EvaluatorSymbolTable.UNKNOWN: 234 250 default: { 235 251 throw new NotImplementedException();
Note: See TracChangeset
for help on using the changeset viewer.