HyperGraph

TheoremAuto изменено поле на тип object для динамики в разных

12/19/2020 12:09:41 AM

Details

diff --git a/HyperGraphModel/Theorem.cs b/HyperGraphModel/Theorem.cs
index d89c58b..3384780 100644
--- a/HyperGraphModel/Theorem.cs
+++ b/HyperGraphModel/Theorem.cs
@@ -16,7 +16,7 @@ namespace HyperGraphModel
             //  Число автоморфизмов
             public long CountAutomorphism;
             //  Список общих вершин
-            public List<string> AutomorphismNodes;
+            public object AutomorphismNodes;
             //  Гипер-граф, содержащий гипер-ребра без общих вершин
             public HyperGraph GraphWithoutAutoEdges;
         }
@@ -62,7 +62,7 @@ namespace HyperGraphModel
             {
                 isSatisfyTheorem = (intersect.Count > 0) ? true : false,
                 CountAutomorphism = count,
-                AutomorphismNodes = intersect,
+                AutomorphismNodes = intersect.OfType<object>().ToList(),
                 GraphWithoutAutoEdges = graph
             };
             //  Вовращаемое значение в виде структуры
@@ -119,7 +119,7 @@ namespace HyperGraphModel
             {
                 isSatisfyTheorem = (intersect.Count > 0) ? true : false,
                 CountAutomorphism = count,
-                AutomorphismNodes = intersect,
+                AutomorphismNodes = intersect.OfType<object>().ToList(),
                 GraphWithoutAutoEdges = graph
             };
             //  Вовращаемое значение в виде структуры
@@ -168,6 +168,12 @@ namespace HyperGraphModel
 
             //  Копирую гипер-граф, чтобы не изменять исходный
             HyperGraph graph = new HyperGraph(Graph);
+
+            foreach (var edge in graph.HyperEdge)
+                foreach (var same in Pain.Keys)
+                    foreach (var vert in same)
+                        edge.RemoveAll(s => s.Equals(vert));
+
             //  Число автоморфизмов
             long count = Graph.HyperEdge.Aggregate((long)1, (sum, x) => sum *= Factorial(x.Count - 2 * k)) * Factorial(k);
 
@@ -175,7 +181,7 @@ namespace HyperGraphModel
             {
                 isSatisfyTheorem = true,
                 CountAutomorphism = count,
-                AutomorphismNodes = null,
+                AutomorphismNodes = Pain.Keys.OfType<object>().ToList(),
                 GraphWithoutAutoEdges = graph
             };
             //  Вовращаемое значение в виде структуры

WPF/Model/Calculate.cs 109(+100 -9)

diff --git a/WPF/Model/Calculate.cs b/WPF/Model/Calculate.cs
index a3e0955..8922076 100644
--- a/WPF/Model/Calculate.cs
+++ b/WPF/Model/Calculate.cs
@@ -165,7 +165,10 @@ namespace WPF.Model
                     }
                 case EnumTheorem.Forth:
                     {
-
+                        using (StreamWriter sw = new StreamWriter(memoryStream))
+                        {
+                            ExportTheoremaForth(result, sw);
+                        }
                         break;
                     }
                 case EnumTheorem.Fifth:
