Exemple #1
0
        public void OnFindPathAlgorithmCall(
            IPresenterConnectedDialog dialog,
            int first,
            int second,
            bool dijkstra,
            bool bellmanFord,
            bool floyd)
        {
            string strPath;

            if (dijkstra)
            {
                strPath = EvaluateDijkstra(first, second);
            }
            else if (bellmanFord)
            {
                strPath = EvaluateBellmanFord(first, second);
            }
            else if (floyd)
            {
                strPath = EvaluateFloyd(first, second);
            }
            else
            {
                strPath = "Algorithm not specified error";
            }

            dialog.SetData(strPath);
        }
Exemple #2
0
        public void OnTotalSstCall(IPresenterConnectedDialog dialog)
        {
            int    total    = MinimumSpanningTree.TotalStAmount(_graphMatrix);
            string totalStr = total > 0 ? total.ToString() : $"More than {Int32.MaxValue}";

            _view.AppendToLog($"{_logEntryNumber++}: Kirchhoff's total amount of spanning trees:" +
                              Environment.NewLine +
                              $"Total amount: {totalStr}" +
                              Environment.NewLine + Environment.NewLine);
        }
Exemple #3
0
        public void OnCheckPathAlgorithmCall(IPresenterConnectedDialog dialog, int first, int second)
        {
            bool   result = PathExistenceChecker.CheckPathExistence(_graphMatrix.GetAdjacencyMatrix(), first, second);
            string data   = $"Path between {first} and {second} " + (result ? "exists" : "doesn't exist");

            _view.AppendToLog($"{_logEntryNumber++}: Check path:" +
                              Environment.NewLine +
                              data +
                              Environment.NewLine + Environment.NewLine);
            dialog.SetData(data);
        }
Exemple #4
0
        public void OnShimbelAlgorithmCall(IPresenterConnectedDialog dialog, int edgesAmount, bool shortestPaths)
        {
            var matrix = ShimbelAlgorithm.FindPaths(_graphMatrix, edgesAmount, shortestPaths);

            string matrixStr = MatrixPrinter.GetMatrix(matrix);

            _view.AppendToLog($"{_logEntryNumber++}: Shimbel's Algorithm for " +
                              (shortestPaths ? "shortest" : "longest") +
                              $" paths ({edgesAmount} edges):" +
                              Environment.NewLine +
                              matrixStr + Environment.NewLine);

            dialog.SetData(matrixStr);
        }
Exemple #5
0
        public void OnKruskalAlgorithmCall(IPresenterConnectedDialog dialog)
        {
            (var tree, int iter) = MinimumSpanningTree.Kruskal(_graphMatrix);
            var builder = new StringBuilder();

            _sstGenerated = true;
            int weight = 0;

            if (tree.Count > 0)
            {
                for (int i = 0; i < tree.Count; ++i)
                {
                    builder.AppendLine((tree[i].Item1 + 1) + " <-> " + (tree[i].Item2 + 1));
                    weight += _graphMatrix.GetWeightMatrix()[
                        Math.Min(tree[i].Item1, tree[i].Item2),
                        Math.Max(tree[i].Item1, tree[i].Item2)];
                }
            }
            else
            {
                builder.Append("SST not found");
                _sstGenerated = false;
            }

            _view.AppendToLog($"{_logEntryNumber++}: Kruskal's Algorithm:" +
                              Environment.NewLine +
                              builder.ToString() +
                              $"Weight: {weight}" +
                              Environment.NewLine +
                              $"Iterations: {iter}" +
                              Environment.NewLine + Environment.NewLine);

            dialog.SetData("Built SST");
            _graphMatrix.OutputToFileWithKruskal();
            UpdateViewGraphImage();
        }