Package ghidra.util.graph
Class SimpleWeightedDigraph
- java.lang.Object
-
- ghidra.util.graph.DirectedGraph
-
- ghidra.util.graph.WeightedDigraph
-
- ghidra.util.graph.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 Summary
Constructors Constructor Description SimpleWeightedDigraph(int vertexCapacity, int edgeCapacity)
Constructor for SimpleWeightedDigraph.SimpleWeightedDigraph(int vertexCapacity, int edgeCapacity, double defaultEdgeWeight)
Constructor for SimpleWeightedDigraph.SimpleWeightedDigraph(int vertexCapacity, int edgeCapacity, double defaultEdgeWeight, boolean loopsAllowed)
Constructor for SimpleWeightedDigraph.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Edge e)
Add an edge with the the default edge weight.boolean
add(Edge e, double weight)
Add an edge with the the specified edge weight.DirectedGraph
copy()
double
getWeight(Edge e)
Returns the weight of the specified edge.boolean
remove(Edge e)
Removes Edge e from the graph.-
Methods inherited from class ghidra.util.graph.WeightedDigraph
degree, getDefaultEdgeWeight, getEdgeWeights, inDegree, intersectionWith, outDegree, selfDegree, setWeight, unionWith
-
Methods inherited from class ghidra.util.graph.DirectedGraph
add, areRelatedAs, assignVerticesToStrongComponents, clear, complexityDepth, contains, contains, containsAsSubgraph, copyAll, copyEdge, copyEdgeAttributeValues, copyVertex, copyVertexAttributeValues, descendantsGraph, edgeAttributes, edgeIterator, edges, getAncestors, getChildren, getChildren, getComponentContaining, getComponents, getDescendants, getDescendants, getEdgeArray, getEdgeAttribute, getEdgeProperty, getEdges, getEdges, getEdgeWithKey, getEntryPoints, getIncomingEdges, getLevels, getNeighborhood, getNeighborhood, getOutgoingEdges, getParents, getParents, getReferent, getSinks, getSources, getVertexArray, getVertexAttribute, getVertexProperty, getVertexWithKey, getVertices, getVerticesHavingReferent, getVerticesInContainingComponent, incomingEdges, inducedSubgraph, inValence, join, loopDegree, numEdges, numLoops, numSinks, numSources, numVertices, outgoingEdges, outValence, remove, selfEdges, setEdgeProperty, setVertexProperty, valence, vertexAttributes, vertexIterator, vertices, verticesUnreachableFromSources, verts2referentSet
-
-
-
-
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 classWeightedDigraph
- 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 classWeightedDigraph
- 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 classDirectedGraph
-
getWeight
public double getWeight(Edge e)
Description copied from class:WeightedDigraph
Returns the weight of the specified edge.- Overrides:
getWeight
in classWeightedDigraph
-
copy
public DirectedGraph copy()
- Overrides:
copy
in classWeightedDigraph
- Returns:
- A directed graph with the same vertices, edges, and attributes.
-
-