Index: branches/1614_GeneralizedQAP/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.cs
===================================================================
--- branches/1614_GeneralizedQAP/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.cs	(revision 15713)
+++ branches/1614_GeneralizedQAP/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.cs	(revision 15718)
@@ -31,4 +31,5 @@
 using HeuristicLab.Analysis;
 using HeuristicLab.Collections;
+using HeuristicLab.Common;
 using HeuristicLab.Core;
 using HeuristicLab.Core.Views;
@@ -146,8 +147,8 @@
         return;
       }
+      if (updateInProgress) return;
       try {
         updateInProgress = true;
-        UpdateGroupAndProblemComboBox();
-        UpdateDataTableComboBox();
+        UpdateComboBoxes();
         GroupRuns();
       } finally { updateInProgress = false; }
@@ -160,8 +161,8 @@
         return;
       }
+      if (updateInProgress) return;
       try {
         updateInProgress = true;
-        UpdateGroupAndProblemComboBox();
-        UpdateDataTableComboBox();
+        UpdateComboBoxes();
         GroupRuns();
       } finally { updateInProgress = false; }
@@ -175,8 +176,8 @@
         return;
       }
+      if (updateInProgress) return;
       try {
         updateInProgress = true;
-        UpdateGroupAndProblemComboBox();
-        UpdateDataTableComboBox();
+        UpdateComboBoxes();
         GroupRuns();
       } finally { updateInProgress = false; }
