Changeset 9723 for branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers
- Timestamp:
- 07/18/13 15:45:03 (11 years ago)
- Location:
- branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers-3.3.csproj
r9711 r9723 113 113 <Compile Include="CombinedOperators\QAPAfterMutationCombinedOperator.cs" /> 114 114 <Compile Include="CombinedOperators\QAPAfterCrossoverCombinedOperator.cs" /> 115 <Compile Include="SolutionsCaching\SolutionCachingAnalyzer.cs" /> 115 116 <Compile Include="SolutionsCaching\PermutationSolutionDictionary.cs" /> 116 117 <Compile Include="SolutionsCaching\PermutationWrapper.cs" /> 118 <Compile Include="SolutionsCaching\PermutationWrapperEqualityComparer.cs" /> 117 119 <Compile Include="SolutionsCaching\SolutionDictionary.cs" /> 118 120 <Compile Include="SelectionPressureAnalyzer.cs" /> -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationSolutionDictionary.cs
r9711 r9723 22 22 using System.Collections.Generic; 23 23 using System.Linq; 24 using HeuristicLab.Common; 25 using HeuristicLab.Core; 24 26 using HeuristicLab.Encodings.PermutationEncoding; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 28 26 29 namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers { 30 [Item("PermutationSolutionDictionary", "Stores permutations generated by an algorithm.")] 31 [StorableClass] 27 32 public class PermutationSolutionDictionary<TKey, TValue> : SolutionDictionary<TKey, TValue> 28 33 where TKey : PermutationWrapper { 29 34 30 35 public PermutationSolutionDictionary() { 31 solutionDictionary = new Dictionary<TKey, List<TValue>>(); 36 solutionDictionary = new Dictionary<TKey, List<TValue>>(new PermutationWrapperEqualityComparer()); 37 } 38 39 [StorableConstructor] 40 protected PermutationSolutionDictionary(bool deserializing) : base(deserializing) { } 41 protected PermutationSolutionDictionary(PermutationSolutionDictionary<TKey, TValue> original, Cloner cloner) 42 : base(original, cloner) { 32 43 } 33 44 … … 51 62 Permutation pr = p.GetPermutation(); 52 63 int diffs = CountDiffs(permutation, pr); 53 if ( min < diffs) {64 if (diffs < min) { 54 65 result = pr; 55 66 min = diffs; … … 62 73 private int CountDiffs(Permutation x, Permutation y) { 63 74 int result = 0; 75 // yes we ignore path encoding at the moment 64 76 for (int i = 0; i < x.Length; i++) { 65 77 if (x[i] != y[i]) result++; … … 67 79 return result; 68 80 } 81 82 public override IDeepCloneable Clone(Cloner cloner) { 83 return new PermutationSolutionDictionary<TKey, TValue>(this, cloner); 84 } 69 85 } 70 86 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationWrapper.cs
r9711 r9723 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Encodings.PermutationEncoding; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 27 26 28 namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers { 27 29 public enum ElementType { Complete, Diff }; 28 30 29 public class PermutationWrapper { 31 [Item("PermutationWrapper", "Wrapper for permutations. Can either store a permutation or a diff.")] 32 [StorableClass] 33 public class PermutationWrapper : Item { 34 [Storable] 30 35 public ElementType ElementType { get; set; } 36 [Storable] 31 37 public Permutation Permutation { get; set; } 38 [Storable] 32 39 public List<int> Diffs { get; set; } 33 40 … … 36 43 Diffs = new List<int>(); 37 44 Permutation = p; 45 } 46 47 public PermutationWrapper() { 48 ElementType = ElementType.Complete; 49 Diffs = new List<int>(); 50 } 51 52 [StorableConstructor] 53 protected PermutationWrapper(bool deserializing) : base(deserializing) { } 54 protected PermutationWrapper(PermutationWrapper original, Cloner cloner) 55 : base(original, cloner) { 56 this.ElementType = original.ElementType; 57 this.Diffs = new List<int>(original.Diffs); 58 this.Permutation = (Permutation)original.Permutation.Clone(cloner); 38 59 } 39 60 … … 52 73 } 53 74 75 //supports efficient diffs up to a permutation length of 30000 54 76 public void StorePartialPermutation(Permutation original, Permutation newPermutation) { 55 77 ElementType = ElementType.Diff; … … 70 92 Permutation = original; 71 93 } 94 95 public override IDeepCloneable Clone(Cloner cloner) { 96 return new PermutationWrapper(this, cloner); 97 } 72 98 } 73 99 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/SolutionDictionary.cs
r9711 r9723 21 21 22 22 using System.Collections.Generic; 23 using HeuristicLab.Common; 24 using HeuristicLab.Core; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.PluginInfrastructure; 23 27 24 28 namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers { 25 public abstract class SolutionDictionary<TKey, TValue> { 29 [Item("SolutionDictionary", "Stores solutions generated by an algorithm.")] 30 [StorableClass] 31 [NonDiscoverableType] 32 public abstract class SolutionDictionary<TKey, TValue> : Item { 33 [Storable] 26 34 protected Dictionary<TKey, List<TValue>> solutionDictionary; 27 35 28 36 public SolutionDictionary() { 29 37 solutionDictionary = new Dictionary<TKey, List<TValue>>(); 38 } 39 40 [StorableConstructor] 41 protected SolutionDictionary(bool deserializing) : base(deserializing) { } 42 protected SolutionDictionary(SolutionDictionary<TKey, TValue> original, Cloner cloner) 43 : base(original, cloner) { 44 this.solutionDictionary = new Dictionary<TKey, List<TValue>>(original.solutionDictionary); 30 45 } 31 46 … … 39 54 40 55 if (ContainsKey(key)) { 41 solutionDictionary[key].Add(value); 56 if (!solutionDictionary[key].Contains(value)) 57 solutionDictionary[key].Add(value); 42 58 } else { 43 59 InsertKeyValue(key, value);
Note: See TracChangeset
for help on using the changeset viewer.