Package org.simplegraph.impl
Class DirectedWeightedDenseGraph<V>
java.lang.Object
org.simplegraph.impl.DirectedWeightedDenseGraph<V>
- All Implemented Interfaces:
DirectedWeightedGraph<V>,WeightedGraph<V>
Dense graph implementation for directed and weighted graphs.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final shortprotected Double[][]protected intprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet a spanning tree if it exists.booleanAdd an edge between two vertices.protected booleanaddSingleEdge(V v1, V v2, Double edge) Add an edge that goes from the first vertex to the second.booleanAdd a vertex to the graph.protected booleanbooleancontainsVertex(V vertex) Check the existence of a vertex in the graph.protected voidCopy constructorprotected voidcopyVertices(org.simplegraph.impl.BaseDenseGraph<V> graph) intGet how many edges the graph contains.intcountNeighbors(V vertex) Get the number of neighbors for a vertex, both incident and outerintGet the number of vertices in the graph.booleanexistsEdge(V v1, V v2) Check the existence of an edge that goes from the first vertex to the second.booleanexistsPath(V source, V destination) Does a path exists between source and destination.intgetInDegree(V vertex) Get the number of incident vertices of a vertex.getInVertices(V vertex) Get the incident vertices of a vertex.getMinimumDistance(V source, V destination) getNeighbors(V vertex) Get the neighbors of a vertex, both incident and outer vertices.intgetOutDegree(V vertex) Get the number of outer vertices of a vertex.getOutVertices(V vertex) Get the outer vertices of a vertex.Get a path between a source and a destinationgetShortestPath(V source, V destination) protected DoublegetSingleEdge(V v1, V v2) protected intgetVertexIndex(V vertex) Get index of the vertex.Get all the vertices in the graphGet the edge between two verticesvoidgrow(int newSize) Grow the graph size to the specified sizeprotected voidinitialize(int startSize) Initialize all attributes for storing graph data.booleanremoveEdge(V v1, V v2) Remove an edge that goes from the first vertex to the second.booleanremoveVertex(V vertex) Remove a vertex from the graphMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.simplegraph.DirectedWeightedGraph
getInDegree, getInVertices, getOutDegree, getOutVerticesMethods inherited from interface org.simplegraph.WeightedGraph
countEdges
-
Field Details
-
edges
-
DEFAULT_SIZE
protected static final short DEFAULT_SIZE- See Also:
-
size
protected int size -
verticesCount
protected int verticesCount -
verticesArray
-
verticesMap
-
-
Constructor Details
-
DirectedWeightedDenseGraph
public DirectedWeightedDenseGraph() -
DirectedWeightedDenseGraph
public DirectedWeightedDenseGraph(int size) -
DirectedWeightedDenseGraph
-
-
Method Details
-
addVertex
Add a vertex to the graph.- Parameters:
vertex- the vertex to add- Returns:
- true if the the graph has been modified
-
containsVertex
Check the existence of a vertex in the graph.- Parameters:
vertex- the vertex to check- Returns:
- true if the graph contains vertex
-
countVertices
public int countVertices()Get the number of vertices in the graph.- Returns:
- number of vertices
-
existsPath
Does a path exists between source and destination.- Parameters:
source- source vertexdestination- destination vertex- Returns:
- true if a path exists
-
existsEdge
Check the existence of an edge that goes from the first vertex to the second.- Parameters:
v1- first vertexv2- second vertex- Returns:
- true if an edge from v1 to v2 exists
-
countNeighbors
Get the number of neighbors for a vertex, both incident and outer- Parameters:
vertex- the specified vertex- Returns:
- number of neighbors, -1 if vertex is not contained in graph
-
getNeighbors
Get the neighbors of a vertex, both incident and outer vertices.- Parameters:
vertex- the specified vertex- Returns:
- the list of vertices that are neighbors of vertex null if the vertex is not contained in the graph
-
getPath
Get a path between a source and a destination- Parameters:
source- The vertex from where the path shall begindestination- The vertex from where the path shall end- Returns:
- Ordered list of the vertices that form a path between source and destination, null if source and destination are the same or if they are not contained in the graph, an empty LinkedList if there is no path between them
-
removeEdge
Remove an edge that goes from the first vertex to the second.- Parameters:
v1- first vertexv2- second vertex- Returns:
- true if an edge from v1 to v2 exists
-
removeVertex
Remove a vertex from the graph- Parameters:
vertex- the vertex to remove- Returns:
- true if the graph has been modified
-
getVertices
Get all the vertices in the graph- Returns:
- a List containing all the graph vertices
-
addEdge
Description copied from interface:WeightedGraphAdd an edge between two vertices. Add the two vertices in the graph if they don't exists- Specified by:
addEdgein interfaceWeightedGraph<V>- Parameters:
v1- first vertexv2- second vertex- Returns:
- true if the graph has been modified
-
getWeight
Description copied from interface:WeightedGraphGet the edge between two vertices- Specified by:
getWeightin interfaceWeightedGraph<V>- Parameters:
v1- first vertexv2- second vertex- Returns:
- the edge between v1 and v2, if it exists, null otherwise
-
getSpanningTree
- Specified by:
getSpanningTreein interfaceWeightedGraph<V>
-
getMinimumDistance
- Specified by:
getMinimumDistancein interfaceWeightedGraph<V>
-
getShortestPath
- Specified by:
getShortestPathin interfaceWeightedGraph<V>
-
getMinimumSpanningTree
- Specified by:
getMinimumSpanningTreein interfaceDirectedWeightedGraph<V>- Specified by:
getMinimumSpanningTreein interfaceWeightedGraph<V>
-
copy
Copy constructor- Parameters:
graph- graph to copy
-
initialize
protected void initialize(int startSize) Initialize all attributes for storing graph data.- Parameters:
startSize- Number of vertices to store initially in the graph.
-
grow
public void grow(int newSize) Grow the graph size to the specified size- Parameters:
newSize- New size for the graph.
-
addSingleEdge
Add an edge that goes from the first vertex to the second. Add the two vertices in the graph if they don't exists.- Parameters:
v1- first vertexv2- second vertexedge- edge to add- Returns:
- true if the graph has been modified
-
getSingleEdge
-
countEdges
public int countEdges()Get how many edges the graph contains.- Returns:
- number of edges
-
checkEdge
-
getInVertices
Get the incident vertices of a vertex.- Parameters:
vertex- the specified vertex- Returns:
- a LinkedList containing the incident vertices of vertex, null if vertex is not contained in the graph
-
getOutVertices
Get the outer vertices of a vertex.- Parameters:
vertex- the specified vertex- Returns:
- a list containing the outer vertices of vertex, null if vertex is not contained in the graph
-
getInDegree
Get the number of incident vertices of a vertex.- Parameters:
vertex- the specified vertex- Returns:
- the number of incident vertices of vertex, -1 if vertex is not contained in the graph
-
getOutDegree
Get the number of outer vertices of a vertex.- Parameters:
vertex- the specified vertex- Returns:
- the number of outer vertices of vertex, -1 if vertex is not contained in the graph
-
_getSpanningTree
Get a spanning tree if it exists.- Returns:
- Graph containing a spanning tree if it exists, null otherwise.
-
copyVertices
-
getVertexIndex
Get index of the vertex.- Parameters:
vertex- Selected vertex.- Returns:
- Index of the selected vertex.
-