@@ -10,12 +10,22 @@ public static class BinaryRelations
10
10
{
11
11
#region Helpers
12
12
13
+ /// <summary>
14
+ /// Creates diagonal matrix with the same size of given matrix
15
+ /// </summary>
16
+ /// <param name="matrix1"></param>
17
+ /// <returns></returns>
13
18
public static bool [ , ] GetDiagonalRelation ( this bool [ , ] matrix1 )
14
19
{
15
20
ThrowIfNotQuad ( matrix1 ) ;
16
21
return GetDiagonalRelation ( matrix1 . GetLength ( 0 ) ) ;
17
22
}
18
23
24
+ /// <summary>
25
+ /// Creates a diagonal matrix of specified length
26
+ /// </summary>
27
+ /// <param name="len"></param>
28
+ /// <returns></returns>
19
29
public static bool [ , ] GetDiagonalRelation ( int len )
20
30
{
21
31
if ( len <= 0 ) throw new ArgumentOutOfRangeException ( nameof ( len ) ) ;
@@ -28,6 +38,7 @@ public static class BinaryRelations
28
38
29
39
return matrix1 ;
30
40
}
41
+
31
42
/// <summary>
32
43
/// Converts elements of one dimensional array from <see cref="R"/> to <see cref="T"/>
33
44
/// </summary>
@@ -49,6 +60,7 @@ public static T[] Cast<R, T>(this R[] array)
49
60
50
61
return result ;
51
62
}
63
+
52
64
/// <summary>
53
65
/// Converts elements of two dimensional array from <see cref="R"/> to <see cref="T"/>
54
66
/// </summary>
@@ -98,7 +110,34 @@ public static T[] Cast<R, T>(this R[] array)
98
110
return matrix1 ;
99
111
}
100
112
101
- public static bool IsEqualTo < T > ( this T [ , ] matrix1 , T [ , ] matrix2 )
113
+ /// <summary>
114
+ /// Prints matrix to <see cref="Console.Out"/> or specified text writer
115
+ /// </summary>
116
+ /// <typeparam name="T"></typeparam>
117
+ /// <param name="matrix1"></param>
118
+ /// <param name="writer"></param>
119
+ /// <returns></returns>
120
+ public static T [ ] PrintThrough < T > ( this T [ ] matrix1 , TextWriter writer = default )
121
+ {
122
+ ThrowIfNull ( matrix1 ) ;
123
+ if ( writer == default ) writer = Console . Out ;
124
+ var length = matrix1 . GetLength ( 0 ) ;
125
+ for ( int i = 0 ; i < length ; i ++ )
126
+ {
127
+ writer . Write ( matrix1 [ i ] . ToString ( ) + ' ' ) ;
128
+ }
129
+
130
+ return matrix1 ;
131
+ }
132
+
133
+ /// <summary>
134
+ /// Sequentially compares elements of two-dimensional arrays using <see cref="object.ReferenceEquals"/>
135
+ /// </summary>
136
+ /// <typeparam name="T"></typeparam>
137
+ /// <param name="matrix1"></param>
138
+ /// <param name="matrix2"></param>
139
+ /// <returns></returns>
140
+ public static bool IsReferenceSequenceEqualTo < T > ( this T [ , ] matrix1 , T [ , ] matrix2 )
102
141
{
103
142
if ( matrix1 is null || matrix2 is null )
104
143
return false ;
@@ -118,6 +157,34 @@ public static bool IsEqualTo<T>(this T[,] matrix1, T[,] matrix2)
118
157
119
158
return true ;
120
159
}
160
+
161
+ /// <summary>
162
+ /// Sequentially compares elements of arrays using <see cref="object.ReferenceEquals"/>
163
+ /// </summary>
164
+ /// <typeparam name="T"></typeparam>
165
+ /// <param name="matrix1"></param>
166
+ /// <param name="matrix2"></param>
167
+ /// <returns></returns>
168
+ public static bool IsReferenceSequenceEqualTo < T > ( this T [ ] matrix1 , T [ ] matrix2 )
169
+ {
170
+ if ( matrix1 is null || matrix2 is null )
171
+ return false ;
172
+ var len1 = matrix1 . GetLength ( 0 ) ;
173
+ var len2 = matrix1 . GetLength ( 1 ) ;
174
+ if ( len1 != matrix2 . GetLength ( 0 )
175
+ && len2 != matrix2 . GetLength ( 1 ) )
176
+ return false ;
177
+ for ( int i = 0 ; i < len1 ; i ++ )
178
+ {
179
+ for ( int j = 0 ; j < len2 ; j ++ )
180
+ {
181
+ if ( ! ReferenceEquals ( matrix1 [ i ] , matrix2 [ i ] ) )
182
+ return false ;
183
+ }
184
+ }
185
+
186
+ return true ;
187
+ }
121
188
#endregion
122
189
123
190
#region Argument check
@@ -458,11 +525,40 @@ private static void ThrowIfNull_NotQuad_SizeDiffers<T>(T[,] array1, T[,] array2)
458
525
459
526
#region Extremums
460
527
528
+ /// <summary>
529
+ /// Returns true if matrix have any relational maximum
530
+ /// </summary>
531
+ /// <param name="matrix1"></param>
532
+ /// <returns></returns>
461
533
public static bool HasMaximum ( this bool [ , ] matrix1 ) => GetMaximums ( matrix1 ) . Any ( ) ;
534
+
535
+ /// <summary>
536
+ /// Returns true if matrix have any relational minimum
537
+ /// </summary>
538
+ /// <param name="matrix1"></param>
539
+ /// <returns></returns>
462
540
public static bool HasMinimum ( this bool [ , ] matrix1 ) => GetMinimums ( matrix1 ) . Any ( ) ;
541
+
542
+ /// <summary>
543
+ /// Returns true if matrix have any relational majorants
544
+ /// </summary>
545
+ /// <param name="matrix1"></param>
546
+ /// <returns></returns>
463
547
public static bool HasMajorant ( this bool [ , ] matrix1 ) => GetMajorants ( matrix1 ) . Any ( ) ;
548
+
549
+ /// <summary>
550
+ /// Returns true if matrix have any relational minorants
551
+ /// </summary>
552
+ /// <param name="matrix1"></param>
553
+ /// <returns></returns>
464
554
public static bool HasMinorant ( this bool [ , ] matrix1 ) => GetMinorants ( matrix1 ) . Any ( ) ;
465
555
556
+ /// <summary>
557
+ /// Returns indexes of relations those are maximums
558
+ /// <see href="http://www.u.arizona.edu/~mwalker/econ519/Econ519LectureNotes/BinaryRelations.pdf"/>
559
+ /// </summary>
560
+ /// <param name="matrix1"></param>
561
+ /// <returns></returns>
466
562
public static IEnumerable < int > GetMaximums ( this bool [ , ] matrix1 )
467
563
{
468
564
ThrowIfNull_NotQuad ( matrix1 ) ;
@@ -486,6 +582,12 @@ public static IEnumerable<int> GetMaximums(this bool[,] matrix1)
486
582
}
487
583
}
488
584
585
+ /// <summary>
586
+ /// Returns indexes of relations those are minimums
587
+ /// <see href="http://www.u.arizona.edu/~mwalker/econ519/Econ519LectureNotes/BinaryRelations.pdf"/>
588
+ /// </summary>
589
+ /// <param name="matrix1"></param>
590
+ /// <returns></returns>
489
591
public static IEnumerable < int > GetMinimums ( this bool [ , ] matrix1 )
490
592
{
491
593
ThrowIfNull_NotQuad ( matrix1 ) ;
@@ -509,6 +611,12 @@ public static IEnumerable<int> GetMinimums(this bool[,] matrix1)
509
611
}
510
612
}
511
613
614
+ /// <summary>
615
+ /// Returns indexes of relations those are majorants
616
+ /// <see href="http://www.u.arizona.edu/~mwalker/econ519/Econ519LectureNotes/BinaryRelations.pdf"/>
617
+ /// </summary>
618
+ /// <param name="matrix1"></param>
619
+ /// <returns></returns>
512
620
public static IEnumerable < int > GetMajorants ( this bool [ , ] matrix1 )
513
621
{
514
622
ThrowIfNull_NotQuad ( matrix1 ) ;
@@ -532,6 +640,12 @@ public static IEnumerable<int> GetMajorants(this bool[,] matrix1)
532
640
}
533
641
}
534
642
643
+ /// <summary>
644
+ /// Returns indexes of relations those are minorants
645
+ /// <see href="http://www.u.arizona.edu/~mwalker/econ519/Econ519LectureNotes/BinaryRelations.pdf"/>
646
+ /// </summary>
647
+ /// <param name="matrix1"></param>
648
+ /// <returns></returns>
535
649
public static IEnumerable < int > GetMinorants ( this bool [ , ] matrix1 )
536
650
{
537
651
ThrowIfNull_NotQuad ( matrix1 ) ;
@@ -559,11 +673,11 @@ public static IEnumerable<int> GetMinorants(this bool[,] matrix1)
559
673
#region Relation properties check
560
674
561
675
/// <summary>
562
- /// Is a full related binary matrix
676
+ /// Is a total relation binary matrix
563
677
/// </summary>
564
678
/// <param name="matrix1">binary matrix</param>
565
679
/// <returns>bool</returns>
566
- public static bool IsFullRelation ( this bool [ , ] matrix1 )
680
+ public static bool IsTotalRelation ( this bool [ , ] matrix1 )
567
681
{
568
682
ThrowIfNull_NotQuad ( matrix1 ) ;
569
683
0 commit comments