Package org.simplegraph.impl
Class WeightedDenseGraph<V>
java.lang.Object
org.simplegraph.impl.WeightedDenseGraph<V>
- All Implemented Interfaces:
WeightedGraph<V>
Dense graph implemention for weighted graphs.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final shortprotected intprotected int -
Constructor Summary
ConstructorsConstructorDescriptionWeightedDenseGraph(int size) WeightedDenseGraph(WeightedDenseGraph<V> graph) -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd an edge between two vertices.protected booleanaddSingleEdge(V v1, V v2, Double edge) booleanAdd a vertex to the graph.booleancontainsVertex(V vertex) Check the existence of a vertex in the graph.protected voidprotected voidcopyVertices(org.simplegraph.impl.BaseDenseGraph<V> graph) intGet the number of edges in the graph.intcountNeighbors(V vertex) Get the number of neighbors for a vertex.intGet the number of vertices in the graph.booleanexistsEdge(V v1, V v2) Check the existence of an edge between the two verticesbooleanexistsPath(V source, V destination) Does a path exists between source and destination.protected intgetEdgeIndex(V v1, V v2) Get index of the edge between v1 and v2.protected intgetEdgesSize(int verticesSize) Get how much edges there are for the size passed.getMinimumDistance(V source, V destination) getNeighbors(V vertex) Get the neighbors of a vertex, both incident and outer vertices.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.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
-
WeightedDenseGraph
public WeightedDenseGraph() -
WeightedDenseGraph
public WeightedDenseGraph(int size) -
WeightedDenseGraph
-
-
Method Details
-
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
-
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 between the two vertices- Parameters:
v1- first vertexv2- second vertex- Returns:
- true if an edge between v1 and v2
-
countNeighbors
Get the number of neighbors for a vertex.- Parameters:
vertex- the spefied vertex- Returns:
- number of neighbors, -1 if vertex does not exists
-
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- source vertexdestination- destination vertex- Returns:
- a list containing the vertices that compose the path, in order; an empty list if there is no path, null if the source and the destination are equals or are not contained in the graph
-
removeEdge
Remove an edge that goes from the first vertex to the second.- Parameters:
v1- first vertexv2- second vertex- Returns:
- true if the graph has been changed
-
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
-
getSpanningTree
- Specified by:
getSpanningTreein interfaceWeightedGraph<V>
-
getMinimumDistance
- Specified by:
getMinimumDistancein interfaceWeightedGraph<V>
-
getShortestPath
- Specified by:
getShortestPathin interfaceWeightedGraph<V>
-
getMinimumSpanningTree
- Specified by:
getMinimumSpanningTreein interfaceWeightedGraph<V>
-
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.
-
getEdgesSize
protected int getEdgesSize(int verticesSize) Get how much edges there are for the size passed.- Parameters:
verticesSize- Number of vertices.- Returns:
- Number of edges based on the number of vertices.
-
addSingleEdge
-
getSingleEdge
-
getEdgeIndex
Get index of the edge between v1 and v2.- Parameters:
v1- first vertexv2- second vertex- Returns:
- index of the edge between v1 and v2
-
countEdges
public int countEdges()Get the number of edges in the graph.- Returns:
- number of edges
-
_getSpanningTree
-
getShortestPath
-
copyVertices
-
getVertexIndex
Get index of the vertex.- Parameters:
vertex- Selected vertex.- Returns:
- Index of the selected vertex.
-