Class WeightedDigraph

  • Direct Known Subclasses:
    SimpleWeightedDigraph

    public class WeightedDigraph
    extends DirectedGraph
    DirectedGraph with edge weights. Weights are assumed to be 0.0 by default.
    • Constructor Detail

      • WeightedDigraph

        public WeightedDigraph​(int vertexCapacity,
                               int edgeCapacity)
        Create weighted directed graph with default edge weight of 0.0 and room for vertexCapicity vertices and edgeCapacity edges.
      • WeightedDigraph

        public WeightedDigraph​(int vertexCapacity,
                               int edgeCapacity,
                               double defaultEdgeWeight)
        Create a weighted directed graph. Use the defaultEdgeWeight for any edges whose weights have not been set.
      • WeightedDigraph

        public WeightedDigraph()
        Default constructor
    • Method Detail

      • inDegree

        public double inDegree​(Vertex v)
        Returns the weighted in-degree of this vertex. The in-degree is the sum of weights of all enges entering this vertex.
        Overrides:
        inDegree in class DirectedGraph
      • outDegree

        public double outDegree​(Vertex v)
        Returns the weighted out-degree of this vertex. The out-degree is the sum of weights of all enges entering this vertex.
        Overrides:
        outDegree in class DirectedGraph
      • selfDegree

        public double selfDegree​(Vertex v)
        Returns the weighted self-degree of this vertex. The self-degree is the sum of weights of all loops at this vertex.
      • degree

        public double degree​(Vertex v)
        Returns the weighted degree of this vertex. The degree is the sum of weights of all edges entering and leaving this vertex.
        Overrides:
        degree in class DirectedGraph
      • getWeight

        public double getWeight​(Edge e)
        Returns the weight of the specified edge.
      • setWeight

        public boolean setWeight​(Edge e,
                                 double value)
        Sets the weight of the specified edge.
      • getDefaultEdgeWeight

        public double getDefaultEdgeWeight()
        Gets the defaultEdgeWeight of this graph specified at creation time.
      • add

        public boolean add​(Edge e)
        Add an edge. If successful (i.e. that edge does not already appear in the graph), set the weight to the default value
        Overrides:
        add in class DirectedGraph
        Returns:
        true if edge added succesfuly.
      • add

        public boolean add​(Edge e,
                           double weight)
        Add an edge. If successful (i.e. that edge does not appear in the graph), then set the weight to the specified value.
        Returns:
        true if edge added succesfuly.
      • getEdgeWeights

        public DoubleAttribute<Edge> getEdgeWeights()
        Get the edge weights for this graph.
      • copy

        public DirectedGraph copy()
        Overrides:
        copy in class DirectedGraph
        Returns:
        A directed graph with the same vertices, edges, and attributes.
      • intersectionWith

        public void intersectionWith​(DirectedGraph otherGraph)
        Creates intersection of graphs in place by adding all vertices and edges of other graph to this graph. This method used to return a different graph as the intersection but now does not.
        Overrides:
        intersectionWith in class DirectedGraph
      • unionWith

        public void unionWith​(DirectedGraph otherGraph)
        Creates union of graphs in place by adding all vertices and edges of other graph to this graph. This method used to return a different graph as the union but now does not.
        Overrides:
        unionWith in class DirectedGraph