@@ -10,12 +10,22 @@ public static class BinaryRelations
1010 {
1111 #region Helpers
1212
13+ /// <summary>
14+ /// Creates diagonal matrix with the same size of given matrix
15+ /// </summary>
16+ /// <param name="matrix1"></param>
17+ /// <returns></returns>
1318 public static bool [ , ] GetDiagonalRelation ( this bool [ , ] matrix1 )
1419 {
1520 ThrowIfNotQuad ( matrix1 ) ;
1621 return GetDiagonalRelation ( matrix1 . GetLength ( 0 ) ) ;
1722 }
1823
24+ /// <summary>
25+ /// Creates a diagonal matrix of specified length
26+ /// </summary>
27+ /// <param name="len"></param>
28+ /// <returns></returns>
1929 public static bool [ , ] GetDiagonalRelation ( int len )
2030 {
2131 if ( len <= 0 ) throw new ArgumentOutOfRangeException ( nameof ( len ) ) ;
@@ -28,6 +38,7 @@ public static class BinaryRelations
2838
2939 return matrix1 ;
3040 }
41+
3142 /// <summary>
3243 /// Converts elements of one dimensional array from <see cref="R"/> to <see cref="T"/>
3344 /// </summary>
@@ -49,6 +60,7 @@ public static T[] Cast<R, T>(this R[] array)
4960
5061 return result ;
5162 }
63+
5264 /// <summary>
5365 /// Converts elements of two dimensional array from <see cref="R"/> to <see cref="T"/>
5466 /// </summary>
@@ -98,7 +110,34 @@ public static T[] Cast<R, T>(this R[] array)
98110 return matrix1 ;
99111 }
100112
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 )
102141 {
103142 if ( matrix1 is null || matrix2 is null )
104143 return false ;
@@ -118,6 +157,34 @@ public static bool IsEqualTo<T>(this T[,] matrix1, T[,] matrix2)
118157
119158 return true ;
120159 }
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+ }
121188 #endregion
122189
123190 #region Argument check
@@ -458,11 +525,40 @@ private static void ThrowIfNull_NotQuad_SizeDiffers<T>(T[,] array1, T[,] array2)
458525
459526 #region Extremums
460527
528+ /// <summary>
529+ /// Returns true if matrix have any relational maximum
530+ /// </summary>
531+ /// <param name="matrix1"></param>
532+ /// <returns></returns>
461533 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>
462540 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>
463547 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>
464554 public static bool HasMinorant ( this bool [ , ] matrix1 ) => GetMinorants ( matrix1 ) . Any ( ) ;
465555
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>
466562 public static IEnumerable < int > GetMaximums ( this bool [ , ] matrix1 )
467563 {
468564 ThrowIfNull_NotQuad ( matrix1 ) ;
@@ -486,6 +582,12 @@ public static IEnumerable<int> GetMaximums(this bool[,] matrix1)
486582 }
487583 }
488584
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>
489591 public static IEnumerable < int > GetMinimums ( this bool [ , ] matrix1 )
490592 {
491593 ThrowIfNull_NotQuad ( matrix1 ) ;
@@ -509,6 +611,12 @@ public static IEnumerable<int> GetMinimums(this bool[,] matrix1)
509611 }
510612 }
511613
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>
512620 public static IEnumerable < int > GetMajorants ( this bool [ , ] matrix1 )
513621 {
514622 ThrowIfNull_NotQuad ( matrix1 ) ;
@@ -532,6 +640,12 @@ public static IEnumerable<int> GetMajorants(this bool[,] matrix1)
532640 }
533641 }
534642
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>
535649 public static IEnumerable < int > GetMinorants ( this bool [ , ] matrix1 )
536650 {
537651 ThrowIfNull_NotQuad ( matrix1 ) ;
@@ -559,11 +673,11 @@ public static IEnumerable<int> GetMinorants(this bool[,] matrix1)
559673 #region Relation properties check
560674
561675 /// <summary>
562- /// Is a full related binary matrix
676+ /// Is a total relation binary matrix
563677 /// </summary>
564678 /// <param name="matrix1">binary matrix</param>
565679 /// <returns>bool</returns>
566- public static bool IsFullRelation ( this bool [ , ] matrix1 )
680+ public static bool IsTotalRelation ( this bool [ , ] matrix1 )
567681 {
568682 ThrowIfNull_NotQuad ( matrix1 ) ;
569683
0 commit comments