Index: /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Mutators/SegmentOptimization/SamplingSegmentOptimizationManipulator.cs
===================================================================
--- /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Mutators/SegmentOptimization/SamplingSegmentOptimizationManipulator.cs	(revision 18211)
+++ /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Mutators/SegmentOptimization/SamplingSegmentOptimizationManipulator.cs	(revision 18212)
@@ -77,4 +77,6 @@
     public ValueParameter<IntValue> SampleCountParameter => (ValueParameter<IntValue>)Parameters["SampleCount"];
     public ValueParameter<EnumValue<SamplingPointsType>> SamplingPointsParameter => (ValueParameter<EnumValue<SamplingPointsType>>)Parameters["SamplingPoints"];
+    public ValueParameter<BoolValue> CountSamplesAsEvaluationsParameter => (ValueParameter<BoolValue>)Parameters["CountSamplesAsEvaluations"];
+    public LookupParameter<IntValue> EvaluatedSolutionsParameter => (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"];
     #endregion
 
@@ -85,4 +87,6 @@
       Parameters.Add(new ValueParameter<IntValue>("SampleCount")); // only used when sampling != Exhaustive
       Parameters.Add(new ValueParameter<EnumValue<SamplingPointsType>>("SamplingPoints", new EnumValue<SamplingPointsType>(SamplingPointsType.BeforeCombinations | SamplingPointsType.AfterCombinations))); 
+      Parameters.Add(new ValueParameter<BoolValue>("CountSamplesAsEvaluations", new BoolValue(false)));
+      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions"));
     }
     public SamplingSegmentOptimizationManipulator(SamplingSegmentOptimizationManipulator original, Cloner cloner)
@@ -110,4 +114,9 @@
         solutions = SampleIndices(solutions, Sampling, random, SampleCount);
 
+      if (CountSamplesAsEvaluationsParameter.Value.Value) {
+        int moves = solutions.Count();
+        EvaluatedSolutionsParameter.ActualValue.Value += moves - 1;
+      }
+
       var best = FindBest(solutions);
       if (best != null) {
@@ -119,5 +128,4 @@
       var indices = new IEnumerable<int>[integerVector.Length];
       int targetIndex = random.Next(indices.Length); // first or second index
-      integerVector = new IntegerVector(new[] { integerVector.Min(), integerVector.Max() });
       for (int i = 0; i < indices.Length; i++) {
         var searchRange = dimension == DimensionType.All || targetIndex == i ? indexRange : SearchRangeType.None;
Index: /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SegmentOptimization/SegmentOptimizationProblem.cs
===================================================================
--- /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SegmentOptimization/SegmentOptimizationProblem.cs	(revision 18211)
+++ /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SegmentOptimization/SegmentOptimizationProblem.cs	(revision 18212)
@@ -21,5 +21,7 @@
 
 using System;
+using System.Collections.Generic;
 using System.Linq;
+using System.Linq.Expressions;
 using HEAL.Attic;
 using HeuristicLab.Common;
@@ -239,4 +241,77 @@
       return matrix;
     }
+
+    private class DoubleArrayComparer : IEqualityComparer<double[,]> {
+      public bool Equals(double[,] x, double[,] y) {
+        if (ReferenceEquals(x, y)) return true;
+        if (x.Length != y.Length) return false;
+        if (x.GetLength(0) != y.GetLength(0)) return false;
+        if (x.GetLength(1) != y.GetLength(1)) return false;
+
+        int rows = x.GetLength(0), cols = x.GetLength(1);
+        for (int i = 0; i < rows; i++) {
+          for (int j = 0; j < cols; j++) {
+            if (x[i, j] != y[i, j])
+              return false;
+          }
+        }
+
+        return true;
+      }
+
+      public int GetHashCode(double[,] obj) {
+        return GetSequenceHashCode(obj.Cast<double>())/*gives matrix enumerated*/;
+      }
+
+      //https://stackoverflow.com/questions/7278136/create-hash-value-on-a-list
+      public static int GetSequenceHashCode<T>(IEnumerable<T> sequence) {
+        const int seed = 487;
+        const int modifier = 31;
+
+        unchecked {
+          return sequence.Aggregate(seed, (current, item) => (current * modifier) + item.GetHashCode());
+        }
+      }
+    }
+
+    private static readonly Action<DoubleMatrix, double[,]> setValues;
+    private static readonly Func<DoubleMatrix, double[,]> getValues;
+    static SegmentOptimizationProblem() {
+      var dataset = Expression.Parameter(typeof(DoubleMatrix));
+      var variableValues = Expression.Parameter(typeof(double[,]));
+      var valuesExpression = Expression.Field(dataset, "matrix");
+      var assignExpression = Expression.Assign(valuesExpression, variableValues);
+
+      var variableValuesSetExpression = Expression.Lambda<Action<DoubleMatrix, double[,]>>(assignExpression, dataset, variableValues);
+      setValues = variableValuesSetExpression.Compile();
+
+      var variableValuesGetExpression = Expression.Lambda<Func<DoubleMatrix, double[,]>>(valuesExpression, dataset);
+      getValues = variableValuesGetExpression.Compile();
+    }
+
+    public static Tuple<int, int, int> RemoveDuplicateMatrices(IContent content) {
+      int overallTests = 0, removedDuplicated = 0;
+      var mappings = new Dictionary<double[,], double[,]>(new DoubleArrayComparer());
+       foreach (var parameter in content.GetObjectGraphObjects(excludeStaticMembers: true).OfType<DoubleMatrix>()) {
+         var originalValue = getValues(parameter);
+         overallTests++;
+         if (mappings.TryGetValue(originalValue, out var mappedValue)) {
+           setValues(parameter, mappedValue);
+           removedDuplicated++;
+         } else {
+           mappings.Add(originalValue, originalValue);
+         }
+       }
+      
+      int removedQualities = 0;
+      // foreach (var run in content.GetObjectGraphObjects(excludeStaticMembers: true).OfType<IRun>()) {
+      //   if (run.Results.ContainsKey("Qualities")) {
+      //     run.Results.Remove("Qualities");
+      //     removedQualities++;
+      //   }
+      // }
+
+      return Tuple.Create(overallTests, removedDuplicated, removedQualities);
+    }
   }
 }
