Changeset 3238 for trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntExpressionGrammar.cs
- Timestamp:
- 03/30/10 19:40:13 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntExpressionGrammar.cs
r3223 r3238 24 24 using System.Collections.Generic; 25 25 using System; 26 using System.Linq; 26 27 using HeuristicLab.Core; 27 28 namespace HeuristicLab.Problems.ArtificialAnt { … … 142 143 143 144 #endregion 145 146 #region ISymbolicExpressionGrammar Members 147 148 149 public bool IsValidExpression(SymbolicExpressionTree expression) { 150 if (expression.Root.Symbol != StartSymbol) return false; 151 return IsValidExpression(expression.Root); 152 } 153 154 #endregion 155 156 private bool IsValidExpression(SymbolicExpressionTreeNode root) { 157 if (root.SubTrees.Count < MinSubTrees(root.Symbol)) return false; 158 if (root.SubTrees.Count > MaxSubTrees(root.Symbol)) return false; 159 for (int i = 0; i < root.SubTrees.Count; i++) { 160 if (!AllowedSymbols(root.Symbol, i).Contains(root.SubTrees[i].Symbol)) return false; 161 if (!IsValidExpression(root.SubTrees[i])) return false; 162 } 163 return true; 164 } 144 165 } 145 166 }
Note: See TracChangeset
for help on using the changeset viewer.