-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlowEdge.java
More file actions
56 lines (44 loc) · 1.56 KB
/
FlowEdge.java
File metadata and controls
56 lines (44 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.Random;
public class FlowEdge implements Comparable<FlowEdge>{
private final int v,w;
private double flow;
private final double capacity;
public FlowEdge(int v,int w,double capacity){
this.v=v;this.w=w;this.capacity=capacity;
this.flow=0.0;
}
public double flow(){return flow;}
public double capacity(){return capacity;}
public int from(){return v;}
public int to(){return w;}
public int other(int i){
if (i==v) return w;
else if (i==w) return v;
else throw new RuntimeException();
}
// public int compareTo(DirectedEdge that){
// if (this.weight()<that.weight()) return -1;
// else if (this.weight()>that.weight()) return -1;
// else return 0;
// }
public String toString(){
return String.format("%d->%d",v,w)+" capacity:"+String.format("%.2f",this.capacity())
+" flow:"+String.format("%.2f",this.flow());
}
public double residualCapacityTo(int i){
if (i==v) return flow;
else if (i==w) return capacity-flow;
else throw new RuntimeException();
}
public void addResidualFlowTo(int i,double delta){
if (i==v) flow-=delta;
else if (i==w) flow+=delta;
else throw new RuntimeException();
}
public static void main(String[] args){
FlowEdge edge=new FlowEdge(2,1,10.0);
int v=edge.from();System.out.println(v);
int k=edge.to();System.out.println(k);
System.out.println(edge);
}
}