Exemplo n.º 1
0
        private void btnMaxFlowPaths_Click(object sender, EventArgs e)
        {
            MyGraph myGraph       = InputControls.getMyGraph();
            var     pathList      = myGraph.getAllPaths();
            var     maxFlowList   = new List <int>();
            var     isMaxFlowList = new List <bool>();

            for (int i = 0; i < pathList.Count(); i++)
            {
                int maxFlow = myGraph.getMaxFlowOfPath(pathList[i]);
                maxFlowList.Add(maxFlow);
            }

            int maxFlowNum = maxFlowList.Max();

            foreach (var maxFlow in maxFlowList)
            {
                if (maxFlow == maxFlowNum)
                {
                    isMaxFlowList.Add(true);
                }
                else
                {
                    isMaxFlowList.Add(false);
                }
            }

            for (int i = 0; i < pathList.Count(); i++)
            {
                FormGraph formGraph = new FormGraph(pathList[i], isMaxFlowList[i] /*, maxFlowList[i]*/);
                formGraph.Text = "Net Flow: " + maxFlowList[i].ToString();
                formGraph.Show();
            }
        }
Exemplo n.º 2
0
        private void btnMaxFlow_Click(object sender, EventArgs e)
        {
            MyGraph myGraph = InputControls.getMyGraph();

            long maxFlow = myGraph.getMaxFlow();

            MessageBox.Show($"Başlangıç Noktası: {myGraph.getStartingPoint()}\n" +
                            $"Bitiş Noktası: {myGraph.getEndPoint()}\n" +
                            $"Maximum flow = {maxFlow}", "Maximum flow",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 3
0
        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]);
            //}
        }
Exemplo n.º 4
0
        //maxFlowPath => { "A", "B", "C", "E" }
        //Constructor 2
        public FormGraph(List <string> maxFlowPath, bool isMaxFlowPath)
        {
            //this.Text = flow.ToString();
            List <string[]> binaryList = new List <string[]>();

            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");

            //listOfNodes = InputControls.getListOfNodes();
            myGraph = InputControls.getMyGraph();
            var nodeList = new List <Node>();

            //node ekle
            foreach (var myNode in myGraph.Nodes)
            {
                graph.AddNode(new Node(myNode.Name));
            }

            List <List <string> > binaryPaths = new List <List <string> >();

            for (int i = 0; i < maxFlowPath.Count() - 1; i++)
            {
                binaryPaths.Add(new List <string> {
                    maxFlowPath[i], maxFlowPath[i + 1]
                });
            }

            //edge ekle
            foreach (var myPipe in myGraph.Pipes)
            {
                if (myPipe.StartingValue != 0)
                {
                    if (IsOnThePath(myPipe, binaryPaths))
                    {
                        if (isMaxFlowPath)
                        {
                            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).Attr.Color = Microsoft.Msagl.Drawing.Color.Blue;
                        }
                    }
                    else
                    {
                        graph.AddEdge(myPipe.StartingPoint, myPipe.StartingValue.ToString(), myPipe.EndPoint);
                    }
                }

                if (myPipe.EndingValue != 0)
                {
                    if (IsOnThePath(myPipe, binaryPaths))
                    {
                        if (isMaxFlowPath)
                        {
                            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).Attr.Color = Microsoft.Msagl.Drawing.Color.Blue;
                        }
                    }
                    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();
        }
Exemplo n.º 5
0
        public FormGraph()
        {
            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");

            this.Text = "Graph";

            myGraph = InputControls.getMyGraph();
            var nodeList = new List <Node>();

            foreach (var myNode in myGraph.Nodes)
            {
                graph.AddNode(new Node(myNode.Name));
            }

            foreach (var myPipe in myGraph.Pipes)
            {
                if (myPipe.StartingValue != 0)
                {
                    graph.AddEdge(myPipe.StartingPoint, myPipe.StartingValue.ToString(), myPipe.EndPoint);
                }
                if (myPipe.EndingValue != 0)
                {
                    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;
            }


            //Microsoft.Msagl.Drawing.Node node = new Microsoft.Msagl.Drawing.Node("a");

            //graph.AddEdge("Ali", "Veli");

            //graph.AddEdge("B", "C");
            //graph.AddEdge("A", "C").Attr.Color = Microsoft.Msagl.Drawing.Color.Green;
            //graph.FindNode("A").Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta;
            //graph.FindNode("B").Attr.FillColor = Microsoft.Msagl.Drawing.Color.MistyRose;
            //Microsoft.Msagl.Drawing.Node c = graph.FindNode("C");
            //c.Attr.FillColor = Microsoft.Msagl.Drawing.Color.PaleGreen;
            //c.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond;
            viewer.Graph = graph;
            this.SuspendLayout();
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            this.Controls.Add(viewer);
            this.ResumeLayout();
        }
Exemplo n.º 6
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();
        }