Пример #1
0
        public static void Test()
        {
            Graph g = new Graph();
            StreamReader fin = new StreamReader("maxflow.in");
            string str = fin.ReadLine();
            string[] ss = str.Split();
            int s = Int32.Parse(ss[0]);
            int t = Int32.Parse(ss[1]);
            int i, j, c;
            while(true)
            {
                str = fin.ReadLine();
                if(str == null)
                    break;
                if(str.Length < 4)
                    break;

                ss = str.Split();
                i = Int32.Parse(ss[0]);
                j = Int32.Parse(ss[1]);
                c = Int32.Parse(ss[2]);
                g.AddEdge(i, j, c);
            }
            g.Source = g.GetVertex(s);
            g.Sink = g.GetVertex(t);
            Console.WriteLine(g.FordFulkerson());

            int n = 10000;
            g = new Graph();
            Random r = new Random();
            g.Source = g.GetVertex(0);
            for(i = 0; i < n; i++)
                for(j = 0; j < n; j++)
                    if(i != j)
                        if(r.Next(100) < 1)
                            g.AddEdge(i, j, r.Next(2) + 1);
            g.Sink = g.GetVertex(n - 1);
            Console.WriteLine(g.FordFulkerson());
        }
Пример #2
0
 public static void FindBarrierByMaxflow(State st0)
 {
     SimpleFlowGraphBuilder builder = new SimpleFlowGraphBuilder();
     mfGraph = builder.BuildGraph(st0);
     Console.WriteLine("Done, running maxflow algorithm with {0} vertices {1} edges", mfGraph.CountVertex(), mfGraph.CountEdge());
     Console.WriteLine("Ford-Fulkerson: {0}", mfGraph.FordFulkerson());
     DateTime maxflowStartTime = DateTime.Now;
     Edge[] edges = mfGraph.MinCut;
     maxflowTime = DateTime.Now.Subtract(maxflowStartTime);
     ArrayList positions = new ArrayList();
     foreach(Edge e in edges)
     {
         CILInstruction inst = ((DelayedAction)e.ExtraInfo).SourceInstruction;
         bool found = false;
         foreach(CILInstruction ii in positions)
             if(ii == inst)
             {
                 found = true;
                 break;
             }
         if(found == false)
             positions.Add(inst);
     }
     foreach(CILInstruction inst in positions)
         Console.WriteLine(inst.ParentMethod + "::" + inst.ToString());
 }