public static void Get_New_Markers(int[][] adjancy_list, int[] next_layer, int[] old_markers, int[] new_markers, HashSet <int> is_in_previous_layers)
        {
            Mark_Int_List marker = new Mark_Int_List();

            for (int i1 = 0; i1 < next_layer.Length; i1++)
            {
                int        current_node     = next_layer[i1];
                List <int> neigburs_markers = new List <int>();
                for (int i2 = 0; i2 < adjancy_list[current_node].Length; i2++)
                {
                    int neighbur = adjancy_list[current_node][i2];
                    if (is_in_previous_layers.Contains(neighbur))
                    {
                        neigburs_markers.Add(new_markers[neighbur]);
                    }
                    else
                    {
                        neigburs_markers.Add(old_markers[neighbur]);
                    }
                }
                int[] arr = neigburs_markers.ToArray();
                Array.Sort(arr);
                new_markers[current_node] = marker.Get_Marker(arr);
            }
            Partial_Replace_Markers_With_Indexes(next_layer, new_markers, marker);
        }
 private static void Get_New_Marker_For_Each_Node(Mark_Int_List G2, int[][] v_b1, int[] t1_b1, int[] t2_b1)
 {
     for (int i1 = 0; i1 < t1_b1.GetLength(0); i1++)
     {
         Get_New_Marker_For_Single_Node(G2, v_b1, i1, t1_b1, t2_b1);
     }
 }
 private static int[] Get_New_Marker_For_Each_NodeV2(Mark_Int_List G2, int[][] adjancy_list, int[] markers)
 {
     int[] new_markers = new int[markers.Length];
     for (int i1 = 0; i1 < markers.GetLength(0); i1++)
     {
         new_markers[i1] = Get_New_Marker_For_Single_NodeV2(G2, adjancy_list[i1], markers);
     }
     return(new_markers);
 }
        private static int Get_New_Marker_For_Single_NodeV2(Mark_Int_List a1, int[] neigburs, int[] markers)
        {
            List <int> L1 = new List <int>();

            for (int i1 = 0; i1 < neigburs.Length; i1++)
            {
                L1.Add(markers[neigburs[i1]]);
            }
            L1.Sort();
            return(a1.Get_Marker(L1.ToArray()));
        }
        private static void Get_New_Marker_For_Single_Node(Mark_Int_List a1, int[][] v_b, int i1, int[] t1_b, int[] t2_b)
        {
            int        i2;
            List <int> L1 = new List <int>();

            for (i2 = 0; i2 < v_b[i1].Length; i2++)
            {
                L1.Add(t1_b[v_b[i1][i2]]);
            }
            L1.Sort();
            t2_b[i1] = a1.Get_Marker(L1.ToArray());
        }
        public static int[] Break_Symetry(int[][] adjancy_list, int[] markers)
        {
            int[]         current_markers = markers;
            Mark_Int_List G2 = new Mark_Int_List();

            for (int i1 = 0; i1 < adjancy_list.Length; i1++)
            {
                current_markers = Get_Next_Markers(adjancy_list, current_markers, G2);
                int duplicate_marker = Find_Lowest_Duplicate(current_markers);
                Change_Marker(duplicate_marker, current_markers);
            }
            return(current_markers);
        }
        private static int[] From_2D_Array_To_1D_Array(int[,] array2D)
        {
            Mark_Int_List mark_int_list = new Mark_Int_List();

            int[] t1;
            int[] array1D = new int[array2D.GetLength(0)];
            for (int i1 = 0; i1 < array2D.GetLength(0); i1++)
            {
                t1 = new int[array2D.GetLength(1)];
                for (int i2 = 0; i2 < array2D.GetLength(1); i2++)
                {
                    t1[i2] = array2D[i1, i2];
                }
                Array.Sort(t1);
                array1D[i1] = mark_int_list.Get_Marker(t1);
            }
            return(Replace_Markers_With_Indexes(mark_int_list.Get_All_Marker_Maping(), array1D));
        }
 public static int[] Get_Next_Markers(int[][] adjancy_list, int[] markers, Mark_Int_List G2)
 {
     int[] current_markers = markers;
     for (int i1 = 0; i1 < adjancy_list.Length; i1++)
     {
         if (All_Diferent(current_markers))
         {
             return(current_markers);
         }
         G2.Clear();
         int[] next_preliminary_markers = Get_New_Marker_For_Each_NodeV2(G2, adjancy_list, current_markers);
         int[] next_secondary_markers   = Replace_Markers_With_Indexes(G2.Get_All_Marker_Maping().ToArray(), next_preliminary_markers);
         if (current_markers.SequenceEqual(next_secondary_markers))
         {
             return(current_markers);
         }
         current_markers = next_secondary_markers;
     }
     return(current_markers);
 }
        private static int[,] From_3D_Array_To_2D_Array(int[][][] array3D)
        {
            Mark_Int_List mark_int_list = new Mark_Int_List();

            int[] t1;
            int   i1, i2, i3;

            int[,] array2D = new int[array3D[0].Length, array3D[0].Length];
            for (i1 = 0; i1 < array3D[0].Length; i1++)
            {
                for (i2 = 0; i2 < array3D[0][0].Length; i2++)
                {
                    t1 = new int[array3D.Length];
                    for (i3 = 0; i3 < array3D.Length; i3++)
                    {
                        t1[i3] = array3D[i3][i1][i2];
                    }
                    array2D[i1, i2] = mark_int_list.Get_Marker(t1);
                }
            }
            return(Replace_Markers_With_Indexes(mark_int_list.Get_All_Marker_Maping(), array2D));
        }