@@ -186,21 +189,22 @@ namespace WPF.Model
             //  Если да, то вывести
             if (result.isSatisfyTheorem)
             {
+                var AutomorphismNodes = (result.AutomorphismNodes as List<object>).OfType<string>().ToList();
                 //  Вывод вершин и числа автоморфизмов в файл
                 output.WriteLine("Общие вершины автоморфизмов: ");
-                foreach (var node in result.AutomorphismNodes)
+                foreach (var node in AutomorphismNodes)
                 {
                     output.Write(node + " ");
                 }
 
                 output.WriteLine();
                 //  Вывод всех перестановок общих вершин
-                List<List<string>> transpos = Combinatorics<string>.Transposition(result.AutomorphismNodes);
+                List<List<string>> transpos = Combinatorics<string>.Transposition(AutomorphismNodes);
                 //  Вывод начальной перестановки
                 output.Write("1:");
-                for (int g = 0; g < result.AutomorphismNodes.Count; g++)
+                for (int g = 0; g < AutomorphismNodes.Count; g++)
                 {
-                    output.Write(" {0}", result.AutomorphismNodes[g]);
+                    output.Write(" {0}", AutomorphismNodes[g]);
                 }
 
                 output.WriteLine("\r\n\t-----------");
@@ -265,21 +269,22 @@ namespace WPF.Model
             //  Если да, то вывести
             if (result.isSatisfyTheorem)
             {
+                var AutomorphismNodes = (result.AutomorphismNodes as List<object>).OfType<string>().ToList();
                 //  Вывод вершин и числа автоморфизмов в файл
                 output.WriteLine("Общие вершины автоморфизмов: ");
-                foreach (var node in result.AutomorphismNodes)
+                foreach (var node in AutomorphismNodes)
                 {
                     output.Write(node + " ");
                 }
 
                 output.WriteLine();
                 //  Вывод всех перестановок общих вершин
-                List<List<string>> transpos = Combinatorics<string>.Transposition(result.AutomorphismNodes);
+                List<List<string>> transpos = Combinatorics<string>.Transposition(AutomorphismNodes);
                 //  Вывод начальной перестановки
                 output.Write("1:");
-                for (int g = 0; g < result.AutomorphismNodes.Count; g++)
+                for (int g = 0; g < AutomorphismNodes.Count; g++)
                 {
-                    output.Write(" {0}", result.AutomorphismNodes[g]);
+                    output.Write(" {0}", AutomorphismNodes[g]);
                 }
 
                 output.WriteLine("\r\n\t-----------");
@@ -418,6 +423,92 @@ namespace WPF.Model
             }
         }
 
+        static void ExportTheoremaForth(TheoremAuto result, StreamWriter output)
+        {
+            //  Выполняется ли условие согласно теореме 3
+            output.WriteLine("Согласно теореме 4: " + result.isSatisfyTheorem);
+            //  Если да, то вывести
+            if (result.isSatisfyTheorem)
+            {
+                List<List<string>> AutomorphismNodesList = (result.AutomorphismNodes as List<object>).OfType<List<string>>().ToList();
+                List<List<string>> transpos;
+
+                output.WriteLine("\nПересекающиеся вершины автоморфизмов: ");
+                foreach (var AutomorphismNodes in AutomorphismNodesList)
+                {
+                    //  Вывод вершин и числа автоморфизмов в файл
+                    output.Write("Группа вершин: ");
+                    foreach (var node in AutomorphismNodes)
+                    {
+                        output.Write(node + " ");
+                    }
+
+                    output.WriteLine();
+                    //  Вывод всех перестановок общих вершин
+                    transpos = Combinatorics<string>.Transposition(AutomorphismNodes);
+                    //  Вывод начальной перестановки
+                    output.Write("1:");
+                    for (int g = 0; g < AutomorphismNodes.Count; g++)
+                    {
+                        output.Write(" {0}", AutomorphismNodes[g]);
+                    }
+
+                    output.WriteLine("\r\n\t-----------");
+                    //  Алгоритм перестановок не учитывает начальную, а начинает со следующей
+                    for (int g = 0; g < transpos.Count; g++)
+                    {
+                        output.Write("{0}: ", g + 2);
+                        for (int f = 0; f < transpos[g].Count; f++)
+                        {
+                            output.Write("{0} ", transpos[g][f]);
+                        }
+
+                        output.WriteLine("\r\n\t-----------");
+                    }
+                }
+
+                output.WriteLine("\r\nКоличество автоморфизмов: " + result.CountAutomorphism + "\r\n");
+
+                //  Обработать все гипер-ребра
+                for (int i = 0; i < result.GraphWithoutAutoEdges.HyperEdge.Count; i++)
+                {
+                    //  Получить массив перестановок текущего гипер-ребра
+                    transpos = Combinatorics<string>.Transposition(result.GraphWithoutAutoEdges.HyperEdge[i]);
+
+                    // Вывод всех вершин текущего гипер-ребра 
+                    output.Write("Текущее ребро включает вершины:");
+                    for (int g = 0; g < result.GraphWithoutAutoEdges.HyperEdge[i].Count; g++)
+                    {
+                        output.Write(" {0}", result.GraphWithoutAutoEdges.HyperEdge[i][g]);
+                    }
+
+                    //  Вывод всех перестановок текущего гипер-ребра
+                    output.WriteLine();
+
+                    //  Вывод начальной перестановки
+                    output.Write("1:");
+                    for (int g = 0; g < result.GraphWithoutAutoEdges.HyperEdge[i].Count; g++)
+                    {
+                        output.Write(" {0}", result.GraphWithoutAutoEdges.HyperEdge[i][g]);
+                    }
+
+                    output.WriteLine("\r\n\t-----------");
+                    //  Алгоритм перестановок не учитывает начальную, а начинает со следующей
+                    for (int g = 0; g < transpos.Count; g++)
+                    {
+                        output.Write("{0}: ", g + 2);
+                        for (int f = 0; f < transpos[g].Count; f++)
+                        {
+                            output.Write("{0} ", transpos[g][f]);
+                        }
+
+                        output.WriteLine("\r\n\t-----------");
+                    }
+                    output.WriteLine();
+                }
+            }
+        }
+
         #endregion
 
     }
