- Timestamp:
- 06/30/10 15:28:07 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/GlobalSymbolicExpressionGrammar.cs
r3885 r3990 40 40 set { 41 41 minFunctionDefinitions = value; 42 Initialize();42 UpdateAdfConstraints(); 43 43 } 44 44 } … … 49 49 set { 50 50 maxFunctionDefinitions = value; 51 Initialize();51 UpdateAdfConstraints(); 52 52 } 53 53 } … … 58 58 set { 59 59 minFunctionArguments = value; 60 Initialize();61 60 } 62 61 } … … 67 66 set { 68 67 maxFunctionArguments = value; 69 Initialize();70 68 } 71 69 } 70 72 71 [Storable] 73 private ISymbolicExpressionGrammar mainBranchGrammar;72 private Defun defunSymbol; 74 73 75 74 public GlobalSymbolicExpressionGrammar() : base() { } // empty constructor for cloning … … 79 78 maxFunctionArguments = 3; 80 79 maxFunctionDefinitions = 3; 81 this.mainBranchGrammar = mainBranchGrammar; 82 Initialize(); 80 Initialize(mainBranchGrammar); 83 81 } 84 82 85 private void Initialize( ) {83 private void Initialize(ISymbolicExpressionGrammar mainBranchGrammar) { 86 84 base.Clear(); 87 85 … … 90 88 91 89 StartSymbol = new ProgramRootSymbol(); 92 vardefunSymbol = new Defun();90 defunSymbol = new Defun(); 93 91 AddSymbol(StartSymbol); 94 92 AddSymbol(defunSymbol); … … 98 96 SetMinSubtreeCount(defunSymbol, 1); 99 97 SetMaxSubtreeCount(defunSymbol, 1); 98 99 // ADF branches maxFunctionDefinitions 100 for (int argumentIndex = 1; argumentIndex < maxFunctionDefinitions + 1; argumentIndex++) { 101 SetAllowedChild(StartSymbol, defunSymbol, argumentIndex); 102 } 100 103 101 104 if (mainBranchGrammar != null) { … … 109 112 // the start symbol of the mainBranchGrammar is allowed as the result producing branch 110 113 SetAllowedChild(StartSymbol, mainBranchGrammar.StartSymbol, 0); 111 112 // ADF branches maxFunctionDefinitions113 for (int argumentIndex = 1; argumentIndex < maxFunctionDefinitions + 1; argumentIndex++) {114 SetAllowedChild(StartSymbol, defunSymbol, argumentIndex);115 }116 114 117 115 // copy syntax constraints from mainBranchGrammar … … 133 131 } 134 132 } 133 private void UpdateAdfConstraints() { 134 SetMinSubtreeCount(StartSymbol, minFunctionDefinitions + 1); 135 SetMaxSubtreeCount(StartSymbol, maxFunctionDefinitions + 1); 136 137 // ADF branches maxFunctionDefinitions 138 for (int argumentIndex = 1; argumentIndex < maxFunctionDefinitions + 1; argumentIndex++) { 139 SetAllowedChild(StartSymbol, defunSymbol, argumentIndex); 140 } 141 } 142 135 143 public override IDeepCloneable Clone(Cloner cloner) { 136 144 GlobalSymbolicExpressionGrammar clone = (GlobalSymbolicExpressionGrammar)base.Clone(cloner); 145 clone.defunSymbol = defunSymbol; 137 146 clone.maxFunctionArguments = maxFunctionArguments; 138 147 clone.maxFunctionDefinitions = maxFunctionDefinitions; 139 148 clone.minFunctionArguments = minFunctionArguments; 140 149 clone.minFunctionDefinitions = minFunctionDefinitions; 141 clone.mainBranchGrammar = (ISymbolicExpressionGrammar)cloner.Clone(mainBranchGrammar);142 150 return clone; 143 151 }
Note: See TracChangeset
for help on using the changeset viewer.