Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/MatrixValueVM.cs @ 17464

Last change on this file since 17464 was 17464, checked in by dpiringe, 4 years ago

#3026:

  • Runner now uses SymbolicDataAnalysisExpressionMATLABFormatter to save instances of ISymbolicRegressionSolution
  • refactored user controls for detail view of json items, now they do not inherit from JsonItemBaseControl -> JsonItemBaseControl uses now an extra control
    • this change was made for fluid repositioning of controls (e.g. when no ActualName is present)
File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7
8namespace HeuristicLab.JsonInterface.OptimizerIntegration {
9
10  public class DoubleMatrixValueVM : MatrixValueVM<double, DoubleMatrixJsonItem> {
11    public override Type JsonItemType => typeof(DoubleMatrixJsonItem);
12    public override JsonItemBaseControl Control => null;
13      //new JsonItemDoubleMatrixValueControl(this);
14
15    public override double[][] Value {
16      get => ((DoubleMatrixJsonItem)Item).Value;
17      set {
18        ((DoubleMatrixJsonItem)Item).Value = value;
19        OnPropertyChange(this, nameof(Value));
20      }
21    }
22
23    protected override double MinTypeValue => double.MinValue;
24
25    protected override double MaxTypeValue => double.MaxValue;
26  }
27
28  public abstract class MatrixValueVM<T, JsonItemType> : RangedValueBaseVM<T>, IMatrixJsonItemVM
29    where JsonItemType : IMatrixJsonItem {
30    public abstract T[][] Value { get; set; }
31    public bool RowsResizable {
32      get => ((IMatrixJsonItem)Item).RowsResizable;
33      set {
34        ((IMatrixJsonItem)Item).RowsResizable = value;
35        OnPropertyChange(this, nameof(RowsResizable));
36      }
37    }
38
39    public bool ColumnsResizable {
40      get => ((IMatrixJsonItem)Item).ColumnsResizable;
41      set {
42        ((IMatrixJsonItem)Item).ColumnsResizable = value;
43        OnPropertyChange(this, nameof(ColumnsResizable));
44      }
45    }
46
47    public void SetCellValue(T data, int row, int col) {
48     
49      T[][] tmp = Value;
50     
51      // increase y
52      if (row >= tmp.Length) { // increasing array
53        T[][] newArr = new T[row + 1][];
54        Array.Copy(tmp, 0, newArr, 0, tmp.Length);
55        newArr[row] = new T[0];
56        tmp = newArr;
57      }
58
59      // increase x
60      for(int i = 0; i < tmp.Length; ++i) {
61        if(col >= tmp[i].Length) {
62          T[] newArr = new T[col + 1];
63          Array.Copy(tmp[i], 0, newArr, 0, tmp[i].Length);
64          tmp[i] = newArr;
65        }
66      }
67
68      tmp[row][col] = data;
69      Value = tmp;
70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.