Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3447 for trunk/sources


Ignore:
Timestamp:
04/20/10 17:37:53 (14 years ago)
Author:
mkommend
Message:

added RowComparer for RunCollectionTabularView (ticket #970)

Location:
trunk/sources
Files:
3 edited

Legend:

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

    r3441 r3447  
    3333using HeuristicLab.Common;
    3434using HeuristicLab.Core;
     35using HeuristicLab.Data;
    3536
    3637namespace HeuristicLab.Optimization.Views {
     
    8283    }
    8384
     85    public IStringConvertibleMatrix Matrix {
     86      get { return this.Content; }
     87    }
     88
    8489    protected override void RegisterContentEvents() {
    8590      base.RegisterContentEvents();
     
    146151      this.yAxisComboBox.Items.Clear();
    147152      this.sizeComboBox.Items.Clear();
    148       this.xAxisComboBox.Items.AddRange(Content.ColumnNames.ToArray());
    149       this.yAxisComboBox.Items.AddRange(Content.ColumnNames.ToArray());
     153      this.xAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
     154      this.yAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
    150155      this.sizeComboBox.Items.Add(constantLabel);
    151       this.sizeComboBox.Items.AddRange(Content.ColumnNames.ToArray());
     156      this.sizeComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
    152157    }
    153158
     
    194199        return null;
    195200
    196       string value = Content.GetValue(row, column);
    197       double d;
    198       double? ret = null;
    199       if (double.TryParse(value, out d))
    200         ret = d;
    201       else if (value != null)
    202         ret = GetCategoricalValue(column, value);
     201      IItem value = Content.GetValue(row, column);
     202      DoubleValue doubleValue = value as DoubleValue;
     203      IntValue intValue = value as IntValue;
     204      double ret;
     205
     206      if (doubleValue != null)
     207        ret = doubleValue.Value;
     208      else if (intValue != null)
     209        ret = intValue.Value;
     210      else
     211        ret = GetCategoricalValue(column, Matrix.GetValue(row, column));
     212
    203213      return ret;
    204214    }
     
    361371      builder.AppendLine(this.Content.ElementAt(runIndex).Name);
    362372      int columnIndex = 0;
    363       foreach (string columnName in this.Content.ColumnNames) {
     373      foreach (string columnName in Matrix.ColumnNames) {
    364374        builder.Append(columnName);
    365375        builder.Append(": ");
    366         builder.AppendLine(this.Content.GetValue(runIndex, columnIndex));
     376        builder.AppendLine(Matrix.GetValue(runIndex, columnIndex));
    367377        columnIndex++;
    368378      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionTabularView.cs

    r3423 r3447  
    3131using HeuristicLab.Data.Views;
    3232using HeuristicLab.Collections;
     33using HeuristicLab.Core;
    3334
    3435namespace HeuristicLab.Optimization.Views {
     
    6869      }
    6970    }
     71
     72
     73    protected override int[] Sort(IEnumerable<KeyValuePair<int, SortOrder>> sortedColumns) {
     74      int[] newSortedIndex = Enumerable.Range(0, Content.Count).ToArray();
     75      RunCollectionRowComparer rowComparer = new RunCollectionRowComparer();
     76      if (sortedColumns.Count() != 0) {
     77        rowComparer.SortedIndizes = sortedColumns;
     78        rowComparer.Matrix = Content;
     79        Array.Sort(newSortedIndex, rowComparer);
     80      }
     81      return newSortedIndex;
     82    }
     83
     84    public class RunCollectionRowComparer : IComparer<int> {
     85      public RunCollectionRowComparer() {
     86      }
     87
     88      private List<KeyValuePair<int, SortOrder>> sortedIndizes;
     89      public IEnumerable<KeyValuePair<int, SortOrder>> SortedIndizes {
     90        get { return this.sortedIndizes; }
     91        set { sortedIndizes = new List<KeyValuePair<int, SortOrder>>(value); }
     92      }
     93      private RunCollection matrix;
     94      public RunCollection Matrix {
     95        get { return this.matrix; }
     96        set { this.matrix = value; }
     97      }
     98
     99      public int Compare(int x, int y) {
     100        int result = 0;
     101        IItem value1, value2;
     102        IComparable comparable1, comparable2;
     103
     104        if (matrix == null)
     105          throw new InvalidOperationException("Could not sort IStringConvertibleMatrix if the matrix member is null.");
     106        if (sortedIndizes == null)
     107          return 0;
     108
     109        foreach (KeyValuePair<int, SortOrder> pair in sortedIndizes.Where(p => p.Value != SortOrder.None)) {
     110          value1 = matrix.GetValue(x, pair.Key);
     111          value2 = matrix.GetValue(y, pair.Key);
     112          comparable1 = value1 as IComparable;
     113          comparable2 = value2 as IComparable;
     114          if (comparable1 != null)
     115            result = comparable1.CompareTo(comparable2);
     116          else {
     117            string string1 = value1 != null ? value1.ToString() : string.Empty;
     118            string string2 = value2 != null ? value2.ToString() : string.Empty;
     119            result = string1.CompareTo(string2);
     120          }
     121          if (pair.Value == SortOrder.Descending)
     122            result *= -1;
     123          if (result != 0)
     124            return result;
     125        }
     126        return result;
     127      }
     128    }
    70129  }
    71130}
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs

    r3441 r3447  
    3535    public RunCollection(int capacity) : base(capacity) { Initialize(); }
    3636    public RunCollection(IEnumerable<IRun> collection) : base(collection) { Initialize(); this.OnItemsAdded(collection); }
     37    private void Initialize() {
     38      parameterNames = new List<string>();
     39      resultNames = new List<string>();
     40    }
    3741
    3842    protected static Type[] viewableDataTypes = new Type[]{typeof(BoolValue), typeof(DoubleValue), typeof(IntValue),
     
    8286    }
    8387
    84     private void Initialize() {
    85       parameterNames = new List<string>();
    86       resultNames = new List<string>();
    87     }
     88
    8889
    8990    private bool AddParameter(string name, IItem value) {
     
    122123    }
    123124
     125    public IItem GetValue(int rowIndex, int columnIndex) {
     126      IRun run = this.list[rowIndex];
     127      IItem value = null;
     128
     129      if (columnIndex < parameterNames.Count) {
     130        string parameterName = parameterNames[columnIndex];
     131        if (run.Parameters.ContainsKey(parameterName))
     132          value = run.Parameters[parameterName];
     133      } else if (columnIndex < parameterNames.Count + resultNames.Count) {
     134        string resultName = resultNames[columnIndex - parameterNames.Count];
     135        if (run.Results.ContainsKey(resultName))
     136          value = run.Results[resultName];
     137      }
     138      return value;
     139    }
     140
    124141    #region IStringConvertibleMatrix Members
    125142    [Storable]
     
    127144    [Storable]
    128145    private List<string> resultNames;
    129     public int Rows {
     146    int IStringConvertibleMatrix.Rows {
    130147      get { return this.Count; }
    131       set { throw new System.NotImplementedException(); }
    132     }
    133     public int Columns {
     148      set { throw new NotSupportedException(); }
     149    }
     150    int IStringConvertibleMatrix.Columns {
    134151      get { return parameterNames.Count + resultNames.Count; }
    135152      set { throw new NotSupportedException(); }
    136153    }
    137     public IEnumerable<string> ColumnNames {
     154    IEnumerable<string> IStringConvertibleMatrix.ColumnNames {
    138155      get {
    139156        List<string> value = new List<string>(parameterNames);
     
    143160      set { throw new NotSupportedException(); }
    144161    }
    145     public IEnumerable<string> RowNames {
     162    IEnumerable<string> IStringConvertibleMatrix.RowNames {
    146163      get { return list.Select(x => x.Name).ToList(); }
    147164      set { throw new NotSupportedException(); }
    148165    }
    149     public bool SortableView {
     166    bool IStringConvertibleMatrix.SortableView {
    150167      get { return true; }
    151168      set { throw new NotSupportedException(); }
    152169    }
    153     public bool ReadOnly {
    154       get { return false; }
    155     }
    156 
    157     public string GetValue(int rowIndex, int columnIndex) {
    158       IRun run = this.list[rowIndex];
    159       string value = string.Empty;
    160 
    161       if (columnIndex < parameterNames.Count) {
    162         string parameterName = parameterNames[columnIndex];
    163         if (run.Parameters.ContainsKey(parameterName)) {
    164           IItem param = run.Parameters[parameterName];
    165           if (param != null) value = param.ToString();
    166         }
    167       } else if (columnIndex < parameterNames.Count + resultNames.Count) {
    168         string resultName = resultNames[columnIndex - parameterNames.Count];
    169         if (run.Results.ContainsKey(resultName)) {
    170           IItem result = run.Results[resultName];
    171           if (result != null) value = result.ToString();
    172         }
    173       }
    174       return value;
     170    bool IStringConvertibleMatrix.ReadOnly {
     171      get { return true; }
     172    }
     173
     174    string IStringConvertibleMatrix.GetValue(int rowIndex, int columnIndex) {
     175      IItem value = GetValue(rowIndex, columnIndex);
     176      if (value == null)
     177        return string.Empty;
     178      return value.ToString();
    175179    }
    176180
Note: See TracChangeset for help on using the changeset viewer.