Changeset 9757
- Timestamp:
- 07/25/13 16:28:49 (11 years ago)
- Location:
- branches/HeuristicLab.Analysis.AlgorithmBehavior
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/UnitTest2.cs
r9754 r9757 35 35 break; 36 36 } 37 38 37 } 39 38 } … … 45 44 break; 46 45 } 47 48 46 } 49 47 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/AfterCrossoverSolutionCachingAnalyzer.cs
r9754 r9757 96 96 info.ParentList.Add(p1Pw); 97 97 info.ParentList.Add(p2Pw); 98 solDict.Add(new PermutationWrapper( solution), info);98 solDict.Add(new PermutationWrapper((Permutation)solution.Clone(new Cloner())), info); 99 99 100 100 return base.Apply(); -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationInformation.cs
r9728 r9757 37 37 [Storable] 38 38 public int Generation { get; set; } 39 [Storable] 40 PermutationWrapperEqualityComparer pweq; 39 41 40 public PermutationInformation() { } 42 public PermutationInformation() { 43 pweq = new PermutationWrapperEqualityComparer(); 44 } 41 45 42 46 [StorableConstructor] … … 47 51 this.ParentList = new List<PermutationWrapper>(original.ParentList); 48 52 this.Generation = original.Generation; 53 this.pweq = new PermutationWrapperEqualityComparer(); 49 54 } 50 55 … … 52 57 return new PermutationInformation(this, cloner); 53 58 } 59 60 public override int GetHashCode() { 61 //use rotating hash, should be enough 62 //see: http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx 63 int h = 0; 64 65 h = (h << 4) ^ (h >> 28) ^ ProducedBy.GetHashCode(); 66 h = (h << 4) ^ (h >> 28) ^ Generation.GetHashCode(); 67 68 if (ParentList != null) { 69 foreach (var parent in ParentList) { 70 h = (h << 4) ^ (h >> 28) ^ pweq.GetHashCode(parent); 71 } 72 } 73 74 return h; 75 } 76 77 public override bool Equals(object obj) { 78 PermutationInformation pi = obj as PermutationInformation; 79 80 if (ProducedBy == pi.ProducedBy && Generation == pi.Generation) { 81 if (pi.ParentList == null && ParentList == null) return true; 82 if (pi.ParentList != null && ParentList == null || 83 pi.ParentList == null && ParentList != null) return false; 84 if (pi.ParentList.Count != ParentList.Count) return false; 85 86 foreach (var p in ParentList) { 87 if (!pi.ParentList.Contains(p)) return false; 88 } 89 return true; 90 } else { 91 return false; 92 } 93 } 54 94 } 55 95 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationSolutionDictionary.cs
r9754 r9757 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; … … 34 33 [Storable] 35 34 protected Dictionary<PermutationWrapper, List<PermutationInformation>> solutionDictionary; 36 public Dictionary<PermutationWrapper, List<PermutationInformation>> SolutionDictionary { get { return solutionDictionary; } } 35 36 public Dictionary<PermutationWrapper, List<PermutationInformation>> SolutionDictionary { 37 get { return solutionDictionary; } 38 } 39 40 [Storable] 41 PermutationEqualityComparer peq; 37 42 38 43 public PermutationSolutionDictionary() { 39 44 solutionDictionary = new Dictionary<PermutationWrapper, List<PermutationInformation>>(new PermutationWrapperEqualityComparer()); 45 peq = new PermutationEqualityComparer(); 40 46 } 41 47 … … 45 51 : base(original, cloner) { 46 52 this.solutionDictionary = new Dictionary<PermutationWrapper, List<PermutationInformation>>(original.solutionDictionary, new PermutationWrapperEqualityComparer()); 53 this.peq = new PermutationEqualityComparer(); 47 54 } 48 55 … … 105 112 106 113 public PermutationWrapper GetPermutationWrapperOfPermutation(Permutation permutation) { 107 PermutationEqualityComparer peq = new PermutationEqualityComparer(); 108 var res = solutionDictionary.Where(x => peq.GetHashCode(x.Key.GetPermutation()) == peq.GetHashCode(permutation)); 109 110 //TODO: fix this 111 if (res.Count() > 1) { 112 throw new Exception("ERROR: Cannot conatin duplicates!"); 113 } 114 115 return res.First().Key; 114 return solutionDictionary.Single(x => peq.GetHashCode(x.Key.GetPermutation()) == peq.GetHashCode(permutation)).Key; 116 115 } 117 116 -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/SolutionCachingAnalyzer.cs
r9754 r9757 93 93 info.ProducedBy = ProducedBy.Mutation; 94 94 95 solDict.Add(new PermutationWrapper( sol), info);95 solDict.Add(new PermutationWrapper((Permutation)sol.Clone(new Cloner())), info); 96 96 } 97 97 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.