public class Graph<V extends SequenceElement,E extends Number> extends Object implements IGraph<V,E>
| Constructor and Description |
|---|
Graph() |
Graph(Collection<V> elements,
boolean allowMultipleEdges) |
Graph(int numVertices,
boolean allowMultipleEdges,
VertexFactory<V> vertexFactory) |
Graph(int numVertices,
VertexFactory<V> vertexFactory) |
Graph(List<Vertex<V>> vertices) |
Graph(List<Vertex<V>> vertices,
boolean allowMultipleEdges) |
| Modifier and Type | Method and Description |
|---|---|
void |
addEdge(Edge<E> edge)
Add an edge to the graph.
|
void |
addEdge(int from,
int to,
E value,
boolean directed)
Convenience method for adding an edge (directed or undirected) to graph
|
void |
addVertex(Vertex<V> vertex,
Collection<Edge<E>> edges) |
void |
addVertex(Vertex<V> vertex,
Edge<E> edge) |
boolean |
equals(Object o) |
int[] |
getConnectedVertexIndices(int vertex)
Return an array of indexes of vertices that the specified vertex is connected to.
Specifically, for undirected graphs return int[] of all X.vertexID() such that (vertex -- X) exists For directed graphs, return int[] of all X.vertexID() such that (vertex -> X) exists |
List<Vertex<V>> |
getConnectedVertices(int vertex)
Get a list of all of the vertices that the specified vertex is connected to
Specifically, for undirected graphs return list of all X such that (vertex -- X) exists For directed graphs, return list of all X such that (vertex -> X) exists |
List<Edge<E>> |
getEdgesOut(int vertex)
Returns a list of edges for a vertex with a given index
For undirected graphs, returns all edges incident on the vertex
For directed graphs, only returns outward directed edges
|
Vertex<V> |
getRandomConnectedVertex(int vertex,
Random rng)
Randomly sample a vertex connected to a given vertex.
|
Vertex<V> |
getVertex(int idx)
Get a vertex in the graph for a given index
|
int |
getVertexDegree(int vertex)
Returns the degree of the vertex.
For undirected graphs, this is just the degree. For directed graphs, this returns the outdegree |
List<Vertex<V>> |
getVertices(int[] indexes)
Get multiple vertices in the graph
|
List<Vertex<V>> |
getVertices(int from,
int to)
Get multiple vertices in the graph, with secified indices
|
int |
hashCode() |
int |
numVertices()
Number of vertices in the graph
|
String |
toString() |
public Graph(int numVertices,
VertexFactory<V> vertexFactory)
public Graph(int numVertices,
boolean allowMultipleEdges,
VertexFactory<V> vertexFactory)
public Graph(Collection<V> elements, boolean allowMultipleEdges)
public Graph()
public void addVertex(Vertex<V> vertex, Collection<Edge<E>> edges)
public int numVertices()
IGraphnumVertices in interface IGraph<V extends SequenceElement,E extends Number>public Vertex<V> getVertex(int idx)
IGraphpublic List<Vertex<V>> getVertices(int[] indexes)
IGraphgetVertices in interface IGraph<V extends SequenceElement,E extends Number>indexes - the indexes of the vertices to retrievepublic List<Vertex<V>> getVertices(int from, int to)
IGraphgetVertices in interface IGraph<V extends SequenceElement,E extends Number>from - first vertex to get, inclusiveto - last vertex to get, inclusivepublic void addEdge(Edge<E> edge)
IGraphpublic void addEdge(int from,
int to,
E value,
boolean directed)
public List<Edge<E>> getEdgesOut(int vertex)
IGraphgetEdgesOut in interface IGraph<V extends SequenceElement,E extends Number>vertex - index of the vertex topublic int getVertexDegree(int vertex)
IGraphgetVertexDegree in interface IGraph<V extends SequenceElement,E extends Number>vertex - vertex to get degree forpublic Vertex<V> getRandomConnectedVertex(int vertex, Random rng) throws NoEdgesException
IGraphgetRandomConnectedVertex in interface IGraph<V extends SequenceElement,E extends Number>vertex - vertex to randomly sample fromrng - Random number generator to useNoEdgesException - thrown if the specified vertex has no edges, or no outgoing edges (in the case
of a directed graph).public List<Vertex<V>> getConnectedVertices(int vertex)
IGraphgetConnectedVertices in interface IGraph<V extends SequenceElement,E extends Number>vertex - Index of the vertexpublic int[] getConnectedVertexIndices(int vertex)
IGraphgetConnectedVertexIndices in interface IGraph<V extends SequenceElement,E extends Number>vertex - index of the vertexIGraph.getConnectedVertices(int)Copyright © 2022. All rights reserved.