Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/20/13 13:06:59 (11 years ago)
Author:
ascheibe
Message:

#1886 worked on solution caching

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/SolutionCachingAnalyzer.cs

    r9723 r9728  
    2020#endregion
    2121
    22 
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    3534  public class SolutionCachingAnalyzer : SingleSuccessorOperator, IAnalyzer {
    3635    private const string ResultsParameterName = "Results";
    37     //TODO: this should be a stateful item!
     36
    3837    #region IAnalyzer Members
    3938    public bool EnabledByDefault {
     
    5857      get { return ResultsParameter.ActualValue; }
    5958    }
    60 
    61     [Storable]
    62     private PermutationSolutionDictionary<PermutationWrapper, int> solDict;
    6359    #endregion
    6460
     
    6864    private SolutionCachingAnalyzer(SolutionCachingAnalyzer original, Cloner cloner)
    6965      : base(original, cloner) {
    70       this.solDict = (PermutationSolutionDictionary<PermutationWrapper, int>)original.solDict.Clone(cloner);
    7166    }
    7267
     
    7671      Parameters.Add(new LookupParameter<IntValue>("Generations", "Nr of generations."));
    7772      Parameters.Add(new ScopeTreeLookupParameter<Permutation>("Solution", "The solutions that should be stored.", "TSPTour", 1));
    78       solDict = new PermutationSolutionDictionary<PermutationWrapper, int>();
    7973    }
    8074
     
    8579    public override IOperation Apply() {
    8680      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      }
    8789
    8890      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);
    9096      }
    91 
    92       if (!ResultsParameter.ActualValue.ContainsKey("SolutionCache")) {
    93         ResultsParameter.ActualValue.Add(new Result("SolutionCache", solDict));
    94       }
    95 
    9697      return base.Apply();
    9798    }
Note: See TracChangeset for help on using the changeset viewer.