diff --git a/bin/algorithms/MaxFlow.class b/bin/algorithms/MaxFlow.class deleted file mode 100644 index 9d8cccf..0000000 Binary files a/bin/algorithms/MaxFlow.class and /dev/null differ diff --git a/bin/algorithms/MaxFlowAlgorithm.class b/bin/algorithms/MaxFlowAlgorithm.class new file mode 100644 index 0000000..1a76660 Binary files /dev/null and b/bin/algorithms/MaxFlowAlgorithm.class differ diff --git a/bin/gui/GraphPanel$1.class b/bin/gui/GraphPanel$1.class index 431ce6e..50bbea7 100644 Binary files a/bin/gui/GraphPanel$1.class and b/bin/gui/GraphPanel$1.class differ diff --git a/bin/gui/GraphPanel$2.class b/bin/gui/GraphPanel$2.class index 7e0be27..446c884 100644 Binary files a/bin/gui/GraphPanel$2.class and b/bin/gui/GraphPanel$2.class differ diff --git a/bin/gui/GraphPanel$3.class b/bin/gui/GraphPanel$3.class index 0c4d3cc..d51132b 100644 Binary files a/bin/gui/GraphPanel$3.class and b/bin/gui/GraphPanel$3.class differ diff --git a/bin/gui/GraphPanel$4.class b/bin/gui/GraphPanel$4.class index f76cbdc..1d8d403 100644 Binary files a/bin/gui/GraphPanel$4.class and b/bin/gui/GraphPanel$4.class differ diff --git a/bin/gui/GraphPanel$5.class b/bin/gui/GraphPanel$5.class index ab43bf7..751a5c0 100644 Binary files a/bin/gui/GraphPanel$5.class and b/bin/gui/GraphPanel$5.class differ diff --git a/bin/gui/PrintingFrame$1.class b/bin/gui/PrintingFrame$1.class index e0d777d..b68496e 100644 Binary files a/bin/gui/PrintingFrame$1.class and b/bin/gui/PrintingFrame$1.class differ diff --git a/bin/gui/PrintingFrame$2.class b/bin/gui/PrintingFrame$2.class deleted file mode 100644 index 9615acc..0000000 Binary files a/bin/gui/PrintingFrame$2.class and /dev/null differ diff --git a/bin/gui/PrintingFrame$3.class b/bin/gui/PrintingFrame$3.class deleted file mode 100644 index 49b83f3..0000000 Binary files a/bin/gui/PrintingFrame$3.class and /dev/null differ diff --git a/bin/gui/PrintingFrame$listen.class b/bin/gui/PrintingFrame$listen.class index dd49153..bacde95 100644 Binary files a/bin/gui/PrintingFrame$listen.class and b/bin/gui/PrintingFrame$listen.class differ diff --git a/bin/gui/PrintingFrame.class b/bin/gui/PrintingFrame.class index 5f54d54..63078ea 100644 Binary files a/bin/gui/PrintingFrame.class and b/bin/gui/PrintingFrame.class differ diff --git a/program.exe b/program.exe index 6461252..ba4c604 100644 Binary files a/program.exe and b/program.exe differ diff --git a/src/algorithms/MaxFlow.java b/src/algorithms/MaxFlow.java deleted file mode 100644 index b7ac076..0000000 --- a/src/algorithms/MaxFlow.java +++ /dev/null @@ -1,73 +0,0 @@ -package algorithms; - -import java.util.*; - -class MaxFlow { - static final int V = 6; - - boolean bfs(int rGraph[][], int s, int t, int parent[]) { - boolean visited[] = new boolean[V]; - for (int i = 0; i < V; ++i) - visited[i] = false; - - LinkedList queue = new LinkedList(); - queue.add(s); - visited[s] = true; - parent[s] = -1; - - while (queue.size() != 0) { - int u = queue.poll(); - - for (int v = 0; v < V; v++) { - if (visited[v] == false && rGraph[u][v] > 0) { - queue.add(v); - parent[v] = u; - visited[v] = true; - } - } - } - - return (visited[t] == true); - } - - int fordFulkerson(int graph[][], int s, int t) { - int u, v; - - int rGraph[][] = new int[V][V]; - - for (u = 0; u < V; u++) - for (v = 0; v < V; v++) - rGraph[u][v] = graph[u][v]; - - int parent[] = new int[V]; - - int max_flow = 0; // There is no flow initially - - while (bfs(rGraph, s, t, parent)) { - int path_flow = Integer.MAX_VALUE; - for (v = t; v != s; v = parent[v]) { - u = parent[v]; - path_flow = Math.min(path_flow, rGraph[u][v]); - } - - for (v = t; v != s; v = parent[v]) { - u = parent[v]; - rGraph[u][v] -= path_flow; - rGraph[v][u] += path_flow; - } - - max_flow += path_flow; - } - - return max_flow; - } - - public static void main(String[] args) throws java.lang.Exception { - int graph[][] = new int[][] { { 0, 16, 13, 0, 0, 0 }, { 0, 0, 10, 12, 0, 0 }, { 0, 4, 0, 0, 14, 0 }, - { 0, 0, 9, 0, 0, 20 }, { 0, 0, 0, 7, 0, 4 }, { 0, 0, 0, 0, 0, 0 } }; - MaxFlow m = new MaxFlow(); - - System.out.println("The maximum possible flow is " + m.fordFulkerson(graph, 0, 5)); - - } -} diff --git a/src/algorithms/MaxFlowAlgorithm.java b/src/algorithms/MaxFlowAlgorithm.java new file mode 100644 index 0000000..1aca01b --- /dev/null +++ b/src/algorithms/MaxFlowAlgorithm.java @@ -0,0 +1,68 @@ +package algorithms; + +import java.util.*; + +public class MaxFlowAlgorithm { + int V; + + public MaxFlowAlgorithm(int v){ + V = v; + } + + boolean search(int arrGraph[][], int s, int t, int pare[]) { + boolean vis[] = new boolean[V]; + for (int i = 0; i < V; ++i) + vis[i] = false; + + LinkedList queue = new LinkedList(); + queue.add(s); + vis[s] = true; + pare[s] = -1; + + while (queue.size() != 0) { + int u = queue.poll(); + + for (int v = 0; v < V; v++) { + if (vis[v] == false && arrGraph[u][v] > 0) { + queue.add(v); + pare[v] = u; + vis[v] = true; + } + } + } + + return (vis[t] == true); + } + + public int getMaxFlow(int graph[][], int s, int t) { + int u, v; + + int arrGraph[][] = new int[V][V]; + + for (u = 0; u < V; u++) + for (v = 0; v < V; v++) + arrGraph[u][v] = graph[u][v]; + + int pare[] = new int[V]; + + int max_flow = 0; + + while (search(arrGraph, s, t, pare)) { + int fPath = Integer.MAX_VALUE; + for (v = t; v != s; v = pare[v]) { + u = pare[v]; + fPath = Math.min(fPath, arrGraph[u][v]); + } + + for (v = t; v != s; v = pare[v]) { + u = pare[v]; + arrGraph[u][v] -= fPath; + arrGraph[v][u] += fPath; + } + + max_flow += fPath; + } + + return max_flow; + } +} diff --git a/src/gui/PrintingFrame.java b/src/gui/PrintingFrame.java index ed35457..0946ec9 100644 --- a/src/gui/PrintingFrame.java +++ b/src/gui/PrintingFrame.java @@ -175,41 +175,34 @@ private void maxFlow(String from, String to) { msg.setText("Invalid Source Or Sink"); return; } - Transformer nev = new Transformer() { - public Number transform(String arg0) { - String cost = arg0.trim(); - if (cost == null || cost.equals("")) { - return 0; - } else { - if (arg0.contains(".")) - return Double.valueOf(arg0.trim()); - else - return Integer.valueOf(arg0.trim()); - } + HashedMap map = new HashedMap(); + int i = 0; + for (Object o : graph.getVertices().toArray()) { + map.put(o.toString(), i); + i++; + } + int[][] repGraph = new int[graph.getVertexCount()][graph.getVertexCount()]; + for (i = 0; i < graph.getVertexCount(); ++i) { + for (int j = 0; j < graph.getVertexCount(); ++j) { + repGraph[i][j] = 0; } - }; - - Map edgeFlowMap = new HashMap(); + } + for (Object e : graph.getEdges().toArray()) { + String f = graph.getEndpoints(e.toString()).getFirst(); + String t = graph.getEndpoints(e.toString()).getSecond(); - Factory edgeFactory = new Factory() { - int count; - public String create() { - Random r = new Random(); - return "" + r.nextInt() % 1000 + 1; + i = map.get(f); + int j = map.get(t); + int weight = 0; + if (!e.toString().trim().equals("")) { + weight = Integer.parseInt(e.toString().trim()); } - }; - DirectedGraph dGraph = new DirectedSparseMultigraph(); - for (String v : graph.getVertices()) { - dGraph.addVertex(v); - } - for (String v : graph.getEdges()) { - dGraph.addEdge(v, graph.getEndpoints(v).getFirst(), graph.getEndpoints(v).getSecond(), EdgeType.DIRECTED); + repGraph[i][j] = weight; } + MaxFlowAlgorithm maxflow = new MaxFlowAlgorithm(graph.getVertexCount()); + int result = maxflow.getMaxFlow(repGraph, map.get(from), map.get(to)); + msg.setText(msg.getText() + result); - EdmondsKarpMaxFlow maxFlow = new EdmondsKarpMaxFlow(dGraph, from, to, nev, - edgeFlowMap, edgeFactory); - maxFlow.evaluate(); - System.out.println(maxFlow.getMaxFlow()); } public void adjacencyList() {