Click or drag to resize
FlowNetwork Class

The FlowNetwork class represents a capacitated network with vertices named 0 through V - 1, where each directed edge is of type and has a real-valued capacity and flow.

It supports the following two primary operations: add an edge to the network, iterate over all of the edges incident to or from a vertex. It also provides methods for returning the number of vertices V and the number of edges E. Parallel edges and self-loops are permitted.

This implementation uses an adjacency-lists representation, which is a vertex-indexed array of BagItem objects. All operations take constant time (in the worst case) except iterating over the edges incident to a given vertex, which takes time proportional to the number of such edges.

Inheritance Hierarchy
SystemObject
  Algs4NetFlowNetwork

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class FlowNetwork

The FlowNetwork type exposes the following members.

Constructors
  NameDescription
Public methodFlowNetwork(Int32)
Initializes an empty flow network with V vertices and 0 edges.
Public methodFlowNetwork(TextInput)
Initializes a flow network from an input stream. The format is the number of vertices V, followed by the number of edges E, followed by E pairs of vertices and edge capacities, with each entry separated by whitespace.
Public methodFlowNetwork(Int32, Int32)
Initializes a random flow network with V vertices and E edges. The capacities are integers between 0 and 99 and the flow values are zero.
Top
Properties
  NameDescription
Public propertyE
Returns the number of edges in the edge-weighted graph.
Public propertyV
Returns the number of vertices in the edge-weighted graph.
Top
Methods
  NameDescription
Public methodAddEdge
Adds the edge e to the network.
Public methodAdj
Returns the edges incident on vertex v (includes both edges pointing to and from v).
Public methodEdges
Returns all edges in this edge-weighted graph, excludeing self loops. To iterate over the edges in this edge-weighted graph, use foreach notation: foreach (Edge e in G.Edges()).
Public methodStatic memberMainTest
Demo test the FlowNetwork data type.
Public methodToString
Returns a string representation of the flow network. This method takes time proportional to E + V.
(Overrides ObjectToString.)
Top
Remarks

For additional documentation, see Section 6.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class FlowNetwork implementation by the respective authors.

See Also