Ejemplo n.º 1
0
        public void ApplyAlgorithm(string algName, Vertex selectedVertex)
        {
            if (requires2Nodes.Contains(algName) && startVertex == null)
            {
                MainWindow.MessageTextBlock.Text = "Please choose the second node!";
                startVertex = selectedVertex;
                startVertex.Body.Background=new SolidColorBrush(Colors.Red);
                return;
            }

            alg = null;

            switch (algName)
            {
                case "BFS":
                    alg = new BFS(Colors.Cyan, Colors.DarkCyan, Colors.LightCyan);
                    break;
                case "DFS":
                    alg = new DFS(Colors.Blue, Colors.Aqua);
                    break;
                case "Post-order":
                    alg = new PostOrder(Colors.Blue, Colors.DodgerBlue, Colors.Aqua);
                    break;
                case "Dijkstra":
                    alg = new Dijkstra(Colors.DarkViolet, Colors.Red, Colors.Gold, Colors.Violet);
                    break;
                case "Bellman-Ford":
                    alg = new BellmanFord(Colors.Firebrick, Colors.Magenta, Colors.OrangeRed);
                    break;
                case "Isolate":
                    alg = new Isolate();
                    break;
                case "A-path-B":
                    alg = new ApathB(startVertex);
                    break;
                case "Prim":
                    alg = new Prim(Colors.DarkGray, Colors.Sienna, Colors.Gold, Colors.ForestGreen);
                    break;
                case "Reposition":
                    alg=new Reposition();
                    break;
            }

            if (alg == null) return;
            MainWindow.ApplicationState = States.AnimationRunning;
            alg.Execute(selectedVertex);
        }
Ejemplo n.º 2
0
        public void ApplyAlgorithm(string algName)
        {
            if (MainWindow.VertexHandler.Verticies.Count == 0)
            {
                MainWindow.MessageTextBlock.Text = "Graph is missing!";
                return;
            }

            startVertex = null;
            if (!MainWindow.EdgeHandler.EdgesAreWeighted)
                if (requiresWeight.Contains(algName))
                {
                    MainWindow.MessageTextBlock.Text = "Graph shall be weighted!";
                    return;
                }
            if (MainWindow.EdgeHandler.EdgesAreDirected)
                if (requiresUndirected.Contains(algName))
                {
                    MainWindow.MessageTextBlock.Text = "Graph shall be undirected!";
                    return;
                }
            if (requiresNode.Contains(algName))
            {
                MainWindow.ApplicationState = States.WaitingForNodeSelection;
                MainWindow.MessageTextBlock.Text = "Please choose a node!";
                return;
            }

            alg = null;

            switch (algName)
            {
                case "Bipartization":
                    alg = new Bipartitzation(Colors.DarkOrange, Colors.DarkOrchid, Colors.Aqua);
                    break;
                case "Do MaxHeap":
                    alg=new DoMaxHeap();
                    break;
                case "Do MinHeap":
                    alg = new DoMinHeap();
                    break;
                case "Complete":
                    alg = new Complete();
                    break;
                case "Connectivity":
                    alg = new Connectivity();
                    break;
                case "S Connectivity" :
                    alg = new SConnectivity();
                    break;
                case "Floyd-Warshall":
                    alg = new FloydWarshall();
                    break;
                case "Kruskal":
                    alg = new Kruskal(Colors.Sienna, Colors.DarkGray, Colors.Red);
                    break;
            }

            if (alg == null) return;
            MainWindow.ApplicationState=States.AnimationRunning;
            alg.Execute();
        }