Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/15/11 13:34:38 (14 years ago)
Author:
mkommend
Message:

#1418: Finally added results from the grammar refactoring.

Location:
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/ArithmeticExpressionGrammar.cs

    r5580 r5686  
    2929  [StorableClass]
    3030  [Item("ArithmeticExpressionGrammar", "Represents a grammar for functional expressions using only arithmetic operations.")]
    31   public class ArithmeticExpressionGrammar : DefaultSymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
     31  public class ArithmeticExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
    3232
    3333    [StorableConstructor]
     
    5959
    6060      foreach (var funSymb in functionSymbols) {
    61         SetMinSubtreeCount(funSymb, 1);
    62         SetMaxSubtreeCount(funSymb, 3);
     61        SetSubtreeCount(funSymb, 1, 3);
    6362      }
    64       SetMinSubtreeCount(constant, 0);
    65       SetMaxSubtreeCount(constant, 0);
    66       SetMinSubtreeCount(variableSymbol, 0);
    67       SetMaxSubtreeCount(variableSymbol, 0);
     63      SetSubtreeCount(constant, 0, 0);
     64      SetSubtreeCount(variableSymbol, 0, 0);
    6865
    6966      // allow each symbol as child of the start symbol
    7067      foreach (var symb in allSymbols) {
    71         SetAllowedChild(StartSymbol, symb, 0);
     68        AddAllowedChildSymbol(StartSymbol, symb);
    7269      }
    7370
    7471      // allow each symbol as child of every other symbol (except for terminals that have maxSubtreeCount == 0)
    75       foreach (var parent in allSymbols) {
    76         for (int i = 0; i < GetMaxSubtreeCount(parent); i++)
    77           foreach (var child in allSymbols) {
    78             SetAllowedChild(parent, child, i);
    79           }
     72      foreach (var parent in functionSymbols) {
     73        foreach (var child in allSymbols)
     74          AddAllowedChildSymbol(parent, child);
    8075      }
    8176    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs

    r5580 r5686  
    2121
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    2930  [StorableClass]
    3031  [Item("FullFunctionalExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")]
    31   public class FullFunctionalExpressionGrammar : DefaultSymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
     32  public class FullFunctionalExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
    3233    [StorableConstructor]
    3334    protected FullFunctionalExpressionGrammar(bool deserializing) : base(deserializing) { }
     
    9293
    9394      foreach (var funSymb in functionSymbols) {
    94         SetMinSubtreeCount(funSymb, 1);
    95         SetMaxSubtreeCount(funSymb, 3);
     95        SetSubtreeCount(funSymb, 1, 3);
    9696      }
    9797      foreach (var funSymb in unaryFunctionSymbols) {
    98         SetMinSubtreeCount(funSymb, 1);
    99         SetMaxSubtreeCount(funSymb, 1);
     98        SetSubtreeCount(funSymb, 1, 1);
    10099      }
    101100      foreach (var funSymb in binaryFunctionSymbols) {
    102         SetMinSubtreeCount(funSymb, 2);
    103         SetMaxSubtreeCount(funSymb, 2);
     101        SetSubtreeCount(funSymb, 2, 2);
     102      }
     103      foreach (var terminalSymbol in terminalSymbols) {
     104        SetSubtreeCount(terminalSymbol, 0, 0);
    104105      }
    105106
    106       foreach (var terminalSymbol in terminalSymbols) {
    107         SetMinSubtreeCount(terminalSymbol, 0);
    108         SetMaxSubtreeCount(terminalSymbol, 0);
    109       }
    110 
    111       SetMinSubtreeCount(@if, 3);
    112       SetMaxSubtreeCount(@if, 3);
     107      SetSubtreeCount(@if, 3, 3);
    113108
    114109
    115110      // allow each symbol as child of the start symbol
    116111      foreach (var symb in allSymbols) {
    117         SetAllowedChild(StartSymbol, symb, 0);
     112        AddAllowedChildSymbol(StartSymbol, symb);
    118113      }
    119114
    120115      // allow each symbol as child of every other symbol (except for terminals that have maxSubtreeCount == 0)
    121       foreach (var parent in allSymbols) {
    122         for (int i = 0; i < GetMaxSubtreeCount(parent); i++)
    123           foreach (var child in allSymbols) {
    124             SetAllowedChild(parent, child, i);
    125           }
     116      foreach (var parent in allSymbols.Except(terminalSymbols)) {
     117        foreach (var child in allSymbols)
     118          AddAllowedChildSymbol(parent, child);
    126119      }
    127120    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs

    r5580 r5686  
    2929  [StorableClass]
    3030  [Item("TypeCoherentExpressionGrammar", "Represents a grammar for functional expressions in which special syntactic constraints are enforced so that boolean and real-valued expressions are not mixed.")]
    31   public class TypeCoherentExpressionGrammar : DefaultSymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
     31  public class TypeCoherentExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
    3232
    3333    [StorableConstructor]
     
    123123
    124124      foreach (var unaryFun in unaryFunctionSymbols.Concat(unaryBooleanFunctionSymbols)) {
    125         SetMinSubtreeCount(unaryFun, 1);
    126         SetMaxSubtreeCount(unaryFun, 1);
     125        SetSubtreeCount(unaryFun, 1, 1);
    127126      }
    128127      foreach (var binaryFun in binaryFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols)) {
    129         SetMinSubtreeCount(binaryFun, 2);
    130         SetMaxSubtreeCount(binaryFun, 2);
     128        SetSubtreeCount(binaryFun, 2, 2);
    131129      }
    132130
    133131      foreach (var terminalSymbol in terminalSymbols) {
    134         SetMinSubtreeCount(terminalSymbol, 0);
    135         SetMaxSubtreeCount(terminalSymbol, 0);
     132        SetSubtreeCount(terminalSymbol, 0, 0);
    136133      }
    137134
    138       SetMinSubtreeCount(@if, 3);
    139       SetMaxSubtreeCount(@if, 3);
     135      SetSubtreeCount(@if, 3, 3);
    140136
    141137
    142138      // allow only real-valued expressions as child of the start symbol
    143139      foreach (var symb in realValuedSymbols) {
    144         SetAllowedChild(StartSymbol, symb, 0);
     140        AddAllowedChildSymbol(StartSymbol, symb);
    145141      }
    146142
    147143      foreach (var symb in unaryFunctionSymbols) {
    148144        foreach (var childSymb in realValuedSymbols) {
    149           SetAllowedChild(symb, childSymb, 0);
     145          AddAllowedChildSymbol(symb, childSymb);
    150146        }
    151147      }
     
    153149      foreach (var symb in binaryFunctionSymbols) {
    154150        foreach (var childSymb in realValuedSymbols) {
    155           SetAllowedChild(symb, childSymb, 0);
    156           SetAllowedChild(symb, childSymb, 1);
     151          AddAllowedChildSymbol(symb, childSymb);
    157152        }
    158153      }
    159154
    160155      foreach (var childSymb in booleanSymbols) {
    161         SetAllowedChild(@if, childSymb, 0);
     156        AddAllowedChildSymbol(@if, childSymb, 0);
    162157      }
    163158      foreach (var childSymb in realValuedSymbols) {
    164         SetAllowedChild(@if, childSymb, 1);
    165         SetAllowedChild(@if, childSymb, 2);
     159        AddAllowedChildSymbol(@if, childSymb, 1);
     160        AddAllowedChildSymbol(@if, childSymb, 2);
    166161      }
    167162
    168163      foreach (var symb in relationalFunctionSymbols) {
    169164        foreach (var childSymb in realValuedSymbols) {
    170           SetAllowedChild(symb, childSymb, 0);
    171           SetAllowedChild(symb, childSymb, 1);
     165          AddAllowedChildSymbol(symb, childSymb);
    172166        }
    173167      }
    174168      foreach (var symb in binaryBooleanFunctionSymbols) {
    175169        foreach (var childSymb in booleanSymbols) {
    176           SetAllowedChild(symb, childSymb, 0);
    177           SetAllowedChild(symb, childSymb, 1);
     170          AddAllowedChildSymbol(symb, childSymb);
    178171        }
    179172      }
    180173      foreach (var symb in unaryBooleanFunctionSymbols) {
    181174        foreach (var childSymb in booleanSymbols) {
    182           SetAllowedChild(symb, childSymb, 0);
     175          AddAllowedChildSymbol(symb, childSymb);
    183176        }
    184177      }
Note: See TracChangeset for help on using the changeset viewer.