Exemple #1
0
        public void CheckAllFilesWithBaseAlgorithm()
        {
            IEnumerable <string> files = Directory.EnumerateFiles(
                PathToSources, "*.graph", SearchOption.AllDirectories);

            Assert.AreNotEqual(files.Count(), 0, "There are no test files");
            Dictionary <Exception, string> exceptions = new Dictionary <Exception, string>();

            foreach (var file in files)
            {
                long[]  xadj;
                int[]   adjncy;
                int[][] graphNumeration;
                Loader.LoadGraphFromMETISFormat(file, out xadj, out adjncy);
                bool valid    = MeshRecovery.Validate(xadj, xadj.Length, adjncy, out int meshDimension);
                int  numerate = MeshRecovery.Numerate(xadj, xadj.Length, adjncy, out graphNumeration);

                bool isGood = valid && numerate == 0;

                if (isGood)
                {
                    try
                    {
                        int errCode = NumerationHelper.ValidateNumeration(xadj, adjncy, meshDimension, graphNumeration);
                        Assert.IsTrue(errCode >= 0,
                                      $"ValidateNumeartion returns {errCode} for numeration {GraphNumerationToString(graphNumeration)}");
                    }
                    catch (Exception e)
                    {
                        exceptions.Add(e, Path.GetFileName(file));
                    }
                }

                DirectoryInfo dirInfo = new DirectoryInfo(Path.GetDirectoryName(file));
                if (dirInfo.Name == GoodFolder)
                {
                    Assert.IsTrue(isGood);
                }
                else if (dirInfo.Name == BadFolder)
                {
                    Assert.IsFalse(isGood);
                }
                else
                {
                    Assert.Fail("Should be good and bad files only");
                }
            }

            if (exceptions.Count > 0)
            {
                string output = "List of exceptions: ";
                foreach (var e in exceptions)
                {
                    output += Environment.NewLine + "There is problem with file: " + e.Value + ". The reason: " + e.Key.Message + "|";
                }
                Assert.Fail(output);
            }
        }
Exemple #2
0
        public void ConnectTest()
        {
            long[] xadj   = { 0, 2, 5, 8, 11, 13, 16, 18 };
            int[]  adjncy = { 1, 3,
                              0,  2, 6,
                              1,  3, 5,
                              0,  2, 4,
                              3,  5,
                              2,  4, 6,
                              1, 5 };
            Graph  graph = new Graph(xadj, adjncy);

            Assert.IsTrue(MeshRecovery.Validate(xadj, 8, adjncy, out int dim));
        }
        static void PrintResultInRT()
        {
            List <string> files = GetAllTestFiles();

            if (files.Count == 0)
            {
                return;
            }
            files.Sort(Comparer <string> .Create((y, x) => x.Split('\\').Last <string>().Length - y.Split('\\').Last <string>().Length));
            string       new_file_name = PathToResults + "/" + GenerateNewName() + result_type;
            StreamWriter result        = new StreamWriter(new_file_name);

            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            PrepareResultsHead(result, files.ToArray());
            for (int i = 0; i < files.Count; ++i)
            {
                string current_file_name = files[i].Split('\\').Last <string>();
                Console.WriteLine("Working on " + current_file_name);
                int     meshDimension = 0;
                long[]  xadj;
                int[]   adjncy;
                bool    valid    = false;
                int     numerate = 0;
                int[][] graphNumeration;
                Loader.LoadGraphFromMETISFormat(files[i], out xadj, out adjncy);
                timer.Start();
                valid    = MeshRecovery.Validate(xadj, xadj.Length, adjncy, out meshDimension);
                numerate = MeshRecovery.Numerate(xadj, xadj.Length, adjncy, out graphNumeration);
                timer.Stop();
                string validationResult = "";
                if (valid && numerate == 0)
                {
                    int validationCode = NumerationHelper.ValidateNumeration(xadj, adjncy, meshDimension, graphNumeration);
                    validationResult = validationCode >= 0 ? "Верно" : "Неверно";
                }
                //TODO: Dinar: check memory usage ?
                //TODO: Dinar: check memory usage ?
                WriteRow(result
                         , current_file_name
                         , valid.ToString()
                         , numerate.ToString()
                         , timer.ElapsedMilliseconds.ToString()
                         , IntArrayToList(graphNumeration)
                         , validationResult);
                timer.Reset();
            }

            result.WriteLine("\tEND OF THE TEST RESULTS");
            result.Close();
        }
