类 FlowEdge
- java.lang.Object
-
- edu.princeton.cs.algs4.FlowEdge
-
public class FlowEdge extends java.lang.ObjectTheFlowEdgeclass represents a capacitated edge with a flow in aFlowNetwork. 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.
-
-
构造器概要
构造器 构造器 说明 FlowEdge(int v, int w, double capacity)Initializes an edge from vertexvto vertexwwith the givencapacityand zero flow.FlowEdge(int v, int w, double capacity, double flow)Initializes an edge from vertexvto vertexwwith the givencapacityandflow.FlowEdge(FlowEdge e)Initializes a flow edge from another flow edge.
-
方法概要
修饰符和类型 方法 说明 voidaddResidualFlowTo(int vertex, double delta)Increases the flow on the edge in the direction to the given vertex.doublecapacity()Returns the capacity of the edge.doubleflow()Returns the flow on the edge.intfrom()Returns the tail vertex of the edge.static voidmain(java.lang.String[] args)Unit tests theFlowEdgedata type.intother(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).doubleresidualCapacityTo(int vertex)Returns the residual capacity of the edge in the direction to the givenvertex.intto()Returns the head vertex of the edge.java.lang.StringtoString()Returns a string representation of the edge.
-
-
-
构造器详细资料
-
FlowEdge
public FlowEdge(int v, int w, double capacity)Initializes an edge from vertexvto vertexwwith the givencapacityand zero flow.- 参数:
v- the tail vertexw- the head vertexcapacity- the capacity of the edge- 抛出:
java.lang.IllegalArgumentException- if eithervorwis a negative integerjava.lang.IllegalArgumentException- ifcapacity < 0.0
-
FlowEdge
public FlowEdge(int v, int w, double capacity, double flow)Initializes an edge from vertexvto vertexwwith the givencapacityandflow.- 参数:
v- the tail vertexw- the head vertexcapacity- the capacity of the edgeflow- the flow on the edge- 抛出:
java.lang.IllegalArgumentException- if eithervorwis a negative integerjava.lang.IllegalArgumentException- ifcapacityis negativejava.lang.IllegalArgumentException- unlessflowis between0.0andcapacity.
-
FlowEdge
public FlowEdge(FlowEdge e)
Initializes a flow edge from another flow edge.- 参数:
e- the edge to copy
-
-
方法详细资料
-
from
public int from()
Returns the tail vertex of the edge.- 返回:
- the tail vertex of the edge
-
to
public int to()
Returns the head vertex of the edge.- 返回:
- the head vertex of the edge
-
capacity
public double capacity()
Returns the capacity of the edge.- 返回:
- the capacity of the edge
-
flow
public double flow()
Returns the flow on the edge.- 返回:
- the flow on the edge
-
other
public 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).- 参数:
vertex- one endpoint of the edge- 返回:
- 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)
- 抛出:
java.lang.IllegalArgumentException- ifvertexis not one of the endpoints of the edge
-
residualCapacityTo
public double residualCapacityTo(int vertex)
Returns the residual capacity of the edge in the direction to the givenvertex.- 参数:
vertex- one endpoint of the edge- 返回:
- the residual capacity of the edge in the direction to the given vertex
If
vertexis the tail vertex, the residual capacity equalscapacity() - flow(); ifvertexis the head vertex, the residual capacity equalsflow(). - 抛出:
java.lang.IllegalArgumentException- ifvertexis not one of the endpoints of the edge
-
addResidualFlowTo
public void addResidualFlowTo(int vertex, double delta)Increases the flow on the edge in the direction to the given vertex. Ifvertexis the tail vertex, this increases the flow on the edge bydelta; ifvertexis the head vertex, this decreases the flow on the edge bydelta.- 参数:
vertex- one endpoint of the edgedelta- amount by which to increase flow- 抛出:
java.lang.IllegalArgumentException- ifvertexis not one of the endpoints of the edgejava.lang.IllegalArgumentException- ifdeltamakes the flow on on the edge either negative or larger than its capacityjava.lang.IllegalArgumentException- ifdeltaisNaN
-
toString
public java.lang.String toString()
Returns a string representation of the edge.- 覆盖:
toString在类中java.lang.Object- 返回:
- a string representation of the edge
-
main
public static void main(java.lang.String[] args)
Unit tests theFlowEdgedata type.- 参数:
args- the command-line arguments
-
-