Esempio n. 1
0
        public static DirectedGraph ReadFromTxtFile(string fileName)
        {
            StreamReader inputFile = new StreamReader(fileName);
            string fileContent = inputFile.ReadToEnd();

            string[] inputData = fileContent.Split(new string[] { " ", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            var result = new DirectedGraph(int.Parse(inputData[0]));

            int edgesCount = int.Parse(inputData[1]);
            for (int i = 0; i < edgesCount; ++i)
            {
                DirectedEdge edge = new DirectedEdge(int.Parse(inputData[i * 2 + 2]) - 1, int.Parse(inputData[i * 2 + 3]) - 1);
                result[edge.Begin].Add(edge);
            }

            return result;
        }
Esempio n. 2
0
        public static DirectedGraph ReadFromConsole()
        {
            AllocConsole();

            Console.Write("Enter a number of vertices, please: ");
            int verticesCount = int.Parse(Console.ReadLine());
            DirectedGraph result = new DirectedGraph(verticesCount);

            Console.Write("Enter a number of edges, please: ");
            int edgesCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < edgesCount; ++i)
            {
                Console.Write("Enter begin and end of {0} edge, please: ", i + 1);
                string[] inputData = Console.ReadLine().Split(new string[]{" "}, StringSplitOptions.RemoveEmptyEntries);

                DirectedEdge edge = new DirectedEdge(int.Parse(inputData[0]) - 1, int.Parse(inputData[1]) - 1);
                result[edge.Begin].Add(edge);
            }

            FreeConsole();
            return result;
        }
Esempio n. 3
0
 public DirectedEdge(DirectedEdge edge)
 {
     Begin = edge.Begin;
     End = edge.End;
 }
Esempio n. 4
0
 public void AddEdge(DirectedEdge edge)
 {
     Graph[edge.Begin].Add(edge);
     ++EdgesCount;
 }
Esempio n. 5
0
        private void DrawVector2D(DirectedEdge edge)
        {
            Vector2DInfo vectorInfo = new Vector2DInfo(new Point(VertexCoords[edge.Begin].X, VertexCoords[edge.Begin].Y),
                                                       new Point(VertexCoords[edge.End].X, VertexCoords[edge.End].Y));

            Gl.glBegin(Gl.GL_LINES);
            Gl.glVertex2d(vectorInfo.Begin.X, vectorInfo.Begin.Y);
            Gl.glVertex2d(vectorInfo.End.X, vectorInfo.End.Y);

            Gl.glVertex2d(vectorInfo.End.X, vectorInfo.End.Y);
            Gl.glVertex2d(vectorInfo.End.X + vectorInfo.LeftArrowPoint.X,
                          vectorInfo.End.Y + vectorInfo.LeftArrowPoint.Y);

            Gl.glVertex2d(vectorInfo.End.X, vectorInfo.End.Y);
            Gl.glVertex2d(vectorInfo.End.X + vectorInfo.RightArrowPoint.X,
                          vectorInfo.End.Y + vectorInfo.RightArrowPoint.Y);
            Gl.glEnd();
        }
Esempio n. 6
0
 public void AddEdge(DirectedEdge edge)
 {
     Graph[edge.Begin].Add(edge);
     ++EdgesCount;
 }
Esempio n. 7
0
 public DirectedEdge(DirectedEdge edge)
 {
     Begin = edge.Begin;
     End   = edge.End;
 }