Changeset 11205 for branches/HiveStatistics/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
- Timestamp:
- 07/18/14 13:44:53 (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.dll 10 11 HeuristicLab 3.3.5.1.ReSharper.user 11 12 HeuristicLab 3.3.6.0.ReSharper.user 12 13 HeuristicLab.4.5.resharper.user 13 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 14 16 HeuristicLab.resharper.user 15 17 ProtoGen.exe … … 17 19 _ReSharper.HeuristicLab 18 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 19 22 _ReSharper.HeuristicLab.ExtLibs 20 23 bin 21 24 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests23 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
r11203 r11205 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2014 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 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; 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 } 331 336 } 332 }333 cachedIsAllowedChildSymbol.Add(key, false);334 return false;337 cachedIsAllowedChildSymbol.Add(key, false); 338 return false; 339 } 335 340 } 336 341 … … 345 350 if (cachedIsAllowedChildSymbolIndex.TryGetValue(key, out result)) return result; 346 351 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; 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 } 352 363 } 353 }354 cachedIsAllowedChildSymbolIndex.Add(key, false);355 return false;364 cachedIsAllowedChildSymbolIndex.Add(key, false); 365 return false; 366 } 356 367 } 357 368 … … 391 402 return res; 392 403 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; 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 } 398 415 } 399 416 … … 418 435 int temp; 419 436 var key = Tuple.Create(symbol.Name, maxDepth); 420 if (!cachedMaxExpressionLength.TryGetValue(key, out temp)) { 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 421 443 cachedMaxExpressionLength[key] = int.MaxValue; // prevent infinite recursion 422 444 long sumOfMaxTrees = 1 + (from argIndex in Enumerable.Range(0, GetMaximumSubtreeCount(symbol)) … … 429 451 return cachedMaxExpressionLength[key]; 430 452 } 431 return temp;432 453 } 433 454 … … 438 459 return res; 439 460 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; 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 } 445 472 } 446 473 private int GetMinimumExpressionDepthRec(ISymbol symbol) { … … 462 489 public int GetMaximumExpressionDepth(ISymbol symbol) { 463 490 int temp; 464 if (!cachedMaxExpressionDepth.TryGetValue(symbol.Name, out 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 465 497 cachedMaxExpressionDepth[symbol.Name] = int.MaxValue; 466 498 long maxDepth = 1 + (from argIndex in Enumerable.Range(0, GetMaximumSubtreeCount(symbol)) … … 472 504 return cachedMaxExpressionDepth[symbol.Name]; 473 505 } 474 return temp;475 506 } 476 507
Note: See TracChangeset
for help on using the changeset viewer.