public class FlowEdge extends Object
FlowNetwork. Each edge consists of two integers
(naming the two vertices), a real-valued capacity, and a real-valued
flow. The data type provides methods for accessing the two endpoints
of the directed edge and the weight. It also provides methods for
changing the amount of flow on the edge and determining the residual
capacity of the edge.
For additional documentation, see Section 6.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
| Constructor and Description |
|---|
FlowEdge(FlowEdge e)
Initializes a flow edge from another flow edge.
|
FlowEdge(int v,
int w,
double capacity)
Initializes an edge from vertex v to vertex w with
the given capacity and zero flow.
|
FlowEdge(int v,
int w,
double capacity,
double flow)
Initializes an edge from vertex v to vertex w with
the given capacity and flow.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addResidualFlowTo(int vertex,
double delta)
Increases the flow on the edge in the direction to the given vertex.
|
double |
capacity()
Returns the capacity of the edge.
|
double |
flow()
Returns the flow on the edge.
|
int |
from()
Returns the tail vertex of the edge.
|
static void |
main(String[] args)
Unit tests the FlowEdge data type.
|
int |
other(int vertex)
Returns the endpoint of the edge that is different from the given vertex
(unless the edge represents a self-loop in which case it returns the same vertex).
|
double |
residualCapacityTo(int vertex)
Returns the residual capacity of the edge in the direction
to the given vertex.
|
int |
to()
Returns the head vertex of the edge.
|
String |
toString()
Returns a string representation of the edge.
|
public FlowEdge(int v,
int w,
double capacity)
v - the tail vertexw - the head vertexcapacity - the capacity of the edgeIndexOutOfBoundsException - if either v or w
is a negative integerIllegalArgumentException - if capacity is negativepublic FlowEdge(int v,
int w,
double capacity,
double flow)
v - the tail vertexw - the head vertexcapacity - the capacity of the edgeflow - the flow on the edgeIndexOutOfBoundsException - if either v or w
is a negative integerIllegalArgumentException - if capacity is negativeIllegalArgumentException - unless flow is between
0.0 and capacity.public FlowEdge(FlowEdge e)
e - the edge to copypublic int from()
public int to()
public double capacity()
public double flow()
public int other(int vertex)
vertex - one endpoint of the edgeIllegalArgumentException - if vertex is not one of the endpoints
of the edgepublic double residualCapacityTo(int vertex)
vertex - one endpoint of the edgeIllegalArgumentException - if vertex is not one of the endpoints
of the edgepublic void addResidualFlowTo(int vertex,
double delta)
vertex - one endpoint of the edgeIllegalArgumentException - if vertex is not one of the endpoints
of the edgeIllegalArgumentException - if delta makes the flow on
on the edge either negative or larger than its capacityIllegalArgumentException - if delta is NaNpublic String toString()
public static void main(String[] args)
Copyright © 2014. All Rights Reserved.