Changeset 11203 for branches/HiveStatistics/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
- Timestamp:
- 07/18/14 12:35:00 (10 years ago)
- Location:
- branches/HiveStatistics/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll11 10 HeuristicLab 3.3.5.1.ReSharper.user 12 11 HeuristicLab 3.3.6.0.ReSharper.user 13 12 HeuristicLab.4.5.resharper.user 14 13 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development16 14 HeuristicLab.resharper.user 17 15 ProtoGen.exe … … 19 17 _ReSharper.HeuristicLab 20 18 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests22 19 _ReSharper.HeuristicLab.ExtLibs 23 20 bin 24 21 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/HiveStatistics/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Property svn:mergeinfo changed
-
branches/HiveStatistics/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 323 323 if (cachedIsAllowedChildSymbol.TryGetValue(key, out result)) return result; 324 324 325 // value has to be calculated and cached make sure this is done in only one thread 326 lock (cachedIsAllowedChildSymbol) { 327 // in case the value has been calculated on another thread in the meanwhile 328 if (cachedIsAllowedChildSymbol.TryGetValue(key, out result)) return result; 329 330 List<string> temp; 331 if (allowedChildSymbols.TryGetValue(parent.Name, out temp)) { 332 if (temp.SelectMany(s => GetSymbol(s).Flatten()).Any(s => s.Name == child.Name)) { 333 cachedIsAllowedChildSymbol.Add(key, true); 334 return true; 335 } 325 List<string> temp; 326 if (allowedChildSymbols.TryGetValue(parent.Name, out temp)) { 327 //if (temp.Contains(child.Name)) return true; 328 if (temp.SelectMany(s => GetSymbol(s).Flatten()).Any(s => s.Name == child.Name)) { 329 cachedIsAllowedChildSymbol.Add(key, true); 330 return true; 336 331 } 337 cachedIsAllowedChildSymbol.Add(key, false);338 return false;339 }332 } 333 cachedIsAllowedChildSymbol.Add(key, false); 334 return false; 340 335 } 341 336 … … 350 345 if (cachedIsAllowedChildSymbolIndex.TryGetValue(key, out result)) return result; 351 346 352 // value has to be calculated and cached make sure this is done in only one thread 353 lock (cachedIsAllowedChildSymbolIndex) { 354 // in case the value has been calculated on another thread in the meanwhile 355 if (cachedIsAllowedChildSymbolIndex.TryGetValue(key, out result)) return result; 356 357 List<string> temp; 358 if (allowedChildSymbolsPerIndex.TryGetValue(Tuple.Create(parent.Name, argumentIndex), out temp)) { 359 if (temp.SelectMany(s => GetSymbol(s).Flatten()).Any(s => s.Name == child.Name)) { 360 cachedIsAllowedChildSymbolIndex.Add(key, true); 361 return true; 362 } 347 List<string> temp; 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); 351 return true; 363 352 } 364 cachedIsAllowedChildSymbolIndex.Add(key, false);365 return false;366 }353 } 354 cachedIsAllowedChildSymbolIndex.Add(key, false); 355 return false; 367 356 } 368 357 … … 402 391 return res; 403 392 404 // value has to be calculated and cached make sure this is done in only one thread 405 lock (cachedMinExpressionLength) { 406 // in case the value has been calculated on another thread in the meanwhile 407 if (cachedMinExpressionLength.TryGetValue(symbol.Name, out res)) return res; 408 409 res = GetMinimumExpressionLengthRec(symbol); 410 foreach (var entry in cachedMinExpressionLength.Where(e => e.Value >= int.MaxValue).ToList()) { 411 if (entry.Key != symbol.Name) cachedMinExpressionLength.Remove(entry.Key); 412 } 413 return res; 414 } 393 res = GetMinimumExpressionLengthRec(symbol); 394 foreach (var entry in cachedMinExpressionLength.Where(e => e.Value >= int.MaxValue).ToList()) { 395 if (entry.Key != symbol.Name) cachedMinExpressionLength.Remove(entry.Key); 396 } 397 return res; 415 398 } 416 399 … … 435 418 int temp; 436 419 var key = Tuple.Create(symbol.Name, maxDepth); 437 if (cachedMaxExpressionLength.TryGetValue(key, out temp)) return temp; 438 // value has to be calculated and cached make sure this is done in only one thread 439 lock (cachedMaxExpressionLength) { 440 // in case the value has been calculated on another thread in the meanwhile 441 if (cachedMaxExpressionLength.TryGetValue(key, out temp)) return temp; 442 420 if (!cachedMaxExpressionLength.TryGetValue(key, out temp)) { 443 421 cachedMaxExpressionLength[key] = int.MaxValue; // prevent infinite recursion 444 422 long sumOfMaxTrees = 1 + (from argIndex in Enumerable.Range(0, GetMaximumSubtreeCount(symbol)) … … 451 429 return cachedMaxExpressionLength[key]; 452 430 } 431 return temp; 453 432 } 454 433 … … 459 438 return res; 460 439 461 // value has to be calculated and cached make sure this is done in only one thread 462 lock (cachedMinExpressionDepth) { 463 // in case the value has been calculated on another thread in the meanwhile 464 if (cachedMinExpressionDepth.TryGetValue(symbol.Name, out res)) return res; 465 466 res = GetMinimumExpressionDepthRec(symbol); 467 foreach (var entry in cachedMinExpressionDepth.Where(e => e.Value >= int.MaxValue).ToList()) { 468 if (entry.Key != symbol.Name) cachedMinExpressionDepth.Remove(entry.Key); 469 } 470 return res; 471 } 440 res = GetMinimumExpressionDepthRec(symbol); 441 foreach (var entry in cachedMinExpressionDepth.Where(e => e.Value >= int.MaxValue).ToList()) { 442 if (entry.Key != symbol.Name) cachedMinExpressionDepth.Remove(entry.Key); 443 } 444 return res; 472 445 } 473 446 private int GetMinimumExpressionDepthRec(ISymbol symbol) { … … 489 462 public int GetMaximumExpressionDepth(ISymbol symbol) { 490 463 int temp; 491 if (cachedMaxExpressionDepth.TryGetValue(symbol.Name, out temp)) return temp; 492 // value has to be calculated and cached make sure this is done in only one thread 493 lock (cachedMaxExpressionDepth) { 494 // in case the value has been calculated on another thread in the meanwhile 495 if (cachedMaxExpressionDepth.TryGetValue(symbol.Name, out temp)) return temp; 496 464 if (!cachedMaxExpressionDepth.TryGetValue(symbol.Name, out temp)) { 497 465 cachedMaxExpressionDepth[symbol.Name] = int.MaxValue; 498 466 long maxDepth = 1 + (from argIndex in Enumerable.Range(0, GetMaximumSubtreeCount(symbol)) … … 504 472 return cachedMaxExpressionDepth[symbol.Name]; 505 473 } 474 return temp; 506 475 } 507 476
Note: See TracChangeset
for help on using the changeset viewer.