- Timestamp:
- 03/22/12 18:05:15 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding 7343-7503
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
r7259 r7656 308 308 } 309 309 public virtual IEnumerable<ISymbol> AllowedSymbols { 310 get { return Symbols.Where(s => s.Enabled); }310 get { foreach (var s in Symbols) if (s.Enabled) yield return s; } 311 311 } 312 312 public virtual bool ContainsSymbol(ISymbol symbol) { … … 316 316 private readonly Dictionary<Tuple<string, string>, bool> cachedIsAllowedChildSymbol; 317 317 public virtual bool IsAllowedChildSymbol(ISymbol parent, ISymbol child) { 318 if (allowedChildSymbols.Count == 0) return false; 318 319 if (!child.Enabled) return false; 319 320 320 321 bool result; 321 if (cachedIsAllowedChildSymbol.TryGetValue(Tuple.Create(parent.Name, child.Name), out result)) return result; 322 var key = Tuple.Create(parent.Name, child.Name); 323 if (cachedIsAllowedChildSymbol.TryGetValue(key, out result)) return result; 324 322 325 List<string> temp; 323 326 if (allowedChildSymbols.TryGetValue(parent.Name, out temp)) { 324 327 //if (temp.Contains(child.Name)) return true; 325 if (temp.SelectMany(s => GetSymbol(s).Flatten()). Where(s => s.Name == child.Name).Any()) {326 cachedIsAllowedChildSymbol.Add( Tuple.Create(parent.Name, child.Name), true);328 if (temp.SelectMany(s => GetSymbol(s).Flatten()).Any(s => s.Name == child.Name)) { 329 cachedIsAllowedChildSymbol.Add(key, true); 327 330 return true; 328 331 } 329 332 } 330 cachedIsAllowedChildSymbol.Add( Tuple.Create(parent.Name, child.Name), false);333 cachedIsAllowedChildSymbol.Add(key, false); 331 334 return false; 332 335 } … … 335 338 public virtual bool IsAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) { 336 339 if (!child.Enabled) return false; 340 if (allowedChildSymbolsPerIndex.Count == 0) return false; 337 341 if (IsAllowedChildSymbol(parent, child)) return true; 338 342 339 343 bool result; 340 if (cachedIsAllowedChildSymbolIndex.TryGetValue(Tuple.Create(parent.Name, child.Name, argumentIndex), out result)) return result; 344 var key = Tuple.Create(parent.Name, child.Name, argumentIndex); 345 if (cachedIsAllowedChildSymbolIndex.TryGetValue(key, out result)) return result; 346 341 347 List<string> temp; 342 var key = Tuple.Create(parent.Name, argumentIndex); 343 if (allowedChildSymbolsPerIndex.TryGetValue(key, out temp)) { 344 //if (temp.Contains(child.Name)) return true; 345 if (temp.SelectMany(s => GetSymbol(s).Flatten()).Where(s => s.Name == child.Name).Any()) { 346 cachedIsAllowedChildSymbolIndex.Add(Tuple.Create(parent.Name, child.Name, argumentIndex), true); 348 if (allowedChildSymbolsPerIndex.TryGetValue(Tuple.Create(parent.Name, argumentIndex), out temp)) { 349 if (temp.SelectMany(s => GetSymbol(s).Flatten()).Any(s => s.Name == child.Name)) { 350 cachedIsAllowedChildSymbolIndex.Add(key, true); 347 351 return true; 348 352 } 349 353 } 350 cachedIsAllowedChildSymbolIndex.Add( Tuple.Create(parent.Name, child.Name, argumentIndex), false);354 cachedIsAllowedChildSymbolIndex.Add(key, false); 351 355 return false; 352 356 } 353 357 354 358 public IEnumerable<ISymbol> GetAllowedChildSymbols(ISymbol parent) { 355 return from child in AllowedSymbols356 where IsAllowedChildSymbol(parent, child)357 select child;359 foreach (ISymbol child in AllowedSymbols) { 360 if (IsAllowedChildSymbol(parent, child)) yield return child; 361 } 358 362 } 359 363 360 364 public IEnumerable<ISymbol> GetAllowedChildSymbols(ISymbol parent, int argumentIndex) { 361 return from child in AllowedSymbols362 where IsAllowedChildSymbol(parent, child, argumentIndex)363 select child;365 foreach (ISymbol child in AllowedSymbols) { 366 if (IsAllowedChildSymbol(parent, child, argumentIndex)) yield return child; 367 } 364 368 } 365 369 -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeGrammar.cs
r7259 r7656 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 51 50 52 51 public override IEnumerable<ISymbol> Symbols { 53 get { return grammar.Symbols.Union(base.Symbols); } 52 get { 53 foreach (var s in base.symbols.Values) yield return s; 54 foreach (var s in grammar.Symbols) yield return s; 55 } 54 56 } 55 57 public override IEnumerable<ISymbol> AllowedSymbols {
Note: See TracChangeset
for help on using the changeset viewer.