-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSparsix.cs
1155 lines (1118 loc) · 53.7 KB
/
Sparsix.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Calc
{
// begin vary
public enum Dimension { None = 0, Item = 1, Dim1 = 2, Dim2 = 3, Dim3 = 4, Dim4 = 5, Dim5 = 6, Dim6 = 7, Dim7 = 8, Dim8 = 9, Dim9 = 10 }
public enum NoDimension { NoItem = 0, NoDim1 = 0, NoDim2 = 0, NoDim3 = 0, NoDim4 = 0, NoDim5 = 0, NoDim6 = 0, NoDim7 = 0, NoDim8 = 0, NoDim9 = 0, }
public class Coords
{
public static int Dims = 10;
public int[] CoordVec = new int[Dims];
public int Item { get { return CoordVec[0]; } set { CoordVec[0] = value; } }
public int Dim1 { get { return CoordVec[1]; } set { CoordVec[1] = value; } }
public int Dim2 { get { return CoordVec[2]; } set { CoordVec[2] = value; } }
public int Dim3 { get { return CoordVec[3]; } set { CoordVec[3] = value; } }
public int Dim4 { get { return CoordVec[4]; } set { CoordVec[4] = value; } }
public int Dim5 { get { return CoordVec[5]; } set { CoordVec[5] = value; } }
public int Dim6 { get { return CoordVec[6]; } set { CoordVec[6] = value; } }
public int Dim7 { get { return CoordVec[7]; } set { CoordVec[7] = value; } }
public int Dim8 { get { return CoordVec[8]; } set { CoordVec[8] = value; } }
public int Dim9 { get { return CoordVec[9]; } set { CoordVec[9] = value; } }
public Coords() { }
public Coords(int item, int type1, int type2, int type3, int type4, int type5, int type6, int type7, int type8, int type9) { Item = item; Dim1 = type1; Dim2 = type2; Dim3 = type3; Dim4 = type4; Dim5 = type5; Dim6 = type6; Dim7 = type7; Dim8 = type8; Dim9 = type9; }
public Coords(Coords coords) { Item = coords.Item; Dim1 = coords.Dim1; Dim2 = coords.Dim2; Dim3 = coords.Dim3; Dim4 = coords.Dim4; Dim5 = coords.Dim5; Dim6 = coords.Dim6; Dim7 = coords.Dim7; Dim8 = coords.Dim8; Dim9 = coords.Dim9; }
public override string ToString() => $"[{Item,-3}, {(Type1)Dim1,-10}, {(Type2)Dim2,-12}, {(Type3)Dim3,-13}, {(Type4)Dim4,-10}, {(Type5)Dim5,-7}, {(Cat6)Dim6,-10}, {(Cat7)Dim7,-16}, {(Cat7)Dim8,-16}, {(Cat9)Dim9,-12}]";
public string ToStringDimInterp() => $"[{(Dimension)Item}, {(Dimension)Dim1}, {(Dimension)Dim2}, {(Dimension)Dim3}, {(Dimension)Dim4}, {(Dimension)Dim5}, {(Dimension)Dim6}, {(Dimension)Dim7}, {(Dimension)Dim8}, {(Dimension)Dim9}]";
public string ToStringUninterp() => $"[{Item}, {Dim1}, {Dim2}, {Dim3}, {Dim4}, {Dim5}, {Dim6}, {Dim7}, {Dim8}, {Dim9}]";
public bool IsEqualTo(Coords c) => Equals(this, c);
public static bool Equals(Coords c1, Coords c2)
{
if (c1 == null && c2 == null) return true;
if (c1 == null || c2 == null) return false;
for (var i = 0; i < Dims; i++)
if (c1.CoordVec[i] != c2.CoordVec[i])
return false;
return true;
}
public static Coords BuildCoords1(int itemId, int type1Id, int type2Id, int type3Id, int type4Id, int type5Id, int type6Id, int type7Id, int type8Id, int type9Id) => new Coords(itemId, type1Id, type2Id, type3Id, type4Id, type5Id, type6Id, type7Id, type8Id, type9Id);
public static Coords BuildCoords2(int itemId, int type1Id, int type2Id, int type4Id, int type5Id, int type6Id, int type7Id, int type8Id, int type9Id) => new Coords(itemId, type1Id, type2Id, (int)Type3.Inst3_1, type4Id, type5Id, type6Id, type7Id, type8Id, type9Id);
public static Coords BuildCoords3(int itemId, int type1Id, int type4Id, int type5Id, int type6Id, int type7Id, int type8Id, int type9Id) => BuildCoords2(itemId, type1Id, (int)Type2.Inst2_2, type4Id, type5Id, type6Id, type7Id, type8Id, type9Id);
public static Coords BuildCoords4(int type1Id, int type4Id, int type7Id, int type8Id, int type9Id) => BuildCoords2((int)NoDimension.NoItem, type1Id, (int)NoDimension.NoDim2, type4Id, (int)NoDimension.NoDim5, (int)NoDimension.NoDim6, type7Id, type8Id, type9Id);
public static Coords BuildCoords5(int type4Id, int type7Id, int type8Id, int type9Id) => new Coords((int)NoDimension.NoItem, (int)NoDimension.NoDim1, (int)NoDimension.NoDim2, (int)NoDimension.NoDim3, type4Id, (int)NoDimension.NoDim5, (int)NoDimension.NoDim6, type7Id, type8Id, type9Id);
public static Coords GetVector1() => new Coords( (int)Dimension.Item, (int)NoDimension.NoDim1, (int)Dimension.Dim2, (int)NoDimension.NoDim3, (int)Dimension.Dim4, (int)Dimension.Dim5, (int)Dimension.Dim6, (int)Dimension.Dim7, (int)NoDimension.NoDim8, (int)NoDimension.NoDim9);
public static Coords GetVector2() => new Coords( (int)Dimension.Item, (int)Dimension.Dim1, (int)Dimension.Dim2, (int)Dimension.Dim3, (int)Dimension.Dim4, (int)Dimension.Dim5, (int)Dimension.Dim6, (int)Dimension.Dim7, (int)Dimension.Dim8, (int)Dimension.Dim9);
public static Coords GetVector3() => new Coords( (int)NoDimension.NoItem, (int)NoDimension.NoDim1, (int)NoDimension.NoDim2, (int)Type3.Inst3_2, (int)Type4.NoApply, (int)NoDimension.NoDim5, (int)NoDimension.NoDim7, (int)NoDimension.NoDim6, (int)NoDimension.NoDim8, (int)NoDimension.NoDim9);
public static Coords GetVector4() => new Coords( (int)Dimension.Item, (int)Dimension.Dim1, (int)Dimension.Dim2, (int)Dimension.Dim3, (int)Dimension.Dim4, (int)Dimension.Dim5, (int)Dimension.Dim6, (int)Dimension.Dim7, (int)NoDimension.NoDim8, (int)NoDimension.NoDim9);
public static Coords GetVector5() => new Coords( (int)NoDimension.NoItem, (int)NoDimension.NoDim1, (int)NoDimension.NoDim2, (int)Type3.Inst3_3, (int)Type4.NoApply, (int)NoDimension.NoDim5, (int)NoDimension.NoDim6, (int)NoDimension.NoDim7, (int)NoDimension.NoDim8, (int)NoDimension.NoDim9);
public static Coords GetVector6(Type5 type5) => new Coords( (int)NoDimension.NoItem, (int)Type1.NoApply, (int)Type2.Inst2_6, (int)Type3.NoApply, (int)Type4.NoApply, (int)type5, (int)NoDimension.NoDim6, (int)NoDimension.NoDim7, (int)NoDimension.NoDim8, (int)NoDimension.NoDim9);
public static Coords GetVector7() => new Coords( (int)Dimension.Item, (int)Dimension.Dim1, (int)NoDimension.NoDim2, (int)NoDimension.NoDim3, (int)Dimension.Dim4, (int)NoDimension.NoDim5, (int)Dimension.Dim6, (int)NoDimension.NoDim7, (int)Dimension.Dim8, (int)Dimension.Dim9);
}
public enum Type1 { NoApply = -1, Inst1_1 = 1, Inst1_2 = 2, Inst1_3 = 4, Inst1_4 = 5, Inst1_5 = 6, Inst1_6 = 7, Inst1_7 = 9 }
public enum Type2 { NoApply = -1, Inst2_1 = 1, Inst2_2 = 2, Inst2_3 = 3, Inst2_4 = 5, Inst2_5 = 8, Inst2_6 = 9 }
public enum Type3 { NoApply = -1, Inst3_1 = 1, Inst3_2 = 2, Inst3_3 = 3 }
public enum Type4 { NoApply = -1, Inst4_1 = 1, Inst4_2 = 2 }
public enum Type5 { NoApply = -1, Inst5_1 = 1, Inst5_2 = 2 }
// end vary
public class DimManager
{
public Dictionary<Dimension, DimSet> DimSets { get; set; } = new Dictionary<Dimension, DimSet>();
public DimManager(bool reset = false)
{
for (var i = 1; i < Coords.Dims + 1; i++)
DimSets[(Dimension)i] = new DimSet();
if (reset) Reset();
}
public Coords Size()
{
var size = new Coords();
for (var i = 0; i < Coords.Dims; i++)
size.CoordVec[i] = DimSets[(Dimension)(i + 1)].Cardinality;
return size;
}
public void Add(Coords pos)
{
for (var i = 0; i < Coords.Dims; i++)
DimSets[(Dimension)(i + 1)].Add(pos.CoordVec[i]);
}
public void Reset()
{
for (var i = 0; i < Coords.Dims; i++)
DimSets[(Dimension)(i + 1)].Add(0);
}
public HashSet<int> GetDimSet(Dimension dimension) => DimSets[dimension].Set;
public DimSet this[Dimension dimension] => DimSets[dimension];
public override string ToString()
{
var sb = new StringBuilder();
foreach (var dimSetPair in DimSets)
sb.Append($"{dimSetPair.Key}: {dimSetPair.Value}, ");
return sb.ToString();
}
}
public class MatrixMethods
{
public static DimManager CopyDimensions(Matrix matrix)
{
var dimMgr = new DimManager();
for (var i = 1; i < Coords.Dims + 1; i++)
dimMgr.DimSets[(Dimension)i].Set.UnionWith(matrix.GetDimSet((Dimension)i));
return dimMgr;
}
public static DimManager CopyDimensions(Matrix matrix, Coords dimensions)
{
var dimMgr = new DimManager();
for (var i = 0; i < Coords.Dims; i++)
{
if (dimensions.CoordVec[i] == 0)
dimMgr.DimSets[(Dimension)(i + 1)].Add(0);
else
dimMgr.DimSets[(Dimension)(i + 1)].Set.UnionWith(matrix.GetDimSet((Dimension)(i + 1)));
}
return dimMgr;
}
public static Matrix Project(Matrix m1, Dimension normal, string name = null)
{
var res = new Matrix($"(Proj: {m1.Name}, norm: {normal})", name);
foreach (var posElPair in m1.Elements)
{
var p1 = posElPair.Key;
var e1 = posElPair.Value;
var p2 = new Coords();
for (var i = 0; i < Coords.Dims; i++)
p2.CoordVec[i] = (int)normal == (i + 1) ? 0 : p1.CoordVec[i];
res.Add(p2, e1);
}
return res;
}
public static Matrix Project(Matrix m1, Coords normal, string name = null)
{
var res = new Matrix($"(Proj: {m1.Name}, norm: {normal.ToStringDimInterp()})", name);
foreach (var posElPair in m1.Elements)
{
var p1 = posElPair.Key;
var e1 = posElPair.Value;
var p2 = new Coords();
for (var i = 0; i < Coords.Dims; i++)
p2.CoordVec[i] = normal.CoordVec[i] != 0 ? 0 : p1.CoordVec[i];
res.Add(p2, e1);
}
return res;
}
public static Matrix FilterIncl(Matrix m1, DimManager range, string name = null)
{
var res = new Matrix($"(Filt: {m1.Name}, range: {range}, filter type: Inclusive)", name);
foreach (var posElPair in m1.Elements)
{
var p1 = posElPair.Key;
var e1 = posElPair.Value;
var remove = false;
for (var i = 0; i < Coords.Dims; i++)
if (range[(Dimension)(i + 1)].Set.Contains(p1.CoordVec[i]) == false)
remove = true;
if (!remove)
res.Add(p1, e1);
}
return res;
}
public static Matrix FilterExcl(Matrix m1, DimManager range, string name = null)
{
var res = new Matrix($"(Filt: {m1.Name}, range: {range}, filter type: Exclusive)", name);
foreach (var posElPair in m1.Elements)
{
var p1 = posElPair.Key;
var e1 = posElPair.Value;
var remove = false;
for (var i = 0; i < Coords.Dims; i++)
if (range[(Dimension)(i + 1)].Set.Contains(p1.CoordVec[i]))
remove = true;
if (!remove)
res.Add(p1, e1);
}
return res;
}
public static Matrix Filter(Matrix m1, Coords filter, FilterType filterType = FilterType.Inclusive, string name = null)
{
var res = new Matrix($"(Filt: {m1.Name}, filter: {filter.ToStringUninterp()}, filter type: {filterType})", name);
var incl = filterType == FilterType.Inclusive;
foreach (var posElPair in m1.Elements)
{
var p1 = posElPair.Key;
var e1 = posElPair.Value;
var remove = false;
var pos = new Coords();
for (var i = 0; i < Coords.Dims; i++)
{
pos.CoordVec[i] = incl
? (filter.CoordVec[i] == 0 ? p1.CoordVec[i] : filter.CoordVec[i] == p1.CoordVec[i] ? p1.CoordVec[i] : -1)
: (filter.CoordVec[i] == 0 ? -1 : filter.CoordVec[i] != p1.CoordVec[i] ? p1.CoordVec[i] : -1);
if (pos.CoordVec[i] == -1)
remove = true;
}
if (!remove)
res.Add(pos, e1);
}
return res;
}
public static Matrix Filter(Matrix m1, Dimension dim, int value, FilterType filterType = FilterType.Inclusive, string name = null)
{
var filter = new Coords { CoordVec = { [((int)dim) - 1] = value } };
return Filter(m1, filter, filterType, name);
}
public static Matrix MultByExtr(Matrix m1, Matrix m2, Coords extr, string name = null)
{
var res = new Matrix($"({m1.Name} x {m2.Name}, extr: {extr.ToStringDimInterp()})", name);
foreach (var posElPair in m1.Elements)
{
var p1 = posElPair.Key;
var e1 = posElPair.Value;
// check if element exists in m2
var e2 = m2[p1];
if (e2 == null)
{
// element does not exist, extrude it!
var p2 = new Coords();
for (var i = 0; i < Coords.Dims; i++)
p2.CoordVec[i] = extr.CoordVec[i] != 0 ? 0 : p1.CoordVec[i];
e2 = m2[p2];
}
res.Add(p1, e1 * e2); // Hadamard product
}
return res;
}
public static Matrix MultByExtr(Matrix m1, decimal value, string name = null)
{
var res = new Matrix($"({m1.Name} x {value})", name);
foreach (var posElPair in m1.Elements)
{
var p1 = posElPair.Key;
var e1 = posElPair.Value;
res.Add(p1, e1 * value);
}
return res;
}
public static Matrix Translate(Matrix m1, Coords trans, string name = null)
{
var res = new Matrix($"({m1.Name}, trans: {trans})", name);
foreach (var posElPair in m1.Elements)
{
var p1 = posElPair.Key;
var e1 = posElPair.Value;
// translate
var p2 = new Coords();
for (var i = 0; i < Coords.Dims; i++)
p2.CoordVec[i] = trans.CoordVec[i] != 0 ? trans.CoordVec[i] : p1.CoordVec[i];
res.Add(p2, e1);
}
return res;
}
} // class CostMatrixMethods
// simulated ids
public enum Cat6 { Inst6_1 = 1, Inst6_2 = 2 }
public enum Cat7 { Inst7_1 = 1, Inst7_2 = 2, Inst7_3 = 3, Inst7_4 = 4 }
public enum Cat9 { Inst9_1 = 1, Inst9_2 = 2, Inst9_3 = 3, Inst9_4 = 5 }
public enum Cat10 { Inst10_1 = 1, Inst10_2 = 2, Inst10_3 = 3, Inst10_4 = 4, Inst10_5 = 5 }
public enum FilterType
{
Inclusive = 1,
Exclusive = 2,
Complement = 3
}
// dimension set ---------------------------------------------------------------------------
public class DimSet
{
public HashSet<int> Set { get; set; } = new HashSet<int>();
public DimSet() { }
public DimSet(int e) { Add(e); }
public DimSet(params int[] els)
{
foreach (var e in els)
Add(e);
}
public int Cardinality => Set.Count;
public int Min => Set.Min(x => x);
public int Max => Set.Max(x => x);
public bool Has(int e) => Set.Contains(e);
public bool Add(int e) => Set.Add(e); // true if set element doesn't exist, false if the set element is already present
public void Add(params int[] els)
{
foreach (var e in els)
Add(e);
}
public bool Remove(int e) => Set.Remove(e);
public void Remove(params int[] els)
{
foreach (var e in els)
Remove(e);
}
public override string ToString() => $"({string.Join(",", Set.ToArray())})";
}
// element of the matrix
// it keeps track of all the ids of the values added to this element
// this means that we can track all the item ids that originated this value
public class Element
{
public decimal Value { get; set; }
public HashSet<int> Ids { get; set; } = new HashSet<int>(); // the ids that originated this value
public Element() { }
public Element(decimal value) { Value = value; }
public Element(decimal value, int id)
{
Value = value;
if (id != 0)
Ids.Add(id);
}
public Element(decimal value, IEnumerable<int> ids)
{
Value = value;
Ids.UnionWith(ids);
}
public Element(Element e)
{
Value = e.Value;
Ids.UnionWith(e.Ids);
}
public void Set(decimal value)
{
Value = value;
Ids = new HashSet<int>(); // reset list of ids
}
public void Add(decimal value, int id = 0)
{
Value += value;
if (id != 0)
Ids.Add(id);
}
public void Add(Element e)
{
Value += e.Value;
Ids.UnionWith(e.Ids);
}
public override string ToString()
{
return $"{Value:#0.00} ({Ids.Count}: {string.Join(",", Ids.ToArray())})";
}
public static Element operator +(Element e1, Element e2)
{
if (e1 == null) return e2;
if (e2 == null) return e1;
var el = new Element { Value = e1.Value + e2.Value };
el.Ids.UnionWith(e1.Ids);
el.Ids.UnionWith(e2.Ids);
return el;
}
public static Element operator -(Element e1, Element e2)
{
if (e2 == null) return e1;
var e3 = new Element { Value = -e2.Value, Ids = e2.Ids };
return e1 + e3;
}
public static Element operator *(Element e1, Element e2)
{
if (e1 == null || e2 == null)
return null;
// we keep always the list of ids of operand e1.
// we ignore always the list of ids of operand e2.
return new Element { Value = e1.Value * e2.Value, Ids = e1.Ids };
}
public static Element operator *(Element e, decimal f)
{
if (e == null)
return null;
// we keep always the list of ids of operand e1
return new Element { Value = e.Value * f, Ids = e.Ids };
}
public static Element operator *(decimal f, Element e)
{
return e * f;
}
}
public class Matrix
{
public string Name { get; set; }
public string Desc { get; set; }
public Dictionary<Coords, Element> Elements { get; set; } = new Dictionary<Coords, Element>();
public DimManager DimManager = new DimManager();
public Matrix(string desc, string name = null)
{
Desc = desc;
Name = name ?? desc;
}
public bool Contains(Coords pos) => Elements.Any(x => x.Key.IsEqualTo(pos));
public Coords Size() => DimManager.Size();
public int Count() => Elements.Count;
public bool Empty() => Count() == 0;
public HashSet<int> GetDimSet(Dimension dimension) => DimManager.GetDimSet(dimension);
public Dictionary<Dimension, DimSet> GetDimSets() => DimManager.DimSets;
public bool HasSameSizeAs(Matrix matrix) => Size().Equals(matrix.Size());
public decimal GetValueOrDefault(Coords pos)
{
var e = this[pos];
if (e == null) return 0;
return e.Value;
}
public void Add(Coords pos, decimal value)
{
if (value == 0) return;
var el = this[pos];
if (el == null)
{
DimManager.Add(pos);
this[pos] = new Element(value, pos.Item);
}
else
el.Add(value);
}
public void Add(Coords pos, Element e)
{
if (e == null) return;
if (e.Value == 0) return;
var el = this[pos];
if (el == null)
{
DimManager.Add(pos);
this[pos] = new Element(e.Value, e.Ids);
}
else
el.Add(e);
}
public void Set(Coords pos, decimal e)
{
var el = this[pos];
if (el == null)
{
DimManager.Add(pos);
this[pos] = new Element(e, pos.Item);
}
else
el.Value = e;
}
public void Set(Coords pos, Element e)
{
if (e == null) return;
if (this[pos] == null)
{
DimManager.Add(pos);
this[pos] = new Element(e);
}
else
this[pos] = e;
}
public Matrix Remove(Matrix m, string name = null)
{
var res = new Matrix($"({Name}.Remove({m.Name})", name);
foreach (var pos in Elements.Select(value => value.Key))
{
if (m.Contains(pos))
continue;
res.DimManager.Add(pos);
res[pos] = this[pos];
}
return res;
}
public void Dump()
{
Console.WriteLine("{0}, count: {1}", Name, Elements.Count);
if (!Name.Equals(Desc)) Console.WriteLine(Desc);
foreach (var pair in Elements)
Console.WriteLine("{0} = {1}", pair.Key, pair.Value);
Console.WriteLine();
}
public Element this[Coords pos]
{
get { return Elements.FirstOrDefault(x => x.Key.IsEqualTo(pos)).Value; }
set { Elements[pos] = value; }
}
public static Matrix operator +(Matrix m1, Matrix m2)
{
var res = new Matrix($"({m1.Name} + {m2.Name})");
foreach (var pos in m1.Elements.Select(value => value.Key).Union(m2.Elements.Select(value => value.Key)).Select(x => new Coords(x)))
{
res.DimManager.Add(pos);
res[pos] = m1[pos] + m2[pos];
}
return res;
}
public static Matrix operator -(Matrix m1, Matrix m2)
{
var res = new Matrix($"({m1.Name} - {m2.Name})");
foreach (var pos in m1.Elements.Select(value => value.Key).Union(m2.Elements.Select(value => value.Key)).Select(x => new Coords(x)))
{
res.DimManager.Add(pos);
res[pos] = m1[pos] - m2[pos];
}
return res;
}
public static Matrix operator *(Matrix m1, Matrix m2)
{
var res = new Matrix($"({m1.Name} * {m2.Name})");
foreach (var pos in m1.Elements.Select(value => value.Key).Where(x => m2.Contains(new Coords(x))).Select(x => new Coords(x)))
{
res.DimManager.Add(pos);
res[pos] = m1[pos] * m2[pos];
}
return res;
}
public DimManager CopyDimensions(Coords dimensions = null)
{
return dimensions == null ?
MatrixMethods.CopyDimensions(this) :
MatrixMethods.CopyDimensions(this, dimensions);
}
public Matrix Project(Dimension normal, string name = null) => MatrixMethods.Project(this, normal, name);
public Matrix Project(Coords normal, string name = null) => MatrixMethods.Project(this, normal, name);
public Matrix Filter(DimManager range, FilterType filterType = FilterType.Inclusive, string name = null)
{
return filterType == FilterType.Inclusive ?
MatrixMethods.FilterIncl(this, range, name) :
filterType == FilterType.Exclusive ?
MatrixMethods.FilterExcl(this, range, name) :
Remove(MatrixMethods.FilterIncl(this, range), name);
}
public Matrix Filter(Coords filter, FilterType filterType = FilterType.Inclusive, string name = null)
{
return filterType == FilterType.Complement ?
Remove(MatrixMethods.Filter(this, filter), name) :
MatrixMethods.Filter(this, filter, filterType, name);
}
public Matrix Filter(Dimension dim, int value, FilterType filterType = FilterType.Inclusive, string name = null)
{
return filterType == FilterType.Complement ?
Remove(MatrixMethods.Filter(this, dim, value), name) :
MatrixMethods.Filter(this, dim, value, filterType, name);
}
public Matrix MultByExtr(Matrix m2, Coords extrusion, string name = null) => MatrixMethods.MultByExtr(this, m2, extrusion, name);
public Matrix MultByExtr(decimal value, string name = null) => MatrixMethods.MultByExtr(this, value, name);
public Matrix Translate(Coords translation, string name = null) => MatrixMethods.Translate(this, translation, name);
}
public class Composite
{
public int Id { get; set; } = 0;
public List<Composite> Children { get; } = new List<Composite>();
public void Add(Composite child) { Children.Add(child); }
public void Remove(Composite child)
{
if (Children.Contains(child))
Children.Remove(child);
}
public virtual void Dump() { Children.ForEach(child => child.Dump()); }
public virtual void CalcIndComp(CalcComps comps) { Children.ForEach(child => child.CalcIndComp(comps)); }
}
public class Container1 : Composite
{
public bool Flag1 { get; set; }
public decimal Value1 { get; set; }
public decimal Value2 { get; set; }
public override void CalcIndComp(CalcComps comps)
{
comps.Value1 = Value1;
comps.Flag1 = Flag1;
comps.Value2 = Value2;
base.CalcIndComp(comps);
}
public override void Dump()
{
Console.WriteLine($"- Cont1: {Id}");
Console.WriteLine($" - Flag1: {Flag1}");
base.Dump();
}
}
public class Container2 : Composite
{
public int Data1 { get; set; }
public override void CalcIndComp(CalcComps comps)
{
comps.Value3 = Id;
comps.Value4 = Data1;
comps.Value5 = Type5.Inst5_2;
comps.Value6 = Type5.Inst5_2;
comps.Value7 = Type5.Inst5_1;
comps.Value8 = Type5.Inst5_1;
base.CalcIndComp(comps);
}
public override void Dump()
{
Console.WriteLine($" - Cont2: {(Cat6)Id}");
Console.WriteLine($" - D1: {Data1}");
base.Dump();
}
}
public class Container3 : Composite
{
public int Value4 { get; set; }
public Type2 Type2 { get; set; }
public Type5 Value5 { get; set; }
public Type5 Value6 { get; set; }
public Type5 Value7 { get; set; }
public Type5 Value8 { get; set; }
public int Attr1 { get; set; }
public int Attr2 { get; set; }
public int Attr3 { get; set; }
public int Attr4 { get; set; }
public decimal Attr5 { get; set; }
public decimal Attr6 { get; set; }
// vary
public override void CalcIndComp(CalcComps comps)
{
comps.Items[Id] = this;
Value4 = comps.Value4;
Value5 = comps.Value5;
Value6 = comps.Value6;
Value7 = comps.Value7;
Value8 = comps.Value8;
var flag2 = true;
var type5Inst1 = flag2 ? Value5 : Value6;
var type5Inst2 = flag2 ? Value7 : Value8;
var amount1 = C1();
var amount2 = C2();
var amount3 = C3();
var type4 = (Attr2 == (int)Cat7.Inst7_3 && Attr3 == (int)Cat9.Inst9_4) ? Type4.Inst4_2 : Type4.Inst4_1;
if (Attr6 > 0)
{
var amount4 = amount1 * Attr6; amount1 -= amount4;
comps.Am1.Add(Coords.BuildCoords3(Id, (int)Type1.Inst1_1, (int)type4, (int)type5Inst1, comps.Value3, Attr1, Attr2, Attr3), amount4);
var amount5 = amount2 * Attr6; amount2 -= amount5;
comps.Am2.Add(Coords.BuildCoords3(Id, (int)Type1.Inst1_2, (int)Type4.Inst4_1, (int)type5Inst1, comps.Value3, Attr1, Attr2, Attr3), amount5);
if (comps.Flag1)
{
var amount6 = amount3 * Attr6; amount3 -= amount6;
comps.Am3.Add(Coords.BuildCoords3(Id, (int)Type1.Inst1_5, (int)type4, (int)type5Inst1, comps.Value3, Attr1, Attr2, Attr3), amount6);
}
}
var type5 = (Type2 == Type2.Inst2_5) || (Type2 == Type2.Inst2_4) || (Type2 == Type2.Inst2_3) ? type5Inst1 : type5Inst2;
comps.Am1.Add(Coords.BuildCoords2(Id, (int)Type1.Inst1_1, (int)Type2, (int)type4, (int)type5, comps.Value3, Attr1, Attr2, Attr3), amount1);
comps.Am2.Add(Coords.BuildCoords2(Id, (int)Type1.Inst1_2, (int)Type2, (int)Type4.Inst4_1, (int)type5, comps.Value3, Attr1, Attr2, Attr3), amount2);
comps.Am3.Add(Coords.BuildCoords2(Id, (int)Type1.Inst1_5, (int)Type2, (int)type4, (int)type5, comps.Value3, Attr1, Attr2, Attr3), amount3);
var amount7 = C4();
if (amount7 > 0) comps.Am6.Add(Coords.BuildCoords4((int)Type1.Inst1_7, 0, 0, Attr2, Attr3), amount7);
comps.Ratios1.Set(Coords.BuildCoords4((int)Type1.Inst1_1, 0, 0, Attr2, Attr3), Read1(Attr2, Attr3));
comps.Ratios2.Set(Coords.BuildCoords4((int)Type1.Inst1_2, 0, 0, Attr2, Attr3), Read2(Attr2, Attr3));
comps.Ratios3.Set(Coords.BuildCoords4((int)Type1.Inst1_5, 0, 0, Attr2, Attr3), Read3(Attr2, Attr3));
comps.Ratios4.Set(Coords.BuildCoords4((int)Type1.Inst1_3, 0, 0, Attr2, Attr3), Read1(Attr2, Attr3));
comps.Ratios5.Set(Coords.BuildCoords4((int)Type1.Inst1_4, 0, 0, Attr2, Attr3), Read5(Attr2, Attr3));
if (Attr2 == (int)Cat7.Inst7_4) comps.Ratios6.Set(Coords.BuildCoords5(0, 0, Attr2, Attr3), Read6(Attr2, Attr3));
}
// end vary
public virtual decimal C1() => Attr5 * 2 * Value4;
public virtual decimal C2() => Attr5 * 3 * Value4;
public virtual decimal C3() => Attr5 * 0.5m * Value4;
public virtual decimal C4() => Id == 100 ? 1.2m * Value4 : 0;
public virtual decimal Read1(int type8Id, int type9Id) => 4 * type8Id * type9Id;
public virtual decimal Read2(int type8Id, int type9Id) => 3 * type8Id * type9Id;
public virtual decimal Read3(int type8Id, int type9Id) => 2 * type8Id * type9Id;
public virtual decimal Read5(int type8Id, int type9Id) => 1 * type8Id * type9Id;
public virtual decimal Read6(int type8Id, int type9Id) => 0.1m * type8Id * type9Id;
public override void Dump()
{
Console.WriteLine($" - Cont3: {Id}");
Console.WriteLine($" - D9 : {(Cat9)Attr3}");
Console.WriteLine($" - D7 : {(Cat7)Attr1}");
Console.WriteLine($" - D8 : {(Cat7)Attr2}");
Console.WriteLine($" - A4: {(Cat10)Attr4}");
Console.WriteLine($" - A5: {Attr5}");
Console.WriteLine($" - A6: {Attr6}");
Console.WriteLine($" - T2: {(Type2)Type2}");
}
}
// end of composite
public class CalcComps
{
public bool Flag1 { get; set; }
public decimal Value1 { get; set; }
public decimal Value2 { get; set; }
public Dictionary<int, Container3> Items { get; set; } = new Dictionary<int, Container3>();
public int Value3 { get; set; }
public int Value4 { get; set; }
public Type5 Value5 { get; set; }
public Type5 Value6 { get; set; }
public Type5 Value7 { get; set; }
public Type5 Value8 { get; set; }
public Matrix Am1 { get; set; } = new Matrix("Am1 [u1]");
public Matrix Am2 { get; set; } = new Matrix("Am2 [$]");
public Matrix Am3 { get; set; } = new Matrix("Am3 [u3]");
public Matrix Am4 { get; set; } = new Matrix("Am4 [u1]");
public Matrix Am5 { get; set; } = new Matrix("Am5 [u5]");
public Matrix Am6 { get; set; } = new Matrix("Am6 [uX]");
public Matrix Am1Pr { get; set; } = new Matrix("Am1Pr [u1]");
public Matrix Am4Ex { get; set; } = new Matrix("Am4Ex [u1]");
public Matrix Am5Ex { get; set; } = new Matrix("Am5Ex [u5]");
public Matrix Ratios1 { get; set; } = new Matrix("R1 [$/u1]");
public Matrix Ratios2 { get; set; } = new Matrix("R2 [$/$]");
public Matrix Ratios3 { get; set; } = new Matrix("R3 [$/u3]");
public Matrix Ratios4 { get; set; } = new Matrix("R4 [$/u1]");
public Matrix Ratios5 { get; set; } = new Matrix("R5 [$/u5]");
public Matrix Ratios6 { get; set; } = new Matrix("R6 [u/u]");
public Matrix Am1Cost { get; set; }
public Matrix Am2Cost { get; set; }
public Matrix Am3Cost { get; set; }
public Matrix Am4Cost { get; set; }
public Matrix Am5Cost { get; set; }
public Matrix Cost0 { get; set; }
public Matrix Cost1 { get; set; }
public Matrix Cost2 { get; set; }
public Matrix Cost3 { get; set; }
public Matrix Cost4 { get; set; }
public Matrix Cost5 { get; set; }
public Matrix CostZ { get; set; }
// vary
public void CalcDepComps()
{
Am1Pr = Am1.Project(Coords.GetVector1(), "am1Pr [u1]");
foreach (var posElPair in Am1Pr.Elements)
{
var am1Pos = posElPair.Key;
var am1Val = posElPair.Value.Value;
var valX = Calc1(am1Val, am1Pos.Dim8, am1Pos.Dim9);
Am6.Add(Coords.BuildCoords4((int)Type1.Inst1_7, 0, 0, am1Pos.Dim8, am1Pos.Dim9), valX);
Am4.Add(Coords.BuildCoords4((int)Type1.Inst1_3, 0, 0, am1Pos.Dim8, am1Pos.Dim9), Calc2(am1Val, valX, am1Pos.Dim8, am1Pos.Dim9));
Am5.Add(Coords.BuildCoords4((int)Type1.Inst1_4, 0, 0, am1Pos.Dim8, am1Pos.Dim9), Calc3(am1Val, valX, am1Pos.Dim8, am1Pos.Dim9));
}
foreach (var posElPair in Am1.Elements)
{
var am1Pos = posElPair.Key;
var am1Val = posElPair.Value.Value;
var am1Tot = Am1Pr[Coords.BuildCoords4((int)Type1.Inst1_1, 0, 0, am1Pos.Dim8, am1Pos.Dim9)].Value;
var ratio = am1Val / am1Tot;
var type2 = Flag1 ? am1Pos.Dim2 : (int)Items[am1Pos.Item].Type2;
var am4Pr = Am4.GetValueOrDefault(Coords.BuildCoords4((int)Type1.Inst1_3, 0, 0, am1Pos.Dim8, am1Pos.Dim9));
Am4Ex.Add(Coords.BuildCoords2(am1Pos.Item, (int)Type1.Inst1_3, am1Pos.Dim2, am1Pos.Dim4, am1Pos.Dim5, am1Pos.Dim6, am1Pos.Dim7, am1Pos.Dim8, am1Pos.Dim9), am4Pr * ratio);
var am5Pr = Am5.GetValueOrDefault(Coords.BuildCoords4((int)Type1.Inst1_4, 0, 0, am1Pos.Dim8, am1Pos.Dim9));
Am5Ex.Add(Coords.BuildCoords2(am1Pos.Item, (int)Type1.Inst1_4, type2, am1Pos.Dim4, am1Pos.Dim5, am1Pos.Dim6, am1Pos.Dim7, am1Pos.Dim8, am1Pos.Dim9), am5Pr * ratio);
}
}
// end vary
private decimal Calc1(decimal u1, int type8, int type9) => type9 == (int)Cat9.Inst9_4 ? 0 : 0.1m * u1 * type8 * type9;
private decimal Calc2(decimal u1, decimal amX, int type8, int type9) => 0.1m * u1 * type8 * type9 * amX;
private decimal Calc3(decimal u1, decimal amX, int type8, int type9) => 0.2m * u1 * type8 * type9 * amX;
public void CalcCostComps()
{
var ratioExtr = Coords.GetVector1();
Am1Cost = Am1.MultByExtr(Ratios1, ratioExtr, "Am1Cost [$]");
Am2Cost = Am2.MultByExtr(Ratios2, ratioExtr, "Am2Cost [$]");
Am3Cost = Am3.MultByExtr(Ratios3, ratioExtr, "Am3Cost [$]");
Am4Cost = Am4Ex.MultByExtr(Ratios4, ratioExtr, "Am4Cost [$]");
Am5Cost = Am5Ex.MultByExtr(Ratios5, ratioExtr, "Am5Cost [$]");
Cost0 = Am1Cost + Am4Cost + Am2Cost + Am5Cost + Am3Cost;
Cost0.Name = "Cost0 [$]";
Cost1 = Cost0.Filter(Dimension.Dim4, (int)Type4.Inst4_2, FilterType.Inclusive, "Cost1 {N} [$]");
Cost2 = Cost0.Filter(Dimension.Dim4, (int)Type4.Inst4_1, FilterType.Inclusive, "Cost2 {T} [$]");
Cost3 = Cost2.MultByExtr(Value1);
Cost3 = Cost3.Translate(Coords.GetVector3(), "Cost3 [$]");
var cost4 = Cost2 + Cost3;
Cost4 = cost4.Filter(Dimension.Dim8, (int)Cat7.Inst7_4, FilterType.Inclusive, "Cost4 [$]");
if (Cost4.Empty()) {
Cost5 = new Matrix("Cost5 [$]");
} else {
Cost5 = Cost4.MultByExtr(Ratios6, Coords.GetVector4());
Cost5 = Cost5.Translate(Coords.GetVector5(), "Cost5 [$]");
}
CostZ = Cost1 + cost4 + Cost5;
CostZ.Name = "CostZ [$]";
}
public void CalcCostRedist1() { CalcCostRedist1_1(); }
public void CalcCostRedist1_1()
{
if (Value2 <= 0) return;
CostZ.Add(Coords.GetVector6(Type5.Inst5_2), Value2);
CostZ.Add(Coords.GetVector6(Type5.Inst5_1), -Value2);
}
}
public class Calculation
{
private Container1 _cont1;
private CalcComps _comps;
public void Calculate()
{
LoadContainer1();
_cont1.CalcIndComp(_comps);
_comps.CalcDepComps();
_comps.CalcCostComps();
_comps.CalcCostRedist1();
PrintIndComps();
PrintDepComps();
PrintCostComps();
PrintCost2Comps();
}
private void LoadContainer1()
{
_comps = new CalcComps();
_cont1 = new Container1
{
Id = 1,
Value1 = 0.25m,
Flag1 = false,
Value2 = 100m,
Children =
{
new Container2
{
Id = (int)Cat6.Inst6_1,
Data1 = 1,
Children =
{
new Container3
{
Id = 100,
Attr3 = (int)Cat9.Inst9_1,
Attr1 = (int)Cat7.Inst7_1,
Attr2 = (int)Cat7.Inst7_1,
Attr4 = (int)Cat10.Inst10_1,
Attr5 = 5,
Attr6 = 0,
Type2 = Type2.Inst2_1
},
new Container3
{
Id = 101,
Attr3 = (int)Cat9.Inst9_1,
Attr1 = (int)Cat7.Inst7_1,
Attr2 = (int)Cat7.Inst7_1,
Attr4 = (int)Cat10.Inst10_2,
Attr5 = 3,
Attr6 = 0,
Type2 = Type2.Inst2_1
},
new Container3
{
Id = 102,
Attr3 = (int)Cat9.Inst9_1,
Attr1 = (int)Cat7.Inst7_1,
Attr2 = (int)Cat7.Inst7_4,
Attr4 = (int)Cat10.Inst10_3,
Attr5 = 1,
Attr6 = 0.1m,
Type2 = Type2.Inst2_3
},
new Container3
{
Id = 103,
Attr3 = (int)Cat9.Inst9_3,
Attr1 = (int)Cat7.Inst7_1,
Attr2 = (int)Cat7.Inst7_1,
Attr4 = (int)Cat10.Inst10_5,
Attr5 = 10,
Attr6 = 0.5m,
Type2 = Type2.Inst2_1
},
new Container3
{
Id = 104,
Attr3 = (int)Cat9.Inst9_1,
Attr1 = (int)Cat7.Inst7_1,
Attr2 = (int)Cat7.Inst7_1,
Attr4 = (int)Cat10.Inst10_4,
Attr5 = 2,
Attr6 = 0,
Type2 = Type2.Inst2_5
},
}
},
new Container2
{
Id = (int)Cat6.Inst6_2,
Data1 = 1,
Children =
{
new Container3
{
Id = 200,
Attr3 = (int)Cat9.Inst9_1,
Attr1 = (int)Cat7.Inst7_2,
Attr2 = (int)Cat7.Inst7_2,
Attr4 = (int)Cat10.Inst10_1,
Attr5 = 3,
Attr6 = 0.1m,
Type2 = Type2.Inst2_1
},
new Container3
{
Id = 201,
Attr3 = (int)Cat9.Inst9_1,
Attr1 = (int)Cat7.Inst7_2,
Attr2 = (int)Cat7.Inst7_2,
Attr4 = (int)Cat10.Inst10_2,
Attr5 = 2,
Attr6 = 0.5m,
Type2 = Type2.Inst2_1
},
new Container3
{
Id = 202,
Attr3 = (int)Cat9.Inst9_3,
Attr1 = (int)Cat7.Inst7_1,
Attr2 = (int)Cat7.Inst7_1,
Attr4 = (int)Cat10.Inst10_5,
Attr5 = 12,
Attr6 = 0,
Type2 = Type2.Inst2_3
},
new Container3
{
Id = 203,
Attr3 = (int)Cat9.Inst9_4,
Attr1 = (int)Cat7.Inst7_3,
Attr2 = (int)Cat7.Inst7_3,
Attr4 = (int)Cat10.Inst10_5,
Attr5 = 1,
Attr6 = 0.2m,
Type2 = Type2.Inst2_5
},
new Container3
{
Id = 204,
Attr3 = (int)Cat9.Inst9_2,
Attr1 = (int)Cat7.Inst7_3,
Attr2 = (int)Cat7.Inst7_3,
Attr4 = (int)Cat10.Inst10_4,
Attr5 = 3,
Attr6 = 0.1m,
Type2 = Type2.Inst2_1
},
}
}
}
};
_cont1.Dump();
}
private void PrintIndComps()
{
_comps.Am1.Dump();
_comps.Am2.Dump();
_comps.Am3.Dump();
_comps.Ratios1.Dump();
_comps.Ratios2.Dump();
_comps.Ratios3.Dump();
_comps.Ratios5.Dump();
_comps.Ratios4.Dump();
_comps.Ratios6.Dump();
}
private void PrintDepComps()
{
var am1NoPr = _comps.Am1;
var am1PrO = am1NoPr.Project(Dimension.Item);
var am1PrA = am1PrO.Project(Dimension.Dim2);
var am1PrT = am1PrA.Project(Dimension.Dim4);
var am1PrD = am1PrT.Project(Dimension.Dim5);
var am1PrS = am1PrD.Project(Dimension.Dim6);
var am1PrG = am1PrS.Project(Dimension.Dim7);
am1NoPr.Dump();
am1PrO.Dump();
am1PrA.Dump();
am1PrT.Dump();
am1PrD.Dump();
am1PrS.Dump();
am1PrG.Dump();
_comps.Am1Pr.Dump();
_comps.Am6.Dump();
_comps.Am4.Dump();
_comps.Am5.Dump();
_comps.Am4Ex.Dump();
_comps.Am5Ex.Dump();
_comps.Am4Ex.
Project(Dimension.Item).
Project(Dimension.Dim2).
Project(Dimension.Dim4).
Project(Dimension.Dim5).
Project(Dimension.Dim6).
Project(Dimension.Dim7).
Dump();
}
private void PrintCostComps()
{
_comps.Am1Cost.Dump();
_comps.Am2Cost.Dump();
_comps.Am3Cost.Dump();
_comps.Am4Cost.Dump();
_comps.Am5Cost.Dump();
_comps.Cost0.Dump();
_comps.Cost1.Dump();
_comps.Cost2.Dump();
_comps.Cost3.Dump();
_comps.Cost4.Dump();
_comps.Cost5.Dump();
_comps.CostZ.Dump();
}