예제 #10
0
 public Mark_Graph()
 {
     mrk_int_list = new Mark_Int_List();
 }
        //Replace_Markers_With_Indexes
        public static void Partial_Replace_Markers_With_Indexes(int[] next_layer, int[] new_markers, Mark_Int_List marker)
        {
            int max = new_markers.Max();

            int[] markers             = marker.Get_All_Marker_Maping();
            Dictionary <int, int> dic = new Dictionary <int, int>();

            for (int i1 = 0; i1 < markers.Length; i1++)
            {
                dic[markers[i1]] = i1;
            }
            for (int i1 = 0; i1 < next_layer.Length; i1++)
            {
                int current_node = next_layer[i1];
                new_markers[current_node] = dic[new_markers[current_node]] + max;
            }
        }
        public static bool Graph_Isomorphism(int[][] adjancy_matrix_A, int[][] adjancy_matrinx_B)
        {
            if (adjancy_matrix_A.Length != adjancy_matrinx_B.Length)
            {
                return(false);
            }
            int[]         next_markers_A;
            int[]         current_markers_A = Get_Primary_Markers(adjancy_matrix_A);
            int[]         next_markers_B;
            int[]         current_markers_B = Get_Primary_Markers(adjancy_matrinx_B);
            int[]         p1;
            int[]         p2;
            Mark_Int_List G2 = new Mark_Int_List();
            int           i2;
            int           r1, r2;
            bool          should_break = true;

            for (r1 = 0; r1 < current_markers_A.Length; r1++)
            {
                for (r2 = 0; r2 < current_markers_A.Length; r2++)
                {
                    p1 = current_markers_A.ToArray();
                    p2 = current_markers_B.ToArray();
                    Array.Sort(p1);
                    Array.Sort(p2);
                    if (!p1.SequenceEqual(p2))
                    {
                        return(false);
                    }
                    should_break = true;
                    for (i2 = 1; i2 < p1.Length; i2++)
                    {
                        if (p1[i2] == p1[i2 - 1])
                        {
                            should_break = false;
                            break;
                        }
                    }
                    if (should_break)
                    {
                        break;
                    }
                    should_break = true;
                    for (i2 = 1; i2 < p1.Length; i2++)
                    {
                        if (p2[i2] == p2[i2 - 1])
                        {
                            should_break = false;
                            break;
                        }
                    }
                    if (should_break)
                    {
                        break;
                    }
                    G2.Clear();
                    next_markers_A = Get_New_Marker_For_Each_NodeV2(G2, adjancy_matrix_A, current_markers_A);
                    next_markers_B = Get_New_Marker_For_Each_NodeV2(G2, adjancy_matrinx_B, current_markers_B);

                    next_markers_A = Replace_Markers_With_Indexes(G2.Get_All_Marker_Maping().ToArray(), next_markers_A);
                    next_markers_B = Replace_Markers_With_Indexes(G2.Get_All_Marker_Maping().ToArray(), next_markers_B);

                    if (current_markers_A.SequenceEqual(next_markers_A))
                    {
                        break;
                    }
                    if (current_markers_B.SequenceEqual(next_markers_B))
                    {
                        break;
                    }
                    current_markers_A = next_markers_A;
                    current_markers_B = next_markers_B;
                }
                if (should_break)
                {
                    break;
                }
                int lowest_duplicate = Find_Lowest_Duplicate(current_markers_A);
                Change_Marker(lowest_duplicate, current_markers_A);
                Change_Marker(lowest_duplicate, current_markers_B);
            }
            bool[,] k1 = Rearange_Matrix_According_To_Markers(To_Adjancy_Matrix_From_Adjency_Lists(adjancy_matrix_A), current_markers_A);
            bool[,] k2 = Rearange_Matrix_According_To_Markers(To_Adjancy_Matrix_From_Adjency_Lists(adjancy_matrinx_B), current_markers_B);
            return(Are_Identical_Matrixes(k1, k2));
        }