Changeset 5695
- Timestamp:
- 03/15/11 17:03:08 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs
r5691 r5695 49 49 public int MinimumFunctionArguments { 50 50 get { return minimumFunctionArguments; } 51 set { 52 minimumFunctionArguments = value; 53 } 51 set { minimumFunctionArguments = value; } 54 52 } 55 53 [Storable] … … 57 55 public int MaximumFunctionArguments { 58 56 get { return maximumFunctionArguments; } 59 set { 60 maximumFunctionArguments = value; 61 } 57 set { maximumFunctionArguments = value; } 62 58 } 63 59 … … 70 66 get { return ProgramRootSymbol; } 71 67 } 68 [Storable(Name = "ProgramRootSymbol")] 69 private ISymbol StorableProgramRootSymbol { 70 get { return programRootSymbol; } 71 set { programRootSymbol = (ProgramRootSymbol)value; } 72 } 72 73 73 [Storable]74 74 private StartSymbol startSymbol; 75 75 public StartSymbol StartSymbol { … … 79 79 get { return StartSymbol; } 80 80 } 81 [Storable(Name = "StartSymbol")] 82 private ISymbol StorableStartSymbol { 83 get { return startSymbol; } 84 set { startSymbol = (StartSymbol)value; } 85 } 81 86 82 87 [Storable] … … 84 89 protected Defun DefunSymbol { 85 90 get { return defunSymbol; } 91 } 92 [Storable(Name = "DefunSymbol")] 93 private ISymbol StorableDefunSymbol { 94 get { return defunSymbol; } 95 set { defunSymbol = (Defun)value; } 86 96 } 87 97 #endregion -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
r5688 r5695 37 37 public abstract class SymbolicExpressionGrammarBase : NamedItem, ISymbolicExpressionGrammarBase { 38 38 #region properties for separation between implementation and persistence 39 40 //TODO implement storable properties; 41 39 [Storable(Name = "Symbols")] 40 private IEnumerable<ISymbol> StorableSymbols { 41 get { return symbols.Values.ToArray(); } 42 set { symbols = value.ToDictionary(sym => sym.Name); } 43 } 44 45 [Storable(Name = "SymbolSubtreeCount")] 46 private IEnumerable<KeyValuePair<ISymbol, Tuple<int, int>>> StorableSymbolSubtreeCount { 47 get { return symbolSubtreeCount.Select(x => new KeyValuePair<ISymbol, Tuple<int, int>>(GetSymbol(x.Key), x.Value)).ToArray(); } 48 set { symbolSubtreeCount = value.ToDictionary(x => x.Key.Name, x => x.Value); } 49 } 50 51 [Storable(Name = "AllowedChildSymbols")] 52 private IEnumerable<KeyValuePair<ISymbol, IEnumerable<ISymbol>>> StorableAllowedChildSymbols { 53 get { return allowedChildSymbols.Select(x => new KeyValuePair<ISymbol, IEnumerable<ISymbol>>(GetSymbol(x.Key), x.Value.Select(y => GetSymbol(y)))).ToArray(); ; } 54 set { allowedChildSymbols = value.ToDictionary(x => x.Key.Name, x => x.Value.Select(y => y.Name).ToList()); } 55 } 56 57 [Storable(Name = "AllowedChildSymbolsPerIndex")] 58 private IEnumerable<KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>> StorableAllowedChildSymbolsPerIndex { 59 get { return allowedChildSymbolsPerIndex.Select(x => new KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>(Tuple.Create(GetSymbol(x.Key.Item1), x.Key.Item2), x.Value.Select(y => GetSymbol(y)))).ToArray(); } 60 set { allowedChildSymbolsPerIndex = value.ToDictionary(x => Tuple.Create(x.Key.Item1.Name, x.Key.Item2), x => x.Value.Select(y => y.Name).ToList()); } 61 } 42 62 #endregion 43 63 44 64 protected Dictionary<string, ISymbol> symbols; 45 protected Dictionary<string, Tuple<int, int>> symbolSub TreeCount;65 protected Dictionary<string, Tuple<int, int>> symbolSubtreeCount; 46 66 protected Dictionary<string, List<string>> allowedChildSymbols; 47 67 protected Dictionary<Tuple<string, int>, List<string>> allowedChildSymbolsPerIndex; … … 67 87 cachedMinExpressionDepth = new Dictionary<string, int>(); 68 88 69 symbolSub TreeCount = new Dictionary<string, Tuple<int, int>>(original.symbolSubTreeCount);89 symbolSubtreeCount = new Dictionary<string, Tuple<int, int>>(original.symbolSubtreeCount); 70 90 symbols = new Dictionary<string, ISymbol>(original.symbols); 71 91 … … 86 106 87 107 symbols = new Dictionary<string, ISymbol>(); 88 symbolSub TreeCount = new Dictionary<string, Tuple<int, int>>();108 symbolSubtreeCount = new Dictionary<string, Tuple<int, int>>(); 89 109 allowedChildSymbols = new Dictionary<string, List<string>>(); 90 110 allowedChildSymbolsPerIndex = new Dictionary<Tuple<string, int>, List<string>>(); … … 95 115 if (ContainsSymbol(symbol)) throw new ArgumentException("Symbol " + symbol + " is already defined."); 96 116 symbols.Add(symbol.Name, symbol); 97 symbolSub TreeCount.Add(symbol.Name, Tuple.Create(0, 0));117 symbolSubtreeCount.Add(symbol.Name, Tuple.Create(0, 0)); 98 118 ClearCaches(); 99 119 } … … 104 124 for (int i = 0; i < GetMaximumSubtreeCount(symbol); i++) 105 125 allowedChildSymbolsPerIndex.Remove(Tuple.Create(symbol.Name, i)); 106 symbolSub TreeCount.Remove(symbol.Name);126 symbolSubtreeCount.Remove(symbol.Name); 107 127 108 128 … … 165 185 } 166 186 167 symbolSub TreeCount[symbol.Name] = Tuple.Create(minimumSubtreeCount, maximumSubtreeCount);187 symbolSubtreeCount[symbol.Name] = Tuple.Create(minimumSubtreeCount, maximumSubtreeCount); 168 188 ClearCaches(); 169 189 } … … 217 237 218 238 public virtual int GetMinimumSubtreeCount(ISymbol symbol) { 219 return symbolSub TreeCount[symbol.Name].Item1;239 return symbolSubtreeCount[symbol.Name].Item1; 220 240 } 221 241 public virtual int GetMaximumSubtreeCount(ISymbol symbol) { 222 return symbolSub TreeCount[symbol.Name].Item2;242 return symbolSubtreeCount[symbol.Name].Item2; 223 243 } 224 244
Note: See TracChangeset
for help on using the changeset viewer.