Exemple #4
0
        public void CheckWorkTime()
        {
            long[]  xadj;
            int[]   adjncy;
            int[][] graphNumeration;
            Loader.LoadGraphFromMETISFormat(@"tests\big_graphs\grid_150x200.graph", out xadj, out adjncy);
            Stopwatch timer = new Stopwatch();

            timer.Start();
            bool valid = MeshRecovery.Validate(xadj, xadj.Length, adjncy, out int meshDimension);

            timer.Stop();
            Assert.IsTrue(valid, "Test graph is not valid");
            Assert.IsTrue(timer.Elapsed.Seconds <= 5, "Validate takes more than 5 seconds.");
            timer.Reset();
            timer.Start();
            int numerate = MeshRecovery.Numerate(xadj, xadj.Length, adjncy, out graphNumeration);

            timer.Stop();
            Assert.AreEqual(0, numerate, "Test graph can not be numerated");
            Assert.IsTrue(timer.Elapsed.Minutes <= 5, "Numerate takes more than 5 minutes.");
        }
        static void PrintResultInExcel()
        {
            try
            {
                var temp = new Excel.Application();
                //don`t forget closing that test app
                temp.Quit();
            }
            catch
            {
                return;
            }

            var excelApp = new Excel.Application();

            excelApp.Workbooks.Add();
            Excel._Worksheet workSheet = excelApp.ActiveSheet;

            WriteRowExcel(workSheet, 1, head_columns);
            //workSheet.Cells[1, 6] = "Memory";
            string[] files = GetAllTestFiles().ToArray();
            if (files.Length == 0)
            {
                return;
            }

            string new_file_name = GenerateNewName() + excel_type;

            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();

            for (int i = 0; i < files.Length; ++i)
            {
                int     meshDimension = 0;
                long[]  xadj;
                int[]   adjncy;
                bool    valid    = false;
                int     numerate = 0;
                int[][] graphNumeration;
                string  current_file_name = files[i].Split('\\').Last <string>();
                Console.WriteLine("Working on " + current_file_name);
                Loader.LoadGraphFromMETISFormat(files[i], out xadj, out adjncy);
                timer.Start();
                valid    = MeshRecovery.Validate(xadj, xadj.Length, adjncy, out meshDimension);
                numerate = MeshRecovery.Numerate(xadj, xadj.Length, adjncy, out graphNumeration);
                timer.Stop();
                //TODO: Dinar: check memory usage ?
                Graph  graph            = new Graph(xadj, adjncy);
                bool   success          = valid && numerate == 0;
                string validationResult = "";
                if (success)
                {
                    int validationCode = NumerationHelper.ValidateNumeration(xadj, adjncy, meshDimension, graphNumeration);
                    validationResult = validationCode >= 0 ? "Верно" : "Неверно";
                }
                WriteRowExcel(
                    workSheet,
                    i + 2,
                    current_file_name,
                    graph.GetVerticesCount().ToString(),
                    graph.GetEdgeCount().ToString(),
                    valid ? "ИСТИНА" : "ЛОЖЬ",
                    numerate.ToString(),
                    validationResult,
                    success ? graphNumeration[0].Length.ToString() : "X",
                    timer.ElapsedMilliseconds.ToString()
                    );

                timer.Reset();
            }
            for (int i = 0; i < head_columns.Length; ++i)
            {
                workSheet.Columns[i + 1].AutoFit();
            }
            workSheet.Name = "Results";
            workSheet.SaveAs(Environment.CurrentDirectory + "/" + PathToExcelResults + "/" + new_file_name);

            // Make the object visible.
            excelApp.Visible = true;
        }
Exemple #6
0
        static void Main(string[] args)
        {
            string sourceFile = null;
            string outputPath = null;

            ArgParser parser = new ArgParser();

            parser.AddArgument("i|input=", "Path to the graph file", v => sourceFile        = v);
            parser.AddArgument("o|out=", "Path to the output file (.json)", v => outputPath = v);

            if (!parser.ParseArguments(args))
            {
                return;
            }

            if (sourceFile == null)
            {
                Console.WriteLine("Please specify the path to graph file");
                return;
            }
            else if (!File.Exists(sourceFile))
            {
                Console.WriteLine($"File is not exist: {sourceFile}");
                return;
            }

            if (outputPath == null)
            {
                outputPath = Path.Combine(new FileInfo(sourceFile).Directory.FullName,
                                          Path.GetFileNameWithoutExtension(sourceFile) + ".json");
            }
            else if (Path.GetExtension(outputPath) != ".json")
            {
                Console.WriteLine("Output file must have .json extension");
                return;
            }

            long[] xadj   = null;
            int[]  adjncy = null;
            Loader.LoadGraphFromMETISFormat(sourceFile, out xadj, out adjncy);
            Stopwatch timer = new Stopwatch();

            timer.Start();
            int  meshDemention;
            bool validateResult = MeshRecovery.Validate(xadj, xadj.Length, adjncy, out meshDemention);

            timer.Stop();
            Console.WriteLine("Function Validate finished {0}. Elapsed: {1} ms"
                              , validateResult ? "successfully" : "unsuccessfully"
                              , timer.ElapsedMilliseconds);

            if (!validateResult)
            {
                Console.WriteLine("Graph can not be numerated");
                return;
            }

            timer.Reset();
            timer.Start();
            int[][] graphNumeration;
            int     numerateResult = MeshRecovery.Numerate(xadj, xadj.Length, adjncy, out graphNumeration);

            timer.Stop();

            Console.WriteLine("Function Numerate finished {0}. Elapsed: {1} ms"
                              , numerateResult == 0 ? "successfully" : "unsuccessfully"
                              , timer.ElapsedMilliseconds);

            if (numerateResult != 0)
            {
                Console.WriteLine("Graph can not be numerated");
                return;
            }

            //Save graphNumeration to file
            string jsonString = null;

            try
            {
                jsonString = JsonSerializer.SerializeNumeration(graphNumeration);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Can not serialize result: {e.Message}");
                return;
            }

            try
            {
                File.WriteAllText(outputPath, jsonString);
                Console.WriteLine($"Result is saved into file: {outputPath}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Can not save result to {args[1]}: {e.Message}");
            }
        }