Index: /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers-3.3.csproj
===================================================================
--- /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers-3.3.csproj (revision 9710)
+++ /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers-3.3.csproj (revision 9711)
@@ -113,4 +113,7 @@
+
+
+
Index: /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationSolutionDictionary.cs
===================================================================
--- /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationSolutionDictionary.cs (revision 9711)
+++ /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationSolutionDictionary.cs (revision 9711)
@@ -0,0 +1,70 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.Collections.Generic;
+using System.Linq;
+using HeuristicLab.Encodings.PermutationEncoding;
+
+namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
+ public class PermutationSolutionDictionary : SolutionDictionary
+ where TKey : PermutationWrapper {
+
+ public PermutationSolutionDictionary() {
+ solutionDictionary = new Dictionary>();
+ }
+
+ protected override void InsertKeyValue(TKey key, TValue value) {
+ int diffCnt;
+ Permutation p = key.GetPermutation();
+ Permutation ms = GetMostSimilarSolution(p, out diffCnt);
+
+ if (diffCnt < ms.Length / 2) {
+ key.StorePartialPermutation(ms, p);
+ }
+
+ var lst = new List();
+ lst.Add(value);
+ solutionDictionary.Add(key, lst);
+ }
+
+ private Permutation GetMostSimilarSolution(Permutation permutation, out int diffCnt) {
+ Permutation result = null; int min = int.MaxValue;
+ foreach (PermutationWrapper p in solutionDictionary.Keys.Where(x => x.ElementType == ElementType.Complete)) {
+ Permutation pr = p.GetPermutation();
+ int diffs = CountDiffs(permutation, pr);
+ if (min < diffs) {
+ result = pr;
+ min = diffs;
+ }
+ }
+ diffCnt = min;
+ return result;
+ }
+
+ private int CountDiffs(Permutation x, Permutation y) {
+ int result = 0;
+ for (int i = 0; i < x.Length; i++) {
+ if (x[i] != y[i]) result++;
+ }
+ return result;
+ }
+ }
+}
Index: /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationWrapper.cs
===================================================================
--- /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationWrapper.cs (revision 9711)
+++ /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/PermutationWrapper.cs (revision 9711)
@@ -0,0 +1,73 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.Collections.Generic;
+using HeuristicLab.Common;
+using HeuristicLab.Encodings.PermutationEncoding;
+
+namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
+ public enum ElementType { Complete, Diff };
+
+ public class PermutationWrapper {
+ public ElementType ElementType { get; set; }
+ public Permutation Permutation { get; set; }
+ public List Diffs { get; set; }
+
+ public PermutationWrapper(Permutation p) {
+ ElementType = ElementType.Complete;
+ Diffs = new List();
+ Permutation = p;
+ }
+
+ public Permutation GetPermutation() {
+ if (ElementType == ElementType.Complete) {
+ return Permutation;
+ } else {
+ Permutation result = (Permutation)Permutation.Clone(new Cloner());
+ for (int i = 0; i < Diffs.Count; i++) {
+ int index = Diffs[i] >> 16;
+ int value = Diffs[i] & 0x0000FFFF;
+ result[index] = value;
+ }
+ return result;
+ }
+ }
+
+ public void StorePartialPermutation(Permutation original, Permutation newPermutation) {
+ ElementType = ElementType.Diff;
+ Diffs = new List();
+ Permutation = original;
+
+ for (int i = 0; i < original.Length; i++) {
+ if (original[i] != newPermutation[i]) {
+ int diff = (i << 16) | newPermutation[i];
+ Diffs.Add(diff);
+ }
+ }
+ }
+
+ public void StoreCompletePermutation(Permutation original) {
+ ElementType = ElementType.Complete;
+ Diffs = new List();
+ Permutation = original;
+ }
+ }
+}
Index: /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/SolutionDictionary.cs
===================================================================
--- /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/SolutionDictionary.cs (revision 9711)
+++ /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/SolutionsCaching/SolutionDictionary.cs (revision 9711)
@@ -0,0 +1,53 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.Collections.Generic;
+
+namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
+ public abstract class SolutionDictionary {
+ protected Dictionary> solutionDictionary;
+
+ public SolutionDictionary() {
+ solutionDictionary = new Dictionary>();
+ }
+
+ public void Add(TKey key, TValue value) {
+ if (solutionDictionary.Count == 0) {
+ var lst = new List();
+ lst.Add(value);
+ solutionDictionary.Add(key, lst);
+ return;
+ }
+
+ if (ContainsKey(key)) {
+ solutionDictionary[key].Add(value);
+ } else {
+ InsertKeyValue(key, value);
+ }
+ }
+
+ protected abstract void InsertKeyValue(TKey key, TValue value);
+
+ public virtual bool ContainsKey(TKey key) {
+ return solutionDictionary.ContainsKey(key);
+ }
+ }
+}