|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.mhhe.clrs2e.AdjacencyListGraph | +--com.mhhe.clrs2e.FlowNetwork
Implementation of a flow network, using adjacency lists.
The representation is based on the superclass AdjacencyListGraph
, but with some significant differences. The
inner class FlowNetwork.FlowNetworkEdge
is a subclass of
AdjacencyListGraph.Edge
, with additional instance variables
for the edge's capacity, net flow, and residual capacity. Whenever
edge (u,v) is present in the flow network, the reverse edge (v,u)
must also be present; the reason is that, in order to maintain skew
symmetry, when updating the flow on edge (u,v), we must also update
the flow on the reverse edge (v,u). The reverse edge must be
present in order to do so. Moreover, each
FlowNetworkEdge
object also includes a reference to
its reverse edge. If edge (u,v) should be in the flow network but
the reverse edge (v,u) should not, then set the capacity of (v,u)
to 0. The FlowNetworkEdge
class includes methods to
access an edge's net flow and capacity.
The iterator for flow network edges, FlowNetwork.EdgeIterator
, implements the FlowNetworkEdgeIterator
interface. When creating this type of
iterator, we specify whether the iterator should return only edges
in the residual network (i.e., those with positive residual
capacity), or all edges.
Finally, the FlowNetwork
class contains a method,
getFlowValue(com.mhhe.clrs2e.Vertex)
, which returns the value of the current flow,
given the net flows on the edges.
Nested Class Summary | |
class |
FlowNetwork.EdgeIterator
Inner class that overrides AdjacencyListGraph.EdgeIterator to implement
FlowNetworkEdgeIterator . |
protected static class |
FlowNetwork.FlowNetworkEdge
Inner class for flow network edges in adjacency lists. |
Nested classes inherited from class com.mhhe.clrs2e.AdjacencyListGraph |
AdjacencyListGraph.AdjListInfo, AdjacencyListGraph.VertexIterator |
Field Summary |
Fields inherited from class com.mhhe.clrs2e.AdjacencyListGraph |
adj, directed, e, lastAdded |
Constructor Summary | |
FlowNetwork(int cardV)
Creates an empty FlowNetwork . |
Method Summary | |
void |
addEdge(int u,
int v)
Unsupported, since edges in a flow network must have capacities. |
void |
addEdge(int u,
int v,
double cuv,
double cvu)
Adds an edge (u,v) and its reverse edge (v,u) to this graph. |
void |
addEdge(com.mhhe.clrs2e.Vertex u,
com.mhhe.clrs2e.Vertex v)
Unsupported, since edges in a flow network must have capacities. |
void |
addEdge(com.mhhe.clrs2e.Vertex u,
com.mhhe.clrs2e.Vertex v,
double cuv,
double cvu)
Adds an edge (u,v) and its reverse edge (v,u) to this graph. |
java.util.Iterator |
edgeIterator(int u)
Returns an iterator that iterates through all the edges (regardless of residual capacity) incident on a given vertex in a flow network. |
java.util.Iterator |
edgeIterator(com.mhhe.clrs2e.Vertex u)
Returns an iterator that iterates through all the edges (regardless of residual capacity) incident on a given vertex in a flow network. |
com.mhhe.clrs2e.FlowNetworkEdgeIterator |
flowNetworkEdgeIterator(int u,
boolean residual)
Returns an iterator, of type FlowNetworkEdgeIterator (so that the caller does
not need to cast the result), that iterates through the edges
incident on a given vertex in a flow network. |
com.mhhe.clrs2e.FlowNetworkEdgeIterator |
flowNetworkEdgeIterator(com.mhhe.clrs2e.Vertex u,
boolean residual)
Returns an iterator, of type FlowNetworkEdgeIterator (so that the caller does
not need to cast the result), that iterates through the edges
incident on a given vertex in a flow network. |
double |
getFlowValue(com.mhhe.clrs2e.Vertex s)
Returns the value of the flow, which is the sum of the net flows out of the source. |
java.lang.String |
toString()
Returns the String representation of this
flow network. |
Methods inherited from class com.mhhe.clrs2e.AdjacencyListGraph |
addVertex, addVertex, addVertex, getCardE, getCardV, getVertex, isDirected, makeEmptyGraph, useSameVertices, vertexIterator |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public FlowNetwork(int cardV)
FlowNetwork
. It is a directed
graph.
cardV
- How many vertices this graph will have.Method Detail |
public void addEdge(com.mhhe.clrs2e.Vertex u, com.mhhe.clrs2e.Vertex v)
addEdge
in interface Graph
addEdge
in class AdjacencyListGraph
u
- One vertex.v
- The other vertex.
java.lang.UnsupportedOperationException
- always.public void addEdge(int u, int v)
addEdge
in interface Graph
addEdge
in class AdjacencyListGraph
u
- The index of one vertex.v
- The index of the other vertex.
java.lang.UnsupportedOperationException
- always.public void addEdge(com.mhhe.clrs2e.Vertex u, com.mhhe.clrs2e.Vertex v, double cuv, double cvu)
Vertex
objects.
u
- One vertex.v
- The other vertex.cuv
- The capacity of edge (u,v); 0 if (u,v) is not in
this flow network.cvu
- The capacity of edge (v,u); 0 if (v,u) is not in
this flow network.public void addEdge(int u, int v, double cuv, double cvu)
u
- One vertex.v
- The other vertex.cuv
- The capacity of edge (u,v); 0 if (u,v) is not in
this flow network.cvu
- The capacity of edge (v,u); 0 if (v,u) is not in
this flow network.public java.util.Iterator edgeIterator(com.mhhe.clrs2e.Vertex u)
edgeIterator
in interface Graph
edgeIterator
in class AdjacencyListGraph
u
- The vertex whose incident edges are returned by the
iterator.public java.util.Iterator edgeIterator(int u)
edgeIterator
in interface Graph
edgeIterator
in class AdjacencyListGraph
u
- The index of the vertex whose incident edges are
returned by the iterator.public com.mhhe.clrs2e.FlowNetworkEdgeIterator flowNetworkEdgeIterator(com.mhhe.clrs2e.Vertex u, boolean residual)
FlowNetworkEdgeIterator
(so that the caller does
not need to cast the result), that iterates through the edges
incident on a given vertex in a flow network. Each incident
edge is indicated by the corresponding adjacent vertex.
u
- The vertex whose incident edges are returned by the
iterator.residual
- true
if this iterator is to return
only edges in the residual network, false
if it is
to return all edges.public com.mhhe.clrs2e.FlowNetworkEdgeIterator flowNetworkEdgeIterator(int u, boolean residual)
FlowNetworkEdgeIterator
(so that the caller does
not need to cast the result), that iterates through the edges
incident on a given vertex in a flow network. Each incident
edge is indicated by the corresponding adjacent vertex.
u
- The index of the vertex whose incident edges are
returned by the iterator.residual
- true
if this iterator is to return
only edges in the residual network, false
if it is
to return all edges.public double getFlowValue(com.mhhe.clrs2e.Vertex s)
s
- The source vertex.public java.lang.String toString()
String
representation of this
flow network.
toString
in class AdjacencyListGraph
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |