Example #1
0
        public void Search_must_work()
        {
            string         path  = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "TestFiles", "TestGraph.txt");
            Graph <string> graph = GraphGenerator.LoadFromFile(path, isDirected: true);

            List <List <Vertex <string> > > stronglyConnectedComponents = StronglyConnectedComponents <string> .Search(graph);

            Assert.AreEqual(2, stronglyConnectedComponents.Count);
            Assert.AreEqual(4, stronglyConnectedComponents[0].Count);
            Assert.AreEqual(1, stronglyConnectedComponents[1].Count);
        }
Example #2
0
        /// <summary>
        /// Lädt einen Graphen aus der angegebenen Datei und berechnet für diesen die strongly connected components
        /// </summary>
        /// <param name="fileName"></param>
        public static void CallStrongConnect(string fileName)
        {
            Graph <string> graph = ApplicationHelper.LoadGraph(fileName, true);

            List <List <Vertex <string> > > components = StronglyConnectedComponents <string> .Search(graph);

            // Das Ergebnis in eine Datei schreiben.
            string baseFileName = fileName.Split('.')[0];

            ApplicationHelper.WriteResult(
                baseFileName,
                "strongConnectResult_",
                "",
                components.Select(
                    (list) => "Component " + components.IndexOf(list) + ":" + Environment.NewLine + list.Select((edge) => edge.ToString()).Aggregate((a, b) => a + Environment.NewLine + b)))
            ;
        }