Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9754


Ignore:
Timestamp:
07/25/13 11:14:56 (11 years ago)
Author:
ascheibe
Message:

#1886 added a caching analyzer for crossover

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

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/AlgorithmBehaviorUnitTests.csproj

    r9723 r9754  
    7272  </Choose>
    7373  <ItemGroup>
     74    <Compile Include="UnitTest2.cs" />
    7475    <Compile Include="UnitTest1.cs" />
    7576    <Compile Include="Properties\AssemblyInfo.cs" />
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/ConvexHullView.cs

    r9730 r9754  
    3030namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views {
    3131  [View("ConvexHull View")]
    32   [Content(typeof(PermutationSolutionDictionary<PermutationWrapper, PermutationInformation>), false)]
     32  [Content(typeof(PermutationSolutionDictionary), false)]
    3333  public partial class ConvexHullView : ItemView {
    3434    public ConvexHullView() {
     
    3636    }
    3737
    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; }
    4040      set { base.Content = value; }
    4141    }
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/PermutationSolutionDictionaryView.cs

    r9730 r9754  
    2929namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views {
    3030  [View("PermutationSolutionDictionary View")]
    31   [Content(typeof(PermutationSolutionDictionary<PermutationWrapper, PermutationInformation>), true)]
     31  [Content(typeof(PermutationSolutionDictionary), true)]
    3232  public partial class PermutationSolutionDictionaryView : ItemView {
    3333    public PermutationSolutionDictionaryView() {
     
    3535    }
    3636
    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; }
    3939      set { base.Content = value; }
    4040    }
     
    5555    protected override void OnInitialized(EventArgs e) {
    5656      base.OnInitialized(e);
    57       var viewTypes = MainFormManager.GetViewTypes(typeof(PermutationSolutionDictionary<PermutationWrapper, PermutationInformation>), true);
     57      var viewTypes = MainFormManager.GetViewTypes(typeof(PermutationSolutionDictionary), true);
    5858      foreach (Type viewType in viewTypes.OrderBy(x => ViewAttribute.GetViewName(x))) {
    5959        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  
    113113    <Compile Include="CombinedOperators\QAPAfterMutationCombinedOperator.cs" />
    114114    <Compile Include="CombinedOperators\QAPAfterCrossoverCombinedOperator.cs" />
     115    <Compile Include="SolutionsCaching\AfterCrossoverSolutionCachingAnalyzer.cs" />
    115116    <Compile Include="SolutionsCaching\SolutionCachingAnalyzer.cs" />
    116117    <Compile Include="SolutionsCaching\PermutationSolutionDictionary.cs" />
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationSolutionDictionary.cs

    r9730 r9754  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    3031  [Item("PermutationSolutionDictionary", "Stores permutations generated by an algorithm.")]
    3132  [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; } }
    3537
    3638    public PermutationSolutionDictionary() {
    37       solutionDictionary = new Dictionary<TKey, List<TValue>>(new PermutationWrapperEqualityComparer());
     39      solutionDictionary = new Dictionary<PermutationWrapper, List<PermutationInformation>>(new PermutationWrapperEqualityComparer());
    3840    }
    3941
    4042    [StorableConstructor]
    4143    protected PermutationSolutionDictionary(bool deserializing) : base(deserializing) { }
    42     protected PermutationSolutionDictionary(PermutationSolutionDictionary<TKey, TValue> original, Cloner cloner)
     44    protected PermutationSolutionDictionary(PermutationSolutionDictionary original, Cloner cloner)
    4345      : base(original, cloner) {
     46      this.solutionDictionary = new Dictionary<PermutationWrapper, List<PermutationInformation>>(original.solutionDictionary, new PermutationWrapperEqualityComparer());
    4447    }
    4548
    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) {
    4770      int diffCnt;
    4871      Permutation p = key.GetPermutation();
     
    5376      }
    5477
    55       var lst = new List<TValue>();
     78      var lst = new List<PermutationInformation>();
    5679      lst.Add(value);
    5780      solutionDictionary.Add(key, lst);
     
    81104    }
    82105
     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
    83118    public override IDeepCloneable Clone(Cloner cloner) {
    84       return new PermutationSolutionDictionary<TKey, TValue>(this, cloner);
     119      return new PermutationSolutionDictionary(this, cloner);
    85120    }
    86121
     
    96131      return solutionDictionary.Where(x => x.Value.Where(y => y.Generation == generation).Count() != 0).Select(x => x.Key).ToList<PermutationWrapper>();
    97132    }
     133
     134    public override bool ContainsKey(PermutationWrapper key) {
     135      return solutionDictionary.ContainsKey(key);
     136    }
    98137  }
    99138}
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/SolutionCachingAnalyzer.cs

    r9728 r9754  
    7979    public override IOperation Apply() {
    8080      ItemArray<Permutation> solutions = SolutionParameter.ActualValue;
    81       PermutationSolutionDictionary<PermutationWrapper, PermutationInformation> solDict;
     81      PermutationSolutionDictionary solDict;
    8282
    8383      if (!Results.ContainsKey("SolutionCache")) {
    84         solDict = new PermutationSolutionDictionary<PermutationWrapper, PermutationInformation>();
     84        solDict = new PermutationSolutionDictionary();
    8585        Results.Add(new Result("SolutionCache", solDict));
    8686      } else {
    87         solDict = (PermutationSolutionDictionary<PermutationWrapper, PermutationInformation>)Results["SolutionCache"].Value;
     87        solDict = (PermutationSolutionDictionary)Results["SolutionCache"].Value;
    8888      }
    8989
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/SolutionDictionary.cs

    r9728 r9754  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    3130  [NonDiscoverableType]
    3231  public abstract class SolutionDictionary<TKey, TValue> : Item {
    33     [Storable]
    34     protected Dictionary<TKey, List<TValue>> solutionDictionary;
    3532
    36     public SolutionDictionary() {
    37       solutionDictionary = new Dictionary<TKey, List<TValue>>();
    38     }
     33    public SolutionDictionary() { }
    3934
    4035    [StorableConstructor]
     
    4237    protected SolutionDictionary(SolutionDictionary<TKey, TValue> original, Cloner cloner)
    4338      : base(original, cloner) {
    44       this.solutionDictionary = new Dictionary<TKey, List<TValue>>(original.solutionDictionary);
    4539    }
    4640
    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);
    6242
    6343    protected abstract void InsertKeyValue(TKey key, TValue value);
    6444
    65     public virtual bool ContainsKey(TKey key) {
    66       return solutionDictionary.ContainsKey(key);
    67     }
     45    public abstract bool ContainsKey(TKey key);
    6846
    69     public int Size() {
    70       return solutionDictionary.Count;
    71     }
     47    public abstract int Size();
    7248  }
    7349}
Note: See TracChangeset for help on using the changeset viewer.