Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2325 for trunk


Ignore:
Timestamp:
09/02/09 12:03:13 (15 years ago)
Author:
mkommend
Message:

changed SparseMatrix.Matrix and MatrixRow to a generic type (ticket #701)

Location:
trunk/sources
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Charting/3.3/BubbleChart.cs

    r2295 r2325  
    137137        } else if (matrix.MultiDimensionalCategoricalVariables.Contains(xDimension)) {
    138138          var path = xDimension.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim());
    139           IEnumerable<MatrixRow> subRows = (IEnumerable<MatrixRow>)r.Get(path.ElementAt(0));
    140           foreach (MatrixRow subRow in subRows) {
     139          IEnumerable<MatrixRow<string, object>> subRows = (IEnumerable<MatrixRow<string,object>>)r.Get(path.ElementAt(0));
     140          foreach (MatrixRow<string, object> subRow in subRows) {
    141141            if (subRow.Get(path.ElementAt(1)) != null) {
    142142              xs.Add(matrix.IndexOfCategoricalValue(xDimension, subRow.Get(path.ElementAt(1))) + r.YJitter * xJitterFactor);
     
    146146        } else if (matrix.MultiDimensionalOrdinalVariables.Contains(xDimension)) {
    147147          var path = xDimension.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim());
    148           IEnumerable<MatrixRow> subRows = (IEnumerable<MatrixRow>)r.Get(path.ElementAt(0));
    149           foreach (MatrixRow subRow in subRows) {
     148          IEnumerable<MatrixRow<string, object>> subRows = (IEnumerable<MatrixRow<string, object>>)r.Get(path.ElementAt(0));
     149          foreach (MatrixRow<string,object> subRow in subRows) {
    150150            if (subRow.Get(path.ElementAt(1)) != null) {
    151151              xs.Add(Convert.ToDouble(subRow.Get(path.ElementAt(1))) + r.XJitter * xJitterFactor);
     
    162162        } else if (matrix.MultiDimensionalCategoricalVariables.Contains(yDimension)) {
    163163          var path = yDimension.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim());
    164           IEnumerable<MatrixRow> subRows = (IEnumerable<MatrixRow>)r.Get(path.ElementAt(0));
    165           foreach (MatrixRow subRow in subRows) {
     164          IEnumerable<MatrixRow<string,object>> subRows = (IEnumerable<MatrixRow<string,object>>)r.Get(path.ElementAt(0));
     165          foreach (MatrixRow<string,object> subRow in subRows) {
    166166            if (subRow.Get(path.ElementAt(1)) != null) {
    167167              ys.Add(matrix.IndexOfCategoricalValue(yDimension, subRow.Get(path.ElementAt(1))) + r.YJitter * yJitterFactor);
     
    171171        } else if (matrix.MultiDimensionalOrdinalVariables.Contains(yDimension)) {
    172172          var path = yDimension.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim());
    173           IEnumerable<MatrixRow> subRows = (IEnumerable<MatrixRow>)r.Get(path.ElementAt(0));
    174           foreach (MatrixRow subRow in subRows) {
     173          IEnumerable<MatrixRow<string, object>> subRows = (IEnumerable<MatrixRow<string, object>>)r.Get(path.ElementAt(0));
     174          foreach (MatrixRow<string,object> subRow in subRows) {
    175175            if (subRow.Get(path.ElementAt(1)) != null) {
    176176              ys.Add(Convert.ToDouble(subRow.Get(path.ElementAt(1))) + r.YJitter * yJitterFactor);
  • trunk/sources/HeuristicLab.CEDMA.Charting/3.3/VisualMatrix.cs

    r2296 r2325  
    99  public class VisualMatrix : ItemBase {
    1010    private Dictionary<string, Dictionary<object, double>> categoricalValueIndices;
    11     private Matrix matrix;
     11    private Matrix<string,object> matrix;
    1212
    1313    public VisualMatrix() {
     
    1919      this.categoricalValueIndices = new Dictionary<string, Dictionary<object, double>>();    }
    2020
    21     public VisualMatrix(Matrix matrix, IEnumerable<string> categoricalVariables, IEnumerable<string> ordinalVariables,
     21    public VisualMatrix(Matrix<string,object> matrix, IEnumerable<string> categoricalVariables, IEnumerable<string> ordinalVariables,
    2222      IEnumerable<string> multiDimensionalCategoricalVariables, IEnumerable<string> multiDimensionalOrdinalVariables)
    2323      : this() {
     
    2525      this.matrix.Changed += new EventHandler(MatrixChanged);
    2626
    27       foreach (MatrixRow row in matrix.GetRows())
     27      foreach (MatrixRow<string,object> row in matrix.GetRows())
    2828        rows.Add(new VisualMatrixRow(row));
    2929
  • trunk/sources/HeuristicLab.CEDMA.Charting/3.3/VisualMatrixRow.cs

    r2299 r2325  
    2727    }
    2828
    29     public VisualMatrixRow(MatrixRow row)
     29    public VisualMatrixRow(MatrixRow<string,object> row)
    3030      : this() {
    3131      foreach (KeyValuePair<string, object> value in row.Values)
  • trunk/sources/HeuristicLab.CEDMA.Core/3.3/Console.cs

    r2321 r2325  
    5656    }
    5757
    58     private Matrix matrix;
    59     public Matrix Matrix {
     58    private Matrix<string,object> matrix;
     59    public Matrix<string,object> Matrix {
    6060      get {
    6161        if (matrix == null) LoadResults();
     
    8282
    8383    private void LoadResults() {
    84       matrix = new Matrix();
     84      matrix = new Matrix<string,object>();
    8585      DatabaseService db = new DatabaseService(sqlServerCompactConnectionString + database);
    8686      db.Connect();
    8787
    8888      foreach (var model in db.GetAllModels()) {
    89         MatrixRow row = new MatrixRow();
     89        MatrixRow<string, object> row = new MatrixRow<string, object>();
    9090        foreach (var modelResult in db.GetModelResults(model)) {
    9191          row.Set(modelResult.Result.Name, modelResult.Value);
    9292        }
    93         Dictionary<HeuristicLab.Modeling.Database.IVariable, MatrixRow> inputVariableResultsEntries =
    94           new Dictionary<HeuristicLab.Modeling.Database.IVariable, MatrixRow>();
     93        Dictionary<HeuristicLab.Modeling.Database.IVariable, MatrixRow<string, object>> inputVariableResultsEntries =
     94          new Dictionary<HeuristicLab.Modeling.Database.IVariable, MatrixRow<string, object>>();
    9595        foreach (IInputVariableResult inputVariableResult in db.GetInputVariableResults(model)) {
    9696          if (!inputVariableResultsEntries.ContainsKey(inputVariableResult.Variable)) {
    97             inputVariableResultsEntries[inputVariableResult.Variable] = new MatrixRow();
     97            inputVariableResultsEntries[inputVariableResult.Variable] = new MatrixRow<string, object>();
    9898            inputVariableResultsEntries[inputVariableResult.Variable].Set("InputVariableName", inputVariableResult.Variable.Name);
    9999          }
  • trunk/sources/HeuristicLab.SparseMatrix/3.2/Matrix.cs

    r2284 r2325  
    2525
    2626namespace HeuristicLab.SparseMatrix {   
    27   public class Matrix : ItemBase {
     27  public class Matrix<KeyType,ValueType> : ItemBase {
    2828    public Matrix() {
    29       this.rows = new List<MatrixRow>();
     29      this.rows = new List<MatrixRow<KeyType,ValueType>>();
    3030    }
    3131
    32     public Matrix(IEnumerable<MatrixRow> rows)
     32    public Matrix(IEnumerable<MatrixRow<KeyType,ValueType>> rows)
    3333      : this() {
    3434      this.rows.AddRange(rows);
    3535    }
    3636
    37     private List<MatrixRow> rows;
    38     public ReadOnlyCollection<MatrixRow> GetRows() {
     37    private List<MatrixRow<KeyType, ValueType>> rows;
     38    public ReadOnlyCollection<MatrixRow<KeyType, ValueType>> GetRows() {
    3939      return rows.AsReadOnly();
    4040    }
    4141
    42     public void AddRow(MatrixRow row) {
     42    public void AddRow(MatrixRow<KeyType, ValueType> row) {
    4343      this.rows.Add(row);
    4444    }
    4545
    46     public void RemoveRow(MatrixRow row) {
     46    public void RemoveRow(MatrixRow<KeyType, ValueType> row) {
    4747      this.rows.Remove(row);
    4848    }
  • trunk/sources/HeuristicLab.SparseMatrix/3.2/MatrixRow.cs

    r2288 r2325  
    2323
    2424namespace HeuristicLab.SparseMatrix {
    25   public class MatrixRow {
    26     private Dictionary<string, object> values;
     25  public class MatrixRow<KeyType, ValueType> {
     26    private Dictionary<KeyType, ValueType> values;
    2727    public MatrixRow() {
    28       values = new Dictionary<string, object>();
    29     }
    30 
    31     public void Set(string name, object value) {
    32       values.Add(name, value);
     28      values = new Dictionary<KeyType, ValueType>();
    3329    }
    3430
    35     public object Get(string name) {
    36       if (name == null || !values.ContainsKey(name)) return null;
    37       return values[name];
     31    public void Set(KeyType key, ValueType value) {
     32      values.Add(key, value);
    3833    }
    3934
    40     public IEnumerable<KeyValuePair<string, object>> Values {
     35    public bool ContainsKey(KeyType key) {
     36      return values.ContainsKey(key);
     37    }
     38
     39    public ValueType Get(KeyType key) {
     40      if (key == null || !values.ContainsKey(key)) return default(ValueType);
     41      return values[key];
     42    }
     43
     44    public IEnumerable<KeyValuePair<KeyType, ValueType>> Values {
    4145      get { return values; }
    4246    }
Note: See TracChangeset for help on using the changeset viewer.