Changeset 9723


Ignore:
Timestamp:
07/18/13 15:45:03 (6 years ago)
Author:
ascheibe
Message:

#1886 worked on solution caching

Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior
Files:
7 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers-3.3.csproj

    r9711 r9723  
    113113    <Compile Include="CombinedOperators\QAPAfterMutationCombinedOperator.cs" />
    114114    <Compile Include="CombinedOperators\QAPAfterCrossoverCombinedOperator.cs" />
     115    <Compile Include="SolutionsCaching\SolutionCachingAnalyzer.cs" />
    115116    <Compile Include="SolutionsCaching\PermutationSolutionDictionary.cs" />
    116117    <Compile Include="SolutionsCaching\PermutationWrapper.cs" />
     118    <Compile Include="SolutionsCaching\PermutationWrapperEqualityComparer.cs" />
    117119    <Compile Include="SolutionsCaching\SolutionDictionary.cs" />
    118120    <Compile Include="SelectionPressureAnalyzer.cs" />
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationSolutionDictionary.cs

    r9711 r9723  
    2222using System.Collections.Generic;
    2323using System.Linq;
     24using HeuristicLab.Common;
     25using HeuristicLab.Core;
    2426using HeuristicLab.Encodings.PermutationEncoding;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2528
    2629namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
     30  [Item("PermutationSolutionDictionary", "Stores permutations generated by an algorithm.")]
     31  [StorableClass]
    2732  public class PermutationSolutionDictionary<TKey, TValue> : SolutionDictionary<TKey, TValue>
    2833    where TKey : PermutationWrapper {
    2934
    3035    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) {
    3243    }
    3344
     
    5162        Permutation pr = p.GetPermutation();
    5263        int diffs = CountDiffs(permutation, pr);
    53         if (min < diffs) {
     64        if (diffs < min) {
    5465          result = pr;
    5566          min = diffs;
     
    6273    private int CountDiffs(Permutation x, Permutation y) {
    6374      int result = 0;
     75      // yes we ignore path encoding at the moment
    6476      for (int i = 0; i < x.Length; i++) {
    6577        if (x[i] != y[i]) result++;
     
    6779      return result;
    6880    }
     81
     82    public override IDeepCloneable Clone(Cloner cloner) {
     83      return new PermutationSolutionDictionary<TKey, TValue>(this, cloner);
     84    }
    6985  }
    7086}
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationWrapper.cs

    r9711 r9723  
    2222using System.Collections.Generic;
    2323using HeuristicLab.Common;
     24using HeuristicLab.Core;
    2425using HeuristicLab.Encodings.PermutationEncoding;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2527
    2628namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
    2729  public enum ElementType { Complete, Diff };
    2830
    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]
    3035    public ElementType ElementType { get; set; }
     36    [Storable]
    3137    public Permutation Permutation { get; set; }
     38    [Storable]
    3239    public List<int> Diffs { get; set; }
    3340
     
    3643      Diffs = new List<int>();
    3744      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);
    3859    }
    3960
     
    5273    }
    5374
     75    //supports efficient diffs up to a permutation length of 30000
    5476    public void StorePartialPermutation(Permutation original, Permutation newPermutation) {
    5577      ElementType = ElementType.Diff;
     
    7092      Permutation = original;
    7193    }
     94
     95    public override IDeepCloneable Clone(Cloner cloner) {
     96      return new PermutationWrapper(this, cloner);
     97    }
    7298  }
    7399}
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/SolutionDictionary.cs

    r9711 r9723  
    2121
    2222using System.Collections.Generic;
     23using HeuristicLab.Common;
     24using HeuristicLab.Core;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.PluginInfrastructure;
    2327
    2428namespace 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]
    2634    protected Dictionary<TKey, List<TValue>> solutionDictionary;
    2735
    2836    public SolutionDictionary() {
    2937      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);
    3045    }
    3146
     
    3954
    4055      if (ContainsKey(key)) {
    41         solutionDictionary[key].Add(value);
     56        if (!solutionDictionary[key].Contains(value))
     57          solutionDictionary[key].Add(value);
    4258      } else {
    4359        InsertKeyValue(key, value);
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.sln

    r9412 r9723  
    1414EndProject
    1515Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Algorithms.ESLimitedGA-3.3", "HeuristicLab.Algorithms.ESLimitedGA\3.3\HeuristicLab.Algorithms.ESLimitedGA-3.3.csproj", "{A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}"
     16EndProject
     17Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlgorithmBehaviorUnitTests", "AlgorithmBehaviorUnitTests\AlgorithmBehaviorUnitTests.csproj", "{8EFDEA16-A348-401F-82FC-C7E08FDA1C5A}"
    1618EndProject
    1719Global
     
    5355    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Release|x86.ActiveCfg = Release|x86
    5456    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Release|x86.Build.0 = Release|x86
     57    {8EFDEA16-A348-401F-82FC-C7E08FDA1C5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     58    {8EFDEA16-A348-401F-82FC-C7E08FDA1C5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
     59    {8EFDEA16-A348-401F-82FC-C7E08FDA1C5A}.Debug|x64.ActiveCfg = Debug|Any CPU
     60    {8EFDEA16-A348-401F-82FC-C7E08FDA1C5A}.Debug|x86.ActiveCfg = Debug|Any CPU
     61    {8EFDEA16-A348-401F-82FC-C7E08FDA1C5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
     62    {8EFDEA16-A348-401F-82FC-C7E08FDA1C5A}.Release|Any CPU.Build.0 = Release|Any CPU
     63    {8EFDEA16-A348-401F-82FC-C7E08FDA1C5A}.Release|x64.ActiveCfg = Release|Any CPU
     64    {8EFDEA16-A348-401F-82FC-C7E08FDA1C5A}.Release|x86.ActiveCfg = Release|Any CPU
    5565  EndGlobalSection
    5666  GlobalSection(SolutionProperties) = preSolution
Note: See TracChangeset for help on using the changeset viewer.