Beispiel #1
0
        private static Stack <Vertice> LoadGraph(StreamReader textreader)
        {
            var graph = new DirectedGraphLoader();

            while (!textreader.EndOfStream)
            {
                var array = textreader.ReadLine().Split(' ', '\t').Select(int.Parse).ToArray();;
                array.Check(c => c.Length == 2, c => new InvalidOperationException("invalid array length"));
                var vertice1 = array[0];
                var vertice2 = -array[1];
                graph.AddEdge(vertice1, vertice2);
                var vertice3 = -array[0];
                var vertice4 = array[1];
                graph.AddEdge(vertice4, vertice3);
            }

            //foreach (var trimmedLine in File.ReadAllLines(fileName).Select(line => line.Trim()).Where(trimmedLine => !string.IsNullOrWhiteSpace(trimmedLine)))
            //{
            //    var array = trimmedLine.Split('\t', ' ').Select(int.Parse).ToArray();
            //    array.Check(c => c.Length == 2, c => new InvalidOperationException("invalid array length"));
            //    var vertice1 = array[0];
            //    var vertice2 = -array[1];
            //    graph.AddEdge(vertice1, vertice2);
            //    var vertice3 = -array[0];
            //    var vertice4 = array[1];
            //    graph.AddEdge(vertice3, vertice4);
            //}
            return(graph.GetVertices());
        }
Beispiel #2
0
        private static Stack <Vertice> GetFromFile(string filename)
        {
            var graph = new DirectedGraphLoader();

            foreach (var trimmedLine in File.ReadAllLines(filename).Select(line => line.Trim()).Where(trimmedLine => !string.IsNullOrWhiteSpace(trimmedLine)))
            {
                var array = trimmedLine.Split('\t', ' ').Select(int.Parse).ToArray();
                array.Check(c => c.Length == 2, c => new InvalidOperationException("invalid array length"));
                var vertice1 = array[0];
                var vertice2 = array[1];
                graph.AddEdge(vertice1, vertice2);
            }
            return(graph.GetVertices());
        }