private void mnRunVisualization_Click(object sender, EventArgs e) { if (Runtime.currentAlgorithm == null) { Log.Write("Can't determine selected algorithm."); return; } if (Runtime.currentGraph == null) { Log.Write("Please, load graph first."); return; } if (Runtime.currentAlgorithm.Instance is BaseMaxFlowAlgorithm) { //Clone selected algorithm. Won't write algorithm reset method BaseMaxFlowAlgorithm algorithm = Runtime.currentAlgorithm.Instance.Clone(); Animator algorithmAnimator = new Animator(); algorithmAnimator.OnAnimationTick += Visualizer.GetAnimation; algorithmAnimator.OnAnimationStarted += animator => { mnStopAnimation.Visible = true; }; algorithmAnimator.OnAnimationFinished += animator => { mnStopAnimation.Visible = false; OnAlgorithmFinished(algorithm); }; algorithmAnimator.Run(); //Subscribe for events for visualization needs algorithm.OnEdgeFlowChanged += algorithmAnimator.EdgeFlowChanged; algorithm.OnEdgeMarked += algorithmAnimator.EdgeMarked; algorithm.OnEdgeUnmarked += algorithmAnimator.EdgeUnmarked; algorithm.OnFinish += flowAlgorithm => { algorithmAnimator.AlgorithmFinished = true; }; algorithm.SetGraph(Runtime.currentGraph); algorithm.RunAsync(); } }
private void runWithoutVisualizationToolStripMenuItem_Click(object sender, EventArgs e) { if (Runtime.currentAlgorithm == null) { Log.Write("Can't determine selected algorithm."); return; } if (Runtime.currentGraph == null) { Log.Write("Please, load graph first."); return; } if (Runtime.currentAlgorithm.Instance is BaseMaxFlowAlgorithm) { BaseMaxFlowAlgorithm algorithm = Runtime.currentAlgorithm.Instance.Clone(); algorithm.OnFinish += OnAlgorithmFinished; algorithm.SetGraph(Runtime.currentGraph); algorithm.RunAsync(); } }