Class SimpleWeightedDigraph


  • public class SimpleWeightedDigraph
    extends WeightedDigraph
    A simple graph is a graph with no parallel edges or loops. This class models a simple digraph -- edges are directed and a single edge may go from any vertex to any other vertex. It is possible to have edges A-->B and B-->A however. Attempting to add an edge from A to B when an edge from A to B already exists causes the edge weight to be increased by the defaultEdgeWeight or the weight specified. This class may be used when simple unweighted graphs are desired. (Simply ignore edge weights.)
    • Constructor Detail

      • SimpleWeightedDigraph

        public SimpleWeightedDigraph​(int vertexCapacity,
                                     int edgeCapacity,
                                     double defaultEdgeWeight,
                                     boolean loopsAllowed)
        Constructor for SimpleWeightedDigraph.
        Parameters:
        vertexCapacity - initially allocate space for this many vertices.
        edgeCapacity - initially allocate space for this many edges.
        defaultEdgeWeight - edges are given this weight at creation time by default. the default is 1.0 for constructors where not specified.
        loopsAllowed - Loops are allowed in the graph if this value set true in constructor. Default value is false. If vertex weights are desired, the class can either be extended or a vertex attribute can be defined using the code DoubleAttribute vertexWeights = (DoubleAttribute)this.vertexAttributes().createAttribute("weight", AttributeManager.DOUBLE_TYPE);
      • SimpleWeightedDigraph

        public SimpleWeightedDigraph​(int vertexCapacity,
                                     int edgeCapacity,
                                     double defaultEdgeWeight)
        Constructor for SimpleWeightedDigraph. AllowLoops is false by default.
        Parameters:
        vertexCapacity -
        edgeCapacity -
        defaultEdgeWeight -
      • SimpleWeightedDigraph

        public SimpleWeightedDigraph​(int vertexCapacity,
                                     int edgeCapacity)
        Constructor for SimpleWeightedDigraph. AllowLoops is false by default. The defaultEdgeWeight is 1.0.
        Parameters:
        vertexCapacity -
        edgeCapacity -
    • Method Detail

      • add

        public boolean add​(Edge e)
        Add an edge with the the default edge weight. If an edge from and to the vertices specified by the edge already exists in the graph, then the edge weight in increased by the default value.
        Overrides:
        add in class WeightedDigraph
        Parameters:
        e - the edge to add.
        Returns:
        true if the edge was added sucessfully.
      • add

        public boolean add​(Edge e,
                           double weight)
        Add an edge with the the specified edge weight. If an edge from and to the vertices specified by the edge already exists in the graph, then the edge weight in increased by the specified value.
        Overrides:
        add in class WeightedDigraph
        Returns:
        true if the edge was added sucessfully.
      • remove

        public boolean remove​(Edge e)
        Description copied from class: DirectedGraph
        Removes Edge e from the graph. No effect if the edge is not in the graph.
        Overrides:
        remove in class DirectedGraph