Example #1
0
        private void SaveGraph(object sender, RoutedEventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.FileName         = "Graph";
            dlg.DefaultExt       = ".matrix";
            dlg.Filter           = "Matrix|*.matrix|List|*.list|Incidency|*.inc";
            dlg.InitialDirectory = SaveLoadWindowHelper.LoadCurrentDialogDirectory();

            bool?result = dlg.ShowDialog();

            if (result == true)
            {
                if (dlg.FileName.ToLower().EndsWith("matrix"))
                {
                    GraphLoad.SaveMatrix(Graph, dlg.FileName);
                }

                else if (dlg.FileName.ToLower().EndsWith("list"))
                {
                    GraphLoad.SaveList(Converter.ConvertToList(Graph), dlg.FileName);
                }

                else if (dlg.FileName.ToLower().EndsWith("inc"))
                {
                    GraphLoad.SaveMatrixInc(Converter.ConvertToMatrixInc(Graph), dlg.FileName);
                }
                SaveLoadWindowHelper.SaveCurrentDialogDirectory(System.IO.Path.GetDirectoryName(dlg.FileName));
            }
            else
            {
                SaveLoadWindowHelper.SaveCurrentDialogDirectory(dlg.InitialDirectory);
            }
        }
Example #2
0
        public void TestHamilton()
        {
            var projectPath = Directory
                              .GetParent(Environment.CurrentDirectory)
                              .Parent
                              .FullName;

            var HamiltonTrueDirectory  = Path.Combine(projectPath, "Graphs", "Hamilton", "True");
            var HamiltonFalseDirectory = Path.Combine(projectPath, "Graphs", "Hamilton", "False");

            var TrueGraphs  = Directory.GetFiles(HamiltonTrueDirectory);
            var FalseGraphs = Directory.GetFiles(HamiltonFalseDirectory);

            foreach (var graph in TrueGraphs)
            {
                var Graph = GraphLoad.LoadMatrix(graph);
                Assert.IsTrue(Hamilton.IsHamilton(Graph), graph);
            }

            foreach (var graph in FalseGraphs)
            {
                var Graph = GraphLoad.LoadMatrix(graph);
                Assert.IsFalse(Hamilton.IsHamilton(Graph), graph);
            }
        }
Example #3
0
        public void TestIncIO()
        {
            createAppdataFolder();
            var file = Path.Combine(AppDataDirectory, "tests\\test.inc");

            Random rand = new Random();

            for (int i = 0; i < 25; ++i)
            {
                GraphMatrix    matrix = GraphGenerator.generatorGnp(10 + rand.Next(100), 0.5);
                GraphMatrixInc inc    = Converter.ConvertToMatrixInc(matrix);
                GraphLoad.SaveMatrixInc(inc, file);
                GraphMatrixInc second = GraphLoad.LoadMatrixInc(file);
                Assert.IsTrue(inc.Equals(second));
            }
        }
Example #4
0
        public void TestListIO()
        {
            createAppdataFolder();
            var file = Path.Combine(AppDataDirectory, "tests\\test.list");

            Random rand = new Random();

            for (int i = 0; i < 25; ++i)
            {
                GraphMatrix matrix = GraphGenerator.generatorGnp(2 + rand.Next(i), 0.5);
                GraphList   list   = Converter.ConvertToList(matrix);
                GraphLoad.SaveList(list, file);
                GraphList second = GraphLoad.LoadList(file);
                Assert.IsTrue(list.Equals(second));
            }
        }
Example #5
0
        public void TestMatrixIO()
        {
            createAppdataFolder();
            var file = Path.Combine(AppDataDirectory, "tests\\test.matrix");



            Random rand = new Random();

            for (int i = 0; i < 25; ++i)
            {
                GraphMatrix matrix = GraphGenerator.generatorGnp(1000 + rand.Next(1000), 0.5);
                GraphLoad.SaveMatrix(matrix, file);
                GraphMatrix second = GraphLoad.LoadMatrix(file);
                Assert.IsTrue(matrix.Equals(second));
            }
        }
Example #6
0
        private void LoadGraph(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.DefaultExt       = ".matrix";
            dlg.Filter           = "Matrix|*.matrix|List|*.list|Incidency|*.inc";
            dlg.InitialDirectory = SaveLoadWindowHelper.LoadCurrentDialogDirectory();

            bool?result = dlg.ShowDialog();

            if (result == true)
            {
                if (dlg.FileName.ToLower().EndsWith("matrix"))
                {
                    Graph.Set(GraphLoad.LoadMatrix(dlg.FileName));
                }

                else if (dlg.FileName.ToLower().EndsWith("list"))
                {
                    Graph.Set(
                        Converter.ConvertToMatrix(GraphLoad.LoadList(dlg.FileName))
                        );
                }

                else if (dlg.FileName.ToLower().EndsWith("inc"))
                {
                    Graph.Set(
                        Converter.ConvertToMatrix(GraphLoad.LoadMatrixInc(dlg.FileName))
                        );
                }

                SaveLoadWindowHelper.SaveCurrentDialogDirectory(System.IO.Path.GetDirectoryName(dlg.FileName));
            }
            else
            {
                SaveLoadWindowHelper.SaveCurrentDialogDirectory(dlg.InitialDirectory);
            }
            Graph.OnChange();
            GraphRenderer.Displayer = new CircleDisplayer();
        }