Changeset 9754
- Timestamp:
- 07/25/13 11:14:56 (11 years ago)
- Location:
- branches/HeuristicLab.Analysis.AlgorithmBehavior
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/AlgorithmBehaviorUnitTests.csproj
r9723 r9754 72 72 </Choose> 73 73 <ItemGroup> 74 <Compile Include="UnitTest2.cs" /> 74 75 <Compile Include="UnitTest1.cs" /> 75 76 <Compile Include="Properties\AssemblyInfo.cs" /> -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/ConvexHullView.cs
r9730 r9754 30 30 namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views { 31 31 [View("ConvexHull View")] 32 [Content(typeof(PermutationSolutionDictionary <PermutationWrapper, PermutationInformation>), false)]32 [Content(typeof(PermutationSolutionDictionary), false)] 33 33 public partial class ConvexHullView : ItemView { 34 34 public ConvexHullView() { … … 36 36 } 37 37 38 public new PermutationSolutionDictionary <PermutationWrapper, PermutationInformation>Content {39 get { return (PermutationSolutionDictionary <PermutationWrapper, PermutationInformation>)base.Content; }38 public new PermutationSolutionDictionary Content { 39 get { return (PermutationSolutionDictionary)base.Content; } 40 40 set { base.Content = value; } 41 41 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/PermutationSolutionDictionaryView.cs
r9730 r9754 29 29 namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views { 30 30 [View("PermutationSolutionDictionary View")] 31 [Content(typeof(PermutationSolutionDictionary <PermutationWrapper, PermutationInformation>), true)]31 [Content(typeof(PermutationSolutionDictionary), true)] 32 32 public partial class PermutationSolutionDictionaryView : ItemView { 33 33 public PermutationSolutionDictionaryView() { … … 35 35 } 36 36 37 public new PermutationSolutionDictionary <PermutationWrapper, PermutationInformation>Content {38 get { return (PermutationSolutionDictionary <PermutationWrapper, PermutationInformation>)base.Content; }37 public new PermutationSolutionDictionary Content { 38 get { return (PermutationSolutionDictionary)base.Content; } 39 39 set { base.Content = value; } 40 40 } … … 55 55 protected override void OnInitialized(EventArgs e) { 56 56 base.OnInitialized(e); 57 var viewTypes = MainFormManager.GetViewTypes(typeof(PermutationSolutionDictionary <PermutationWrapper, PermutationInformation>), true);57 var viewTypes = MainFormManager.GetViewTypes(typeof(PermutationSolutionDictionary), true); 58 58 foreach (Type viewType in viewTypes.OrderBy(x => ViewAttribute.GetViewName(x))) { 59 59 if ((viewType != typeof(PermutationSolutionDictionaryView)) && (viewType != typeof(ViewHost))) { -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers-3.3.csproj
r9728 r9754 113 113 <Compile Include="CombinedOperators\QAPAfterMutationCombinedOperator.cs" /> 114 114 <Compile Include="CombinedOperators\QAPAfterCrossoverCombinedOperator.cs" /> 115 <Compile Include="SolutionsCaching\AfterCrossoverSolutionCachingAnalyzer.cs" /> 115 116 <Compile Include="SolutionsCaching\SolutionCachingAnalyzer.cs" /> 116 117 <Compile Include="SolutionsCaching\PermutationSolutionDictionary.cs" /> -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationSolutionDictionary.cs
r9730 r9754 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 30 31 [Item("PermutationSolutionDictionary", "Stores permutations generated by an algorithm.")] 31 32 [StorableClass] 32 public class PermutationSolutionDictionary<TKey, TValue> : SolutionDictionary<TKey, TValue> 33 where TKey : PermutationWrapper 34 where TValue : PermutationInformation { 33 public class PermutationSolutionDictionary : SolutionDictionary<PermutationWrapper, PermutationInformation> { 34 [Storable] 35 protected Dictionary<PermutationWrapper, List<PermutationInformation>> solutionDictionary; 36 public Dictionary<PermutationWrapper, List<PermutationInformation>> SolutionDictionary { get { return solutionDictionary; } } 35 37 36 38 public PermutationSolutionDictionary() { 37 solutionDictionary = new Dictionary< TKey, List<TValue>>(new PermutationWrapperEqualityComparer());39 solutionDictionary = new Dictionary<PermutationWrapper, List<PermutationInformation>>(new PermutationWrapperEqualityComparer()); 38 40 } 39 41 40 42 [StorableConstructor] 41 43 protected PermutationSolutionDictionary(bool deserializing) : base(deserializing) { } 42 protected PermutationSolutionDictionary(PermutationSolutionDictionary <TKey, TValue>original, Cloner cloner)44 protected PermutationSolutionDictionary(PermutationSolutionDictionary original, Cloner cloner) 43 45 : base(original, cloner) { 46 this.solutionDictionary = new Dictionary<PermutationWrapper, List<PermutationInformation>>(original.solutionDictionary, new PermutationWrapperEqualityComparer()); 44 47 } 45 48 46 protected override void InsertKeyValue(TKey key, TValue value) { 49 public override int Size() { 50 return solutionDictionary.Count; 51 } 52 53 public override void Add(PermutationWrapper key, PermutationInformation value) { 54 if (solutionDictionary.Count == 0) { 55 var lst = new List<PermutationInformation>(); 56 lst.Add(value); 57 solutionDictionary.Add(key, lst); 58 return; 59 } 60 61 if (ContainsKey(key)) { 62 if (!solutionDictionary[key].Contains(value)) 63 solutionDictionary[key].Add(value); 64 } else { 65 InsertKeyValue(key, value); 66 } 67 } 68 69 protected override void InsertKeyValue(PermutationWrapper key, PermutationInformation value) { 47 70 int diffCnt; 48 71 Permutation p = key.GetPermutation(); … … 53 76 } 54 77 55 var lst = new List< TValue>();78 var lst = new List<PermutationInformation>(); 56 79 lst.Add(value); 57 80 solutionDictionary.Add(key, lst); … … 81 104 } 82 105 106 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; 116 } 117 83 118 public override IDeepCloneable Clone(Cloner cloner) { 84 return new PermutationSolutionDictionary <TKey, TValue>(this, cloner);119 return new PermutationSolutionDictionary(this, cloner); 85 120 } 86 121 … … 96 131 return solutionDictionary.Where(x => x.Value.Where(y => y.Generation == generation).Count() != 0).Select(x => x.Key).ToList<PermutationWrapper>(); 97 132 } 133 134 public override bool ContainsKey(PermutationWrapper key) { 135 return solutionDictionary.ContainsKey(key); 136 } 98 137 } 99 138 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/SolutionCachingAnalyzer.cs
r9728 r9754 79 79 public override IOperation Apply() { 80 80 ItemArray<Permutation> solutions = SolutionParameter.ActualValue; 81 PermutationSolutionDictionary <PermutationWrapper, PermutationInformation>solDict;81 PermutationSolutionDictionary solDict; 82 82 83 83 if (!Results.ContainsKey("SolutionCache")) { 84 solDict = new PermutationSolutionDictionary <PermutationWrapper, PermutationInformation>();84 solDict = new PermutationSolutionDictionary(); 85 85 Results.Add(new Result("SolutionCache", solDict)); 86 86 } else { 87 solDict = (PermutationSolutionDictionary <PermutationWrapper, PermutationInformation>)Results["SolutionCache"].Value;87 solDict = (PermutationSolutionDictionary)Results["SolutionCache"].Value; 88 88 } 89 89 -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/SolutionDictionary.cs
r9728 r9754 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; … … 31 30 [NonDiscoverableType] 32 31 public abstract class SolutionDictionary<TKey, TValue> : Item { 33 [Storable]34 protected Dictionary<TKey, List<TValue>> solutionDictionary;35 32 36 public SolutionDictionary() { 37 solutionDictionary = new Dictionary<TKey, List<TValue>>(); 38 } 33 public SolutionDictionary() { } 39 34 40 35 [StorableConstructor] … … 42 37 protected SolutionDictionary(SolutionDictionary<TKey, TValue> original, Cloner cloner) 43 38 : base(original, cloner) { 44 this.solutionDictionary = new Dictionary<TKey, List<TValue>>(original.solutionDictionary);45 39 } 46 40 47 public void Add(TKey key, TValue value) { 48 if (solutionDictionary.Count == 0) { 49 var lst = new List<TValue>(); 50 lst.Add(value); 51 solutionDictionary.Add(key, lst); 52 return; 53 } 54 55 if (ContainsKey(key)) { 56 if (!solutionDictionary[key].Contains(value)) 57 solutionDictionary[key].Add(value); 58 } else { 59 InsertKeyValue(key, value); 60 } 61 } 41 public abstract void Add(TKey key, TValue value); 62 42 63 43 protected abstract void InsertKeyValue(TKey key, TValue value); 64 44 65 public virtual bool ContainsKey(TKey key) { 66 return solutionDictionary.ContainsKey(key); 67 } 45 public abstract bool ContainsKey(TKey key); 68 46 69 public int Size() { 70 return solutionDictionary.Count; 71 } 47 public abstract int Size(); 72 48 } 73 49 }
Note: See TracChangeset
for help on using the changeset viewer.