diff --git a/WPF/View/MainWindow.xaml b/WPF/View/MainWindow.xaml
index 40aaeeb..ae474a9 100644
--- a/WPF/View/MainWindow.xaml
+++ b/WPF/View/MainWindow.xaml
@@ -19,8 +19,8 @@
         AllowsTransparency="True"
         Loaded="Window_Loaded"
         Title="{Binding TitleText}" 
-        Height="235" Width="790"
-        MinHeight="235" MinWidth="790"
+        Height="260" Width="725"
+        MinHeight="260" MinWidth="725"
         BorderBrush="#FF494957"
         BorderThickness="1">
     <Window.Resources>
@@ -174,7 +174,7 @@
 
             <Grid Grid.Row="0" Grid.Column="3" Grid.RowSpan="3">
                 <Grid.ColumnDefinitions>
-                    <ColumnDefinition Width="Auto"/>
+                    <ColumnDefinition MaxWidth="150" Width="Auto"/>
                     <ColumnDefinition Width="Auto"/>
                 </Grid.ColumnDefinitions>
                 <Grid.RowDefinitions>
@@ -182,7 +182,7 @@
                     <RowDefinition Height="Auto"/>
                 </Grid.RowDefinitions>
 
-                <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding TheoremOKText}" Margin="2" Style="{StaticResource WhiteCaptionTextStyle}" ToolTipService.InitialShowDelay="1000">
+                <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding TheoremOKText}" HorizontalAlignment="Left" TextWrapping="WrapWithOverflow" MaxWidth="150" Margin="5,2,2,2" Style="{StaticResource WhiteCaptionTextStyle}" ToolTipService.InitialShowDelay="1000">
                     <TextBlock.ToolTip>
                         <TextBlock Text="{Binding TheoremOKTooltip}" Foreground="GhostWhite" Margin="1"/>
                     </TextBlock.ToolTip>
@@ -212,12 +212,12 @@
                     </Rectangle.Style>
                 </Rectangle>
 
-                <TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding AutomorphismText}" Margin="2" Style="{StaticResource WhiteCaptionTextStyle}" ToolTipService.InitialShowDelay="1000">
+                <TextBlock Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Text="{Binding AutomorphismText}" TextWrapping="WrapWithOverflow" MaxWidth="150" Margin="5,2,2,2" Style="{StaticResource WhiteCaptionTextStyle}" ToolTipService.InitialShowDelay="1000">
                     <TextBlock.ToolTip>
                         <TextBlock Text="{Binding AutomorphismTooltip}" Foreground="GhostWhite" Margin="1"/>
                     </TextBlock.ToolTip>
                 </TextBlock>
-                <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding AutomorphismCount}" Margin="5 0" VerticalAlignment="Bottom" TextAlignment="Center" FontWeight="Bold" FontSize="18" Foreground="{StaticResource Yellow}" MinWidth="100"/>
+                <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding AutomorphismCount}" Margin="5 0" TextAlignment="Center" FontWeight="Bold" FontSize="18" Foreground="{StaticResource Yellow}"/>
 
             </Grid>
 
diff --git a/WPF/ViewModel/MainViewModel.cs b/WPF/ViewModel/MainViewModel.cs
index 1d3f37e..f47f13b 100644
--- a/WPF/ViewModel/MainViewModel.cs
+++ b/WPF/ViewModel/MainViewModel.cs
@@ -31,6 +31,7 @@ namespace WPF.ViewModel
             SelectedTheorem = EnumTheorems.First();
             EdgesNum = 1;
             SameVertNum = 1;
+            KoeffForMinSameVert = 1;
             PathToSave = DefaultPathToSave;
 
             CalculateCommand = new RelayCommand(OnCalculate);
@@ -52,12 +53,12 @@ namespace WPF.ViewModel
             //Verticies[4].Value = 2;
             //Verticies[5].Value = 7;
             EdgesNum = 4;
