Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4200


Ignore:
Timestamp:
08/11/10 17:40:00 (12 years ago)
Author:
mkommend
Message:

improved the performance of RunCollections by caching some properties and corrected some bugs in the RunCollectionTabularView (ticket #1144)

Location:
trunk/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionTabularView.Designer.cs

    r3742 r4200  
    4646    private void InitializeComponent() {
    4747      this.components = new System.ComponentModel.Container();
     48      this.dataGridView.RowHeaderMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(dataGridView_RowHeaderMouseDoubleClick);
    4849    }
    4950
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionTabularView.cs

    r4068 r4200  
    3131  [View("RunCollection Tabular View")]
    3232  [Content(typeof(RunCollection), false)]
    33   public partial class RunCollectionTabularView : StringConvertibleMatrixView {
     33  public sealed partial class RunCollectionTabularView : StringConvertibleMatrixView {
     34    private int[] runToRowMapping;
    3435    public RunCollectionTabularView() {
    3536      InitializeComponent();
    36       this.dataGridView.RowHeaderMouseDoubleClick += new DataGridViewCellMouseEventHandler(dataGridView_RowHeaderMouseDoubleClick);
    3737      base.ReadOnly = true;
    3838    }
     
    5151      base.OnContentChanged();
    5252      if (Content != null) {
    53         foreach (IRun run in Content)
    54           UpdateRun(run);
    55       }
    56     }
    57 
     53        runToRowMapping = Enumerable.Range(0, Content.Count).ToArray();
     54        UpdateRowAttributes();
     55      }
     56    }
     57
     58    #region events
    5859    protected override void RegisterContentEvents() {
    5960      base.RegisterContentEvents();
     
    6364      RegisterRunEvents(Content);
    6465    }
    65     protected virtual void RegisterRunEvents(IEnumerable<IRun> runs) {
     66    private void RegisterRunEvents(IEnumerable<IRun> runs) {
    6667      foreach (IRun run in runs)
    6768        run.Changed += new EventHandler(run_Changed);
     
    7475      DeregisterRunEvents(Content);
    7576    }
    76     protected virtual void DeregisterRunEvents(IEnumerable<IRun> runs) {
     77    private void DeregisterRunEvents(IEnumerable<IRun> runs) {
    7778      foreach (IRun run in runs)
    7879        run.Changed -= new EventHandler(run_Changed);
     
    8182      DeregisterRunEvents(e.OldItems);
    8283      RegisterRunEvents(e.Items);
     84      OnContentChanged();
    8385    }
    8486    private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
     
    9698      }
    9799    }
     100    #endregion
    98101
    99102    private void UpdateRun(IRun run) {
    100       int rowIndex = Content.ToList().IndexOf(run);
    101       rowIndex = virtualRowIndizes[rowIndex];
     103      int runIndex = GetIndexOfRun(run);
     104      int rowIndex = runToRowMapping[runIndex];
    102105      this.dataGridView.Rows[rowIndex].Visible = run.Visible;
    103106      this.dataGridView.Rows[rowIndex].DefaultCellStyle.ForeColor = run.Color;
    104       this.rowsTextBox.Text = this.Content.Count(r => r.Visible).ToString();
     107      this.UpdateRowHeaders();
     108    }
     109
     110    private int GetIndexOfRun(IRun run) {
     111      int i = 0;
     112      foreach (IRun actualRun in Content) {
     113        if (actualRun == run)
     114          return i;
     115        i++;
     116      }
     117      throw new ArgumentException("Run " + run.Name + "could not be found in the RunCollection.");
    105118    }
    106119
    107120    private void dataGridView_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) {
    108121      if (e.RowIndex >= 0) {
    109         IRun run = Content.ElementAt(virtualRowIndizes[e.RowIndex]);
     122        IRun run = Content.ElementAt(runToRowMapping.ToList().IndexOf(e.RowIndex));
    110123        IContentView view = MainFormManager.MainForm.ShowContent(run);
    111124        if (view != null) {
     
    124137        Array.Sort(newSortedIndex, rowComparer);
    125138      }
     139
     140      runToRowMapping = new int[newSortedIndex.Length];
     141      int i = 0;
     142      foreach (int runIndex in newSortedIndex) {
     143        runToRowMapping[runIndex] = i;
     144        i++;
     145      }
     146      UpdateRowAttributes();
    126147      return newSortedIndex;
     148    }
     149
     150    private void UpdateRowAttributes() {
     151      int runIndex = 0;
     152      foreach (IRun run in Content) {
     153        int rowIndex = this.runToRowMapping[runIndex];
     154        this.dataGridView.Rows[rowIndex].Visible = run.Visible;
     155        this.dataGridView.Rows[rowIndex].DefaultCellStyle.ForeColor = run.Color;
     156        runIndex++;
     157      }
    127158    }
    128159
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs

    r4163 r4200  
    111111          ListViewItem listViewItem = CreateListViewItem(item);
    112112          AddListViewItem(listViewItem);
    113           UpdateRun(item);
    114113          if ((selectedName != null) && item.Name.Equals(selectedName))
    115114            listViewItem.Selected = true;
    116115        }
     116        AdjustListViewColumnSizes();
    117117      } else {
    118118        runCollectionConstraintCollectionView.Content = null;
     
    150150      listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
    151151      listViewItem.Tag = item;
     152
     153      if (item.Visible) {
     154        listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
     155        listViewItem.ForeColor = item.Color;
     156      } else {
     157        listViewItem.Font = new Font(listViewItem.Font, FontStyle.Italic);
     158        listViewItem.ForeColor = Color.LightGray;
     159      }
    152160      return listViewItem;
    153161    }
     
    156164      ((IRun)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged);
    157165      ((IRun)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged);
    158       AdjustListViewColumnSizes();
    159166    }
    160167    protected virtual void RemoveListViewItem(ListViewItem listViewItem) {
     
    294301      else {
    295302        RegisterRunEvents(e.Items);
    296         foreach (IRun item in e.Items) {
     303        foreach (IRun item in e.Items)
    297304          AddListViewItem(CreateListViewItem(item));
    298           UpdateRun(item);
    299         }
     305
     306        AdjustListViewColumnSizes();
    300307        analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
    301308        clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
     
    331338        }
    332339        RegisterRunEvents(e.Items);
    333         foreach (IRun item in e.Items) {
     340        foreach (IRun item in e.Items)
    334341          AddListViewItem(CreateListViewItem(item));
    335           UpdateRun(item);
    336         }
     342
     343        AdjustListViewColumnSizes();
    337344        analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
    338345        clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
  • trunk/sources/HeuristicLab.Optimization/3.3/Run.cs

    r4161 r4200  
    3434  [StorableClass]
    3535  public sealed class Run : NamedItem, IRun {
     36    [StorableConstructor]
     37    private Run(bool deserializing) : base(deserializing) { }
     38    public Run()
     39      : base() {
     40      name = ItemName;
     41      description = ItemDescription;
     42      color = Color.Black;
     43      algorithm = null;
     44      parameters = new Dictionary<string, IItem>();
     45      results = new Dictionary<string, IItem>();
     46    }
     47    public Run(IAlgorithm algorithm)
     48      : base() {
     49      if (algorithm == null) throw new ArgumentNullException();
     50      name = algorithm.Name + " Run (" + algorithm.ExecutionTime.ToString() + ")";
     51      description = ItemDescription;
     52      color = Color.Black;
     53      Initialize(algorithm);
     54    }
     55    public Run(string name, IAlgorithm algorithm)
     56      : base(name) {
     57      if (algorithm == null) throw new ArgumentNullException();
     58      color = Color.Black;
     59      description = ItemDescription;
     60      Initialize(algorithm);
     61    }
     62    public Run(string name, string description, IAlgorithm algorithm)
     63      : base(name, description) {
     64      if (algorithm == null) throw new ArgumentNullException();
     65      color = Color.Black;
     66      Initialize(algorithm);
     67    }
     68
     69    private void Initialize(IAlgorithm algorithm) {
     70      IAlgorithm clone = (IAlgorithm)algorithm.Clone();
     71      parameters = new Dictionary<string, IItem>();
     72      results = new Dictionary<string, IItem>();
     73      clone.CollectParameterValues(parameters);
     74      clone.CollectResultValues(results);
     75      if (clone.StoreAlgorithmInEachRun) {
     76        clone.Prepare(true);
     77        this.algorithm = clone;
     78      }
     79    }
     80    [StorableHook(HookType.AfterDeserialization)]
     81    private void AfterDeserializationHook() {
     82      if (color == Color.Empty) color = Color.Black;
     83    }
     84
    3685    [Storable]
    3786    private IAlgorithm algorithm;
     
    78127    }
    79128
    80     [StorableConstructor]
    81     private Run(bool deserializing) : base(deserializing) { }
    82     public Run()
    83       : base() {
    84       name = ItemName;
    85       description = ItemDescription;
    86       color = Color.Black;
    87       algorithm = null;
    88       parameters = new Dictionary<string, IItem>();
    89       results = new Dictionary<string, IItem>();
    90     }
    91     public Run(IAlgorithm algorithm)
    92       : base() {
    93       if (algorithm == null) throw new ArgumentNullException();
    94       name = algorithm.Name + " Run (" + algorithm.ExecutionTime.ToString() + ")";
    95       description = ItemDescription;
    96       color = Color.Black;
    97       Initialize(algorithm);
    98     }
    99     public Run(string name, IAlgorithm algorithm)
    100       : base(name) {
    101       if (algorithm == null) throw new ArgumentNullException();
    102       color = Color.Black;
    103       description = ItemDescription;
    104       Initialize(algorithm);
    105     }
    106     public Run(string name, string description, IAlgorithm algorithm)
    107       : base(name, description) {
    108       if (algorithm == null) throw new ArgumentNullException();
    109       color = Color.Black;
    110       Initialize(algorithm);
    111     }
    112 
    113     private void Initialize(IAlgorithm algorithm) {
    114       IAlgorithm clone = (IAlgorithm)algorithm.Clone();
    115       parameters = new Dictionary<string, IItem>();
    116       results = new Dictionary<string, IItem>();
    117       clone.CollectParameterValues(parameters);
    118       clone.CollectResultValues(results);
    119       if (clone.StoreAlgorithmInEachRun) {
    120         clone.Prepare(true);
    121         this.algorithm = clone;
    122       }
    123     }
    124 
    125     [StorableHook(HookType.AfterDeserialization)]
    126     private void AfterDeserializationHook() {
    127       if (color == Color.Empty) color = Color.Black;
    128     }
    129 
    130129    public override IDeepCloneable Clone(Cloner cloner) {
    131130      Run clone = (Run)base.Clone(cloner);
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs

    r4164 r4200  
    7272      base.OnCollectionReset(items, oldItems);
    7373      OnReset();
     74      columnNameCache = null;
    7475      OnColumnNamesChanged();
     76      rowNamesCache = null;
    7577      OnRowNamesChanged();
    7678    }
     
    8587      base.OnItemsAdded(items);
    8688      OnReset();
    87       if (columnNamesChanged)
     89      if (columnNamesChanged) {
     90        columnNameCache = null;
    8891        OnColumnNamesChanged();
     92      }
     93      rowNamesCache = null;
    8994      OnRowNamesChanged();
    9095      this.UpdateFiltering(false);
     
    100105      base.OnItemsRemoved(items);
    101106      OnReset();
    102       if (columnNamesChanged)
     107      if (columnNamesChanged) {
     108        columnNameCache = null;
    103109        OnColumnNamesChanged();
     110      }
     111      rowNamesCache = null;
    104112      OnRowNamesChanged();
    105113    }
     
    207215      set { throw new NotSupportedException(); }
    208216    }
     217    private List<string> columnNameCache;
    209218    IEnumerable<string> IStringConvertibleMatrix.ColumnNames {
    210219      get {
    211         List<string> value = new List<string>(parameterNames);
    212         value.AddRange(resultNames);
    213         value.Sort();
    214         return value;
    215       }
    216       set { throw new NotSupportedException(); }
    217     }
     220        if (columnNameCache == null) {
     221          columnNameCache = new List<string>(parameterNames);
     222          columnNameCache.AddRange(resultNames);
     223          columnNameCache.Sort();
     224        }
     225        return columnNameCache;
     226      }
     227      set { throw new NotSupportedException(); }
     228    }
     229    private List<string> rowNamesCache;
    218230    IEnumerable<string> IStringConvertibleMatrix.RowNames {
    219       get { return list.Select(x => x.Name).ToList(); }
     231      get {
     232        if (rowNamesCache == null)
     233          rowNamesCache = list.Select(x => x.Name).ToList();
     234        return rowNamesCache;
     235      }
    220236      set { throw new NotSupportedException(); }
    221237    }
Note: See TracChangeset for help on using the changeset viewer.