Changeset 11895 for branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization
- Timestamp:
- 02/05/15 07:03:15 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/ExpressionInterpreter.cs
r11848 r11895 17 17 // interprets sentences from L(G(Expr)): 18 18 // Expr -> Term { ('+' | '-' | '^' ) Term } 19 // Term -> Fact { ('*' | ' /') Fact }19 // Term -> Fact { ('*' | '%') Fact } 20 20 // Fact -> '!' Expr | '(' Expr ')' | Var | const 21 21 // Var -> 'a'..'z' 22 22 // const -> '0' .. '9' 23 23 24 // uses protected division symbol % 24 25 // constants are Koza-style ephemeral random constants (ERC). for now we only allow up to 10 constants. 25 26 // The constant symbols '0' .. '9' are treated as ERC indices … … 35 36 var d = new double[vars.Length]; 36 37 for (int i = 0; i < vars.Length; i++) d[i] = vars[i] ? 1.0 : 0.0; 37 return ! 38 return !DoubleExtensions.IsAlmost(Expr(d, erc), 0); 38 39 } 39 40 … … 73 74 if (curSy == '+') { 74 75 NewSy(); 75 r += Expr(d, erc);76 r += Term(d, erc); 76 77 } else if (curSy == '-') { 77 78 NewSy(); 78 r -= Expr(d, erc);79 r -= Term(d, erc); 79 80 } else { 80 81 NewSy(); 81 var e = Expr(d, erc); 82 r = Not(r) * e + r * Not(e); // xor = (!x AND y) OR (x AND !y) 82 throw new NotImplementedException(); 83 // var e = Expr(d, erc); 84 // r = Not(r) * e + r * Not(e); // xor = (!x AND y) OR (x AND !y) 83 85 } 84 86 curSy = CurSy(); … … 91 93 r = Fact(d, erc); 92 94 var curSy = CurSy(); 93 while (curSy == '*' || curSy == ' /') {95 while (curSy == '*' || curSy == '%') { 94 96 if (curSy == '*') { 95 97 NewSy(); 96 r *= Term(d, erc);98 r *= Fact(d, erc); 97 99 } else { 98 100 NewSy(); 99 r /= Term(d, erc); 101 var nom = Fact(d, erc); 102 if (HeuristicLab.Common.Extensions.IsAlmost(nom, 0.0)) nom = 1.0; 103 r /= nom; 100 104 } 101 105 curSy = CurSy();
Note: See TracChangeset
for help on using the changeset viewer.