Class Dinic
java.lang.Object
es.urjc.etsii.grafo.util.graph_algorithms.Dinic
Dinic's algorithm for the maxflow problem.
See ...
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int v1, int v2, int cap) Just adds an edge and ALSO adds it going backwards.boolean
bfs
(int source, int sink) BFSint
dfs
(int source, int sink, int min) Runs inner DFS in Dinic's, from node pos with a flow of min.int
flow
(int source, int sink) Calculate flow from a source to a destination
-
Constructor Details
-
Dinic
public Dinic(int N) New Dinic algorithm or graph of size N- Parameters:
N
- graph size
-
-
Method Details
-
add
public void add(int v1, int v2, int cap) Just adds an edge and ALSO adds it going backwards. EDGES ARE IGNORED IF ALREADY EXISTS FROM V1 TO V2- Parameters:
v1
- Originv2
- Destinationcap
- Capacity
-
bfs
public boolean bfs(int source, int sink) BFS- Parameters:
source
- start pointsink
- end point- Returns:
- true if path exists, false otherwise
-
dfs
public int dfs(int source, int sink, int min) Runs inner DFS in Dinic's, from node pos with a flow of min.- Parameters:
source
- start pointsink
- end pointmin
- flow- Returns:
- flow
-
flow
public int flow(int source, int sink) Calculate flow from a source to a destination- Parameters:
source
- start pointsink
- end point- Returns:
- flow
-