private void btnMinCut_Click(object sender, EventArgs e) { var myGraph = InputControls.getMyGraph(); var matrixOfGraph = MinCut.getMatrixOfGraph(myGraph); string start = myGraph.getStartingPoint(); string end = myGraph.getEndPoint(); int startNum = MinCut.getNodeNum(start); int endNum = MinCut.getNodeNum(end); var pipeList = MinCut.minCut(matrixOfGraph, startNum, endNum); //var pipeList = MinCut.minCut(matrixOfGraph, Int32.Parse(myGraph.getStartingPoint()), // Int32.Parse(myGraph.getEndPoint())); FormGraph formGraph = new FormGraph(pipeList); formGraph.Text = "MinCut"; formGraph.Show(); StringBuilder sb = new StringBuilder("MinCut Edges:\n"); for (int i = 0; i < pipeList.GetLength(0); i++) { sb.Append(MinCut.getNodeName(pipeList[i, 0]) + " - " + MinCut.getNodeName(pipeList[i, 1]) + "\n"); } MessageBox.Show(sb.ToString(), "MinCut Kenarları", MessageBoxButtons.OK, MessageBoxIcon.Information); //var pipeNameArray = new int[pipeList.GetLength(0), pipeList.GetLength(1)]; //for (int i = 0; i < pipeList.GetLength(0); i++) //{ // for (int i = 0; i < length; i++) // { // } // pipeNameArray[i, 0] = MinCut.getNodeName(pipeList[i, 0]); //} }
//Constructor 3 public FormGraph(int[,] pipeArray) { InitializeComponent(); System.Windows.Forms.Form form = new System.Windows.Forms.Form(); Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); myGraph = InputControls.getMyGraph(); var minCutPipes = new List <MyPipe>(); for (int i = 0; i < myGraph.Pipes.Count(); i++) { //if (MinCut.getNodeNum(myGraph.Pipes[i].StartingPoint) == pipeList[i, 0] // && MinCut.getNodeNum(myGraph.Pipes[i].EndPoint) == pipeList[i, 1]) //{ // minCutPipes.Add(myGraph.Pipes[i]); //} for (int k = 0; k < pipeArray.GetLength(0); k++) { if (MinCut.getNodeNum(myGraph.Pipes[i].StartingPoint) == pipeArray[k, 0] && MinCut.getNodeNum(myGraph.Pipes[i].EndPoint) == pipeArray[k, 1]) { minCutPipes.Add(myGraph.Pipes[i]); } } } var nodeList = new List <Node>(); //node ekle foreach (var myNode in myGraph.Nodes) { graph.AddNode(new Node(myNode.Name)); } //edge ekle foreach (var myPipe in myGraph.Pipes) { if (myPipe.StartingValue != 0) { if (IsMinCutPipe(myPipe, minCutPipes)) { graph.AddEdge(myPipe.StartingPoint, myPipe.StartingValue.ToString(), myPipe.EndPoint).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } else { graph.AddEdge(myPipe.StartingPoint, myPipe.StartingValue.ToString(), myPipe.EndPoint); } } if (myPipe.EndingValue != 0) { if (true) { graph.AddEdge(myPipe.EndPoint, myPipe.EndingValue.ToString(), myPipe.StartingPoint).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } else { graph.AddEdge(myPipe.EndPoint, myPipe.EndingValue.ToString(), myPipe.StartingPoint); } } } string startingPointName = myGraph.Nodes.Where(x => x.IsStartingPoint == true) .Select(x => x.Name).FirstOrDefault(); string endPointName = myGraph.Nodes.Where(x => x.IsEndPoint == true) .Select(x => x.Name).FirstOrDefault(); if (startingPointName != null && endPointName != null) { graph.FindNode(startingPointName).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode(startingPointName).Attr.Color = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode(endPointName).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Red; graph.FindNode(endPointName).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } viewer.Graph = graph; this.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; this.Controls.Add(viewer); this.ResumeLayout(); }