Changeset 9728 for branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/SolutionCachingAnalyzer.cs
- Timestamp:
- 07/20/13 13:06:59 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/SolutionCachingAnalyzer.cs
r9723 r9728 20 20 #endregion 21 21 22 23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; … … 35 34 public class SolutionCachingAnalyzer : SingleSuccessorOperator, IAnalyzer { 36 35 private const string ResultsParameterName = "Results"; 37 //TODO: this should be a stateful item! 36 38 37 #region IAnalyzer Members 39 38 public bool EnabledByDefault { … … 58 57 get { return ResultsParameter.ActualValue; } 59 58 } 60 61 [Storable]62 private PermutationSolutionDictionary<PermutationWrapper, int> solDict;63 59 #endregion 64 60 … … 68 64 private SolutionCachingAnalyzer(SolutionCachingAnalyzer original, Cloner cloner) 69 65 : base(original, cloner) { 70 this.solDict = (PermutationSolutionDictionary<PermutationWrapper, int>)original.solDict.Clone(cloner);71 66 } 72 67 … … 76 71 Parameters.Add(new LookupParameter<IntValue>("Generations", "Nr of generations.")); 77 72 Parameters.Add(new ScopeTreeLookupParameter<Permutation>("Solution", "The solutions that should be stored.", "TSPTour", 1)); 78 solDict = new PermutationSolutionDictionary<PermutationWrapper, int>();79 73 } 80 74 … … 85 79 public override IOperation Apply() { 86 80 ItemArray<Permutation> solutions = SolutionParameter.ActualValue; 81 PermutationSolutionDictionary<PermutationWrapper, PermutationInformation> solDict; 82 83 if (!Results.ContainsKey("SolutionCache")) { 84 solDict = new PermutationSolutionDictionary<PermutationWrapper, PermutationInformation>(); 85 Results.Add(new Result("SolutionCache", solDict)); 86 } else { 87 solDict = (PermutationSolutionDictionary<PermutationWrapper, PermutationInformation>)Results["SolutionCache"].Value; 88 } 87 89 88 90 foreach (var sol in solutions) { 89 solDict.Add(new PermutationWrapper(sol), GenerationsParameter.ActualValue.Value); 91 PermutationInformation info = new PermutationInformation(); 92 info.Generation = GenerationsParameter.ActualValue.Value; 93 info.ProducedBy = ProducedBy.Mutation; 94 95 solDict.Add(new PermutationWrapper(sol), info); 90 96 } 91 92 if (!ResultsParameter.ActualValue.ContainsKey("SolutionCache")) {93 ResultsParameter.ActualValue.Add(new Result("SolutionCache", solDict));94 }95 96 97 return base.Apply(); 97 98 }
Note: See TracChangeset
for help on using the changeset viewer.