Example #1
0
        public void OnDecodePruferCall(List <int> code)
        {
            var graphMatrix = MinimumSpanningTree.DecodePrufer(code);

            if (_graphMatrix == null)
            {
                _graphMatrix = new GraphMatrix(code.Count + 2, 1, -10, 10);
                _graphMatrix.SetAdjacencyMatrix(graphMatrix);
                _graphMatrix.SetWeightMatrix(graphMatrix);
                _graphMatrix.SetSstMatrix(graphMatrix);
                _graphGenerated       = false;
                _sstGenerated         = true;
                _flowNetworkGenerated = false;
            }
            else
            {
                _graphMatrix.SetSstMatrix(graphMatrix);
            }

            string pruferCode = String.Join(" ", code);

            _view.AppendToLog($"{_logEntryNumber++}: Prufer's Decode:" +
                              Environment.NewLine +
                              "Matrix: " +
                              Environment.NewLine +
                              MatrixPrinter.GetMatrix(graphMatrix) +
                              $"Code: {pruferCode}" +
                              Environment.NewLine + Environment.NewLine);

            _graphMatrix.OutputToFileSst();
            UpdateViewGraphImage();
        }
Example #2
0
        public string OnGetPruferCall()
        {
            var(tree, vertices) = MinimumSpanningTree.GetPruferCode(_graphMatrix);
            for (int i = 0; i < vertices.Count; ++i)
            {
                vertices[i] += 1;
            }

            string code = String.Join(" ", vertices);

            if (code.Equals(""))
            {
                code = "Empty";
            }

            _view.AppendToLog($"{_logEntryNumber++}: Prufer's code:" +
                              Environment.NewLine +
                              "Matrix: " +
                              Environment.NewLine +
                              MatrixPrinter.GetMatrix(tree) +
                              $"Code: {code}" +
                              Environment.NewLine + Environment.NewLine);

            return(code);
        }
Example #3
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);
        }
Example #4
0
        public void OnCreateFlowNetworkCall()
        {
            FlowAlgorithms.TurnIntoFlowNetwork(_graphMatrix);
            _flowNetworkGenerated = true;

            _view.AppendToLog($"{_logEntryNumber++}: Flow Network Generated:" +
                              Environment.NewLine +
                              "Adjacency Matrix: " +
                              Environment.NewLine +
                              MatrixPrinter.GetMatrix(_graphMatrix.GetAdjacencyMatrix()) +
                              "Weight Matrix: " +
                              Environment.NewLine +
                              MatrixPrinter.GetMatrix(_graphMatrix.GetWeightMatrix()) +
                              "Capacities Matrix: " +
                              Environment.NewLine +
                              MatrixPrinter.GetMatrix(_graphMatrix.GetCapacitiesMatrix()) +
                              Environment.NewLine);

            _graphMatrix.OutputToFile();
            UpdateViewGraphImage();
        }
Example #5
0
 public string GetStringWeightMatrix()
 {
     return(MatrixPrinter.GetMatrix(_weightMatrix));
 }
Example #6
0
 public string GetStringAdjacencyMatrix()
 {
     return(MatrixPrinter.GetMatrix(_adjacencyMatrix));
 }