Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/27/10 11:44:36 (14 years ago)
Author:
gkronber
Message:

Fixed bugs in persistence of grammars.#937 (Data types and operators for symbolic expression tree encoding)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/GlobalSymbolicExpressionGrammar.cs

    r3484 r3541  
    4040      set {
    4141        minFunctionDefinitions = value;
    42         Reset();
     42        Initialize();
    4343      }
    4444    }
     
    4949      set {
    5050        maxFunctionDefinitions = value;
    51         Reset();
     51        Initialize();
    5252      }
    5353    }
     
    5858      set {
    5959        minFunctionArguments = value;
    60         Reset();
     60        Initialize();
    6161      }
    6262    }
     
    6767      set {
    6868        maxFunctionArguments = value;
    69         Reset();
     69        Initialize();
    7070      }
    7171    }
     
    8383    }
    8484
    85     [StorableHook(HookType.AfterDeserialization)]
    86     private void AfterDeserializationHook() {
    87       Reset();
    88     }
     85    private void Initialize() {
     86      base.Clear();
    8987
    90     private new void Reset() {
    91       base.Reset();
    92       Initialize();
    93     }
    94 
    95     private void Initialize() {
    9688      // remove the start symbol of the default grammar
    9789      RemoveSymbol(StartSymbol);
     
    10799      SetMaxSubtreeCount(defunSymbol, 1);
    108100
    109       // copy symbols from mainBranchGrammar
    110       foreach (var symb in mainBranchGrammar.Symbols) {
    111         AddSymbol(symb);
    112         SetMinSubtreeCount(symb, mainBranchGrammar.GetMinSubtreeCount(symb));
    113         SetMaxSubtreeCount(symb, mainBranchGrammar.GetMaxSubtreeCount(symb));
    114       }
     101      if (mainBranchGrammar != null) {
     102        // copy symbols from mainBranchGrammar
     103        foreach (var symb in mainBranchGrammar.Symbols) {
     104          AddSymbol(symb);
     105          SetMinSubtreeCount(symb, mainBranchGrammar.GetMinSubtreeCount(symb));
     106          SetMaxSubtreeCount(symb, mainBranchGrammar.GetMaxSubtreeCount(symb));
     107        }
    115108
    116       // the start symbol of the mainBranchGrammar is allowed as the result producing branch
    117       SetAllowedChild(StartSymbol, mainBranchGrammar.StartSymbol, 0);
     109        // the start symbol of the mainBranchGrammar is allowed as the result producing branch
     110        SetAllowedChild(StartSymbol, mainBranchGrammar.StartSymbol, 0);
    118111
    119       // ADF branches maxFunctionDefinitions
    120       for (int argumentIndex = 1; argumentIndex < maxFunctionDefinitions + 1; argumentIndex++) {
    121         SetAllowedChild(StartSymbol, defunSymbol, argumentIndex);
    122       }
     112        // ADF branches maxFunctionDefinitions
     113        for (int argumentIndex = 1; argumentIndex < maxFunctionDefinitions + 1; argumentIndex++) {
     114          SetAllowedChild(StartSymbol, defunSymbol, argumentIndex);
     115        }
    123116
    124       // copy syntax constraints from mainBranchGrammar
    125       foreach (var parent in mainBranchGrammar.Symbols) {
    126         for (int i = 0; i < mainBranchGrammar.GetMaxSubtreeCount(parent); i++) {
    127           foreach (var child in mainBranchGrammar.Symbols) {
    128             if (mainBranchGrammar.IsAllowedChild(parent, child, i)) {
    129               SetAllowedChild(parent, child, i);
     117        // copy syntax constraints from mainBranchGrammar
     118        foreach (var parent in mainBranchGrammar.Symbols) {
     119          for (int i = 0; i < mainBranchGrammar.GetMaxSubtreeCount(parent); i++) {
     120            foreach (var child in mainBranchGrammar.Symbols) {
     121              if (mainBranchGrammar.IsAllowedChild(parent, child, i)) {
     122                SetAllowedChild(parent, child, i);
     123              }
    130124            }
    131125          }
    132126        }
    133       }
    134127
    135       // every symbol of the mainBranchGrammar that is allowed as child of the start symbol is also allowed as direct child of defun
    136       foreach (var symb in mainBranchGrammar.Symbols) {
    137         if (mainBranchGrammar.IsAllowedChild(mainBranchGrammar.StartSymbol, symb, 0))
    138           SetAllowedChild(defunSymbol, symb, 0);
     128        // every symbol of the mainBranchGrammar that is allowed as child of the start symbol is also allowed as direct child of defun
     129        foreach (var symb in mainBranchGrammar.Symbols) {
     130          if (mainBranchGrammar.IsAllowedChild(mainBranchGrammar.StartSymbol, symb, 0))
     131            SetAllowedChild(defunSymbol, symb, 0);
     132        }
    139133      }
    140134    }
Note: See TracChangeset for help on using the changeset viewer.