Ejemplo n.º 1
0
        private void runCasa()
        {
            UpperTriangleMatrix edgeMatrix   = graph.getConnections();
            List <Point>        edgesToDraw  = edgeMatrix.getValues();
            List <Point>        enabledEdges = edgeMatrix.getEnabledValues();


            for (int i = 0; i < enabledEdges.Count; i++)
            {
                if (minPoints.Contains(new Point(enabledEdges[i].X, enabledEdges[i].Y)) || minPoints.Contains(new Point(enabledEdges[i].Y, enabledEdges[i].X)))
                {
                    findNextArb(enabledEdges, minPoints);
                }
            }

            refreshGraphics();
        }
Ejemplo n.º 2
0
        private void refreshGraphics()
        {
            List <Point> vertexToDraw = new List <Point>();

            vertexToDraw = graph.getVertices();
            UpperTriangleMatrix edgeMatrix = graph.getConnections();

            for (int i = 0; i < vertexToDraw.Count; i++)
            {
                if (i == graph.startIndex)
                {
                    vertexPen.Color = Color.Green;
                }
                else if (i == graph.destIndex)
                {
                    vertexPen.Color = Color.Orange;
                }
                else
                {
                    vertexPen.Color = Color.Black;
                }

                Font       drawFont  = new Font("Arial", 12);
                SolidBrush drawBrush = new SolidBrush(Color.DarkOrange);

                graphics.DrawEllipse(vertexPen, vertexToDraw[i].X - 5, vertexToDraw[i].Y - 5, 10, 10);
                graphics.DrawString(i.ToString(), drawFont, drawBrush, new PointF(vertexToDraw[i].X - 5, vertexToDraw[i].Y + 5));
            }

            List <Point> edgesToDraw  = edgeMatrix.getValues();
            List <Point> enabledEdges = edgeMatrix.getEnabledValues();

            if (isCasaActive)
            {
                for (int i = 0; i < graph.Vertices.Count; i++)
                {
                    Point firstPoint = graph.Vertices[i];

                    for (int j = 0; j < graph.adjList[i].Count; j++)
                    {
                        Point secondPoint = graph.Vertices[graph.adjList[i][j]];
                        //Console.WriteLine(i + "-től fut él " + graph.adjList[i][j] + "-be");
                        DrawArrow(firstPoint, secondPoint);
                    }
                }
            }
            else
            {
                foreach (var e in edgesToDraw)
                {
                    Point firstPoint  = vertexToDraw[e.X];
                    Point secondPoint = vertexToDraw[e.Y];

                    graphics.DrawLine(edgePen, firstPoint, secondPoint);

                    for (int i = 0; i < casaDefaultPath.Count - 1; i++)
                    {
                        edgePen.Color = Color.BlueViolet;
                        graphics.DrawLine(edgePen, casaDefaultPath[i], casaDefaultPath[i + 1]);
                    }

                    for (int i = 0; i < graph.shortestPathToColor.Count - 1; i++)
                    {
                        edgePen.Color = Color.Orange;
                        graphics.DrawLine(edgePen, graph.shortestPathToColor[i], graph.shortestPathToColor[i + 1]);
                    }
                    edgePen.Color = Color.Black;

                    if (firstDijkstra)
                    {
                        graph.Dijkstra();
                        needrefreshDijkstra = true;
                    }
                }
            }
            try
            {
                foreach (var e in enabledEdges)
                {
                    edgePen.Color = Color.Red;
                    if (squareOneCheckBox.Checked)
                    {
                        needrefreshDijkstra = true;
                    }
                    else if (CasaCheckBox.Checked)
                    {
                        needrefreshCASA = true;
                    }
                    graphics.DrawLine(edgePen, vertexToDraw[e.X], vertexToDraw[e.Y]);
                }
                edgePen.Color = Color.Black;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Nincs törlendő él!");
            }
        }