Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/17/15 09:25:44 (9 years ago)
Author:
abeham
Message:

#2431:

  • Added run collection view
  • Changed name of analyzers
  • Modified algorithms to include Execution Time as a result
Location:
branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3
Files:
1 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

    r12764 r12771  
    338338      <DependentUpon>RunCollectionEqualityConstraintView.cs</DependentUpon>
    339339    </Compile>
     340    <Compile Include="RunCollectionViews\RunCollectionECDFView.cs">
     341      <SubType>UserControl</SubType>
     342    </Compile>
     343    <Compile Include="RunCollectionViews\RunCollectionECDFView.Designer.cs">
     344      <DependentUpon>RunCollectionECDFView.cs</DependentUpon>
     345    </Compile>
    340346    <Compile Include="RunCollectionViews\RunCollectionTableView.cs">
    341347      <SubType>UserControl</SubType>
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionECDFView.Designer.cs

    r12764 r12771  
    2020#endregion
    2121namespace HeuristicLab.Optimization.Views {
    22   partial class RunCollectionChartAggregationView {
     22  partial class RunCollectionECDFView {
    2323    /// <summary>
    2424    /// Required designer variable.
     
    4848      this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    4949      this.label2 = new System.Windows.Forms.Label();
    50       this.dataRowComboBox = new System.Windows.Forms.ComboBox();
     50      this.groupComboBox = new System.Windows.Forms.ComboBox();
     51      this.logScalingCheckBox = new System.Windows.Forms.CheckBox();
    5152      this.SuspendLayout();
    5253      //
    5354      // dataTableComboBox
    5455      //
    55       this.dataTableComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     56      this.dataTableComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
    5657            | System.Windows.Forms.AnchorStyles.Right)));
    5758      this.dataTableComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    5859      this.dataTableComboBox.FormattingEnabled = true;
    59       this.dataTableComboBox.Location = new System.Drawing.Point(69, 3);
     60      this.dataTableComboBox.Location = new System.Drawing.Point(69, 30);
    6061      this.dataTableComboBox.Name = "dataTableComboBox";
    6162      this.dataTableComboBox.Size = new System.Drawing.Size(455, 21);
     
    6667      //
    6768      this.label1.AutoSize = true;
    68       this.label1.Location = new System.Drawing.Point(3, 6);
     69      this.label1.Location = new System.Drawing.Point(3, 33);
    6970      this.label1.Name = "label1";
    7071      this.label1.Size = new System.Drawing.Size(60, 13);
     
    7475      // viewHost
    7576      //
    76       this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    77             | System.Windows.Forms.AnchorStyles.Left)
     77      this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     78            | System.Windows.Forms.AnchorStyles.Left) 
    7879            | System.Windows.Forms.AnchorStyles.Right)));
    7980      this.viewHost.Caption = "View";
     
    8384      this.viewHost.Name = "viewHost";
    8485      this.viewHost.ReadOnly = false;
    85       this.viewHost.Size = new System.Drawing.Size(520, 314);
     86      this.viewHost.Size = new System.Drawing.Size(520, 291);
    8687      this.viewHost.TabIndex = 2;
    8788      this.viewHost.ViewsLabelVisible = true;
     
    9192      //
    9293      this.label2.AutoSize = true;
    93       this.label2.Location = new System.Drawing.Point(3, 33);
     94      this.label2.Location = new System.Drawing.Point(3, 6);
    9495      this.label2.Name = "label2";
    95       this.label2.Size = new System.Drawing.Size(55, 13);
     96      this.label2.Size = new System.Drawing.Size(39, 13);
    9697      this.label2.TabIndex = 3;
    97       this.label2.Text = "DataRow:";
     98      this.label2.Text = "Group:";
    9899      //
    99       // dataRowComboBox
     100      // groupComboBox
    100101      //
    101       this.dataRowComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     102      this.groupComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    102103            | System.Windows.Forms.AnchorStyles.Right)));
    103       this.dataRowComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    104       this.dataRowComboBox.FormattingEnabled = true;
    105       this.dataRowComboBox.Location = new System.Drawing.Point(69, 30);
    106       this.dataRowComboBox.Name = "dataRowComboBox";
    107       this.dataRowComboBox.Size = new System.Drawing.Size(455, 21);
    108       this.dataRowComboBox.TabIndex = 4;
    109       this.dataRowComboBox.SelectedIndexChanged += new System.EventHandler(this.dataRowComboBox_SelectedIndexChanged);
     104      this.groupComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     105      this.groupComboBox.FormattingEnabled = true;
     106      this.groupComboBox.Location = new System.Drawing.Point(69, 3);
     107      this.groupComboBox.Name = "groupComboBox";
     108      this.groupComboBox.Size = new System.Drawing.Size(455, 21);
     109      this.groupComboBox.TabIndex = 4;
     110      this.groupComboBox.SelectedIndexChanged += new System.EventHandler(this.groupComboBox_SelectedIndexChanged);
    110111      //
    111       // RunCollectionChartAggregationView
     112      // logScalingCheckBox
    112113      //
    113       this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
     114      this.logScalingCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     115      this.logScalingCheckBox.AutoSize = true;
     116      this.logScalingCheckBox.Location = new System.Drawing.Point(0, 354);
     117      this.logScalingCheckBox.Name = "logScalingCheckBox";
     118      this.logScalingCheckBox.Size = new System.Drawing.Size(112, 17);
     119      this.logScalingCheckBox.TabIndex = 5;
     120      this.logScalingCheckBox.Text = "logarithmic scaling";
     121      this.logScalingCheckBox.UseVisualStyleBackColor = true;
     122      this.logScalingCheckBox.CheckedChanged += new System.EventHandler(this.logScalingCheckBox_CheckedChanged);
     123      //
     124      // RunCollectionECDFView
     125      //
    114126      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    115       this.Controls.Add(this.dataRowComboBox);
     127      this.Controls.Add(this.logScalingCheckBox);
     128      this.Controls.Add(this.groupComboBox);
    116129      this.Controls.Add(this.label2);
    117130      this.Controls.Add(this.viewHost);
    118131      this.Controls.Add(this.label1);
    119132      this.Controls.Add(this.dataTableComboBox);
    120       this.Name = "RunCollectionChartAggregationView";
     133      this.Name = "RunCollectionECDFView";
    121134      this.Size = new System.Drawing.Size(527, 374);
    122135      this.ResumeLayout(false);
     
    131144    private MainForm.WindowsForms.ViewHost viewHost;
    132145    private System.Windows.Forms.Label label2;
    133     private System.Windows.Forms.ComboBox dataRowComboBox;
     146    private System.Windows.Forms.ComboBox groupComboBox;
     147    private System.Windows.Forms.CheckBox logScalingCheckBox;
    134148  }
    135149}
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionECDFView.cs

    r12764 r12771  
    2424using System.ComponentModel;
    2525using System.Linq;
     26using System.Windows.Forms;
    2627using HeuristicLab.Analysis;
    2728using HeuristicLab.Collections;
     29using HeuristicLab.Common;
    2830using HeuristicLab.Core.Views;
    2931using HeuristicLab.MainForm;
    3032
    3133namespace HeuristicLab.Optimization.Views {
    32   [View("Chart Aggregation")]
     34  [View("ECDF Performance Comparison")]
    3335  [Content(typeof(RunCollection), false)]
    34   public partial class RunCollectionChartAggregationView : ItemView {
    35     private const string AllDataRows = "All DataRows";
     36  public partial class RunCollectionECDFView : ItemView {
     37    private const string AllRuns = "All Runs";
    3638
    3739    public new RunCollection Content {
     
    4042    }
    4143
    42     private int rowNumber;
    4344    private bool suppressUpdates;
    44     private readonly Dictionary<IRun, IEnumerable<DataRow>> runMapping;
    45     private readonly DataTable combinedDataTable;
    46     public DataTable CombinedDataTable {
     45    private readonly IndexedDataTable<double> combinedDataTable;
     46    public IndexedDataTable<double> CombinedDataTable {
    4747      get { return combinedDataTable; }
    4848    }
    4949
    50     public RunCollectionChartAggregationView() {
     50    public RunCollectionECDFView() {
    5151      InitializeComponent();
    52       runMapping = new Dictionary<IRun, IEnumerable<DataRow>>();
    53       combinedDataTable = new DataTable("Combined DataTable", "A data table containing data rows from multiple runs.");
     52      combinedDataTable = new IndexedDataTable<double>("Combined DataTable", "A data table containing the ECDF of each of a number of groups.") {
     53        VisualProperties = { YAxisTitle = "Proportion of reached targets" }
     54      };
    5455      viewHost.Content = combinedDataTable;
    5556      suppressUpdates = false;
     
    8081        return;
    8182      }
     83      UpdateGroupComboBox();
    8284      UpdateDataTableComboBox();
    83       UpdateDataRowComboBox();
    84       AddRuns(e.Items);
     85      foreach (var run in e.Items)
     86        RegisterRunEvents(run);
    8587    }
    8688    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     
    9092        return;
    9193      }
     94      UpdateGroupComboBox();
    9295      UpdateDataTableComboBox();
    93       UpdateDataRowComboBox();
    94       RemoveRuns(e.Items);
     96      foreach (var run in e.Items)
     97        DeregisterRunEvents(run);
    9598    }
    9699    private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     
    100103        return;
    101104      }
     105      UpdateGroupComboBox();
    102106      UpdateDataTableComboBox();
    103       UpdateDataRowComboBox();
    104       RemoveRuns(e.OldItems);
    105       AddRuns(e.Items);
     107      foreach (var run in e.OldItems)
     108        DeregisterRunEvents(run);
    106109    }
    107110    private void Content_AlgorithmNameChanged(object sender, EventArgs e) {
     
    118121      if (!suppressUpdates) {
    119122        UpdateDataTableComboBox();
    120         UpdateDataRowComboBox();
    121         UpdateRuns(Content);
     123        UpdateGroupComboBox();
     124        UpdateRuns();
    122125      }
    123126    }
     
    134137        Invoke((Action<object, PropertyChangedEventArgs>)run_PropertyChanged, sender, e);
    135138      } else {
    136         var run = (IRun)sender;
    137         if (e.PropertyName == "Color" || e.PropertyName == "Visible")
    138           UpdateRuns(new[] { run });
     139        if (e.PropertyName == "Visible")
     140          UpdateRuns();
    139141      }
    140142    }
     
    144146      base.OnContentChanged();
    145147      dataTableComboBox.Items.Clear();
    146       dataRowComboBox.Items.Clear();
     148      groupComboBox.Items.Clear();
    147149      combinedDataTable.Rows.Clear();
    148       runMapping.Clear();
    149150
    150151      UpdateCaption();
    151152      if (Content != null) {
     153        UpdateGroupComboBox();
    152154        UpdateDataTableComboBox();
    153155      }
    154156    }
    155157
    156     private void RebuildCombinedDataTable() {
    157       RemoveRuns(Content);
    158       rowNumber = 0;
    159       AddRuns(Content);
    160     }
    161 
    162     private void AddRuns(IEnumerable<IRun> runs) {
    163       foreach (var run in runs) {
    164         runMapping[run] = ExtractDataRowsFromRun(run).ToList();
    165         RegisterRunEvents(run);
    166       }
    167       var dataRows = runs.Where(r => r.Visible && runMapping.ContainsKey(r)).SelectMany(r => runMapping[r]);
    168       combinedDataTable.Rows.AddRange(dataRows);
    169     }
    170 
    171     private void RemoveRuns(IEnumerable<IRun> runs) {
    172       var dataRows = runs.Where(r => runMapping.ContainsKey(r)).SelectMany(r => runMapping[r]).ToList();
    173       foreach (var run in runs) {
    174         if (!runMapping.ContainsKey(run)) continue;
    175         runMapping.Remove(run);
    176         DeregisterRunEvents(run);
    177       }
    178       combinedDataTable.Rows.RemoveRange(dataRows);
    179     }
    180 
    181     private void UpdateRuns(IEnumerable<IRun> runs) {
    182       foreach (var run in runs) {
    183         //update color
    184         if (!runMapping.ContainsKey(run)) {
    185           runMapping[run] = ExtractDataRowsFromRun(run).ToList();
    186           RegisterRunEvents(run);
    187         } else {
    188           foreach (var dataRow in runMapping[run]) {
    189             dataRow.VisualProperties.Color = run.Color;
     158    private void UpdateRuns() {
     159      if (InvokeRequired) {
     160        Invoke((Action)UpdateRuns);
     161        return;
     162      }
     163      SuspendRepaint();
     164      try {
     165        combinedDataTable.Rows.Clear();
     166        var table = (string)dataTableComboBox.SelectedItem;
     167        if (string.IsNullOrEmpty(table)) return;
     168        var maximum = Content.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Max(y => y.Item2)).Max();
     169        var minimum = Content.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Min(y => y.Item2)).Min();
     170        var levels = Enumerable.Range(0, 51).Select(x => maximum - (x / 50.0) * (maximum - minimum)).ToArray();
     171        var selectedGroup = (string)groupComboBox.SelectedItem;
     172        if (string.IsNullOrEmpty(selectedGroup)) return;
     173        List<Tuple<string, List<IRun>>> groupedRuns;
     174        if (selectedGroup == AllRuns)
     175          groupedRuns = new List<Tuple<string, List<IRun>>> { Tuple.Create(AllRuns, Content.ToList()) };
     176        else groupedRuns = (from r in Content
     177                            group r by r.Parameters[selectedGroup].ToString() into g
     178                            select Tuple.Create(g.Key, g.ToList())).ToList();
     179        var xAxisTitles = new HashSet<string>();
     180        foreach (var group in groupedRuns) {
     181          var hits = new SortedList<double, int>();
     182          foreach (var run in group.Item2) {
     183            var resultsTable = (IndexedDataTable<double>)run.Results[table];
     184            xAxisTitles.Add(resultsTable.VisualProperties.XAxisTitle);
     185            var graph = new LinkedList<Tuple<double, double>>(resultsTable.Rows.First().Values);
     186            var current = graph.First.Next;
     187            // prune convergence graph to obtain first hit times only
     188            while (current != null) {
     189              if (current.Value.Item2.IsAlmost(current.Previous.Value.Item2)) {
     190                var h = current;
     191                current = current.Previous;
     192                graph.Remove(h);
     193              }
     194              current = current.Next;
     195            }
     196            var i = 0;
     197            current = graph.First;
     198            while (i < levels.Length && current != null) {
     199              if (current.Value.Item2 < levels[i]) {
     200                if (hits.ContainsKey(current.Value.Item1))
     201                  hits[current.Value.Item1]++;
     202                else hits[current.Value.Item1] = 1;
     203                i++;
     204              } else {
     205                current = current.Next;
     206              }
     207            }
    190208          }
     209          var row = new IndexedDataRow<double>(group.Item1) { VisualProperties = { ChartType = DataRowVisualProperties.DataRowChartType.StepLine } };
     210          var total = 0.0;
     211          foreach (var h in hits) {
     212            total += h.Value;
     213            row.Values.Add(Tuple.Create(Math.Max(1, h.Key), total / (group.Item2.Count * levels.Length)));
     214          }
     215          combinedDataTable.Rows.Add(row);
    191216        }
    192       }
    193       //update visibility - remove and add all rows to keep the same order as before
    194       combinedDataTable.Rows.Clear();
    195       combinedDataTable.Rows.AddRange(runMapping.Where(mapping => mapping.Key.Visible).SelectMany(mapping => mapping.Value));
    196     }
    197 
    198     private IEnumerable<DataRow> ExtractDataRowsFromRun(IRun run) {
    199       var resultName = (string)dataTableComboBox.SelectedItem;
    200       if (string.IsNullOrEmpty(resultName)) yield break;
    201 
    202       var rowName = (string)dataRowComboBox.SelectedItem;
    203       if (!run.Results.ContainsKey(resultName)) yield break;
    204 
    205       var dataTable = (DataTable)run.Results[resultName];
    206       foreach (var dataRow in dataTable.Rows) {
    207         if (dataRow.Name != rowName && rowName != AllDataRows) continue;
    208         rowNumber++;
    209         var clonedRow = (DataRow)dataRow.Clone();
    210         //row names must be unique -> add incremented number to the row name
    211         clonedRow.Name = run.Name + "." + dataRow.Name + rowNumber;
    212         clonedRow.VisualProperties.DisplayName = run.Name + "." + dataRow.Name;
    213         clonedRow.VisualProperties.Color = run.Color;
    214         yield return clonedRow;
     217        combinedDataTable.VisualProperties.XAxisTitle = string.Join(" / ", xAxisTitles);
     218      } finally { ResumeRepaint(true); }
     219    }
     220
     221    private void UpdateGroupComboBox() {
     222      string selectedItem = (string)groupComboBox.SelectedItem;
     223
     224      var groupings = Content.ParameterNames.ToArray();
     225      groupComboBox.Items.Clear();
     226      groupComboBox.Items.Add(AllRuns);
     227      groupComboBox.Items.AddRange(groupings);
     228      if (selectedItem != null && groupComboBox.Items.Contains(selectedItem)) {
     229        groupComboBox.SelectedItem = selectedItem;
     230      } else if (groupComboBox.Items.Count > 0) {
     231        groupComboBox.SelectedItem = groupComboBox.Items[0];
    215232      }
    216233    }
     
    222239      var dataTables = (from run in Content
    223240                        from result in run.Results
    224                         where result.Value is DataTable
     241                        where result.Value is IndexedDataTable<double>
    225242                        select result.Key).Distinct().ToArray();
    226243
     
    234251
    235252    private void UpdateCaption() {
    236       Caption = Content != null ? Content.OptimizerName + " Chart Aggregation" : ViewAttribute.GetViewName(GetType());
    237     }
    238 
    239     private void UpdateDataRowComboBox() {
    240       string selectedItem = (string)dataRowComboBox.SelectedItem;
    241 
    242       dataRowComboBox.Items.Clear();
    243       var resultName = (string)dataTableComboBox.SelectedItem;
    244       if (resultName == null) return;
    245 
    246       var dataTables = from run in Content
    247                        where run.Results.ContainsKey(resultName)
    248                        select run.Results[resultName] as DataTable;
    249       var rowNames = (from dataTable in dataTables
    250                       from row in dataTable.Rows
    251                       select row.Name).Distinct().ToArray();
    252 
    253       dataRowComboBox.Items.AddRange(rowNames);
    254       dataRowComboBox.Items.Add(AllDataRows);
    255       if (selectedItem != null && dataRowComboBox.Items.Contains(selectedItem)) {
    256         dataRowComboBox.SelectedItem = selectedItem;
    257       } else if (dataRowComboBox.Items.Count > 0) {
    258         dataRowComboBox.SelectedItem = dataRowComboBox.Items[0];
    259       }
    260     }
    261 
     253      Caption = Content != null ? Content.OptimizerName + " ECDF Comparison" : ViewAttribute.GetViewName(GetType());
     254    }
     255
     256    private void groupComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     257      UpdateRuns();
     258    }
    262259    private void dataTableComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    263       UpdateDataRowComboBox();
    264     }
    265     private void dataRowComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    266       if (suppressUpdates) return;
    267       RebuildCombinedDataTable();
     260      UpdateRuns();
     261    }
     262
     263    private void logScalingCheckBox_CheckedChanged(object sender, EventArgs e) {
     264      combinedDataTable.VisualProperties.XAxisLogScale = logScalingCheckBox.Checked;
    268265    }
    269266  }
Note: See TracChangeset for help on using the changeset viewer.