类 FlowNetwork


  • public class FlowNetwork
    extends java.lang.Object
    The FlowNetwork class represents a capacitated network with vertices named 0 through V - 1, where each directed edge is of type FlowEdge 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 Bag 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.

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

    • 构造器概要

      构造器 
      构造器 说明
      FlowNetwork​(int V)
      Initializes an empty flow network with V vertices and 0 edges.
      FlowNetwork​(int V, int E)
      Initializes a random flow network with V vertices and E edges.
      FlowNetwork​(In in)
      Initializes a flow network from an input stream.
    • 方法概要

      修饰符和类型 方法 说明
      void addEdge​(FlowEdge e)
      Adds the edge e to the network.
      java.lang.Iterable<FlowEdge> adj​(int v)
      Returns the edges incident on vertex v (includes both edges pointing to and from v).
      int E()
      Returns the number of edges in the edge-weighted graph.
      java.lang.Iterable<FlowEdge> edges()  
      static void main​(java.lang.String[] args)
      Unit tests the FlowNetwork data type.
      java.lang.String toString()
      Returns a string representation of the flow network.
      int V()
      Returns the number of vertices in the edge-weighted graph.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 构造器详细资料

      • FlowNetwork

        public FlowNetwork​(int V)
        Initializes an empty flow network with V vertices and 0 edges.
        参数:
        V - the number of vertices
        抛出:
        java.lang.IllegalArgumentException - if V < 0
      • FlowNetwork

        public FlowNetwork​(int V,
                           int E)
        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.
        参数:
        V - the number of vertices
        E - the number of edges
        抛出:
        java.lang.IllegalArgumentException - if V < 0
        java.lang.IllegalArgumentException - if E < 0
      • FlowNetwork

        public FlowNetwork​(In in)
        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.
        参数:
        in - the input stream
        抛出:
        java.lang.IllegalArgumentException - if the endpoints of any edge are not in prescribed range
        java.lang.IllegalArgumentException - if the number of vertices or edges is negative
    • 方法详细资料

      • V

        public int V()
        Returns the number of vertices in the edge-weighted graph.
        返回:
        the number of vertices in the edge-weighted graph
      • E

        public int E()
        Returns the number of edges in the edge-weighted graph.
        返回:
        the number of edges in the edge-weighted graph
      • addEdge

        public void addEdge​(FlowEdge e)
        Adds the edge e to the network.
        参数:
        e - the edge
        抛出:
        java.lang.IllegalArgumentException - unless endpoints of edge are between 0 and V-1
      • adj

        public java.lang.Iterable<FlowEdge> adj​(int v)
        Returns the edges incident on vertex v (includes both edges pointing to and from v).
        参数:
        v - the vertex
        返回:
        the edges incident on vertex v as an Iterable
        抛出:
        java.lang.IllegalArgumentException - unless 0 <= v < V
      • edges

        public java.lang.Iterable<FlowEdge> edges()
      • toString

        public java.lang.String toString()
        Returns a string representation of the flow network. This method takes time proportional to E + V.
        覆盖:
        toString 在类中 java.lang.Object
        返回:
        the number of vertices V, followed by the number of edges E, followed by the V adjacency lists
      • main

        public static void main​(java.lang.String[] args)
        Unit tests the FlowNetwork data type.
        参数:
        args - the command-line arguments