-            SameVertNum = 1;
-            Verticies[0].Value = 4;
-            Verticies[1].Value = 4;
-            Verticies[2].Value = 4;
-            Verticies[3].Value = 4;
-            SelectedTheorem = EnumTheorem.Fifth;
+            SameVertNum = 2;
+            Verticies[0].Value = 7;
+            Verticies[1].Value = 5;
+            Verticies[2].Value = 6;
+            Verticies[3].Value = 8;
+            SelectedTheorem = EnumTheorem.Forth;
 #endif
         }
 
@@ -80,7 +81,7 @@ namespace WPF.ViewModel
             {
                 _selectedTheorem = value;
                 SetResultDefault();
-                UpdateText();
+                OnSelectedTheoremChange();
                 OnPropertyChanged(() => SelectedTheorem);
             }
 
@@ -136,11 +137,6 @@ namespace WPF.ViewModel
 
         public ObservableCollection<VertViewModel> Verticies { get; }
 
-        public string TitleText { get => "Расчет гиперграфов"; }
-
-        public string EdgesText { get => "Количество ребер"; }
-        public string EdgesTextTooltip { get => "Подсказка. Количество ребер"; }
-
         private string _sameVertText;
         public string SameVertText 
         { 
@@ -162,14 +158,19 @@ namespace WPF.ViewModel
             }
         }
 
+        public string TitleText { get => "Расчет гиперграфов"; }
+
+        public string EdgesText { get => "Количество ребер"; }
+        public string EdgesTextTooltip { get => "Подсказка. Количество ребер"; }
+
         public string VerticiesText { get => "Номер ребра"; }
         public string VerticiesTextTooltip { get => "Подсказка. Номер ребра"; }
 
         public string VerticiesValueText { get => "Число вершин"; }
         public string VerticiesValueTooltip { get => "Подсказка. Число вершин в каждом ребре"; }
 
-        public string TheoremOKText { get => "Удовлетворяет теореме"; }
-        public string TheoremOKTooltip { get => "Подсказка. Удовлетворяет теореме"; }
+        public string TheoremOKText { get => "Удовлетворяет условиям теоремы"; }
+        public string TheoremOKTooltip { get => "Подсказка. Удовлетворяет условиям теоремы"; }
 
         public string AutomorphismText { get => "Число автоморфизмов"; }
         public string AutomorphismTooltip { get => "Подсказка. Число автоморфизмов"; }
@@ -231,6 +232,18 @@ namespace WPF.ViewModel
             }
         }
 
+        private int _koeffForMinSameVert;
+        public int KoeffForMinSameVert
+        {
+            get => _koeffForMinSameVert;
+            set
+            {
+                _koeffForMinSameVert = value >= 1 ? value : 1;
+                UpdateVerticiesValue();
+                OnPropertyChanged(() => KoeffForMinSameVert);
+            }
+        }
+
         #endregion
 
         #region Методы и команды
@@ -241,7 +254,7 @@ namespace WPF.ViewModel
             //LoadDataAsync(App.DataFilePath, true);
         }
 
-        private void UpdateText()
+        private void OnSelectedTheoremChange()
         {
             switch(SelectedTheorem)
             {
@@ -249,14 +262,23 @@ namespace WPF.ViewModel
                 case EnumTheorem.Third:
                     {
                         CanSave = true;
+                        KoeffForMinSameVert = 1;
                         SameVertText = "Количество общих вершин";
                         SameVertTextTooltip = "Подсказка. Количество общих вершин";
                         break;
-                    }
+                    }  
                 case EnumTheorem.Forth:
+                    {
+                        CanSave = true;
+                        KoeffForMinSameVert = 2;
+                        SameVertText = "Количество пересекающихся вершин";
+                        SameVertTextTooltip = "Подсказка. Количество вершин, являющихся общими между соседними ребрами";
+                        break;
+                    }
                 case EnumTheorem.Fifth:
                     {
                         CanSave = false;
+                        KoeffForMinSameVert = 2;
                         SameVertText = "Количество пересекающихся вершин";
                         SameVertTextTooltip = "Подсказка. Количество вершин, являющихся общими между соседними ребрами";
                         break;
@@ -287,7 +309,7 @@ namespace WPF.ViewModel
             {
                 if (vert.Value < SameVertNum)
                     vert.Value = SameVertNum;
-                vert.MinValue = SameVertNum;
+                vert.MinValue = SameVertNum * KoeffForMinSameVert;
             }
         }