static void DestroyMinimumCut(ref NetworkGraph graph, bool isDynamic, StreamWriter write) { // get the minimum cut and sort it by highest flow. List <NetworkLink> minCut = FindMinimumCut(graph.source); int halfFlowTime = -1; int totalFlowMaximum = graph.maxFlow; // Console.WriteLine("Beginning 'DestroyMinimumCut()'."); int t = 0; while (graph.maxFlow != 0) { minCut.Sort((x, y) => - x.flow.CompareTo(y.flow)); graph.DestroyLink(minCut[0]); if (isDynamic) { graph.FillGraph(); } if (halfFlowTime == -1 && graph.maxFlow < 0.5f * totalFlowMaximum) { halfFlowTime = t; } PrintGraphInfo(graph, t, write); t++; } Console.WriteLine("'DestroyMinimumCut()' complete. \t|Max flow: " + graph.maxFlow + " \t|Half flow time: " + halfFlowTime); write.WriteLine("MaxFlow: " + graph.maxFlow + " Half flow time: " + halfFlowTime + "\n"); }
static void DestroyHighestFlowing(ref NetworkGraph graph, bool isDynamic, StreamWriter write) { // get the list of all edges and sort it by maximum flow. List <NetworkLink> edges = new List <NetworkLink>(); for (int i = 0; i < EDGE_COUNT; i++) { edges.Add(graph.edges[i]); } edges.Sort((x, y) => - x.flow.CompareTo(y.flow)); int halfFlowTime = -1; int totalFlowMaximum = graph.maxFlow; // Console.WriteLine("Beginning 'DestroyHighestFlowing()'"); // destroy each edge in order. int t = 0; int j = 0; while (graph.maxFlow > 0) { if (!isDynamic) { while (edges[j].flow == 0) { j++; } } graph.DestroyLink(edges[j]); if (halfFlowTime == -1 && graph.maxFlow < 0.5f * totalFlowMaximum) { halfFlowTime = t; } if (isDynamic) { graph.FillGraph(); edges.Sort((x, y) => - x.flow.CompareTo(y.flow)); } else { j++; } PrintGraphInfo(graph, t, write); t++; } Console.WriteLine("'DestroyHighestFlowing()' complete. \t|Max flow: " + graph.maxFlow + " \t|Half flow time: " + halfFlowTime); write.WriteLine("MaxFlow: " + graph.maxFlow + " Half flow time: " + halfFlowTime + "\n"); }
static void DestroyAtRandom(ref NetworkGraph graph, bool isDynamic, StreamWriter write, int seed) { // set up a list containing the indeces of the possible-to-destroy edges. List <int> choices = new List <int>(EDGE_COUNT); for (int i = 0; i < EDGE_COUNT; i++) { choices.Add(i); } int count = choices.Count; int halfFlowTime = -1; int totalFlowMaximum = graph.maxFlow; // Console.WriteLine("Beginning 'DestroyAtRandom()'"); // loop until the maximum flow has been reduced to 0. int t = 1; while (graph.maxFlow != 0) { // get a random number from 0 to the number of possible edge choices Random random = new Random(seed); int rand = random.Next(0, count); // select the int at that index as the chosen index of the edge to destroy int choice = choices[rand]; // 'delete' the element that we chose (move the last element to the index that we chose, then reduce the count) choices[rand] = choices[count - 1]; count--; // destroy the link, updating the other nodes in the graph as needed. graph.DestroyLink(graph.edges[choice]); // if the routing method is 'dynamic', then recalculate the flow path. if (isDynamic) { graph.FillGraph(); } if (halfFlowTime == -1 && graph.maxFlow < 0.5f * totalFlowMaximum) { halfFlowTime = t; } PrintGraphInfo(graph, t, write); t++; } Console.WriteLine("'DestroyAtRandom()' complete. \t\t|Max flow: " + graph.maxFlow + " \t|Half flow time: " + halfFlowTime); write.WriteLine("MaxFlow: " + graph.maxFlow + " Half flow time: " + halfFlowTime + "\n"); }