Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/19/15 21:20:01 (9 years ago)
Author:
abeham
Message:

#2431: Extracted class that calculates ERT values from runs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.cs

    r12939 r12956  
    423423      var maximization = IsMaximization();
    424424
    425       var targetsPerProblem = CalculateBestTargetPerProblemInstance((string)dataTableComboBox.SelectedItem, maximization);
     425      var tableName = (string)dataTableComboBox.SelectedItem;
     426      if (string.IsNullOrEmpty(tableName)) return;
     427
     428      var targetsPerProblem = CalculateBestTargetPerProblemInstance(tableName, maximization);
    426429
    427430      var colNames = new string[columns];
     
    448451          }
    449452          var runs = group.Value[problem].Item2;
    450           var bestSucc = string.Empty;
     453          ErtCalculationResult result = default(ErtCalculationResult);
    451454          for (var i = 0; i < targets.Length; i++) {
    452             string succ;
    453             matrix[rowCount, i + 1] = CalculateExpectedRunTime(runs, (maximization ? (1 - targets[i]) : (1 + targets[i])) * group.Value[problem].Item1, maximization, out succ);
    454             if (i == targets.Length - 1) bestSucc = succ;
    455           }
    456           matrix[rowCount, columns - 1] = bestSucc;
     455            result = ExpectedRuntimeHelper.CalculateErt(runs, tableName, (maximization ? (1 - targets[i]) : (1 + targets[i])) * group.Value[problem].Item1, maximization);
     456            matrix[rowCount, i + 1] = result.ToString();
     457          }
     458          matrix[rowCount, columns - 1] = targets.Length > 0 ? result.SuccessfulRuns + "/" + result.TotalRuns : "-";
    457459          rowCount++;
    458460        }
     
    462464    }
    463465
    464     private string CalculateExpectedRunTime(List<IRun> group, double target, bool maximization, out string successProb) {
    465       var table = (string)dataTableComboBox.SelectedItem;
    466       successProb = "-";
    467       if (string.IsNullOrEmpty(table)) return "N/A";
    468       var successful = new List<double>();
    469       var unsuccessful = new List<double>();
    470       foreach (var r in group) {
    471         var targetAchieved = false;
    472         var row = ((IndexedDataTable<double>)r.Results[table]).Rows.First();
    473         foreach (var v in row.Values) {
    474           if (maximization && v.Item2 >= target || !maximization && v.Item2 <= target) {
    475             successful.Add(v.Item1);
    476             targetAchieved = true;
    477             break;
    478           }
    479         }
    480         if (!targetAchieved) unsuccessful.Add(row.Values.Last().Item1);
    481       }
    482       successProb = successful.Count + "/" + (successful.Count + unsuccessful.Count);
    483       if (successful.Count == 0) return "\u221e"; // infinity symbol
    484       if (unsuccessful.Count == 0) return successful.Average().ToString("##,0.0", CultureInfo.CurrentCulture.NumberFormat);
    485 
    486       var ps = successful.Count / (double)(successful.Count + unsuccessful.Count);
    487       return (successful.Average() + ((1.0 - ps) / ps) * unsuccessful.Average()).ToString("##,0.0", CultureInfo.CurrentCulture.NumberFormat);
    488     }
     466
    489467    #endregion
    490468
Note: See TracChangeset for help on using the changeset viewer.