Exemple #1
0
        private void MaxFlow(object sender, RoutedEventArgs args)
        {
            MaxFlow1 mf      = new MaxFlow1(Graph);
            string   message = string.Format("Maxymalny przeplyw to {0}", mf.findMaxFlow(Graph));

            var current = mf.getFlowMatrix();

            for (int y = 0; y < Graph.NodesNr; ++y)
            {
                for (int x = 0; x < Graph.NodesNr; ++x)
                {
                    Graph.Current[x, y] = current[x, y];
                }
            }

            Renderer.Displayer = new DirectedColumnFlowDisplayer();
            MessageBox.Show(message);
        }
        public DirectedGraphMatrix GenerateSkojarzenie()
        {
            RandomNetworkGraphCreator generator = new RandomNetworkGraphCreator();

            generator.MinimumNodePerRowLeft  = int.Parse(NodeCountLeft.Text);
            generator.MinimumNodePerRowRight = int.Parse(NodeCountRight.Text);

            generator.NoRandoms = true;
            generator.RowCount  = 2;

            var graph = generator.Generate();

            for (int x = 0; x < graph.NodesNr; ++x)
            {
                for (int y = 0; y < graph.NodesNr; ++y)
                {
                    if (graph.GetConnection(x, y))
                    {
                        graph.setWeight(x, y, 1);
                    }
                }
            }

            MaxFlow1 mf = new MaxFlow1(graph);

            mf.findMaxFlow(graph);

            var current = mf.getFlowMatrix();

            for (int y = 0; y < graph.NodesNr; ++y)
            {
                for (int x = 0; x < graph.NodesNr; ++x)
                {
                    graph.Current[x, y] = current[x, y];
                }
            }

            //teraz pokolorujmy
            int number = 1;

            for (int y = 0; y < graph.NodesNr; ++y)
            {
                for (int x = 0; x < graph.NodesNr; ++x)
                {
                    if (y == 0 || y == graph.NodesNr - 1)
                    {
                        continue;
                    }
                    if (x == 0 || x == graph.NodesNr - 1)
                    {
                        continue;
                    }
                    if (graph.SkojarzenieKolor[x] == 0 && graph.GetCurrent(x, y) > 0)
                    {
                        graph.SkojarzenieKolor[x] = number;
                        graph.SkojarzenieKolor[y] = number++;
                    }
                }
            }

            return(graph);
        }