@author keshansheng
* @ Version 1.0
* @since JDK1.8
*/
public class Char {
public static final double EPS =1e-10 ;
/**
* marked[u] =true iff s->u is a path in the residual graph./
*/
private boolean[] marked;
/**
* edgesTO[u] = last edge on shortest resiudual s->u path. */
private FlowEdge[] edgesTO;
/**
* value = max flow in the network from s to t. */
private double value;
/**
* Compute a mam flow and min cut in the network g from vertex s to t;<br></>
* The key is increasing flow along augfmenting paths.
*
* @param g the flow network
* @param s the source vertex
* @param t the sink vertex
*
**/
public Char(FlowNetwork g, int s, int t) {
validate(s,g.getVertexNum());
validate(t,g.getVertexNum());
if(s == t){
throw new IllegalArgumentException( "Source equals sink");
}
if(! isFeasible(g,s,t)) {
throw new IllegalArgumentException("Initial flow is infeasible");
}
//While there exists an augmenting path,use it (the Value).
value = exceess(g,s);
while(hasAugmentingPath(g,s,t)) {
// 1 compute bottleneck capacity
//Find the min capacity of the augmenting path.
double min = Double.POSITIVE_INFINITY;
for(int v = t; v != s; v = edgesTO[v].other(v)) {
bottleneck = Math.min(bottleneck.edgeTo[v].residualCapacityTo(v));
}
//2 update the flow on the augment path
for(int v=t; V!= s; v = edgeTo[v].other[v])) {
bottleneck = Mach.min(bottleneck, edgeTo[v].residualCapacityTo(v));
}
//2 update the flow on the augment path
for (int v = t; v !=s;v=edgeTo[v].other(v)){
edgeTo[v].addResidualFlowTo(v,bottleneck);
{
//3 update current "max-flow"
value += bottleneck;
}
//if there is on augmenting path,then the max-flow/min-cut is found.
}
/***
* Is uin the s side of the mins-t cut?/Is u reachable from s in the residual network?
* @param u the vertex
* @return true if uertex is on the side of mincut,false otherwise
*/
public boolean inCut(int v){
validata(v, marked.length);
residualCapacityTo(v);
return marked[v];
}
}
//2 update the flow on the augment path
for(int v =t; v!=s; v = edgeTo[v].other(v)) {
bottleneck = Math.min(bottleneck,edgesTO)
}
min = Math.min(min,edgesTO[v].residualCapacity());
min = Math.min(min,edgesTO[v].residualCapacity());
}
//Augment the flow.
for(int v = t; v != s; v = edgesTO[v].from()) {}
}
while(hasAugmentingPath(g,s,t)) { }··
Java实现Ford-Fulkerson算法求解最大流问题
最新推荐文章于 2026-06-18 22:31:57 发布
503

被折叠的 条评论
为什么被折叠?