@@ -194,8 +195,8 @@
       suppressContentEvents = Content.UpdateOfRunsInProgress;
       if (!suppressContentEvents) {
+        if (updateInProgress) return;
         try {
           updateInProgress = true;
-          UpdateGroupAndProblemComboBox();
-          UpdateDataTableComboBox();
+          UpdateComboBoxes();
           GroupRuns();
         } finally { updateInProgress = false; }
@@ -215,4 +216,5 @@
       } else {
         if (e.PropertyName == "Visible") {
+          if (updateInProgress) return;
           try {
             updateInProgress = true;
@@ -238,6 +240,5 @@
         try {
           updateInProgress = true;
-          UpdateGroupAndProblemComboBox();
-          UpdateDataTableComboBox();
+          UpdateComboBoxes();
           UpdateRuns();
         } finally { updateInProgress = false; }
@@ -246,5 +247,5 @@
 
 
-    private void UpdateGroupAndProblemComboBox() {
+    private void UpdateComboBoxes() {
       var selectedGroupItem = (string)groupComboBox.SelectedItem;
 
@@ -259,4 +260,19 @@
       }
 
+      string selectedDataTable = (string)dataTableComboBox.SelectedItem;
+
+      dataTableComboBox.Items.Clear();
+      var dataTables = (from run in Content
+                        from result in run.Results
+                        where result.Value is IndexedDataTable<double>
+                        select result.Key).Distinct().ToArray();
+
+      dataTableComboBox.Items.AddRange(dataTables);
+      if (selectedDataTable != null && dataTableComboBox.Items.Contains(selectedDataTable)) {
+        dataTableComboBox.SelectedItem = selectedDataTable;
+      } else if (dataTableComboBox.Items.Count > 0) {
+        dataTableComboBox.SelectedItem = dataTableComboBox.Items[0];
+      }
+
       var selectedProblemItem = (ProblemInstance)problemComboBox.SelectedItem;
       
@@ -271,23 +287,4 @@
 
       SetEnabledStateOfControls();
-    }
-
-    private void UpdateDataTableComboBox() {
-      string selectedItem = (string)dataTableComboBox.SelectedItem;
-
-      dataTableComboBox.Items.Clear();
-      var dataTables = (from run in Content
-                        from result in run.Results
-                        where result.Value is IndexedDataTable<double>
-                        select result.Key).Distinct().ToArray();
-
-      dataTableComboBox.Items.AddRange(dataTables);
-      if (selectedItem != null && dataTableComboBox.Items.Contains(selectedItem)) {
-        dataTableComboBox.SelectedItem = selectedItem;
-      } else if (dataTableComboBox.Items.Count > 0) {
-        dataTableComboBox.SelectedItem = dataTableComboBox.Items[0];
-      }
-
-      UpdateProblemInstances();
     }
 
@@ -318,17 +315,18 @@
                             && r.Visible
                             && selectedProblem.Match(r)
-                            && r.Results.ContainsKey(table)
-                            && r.Results[table] is IndexedDataTable<double>
-                          let key = selectedGroup == AllInstances ? AllInstances : r.Parameters[selectedGroup].ToString()
+                          let key = selectedGroup == AllInstances
+                            ? AllInstances : r.Parameters[selectedGroup].ToString()
                           group r by key into g
                           select g) {
-        var trials = from run in alg
-                     from pd in problems
-                     where pd.Equals(new ProblemInstance(run))
-                     let cgraph = ((IndexedDataTable<double>)run.Results[table])
-                     where cgraph.Rows.Count > 0 && cgraph.Rows.First().Values.Count > 0
+        var trials = (from run in alg
+                     from pd in problems.Skip(1) // exclude artificial match all
+                     where pd.Match(run) && run.Results.ContainsKey(table)
+                     let cgraph = run.Results[table] as IndexedDataTable<double>
+                     where cgraph != null && cgraph.Rows.Count > 0
+                        && cgraph.Rows.First().Values.Count > 0
                      group cgraph by pd into g
-                     select g;
-
+                     select g).ToList();
+
+        if (trials.Count == 0) continue;
         groups.Add(new AlgorithmInstance(alg.Key, trials));
       }
@@ -339,6 +337,5 @@
         problems.Clear();
         var table = (string)dataTableComboBox.SelectedItem;
-        if (string.IsNullOrEmpty(table)) return;
-
+        
         var problemDict = CalculateBestTargetPerProblemInstance(table);
 
@@ -350,5 +347,5 @@
 
         problems.Add(ProblemInstance.MatchAll);
-        foreach (var p in problemDict.ToList()) {
+        foreach (var p in problemDict.OrderBy(x => x.Key.ProblemName, new NaturalStringComparer()).ToList()) {
           p.Key.BestKnownQuality = p.Value;
           p.Key.DisplayProblemType = problemTypesDifferent;
@@ -394,6 +391,6 @@
           misses[alg.Name] = epdfMisses = new SortedList<double, int>();
         }
-        foreach (var problem in alg.GetCases()) {
-          var max = problem.IsMaximization();
+        foreach (var problem in alg.GetCases().Where(x => x.Maximization.HasValue)) {
+          var max = problem.Maximization.Value;
           var absTargets = GetAbsoluteTargets(problem).ToArray();
           foreach (var run in alg.GetTrials(problem)) {
@@ -450,5 +447,5 @@
       foreach (var list in hits) {
         var row = new Series(list.Key) {
-          ChartType = SeriesChartType.StepLine,
+          ChartType = list.Value.Count > 1000 ? SeriesChartType.FastLine : SeriesChartType.StepLine,
           BorderWidth = 3,
           Color = colors[colorCount],
@@ -603,6 +600,7 @@
     private IEnumerable<double> GetAbsoluteTargets(ProblemInstance pInstance) {
       if (!targetsAreRelative) return targets;
-
-      var maximization = pInstance.IsMaximization();
+      if (!pInstance.Maximization.HasValue) throw new ArgumentException("Problem doesn't specify if it is to be maximized or minimized.");
+
+      var maximization = pInstance.Maximization.Value;
       var bestKnown = pInstance.BestKnownQuality;
       if (double.IsNaN(bestKnown)) throw new ArgumentException("Problem instance does not have a defined best - known quality.");
@@ -621,6 +619,7 @@
     private double[] GetAbsoluteTargetsWorstToBest(ProblemInstance pInstance) {
       if (targetsAreRelative && double.IsNaN(pInstance.BestKnownQuality)) throw new ArgumentException("Problem instance does not have a defined best-known quality.");
+      if (!pInstance.Maximization.HasValue) throw new ArgumentException("Problem doesn't specify if it is to be maximized or minimized.");
       var absTargets = GetAbsoluteTargets(pInstance);
-      return (pInstance.IsMaximization()
+      return (pInstance.Maximization.Value
         ? absTargets.OrderBy(x => x) : absTargets.OrderByDescending(x => x)).ToArray();
     }
@@ -663,8 +662,8 @@
       var problems = groups.SelectMany(x => x.GetCases()).Distinct().ToList();
 
-      foreach (var problem in problems) {
-        if (double.IsNaN(problem.BestKnownQuality)) continue;
+      foreach (var problem in problems.OrderBy(x => x.ProblemName, new NaturalStringComparer())) {
+        if (double.IsNaN(problem.BestKnownQuality) || !problem.Maximization.HasValue) continue;
         rowNames.Add(problem.ToString());
-        var max = problem.IsMaximization();
+        var max = problem.Maximization.Value;
         var absTargets = GetAbsoluteTargetsWorstToBest(problem);
         if (targetsAreRelative) {
@@ -776,5 +775,5 @@
 
     private void CalculateHitsForEachBudget(Dictionary<string, SortedList<double, double>> hits, ConvergenceGraph cgraph, ProblemInstance problem, string groupName) {
-      var max = problem.IsMaximization();
+      var max = problem.Maximization.Value;
       var prevIndex = 0;
       foreach (var b in budgets) {
@@ -897,6 +896,6 @@
         updateInProgress = true;
         var pd = (ProblemInstance)problemComboBox.SelectedItem;
-        if (!double.IsNaN(pd.BestKnownQuality)) {
-          var max = pd.IsMaximization();
+        if (!double.IsNaN(pd.BestKnownQuality) && pd.Maximization.HasValue) {
+          var max = pd.Maximization.Value;
           if (targetsAreRelative) targets = GetAbsoluteTargets(pd).ToArray();
           else {
@@ -957,8 +956,9 @@
         var values = resultsTable.Rows.First().Values;
         var pd = new ProblemInstance(run);
+        if (!pd.Maximization.HasValue) continue;
         pd = problems.Single(x => x.Equals(pd));
         if (targetsAreRelative && double.IsNaN(pd.BestKnownQuality)) continue;
 
-        var max = pd.IsMaximization();
+        var max = pd.Maximization.Value;
         var absTargets = GetAbsoluteTargetsWorstToBest(pd);
         var cgraph = new ConvergenceGraph(resultsTable, max);
@@ -1071,6 +1071,7 @@
         var values = resultsTable.Rows.First().Values;
         var pd = new ProblemInstance(run);
+        if (!pd.Maximization.HasValue) continue;
         pd = problems.Single(x => x.Equals(pd));
-        var max = pd.IsMaximization();
+        var max = pd.Maximization.Value;
         var cgraph = new ConvergenceGraph(resultsTable, max);
         var prevIndex = 0;
@@ -1082,5 +1083,5 @@
           }
           var v = values[index];
-          var tgt = targetsAreRelative ? CalculateRelativeDifference(pd.IsMaximization(), pd.BestKnownQuality, v.Item2) : v.Item2;
+          var tgt = targetsAreRelative ? CalculateRelativeDifference(max, pd.BestKnownQuality, v.Item2) : v.Item2;
           run.Results[table + (targetsAreRelative ? ".CostForRelTarget " : ".CostForAbsTarget ") + b] = new DoubleValue(tgt);
           prevIndex = index;
@@ -1109,9 +1110,10 @@
       var dict = new Dictionary<ProblemInstance, double>();
       foreach (var k in from r in Content where r.Visible let pd = new ProblemInstance(r) group r by pd into g select new { Problem = g.Key, Runs = g.ToList() }) {
-        var pd = new ProblemInstance(k.Runs[0]);
+        var pd = k.Problem;
+        if (!pd.Maximization.HasValue) continue;
         var values = GetQualityValues(k.Runs, table).ToList();
         var target = double.NaN;
         if (values.Count > 0) {
-          target = pd.IsMaximization() ? values.Max() : values.Min();
+          target = pd.Maximization.Value ? values.Max() : values.Min();
         }
         dict[pd] = target;
@@ -1133,5 +1135,5 @@
             var last = dt.Rows.First().Values.Last().Item2;
             if (!double.IsNaN(last))
-              yield return last;
+              yield return Math.Round(last, 10);
           }
         }
@@ -1296,7 +1298,6 @@
         performanceData = new Dictionary<ProblemInstance, List<ConvergenceGraph>>();
         foreach (var t in trials) {
-          if (double.IsNaN(t.Key.BestKnownQuality)) continue;
-          var max = t.Key.IsMaximization();
-          performanceData[t.Key] = t.Select(c => new ConvergenceGraph(c, max)).ToList();
+          if (double.IsNaN(t.Key.BestKnownQuality) || !t.Key.Maximization.HasValue) continue;
+          performanceData[t.Key] = t.Select(c => new ConvergenceGraph(c, t.Key.Maximization.Value)).ToList();
         }
       }
@@ -1329,5 +1330,5 @@
         ProblemName = string.Empty;
         Evaluator = string.Empty;
-        Maximization = string.Empty;
+        Maximization = null;
         DisplayProblemType = false;
         DisplayProblemName = false;
@@ -1342,9 +1343,9 @@
         ProblemName = GetStringValueOrEmpty(run, "Problem Name");
         Evaluator = GetStringValueOrEmpty(run, "Evaluator");
-        Maximization = GetMaximizationValueOrEmpty(run, "Maximization");
+        Maximization = GetBoolValueOrEmpty(run, "Maximization");
         DisplayProblemType = !string.IsNullOrEmpty(ProblemType);
         DisplayProblemName = !string.IsNullOrEmpty(ProblemName);
         DisplayEvaluator = !string.IsNullOrEmpty(Evaluator);
-        DisplayMaximization = !string.IsNullOrEmpty(Maximization);
+        DisplayMaximization = Maximization.HasValue;
         matchAll = false;
         BestKnownQuality = GetDoubleValueOrNaN(run, "BestKnownQuality");
@@ -1414,6 +1415,6 @@
         }
       }
-      private string maximization;
-      public string Maximization {
+      private bool? maximization;
+      public bool? Maximization {
         get { return maximization; }
         set {
@@ -1433,14 +1434,10 @@
       }
 
-      public bool IsMaximization() {
-        return Maximization == "MAX";
-      }
-
       public bool Match(IRun run) {
         return matchAll ||
-               GetStringValueOrEmpty(run, "Problem Type") == ProblemType
+               (GetStringValueOrEmpty(run, "Problem Type") == ProblemType
                && GetStringValueOrEmpty(run, "Problem Name") == ProblemName
                && GetStringValueOrEmpty(run, "Evaluator") == Evaluator
-               && GetMaximizationValueOrEmpty(run, "Maximization") == Maximization;
+               && GetBoolValueOrEmpty(run, "Maximization") == Maximization);
       }
 
@@ -1463,11 +1460,11 @@
       }
 
-      private string GetMaximizationValueOrEmpty(IRun run, string key) {
+      private bool? GetBoolValueOrEmpty(IRun run, string key) {
         IItem param;
         if (run.Parameters.TryGetValue(key, out param)) {
           var bv = param as BoolValue;
-          return bv != null ? (bv.Value ? "MAX" : "MIN") : string.Empty;
-        }
-        return string.Empty;
+          if (bv != null) return bv.Value;
+        }
+        return null;
       }
 
@@ -1490,5 +1487,5 @@
           (DisplayProblemName ? ProblemName : string.Empty),
           (DisplayEvaluator ? Evaluator : string.Empty),
-          (DisplayMaximization ? Maximization : string.Empty),
+          (DisplayMaximization && Maximization.HasValue ? (Maximization.Value ? "MAX" : "MIN") : string.Empty),
           !double.IsNaN(BestKnownQuality) ? BestKnownQuality.ToString(CultureInfo.CurrentCulture.NumberFormat) : string.Empty }.Where(x => !string.IsNullOrEmpty(x)));
       }
