-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathViewModel.cs
352 lines (298 loc) · 10.8 KB
/
ViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
using LiveCharts;
using MCSLib.Abstraction;
using MCSLib.PDFs;
using MCSLib.Simulation;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
namespace MCS
{
internal class ViewModel: INotifyPropertyChanged
{
public ViewModel()
{
DistributionTypes = new List<DistributionType>() {
DistributionType.Uniform,
DistributionType.Triangular,
DistributionType.Normal,
DistributionType.Log_Normal
};
IsTableView = true;
IsChartView = false;
IsMinEnabled = true;
IsMaxEnabled = true;
IsModeEnabled = false;
IsAvgEnabled = false;
IsStDevEnabled = false;
SimResultList = new List<StatisticalResult>();
RunMCSCommand = new Command(RumMCSAction, (x)=>true);
ChartCommand = new Command(ViewPlotAction, (x) => SimResultList.Count > 0);
_distributionInput = new DistributionInput();
_simulator = new Simulator();
}
private void ViewPlotAction(object obj)
{
IsTableView = false;
IsChartView = true;
ColumnValues = new ChartValues<double>();
LineValues = new ChartValues<double>();
ExpectationValues = new ChartValues<double>();
Labels = new string[SimResultList.Count];
ExpectationLables = new string[SimResultList.Count];
for (int i = 0; i < SimResultList.Count; i++)
{
if (SimResultList[i].RelativeFrequency >= 0)
{
ColumnValues.Add(SimResultList[i].RelativeFrequency);
Labels[i] = Math.Round(_simulatedValues[i], 0).ToString();
LineValues.Add(SimResultList[i].RelativeFrequency);
ExpectationValues.Add(SimResultList[i].Expectation);
ExpectationLables[i] = Math.Round(SimResultList[i].BinSize, 0).ToString();
}
}
Formatter = value => value.ToString();
}
private void RumMCSAction(object obj)
{
IsTableView = true;
IsChartView = false;
if (Iteration > 0)
{
_distributionInput.Delegate = GetSimResult;
_distributionInput.Iteration = Iteration;
_distributionInput.Interval = Interval;
switch (SelectedDistribution)
{
case DistributionType.Uniform:
_distributionInput.UncertaintyArray = new[] { Min, Max };
_distributionInput.UncertaintyList = new List<double> { Min, Max };
break;
case DistributionType.Triangular:
_distributionInput.UncertaintyArray = new[] { Min, Max, Mode };
_distributionInput.UncertaintyList = new List<double> { Min, Max, Mode };
break;
case DistributionType.Normal:
break;
case DistributionType.Log_Normal:
break;
}
SimResultList = _simulator.Run(_distributionInput, SelectedDistribution);
_simulatedValues = _simulator.SimulationResult.SimulatedValues;
}
}
private double GetSimResult(double safetyFactor)
{
return WSLoad * safetyFactor;
}
protected virtual void RaisePropertyChanged([CallerMemberName] string propName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
private void ToggleDistribution(DistributionType distributionType)
{
switch (distributionType)
{
case DistributionType.Uniform:
IsMinEnabled = true;
IsMaxEnabled = true;
IsModeEnabled = false;
IsAvgEnabled = false;
IsStDevEnabled = false;
Mode = 0;
Average = 0;
StandardDeviation = 0;
break;
case DistributionType.Triangular:
IsMinEnabled = true;
IsMaxEnabled = true;
IsModeEnabled = true;
IsAvgEnabled = false;
IsStDevEnabled = false;
Average = 0;
StandardDeviation = 0;
break;
case DistributionType.Normal:
IsMinEnabled = false;
IsMaxEnabled = false;
IsModeEnabled = false;
IsAvgEnabled = true;
IsStDevEnabled = true;
Min = 0;
Max = 0;
Mode = 0;
break;
case DistributionType.Log_Normal:
IsMinEnabled = false;
IsMaxEnabled = false;
IsModeEnabled = false;
IsAvgEnabled = true;
IsStDevEnabled = true;
Min = 0;
Max = 0;
Mode = 0;
break;
}
}
public event PropertyChangedEventHandler PropertyChanged;
private DistributionType _distributionType;
public DistributionType SelectedDistribution {
get => _distributionType;
set
{
_distributionType = value;
RaisePropertyChanged();
ToggleDistribution(_distributionType);
}
}
public IEnumerable<DistributionType> DistributionTypes { get; set; }
private bool isMinEnabled;
public bool IsMinEnabled
{
get { return isMinEnabled; }
set { isMinEnabled = value; RaisePropertyChanged(); }
}
private bool isMaxEnabled;
public bool IsMaxEnabled
{
get { return isMaxEnabled; }
set { isMaxEnabled = value; RaisePropertyChanged(); }
}
private bool isModeEnabled;
public bool IsModeEnabled
{
get { return isModeEnabled; }
set { isModeEnabled = value; RaisePropertyChanged(); }
}
private bool isAvgEnabled;
public bool IsAvgEnabled
{
get { return isAvgEnabled; }
set { isAvgEnabled = value; RaisePropertyChanged(); }
}
private bool isStDevEnabled;
public bool IsStDevEnabled
{
get { return isStDevEnabled; }
set { isStDevEnabled = value; RaisePropertyChanged(); }
}
private double min;
public double Min
{
get { return min; }
set { min = value; RaisePropertyChanged(); }
}
private double max;
public double Max
{
get { return max; }
set { max = value; RaisePropertyChanged(); }
}
private double mode;
public double Mode
{
get { return mode; }
set { mode = value; RaisePropertyChanged(); }
}
private double average;
public double Average
{
get { return average; }
set { average = value; RaisePropertyChanged(); }
}
private double standardDeviation;
public double StandardDeviation
{
get { return standardDeviation; }
set { standardDeviation = value; RaisePropertyChanged(); }
}
private IList<StatisticalResult> simulationResults;
public IList<StatisticalResult> SimResultList
{
get { return simulationResults; }
set { simulationResults = value; RaisePropertyChanged(); }
}
private ObservableCollection<ColumnItem> relativePlot;
public ObservableCollection<ColumnItem> RelativePlot
{
get { return relativePlot; }
set { relativePlot = value; RaisePropertyChanged(); }
}
private bool isChartView;
public bool IsChartView
{
get { return isChartView; }
set { isChartView = value; RaisePropertyChanged(); }
}
private bool isTableView;
public bool IsTableView
{
get { return isTableView; }
set { isTableView = value; RaisePropertyChanged(); }
}
private int abMax;
public int AbsoluteMaximum
{
get { return abMax; }
set { abMax = value; RaisePropertyChanged(); }
}
public ICommand RunMCSCommand { get; set; }
public ICommand ChartCommand { get; set; }
public int Iteration { get; set; }
public int Interval { get; set; }
public double WSLoad { get; set; }
private DistributionInput _distributionInput;
private IList<double> _simulatedValues;
private ISimulator _simulator;
//LiveChart
private SeriesCollection sc;
public SeriesCollection SeriesCollection
{
get { return sc; }
set { sc = value; RaisePropertyChanged(); }
}
private string[] lables;
public string[] Labels
{
get { return lables; }
set { lables = value; RaisePropertyChanged(); }
}
private string[] expectationLables;
public string[] ExpectationLables
{
get { return expectationLables; }
set { expectationLables = value; RaisePropertyChanged(); }
}
private Func<double, string> formater;
public Func<double, string> Formatter
{
get { return formater; }
set { formater = value; RaisePropertyChanged(); }
}
private ChartValues<double> lineValues;
public ChartValues<double> LineValues
{
get { return lineValues; }
set { lineValues = value; RaisePropertyChanged(); }
}
private ChartValues<double> columnvalues;
public ChartValues<double> ColumnValues
{
get { return columnvalues; }
set { columnvalues = value; RaisePropertyChanged(); }
}
private ChartValues<double> expectationvalues;
public ChartValues<double> ExpectationValues
{
get { return expectationvalues; }
set { expectationvalues = value; RaisePropertyChanged(); }
}
}
public class ColumnItem
{
public double YValue { get; set; }
public double XValue { get; set; }
}
}