Пример #1
0
        /// <summary>
        /// Method that find count of hamiltonian graphs
        /// and count of Ore graphs, Posha graphs and Chvatal graphs
        /// </summary>
        public static void GetConditionsStatistics()
        {
            try
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                using (StreamWriter sw = new StreamWriter(@"D:\Shared Folder\conditions_statistics.txt"))
                {
                    for (int i = 3; i <= 11; i++)
                    {
                        int ore_true      = 0;
                        int ore_false     = 0;
                        int posha_true    = 0;
                        int posha_false   = 0;
                        int chvatal_true  = 0;
                        int chvatal_false = 0;

                        int hamiltonian_graph = 0;

                        using (StreamReader sr = new StreamReader(@"D:\Shared Folder\Generated G6\graphs" + i + ".g6"))
                        {
                            string s;
                            while ((s = sr.ReadLine()) != null)
                            {
                                int[,] matrix = Helper.DecodeGraph6(s);
                                List <int> vector = GetVector(matrix);

                                if (HamiltonianGraphsHelper.IsHamiltonianGraph(matrix))
                                {
                                    hamiltonian_graph++;
                                }

                                if (HamiltonianGraphsHelper.OreCondition(matrix))
                                {
                                    ore_true++;
                                }
                                else
                                {
                                    ore_false++;
                                }

                                if (HamiltonianGraphsHelper.PoshaCondition(vector))
                                {
                                    posha_true++;
                                }
                                else
                                {
                                    posha_false++;
                                }

                                if (HamiltonianGraphsHelper.ChvatalCondition(vector))
                                {
                                    chvatal_true++;
                                }
                                else
                                {
                                    chvatal_false++;
                                }
                            }
                        }

                        sw.WriteLine("Количество {0}-вершинных гамильтоновых графов равно = {1}.", i, hamiltonian_graph);
                        sw.WriteLine("Количество {0}-вершинных графов, удовлетворяющих условию Оре, равно = {1}.", i, ore_true);
                        sw.WriteLine("Количество {0}-вершинных графов, не удовлетворяющих условию Оре, равно = {1}.\n", i, ore_false);

                        sw.WriteLine("Количество {0}-вершинных графов, удовлетворяющих условию Поша, равно = {1}.", i, posha_true);
                        sw.WriteLine("Количество {0}-вершинных графов, не удовлетворяющих условию Поша, равно = {1}.\n", i, posha_false);

                        sw.WriteLine("Количество {0}-вершинных графов, удовлетворяющих условию Хватала, равно = {1}.", i, chvatal_true);
                        sw.WriteLine("Количество {0}-вершинных графов, не удовлетворяющих условию Хватала, равно = {1}.\n", i, chvatal_false);
                    }

                    stopWatch.Stop();

                    TimeSpan ts          = stopWatch.Elapsed;
                    string   elapsedTime = String.Format("{0:00} дней {1:00} час {2:00} минут {3:00}.{4:00} секунд",
                                                         ts.Days, ts.Hours, ts.Minutes, ts.Seconds,
                                                         ts.Milliseconds / 10);
                    sw.WriteLine("\nЗатраченное время: " + elapsedTime);
                }
            }
            catch (Exception e)
            {
                Console.Write("Файл не может быть открыт: ");
                Console.WriteLine(e.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// Method that find all degrees vectors, that
        /// all connected implementations are hamiltonian
        /// </summary>
        public static void GetAllHamiltonianVectors()
        {
            try
            {
                List <string> all_gamiltonian_vectors = new List <string>();
                List <string> not_gamiltonian         = new List <string>();

                for (int i = 3; i <= 11; i++)
                {
                    using (StreamReader sr = new StreamReader(@"D:\Shared Folder\Generated G6\graphs" + i + ".g6"))
                    {
                        string s;
                        while ((s = sr.ReadLine()) != null)
                        {
                            int[,] matrix = Helper.DecodeGraph6(s);
                            string vector = Helper.GetStringVector(GetVector(matrix));

                            if (HamiltonianGraphsHelper.IsHamiltonianGraph(matrix) && !all_gamiltonian_vectors.Contains(vector) &&
                                !not_gamiltonian.Contains(vector))
                            {
                                all_gamiltonian_vectors.Add(vector);
                            }

                            if (!HamiltonianGraphsHelper.IsHamiltonianGraph(matrix) && !not_gamiltonian.Contains(vector))
                            {
                                not_gamiltonian.Add(vector);
                            }
                        }
                    }
                }

                foreach (string vector in not_gamiltonian)
                {
                    if (all_gamiltonian_vectors.Contains(vector))
                    {
                        all_gamiltonian_vectors.Remove(vector);
                    }
                }

                Console.WriteLine("Количество векторов степеней, все реализации которых гамильтоновы: " + all_gamiltonian_vectors.Count);

                List <List <int> > gamiltonesVectors = new List <List <int> >();
                foreach (string v in all_gamiltonian_vectors)
                {
                    List <int> vector = v.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(Int32.Parse).ToList();
                    gamiltonesVectors.Add(vector);
                }

                gamiltonesVectors.Sort(Helper.CompareListByCount);
                using (StreamWriter sw = new StreamWriter(@"D:\Shared Folder\gamiltones_vectors.txt"))
                {
                    foreach (List <int> s in gamiltonesVectors)
                    {
                        string vec = Helper.GetStringVector(s);
                        sw.WriteLine(vec);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write("Файл не может быть открыт: ");
                Console.WriteLine(e.Message);
            }
        }