Index: /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
===================================================================
--- /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj	(revision 18211)
+++ /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj	(revision 18212)
@@ -47,4 +47,5 @@
     <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     <Prefer32Bit>false</Prefer32Bit>
+    <LangVersion>latest</LangVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@@ -57,4 +58,5 @@
     <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     <Prefer32Bit>false</Prefer32Bit>
+    <LangVersion>latest</LangVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
@@ -67,4 +69,5 @@
     <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     <Prefer32Bit>false</Prefer32Bit>
+    <LangVersion>latest</LangVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
@@ -77,4 +80,5 @@
     <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     <Prefer32Bit>false</Prefer32Bit>
+    <LangVersion>latest</LangVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
@@ -87,4 +91,5 @@
     <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     <Prefer32Bit>false</Prefer32Bit>
+    <LangVersion>latest</LangVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
@@ -97,4 +102,5 @@
     <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     <Prefer32Bit>false</Prefer32Bit>
+    <LangVersion>latest</LangVersion>
   </PropertyGroup>
   <ItemGroup>
Index: /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/ShrinkDataAnalysisRunsMenuItem.cs
===================================================================
--- /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/ShrinkDataAnalysisRunsMenuItem.cs	(revision 18211)
+++ /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/ShrinkDataAnalysisRunsMenuItem.cs	(revision 18212)
@@ -25,8 +25,10 @@
 using System.Collections.Generic;
 using System.Linq;
+using System.Threading.Tasks;
+using System.Windows.Forms;
 using HeuristicLab.MainForm;
 using HeuristicLab.Optimization;
 using HeuristicLab.Optimizer;
-
+using HeuristicLab.Problems.DataAnalysis.Symbolic.SegmentOptimization;
 using MenuItem = HeuristicLab.MainForm.WindowsForms.MenuItem;
 
@@ -67,18 +69,20 @@
       }
 
-      ToolStripItem.Enabled = runCollection.Any(run => run.Parameters.Any(p => p.Value is IDataAnalysisProblemData));
+      ToolStripItem.Enabled = true;
+      //ToolStripItem.Enabled = runCollection.Any(run => run.Parameters.Any(p => p.Value is IDataAnalysisProblemData));
     }
 
-    public override void Execute() {
+    public override async void Execute() {
       IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
       var content = activeView.Content;
       Progress.Show(content, "Removing duplicate datasets.", ProgressMode.Indeterminate);
+      
+      var results = await Task.Run(() => {
+        DatasetUtil.RemoveDuplicateDatasets(content);
+        return SegmentOptimizationProblem.RemoveDuplicateMatrices(content);
+      });
 
-      Action<IContentView> action = (view) => DatasetUtil.RemoveDuplicateDatasets(view.Content);
-
-      action.BeginInvoke(activeView, delegate (IAsyncResult result) {
-        action.EndInvoke(result);
-        Progress.Hide(content);
-      }, null);
+      Progress.Hide(content);
+      MessageBox.Show($"DoubleMatrix-Count:{results.Item1}\nDoubleMatrix-RemovedDuplicates:{results.Item2}\nQualities-Removed:{results.Item3}");
     }
   }
