Class IncidenceMatrixSparseUndirectedSpecifics
- All Implemented Interfaces:
SparseGraphSpecifics
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CSRBooleanMatrix
protected int[]
protected int[]
protected static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlong
Returns the degree of the specified vertex.long
Get the number of edges.Returns a set of all edges touching the specified vertex.getAllEdges
(Integer sourceVertex, Integer targetVertex) Returns a set of all edges connecting source vertex to target vertex if such vertices exist in this graph.Returns an edge connecting source vertex to target vertex if such vertices and such edge exist in this graph.Returns the source vertex of an edge.Returns the target vertex of an edge.getType()
Get the graph type.incomingEdgesOf
(Integer vertex) Returns a set of all edges incoming into the specified vertex.long
inDegreeOf
(Integer vertex) Returns the "in degree" of the specified vertex.long
outDegreeOf
(Integer vertex) Returns the "out degree" of the specified vertex.outgoingEdgesOf
(Integer vertex) Returns a set of all edges outgoing from the specified vertex.long
Get the number of verticesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jgrapht.opt.graph.sparse.specifics.SparseGraphSpecifics
assertEdgeExist, assertVertexExist, containsEdge, containsVertex, edgeSet, getEdgeWeight, setEdgeWeight, vertexSet
-
Field Details
-
UNMODIFIABLE
- See Also:
-
incidenceMatrix
-
source
protected int[] source -
target
protected int[] target
-
-
Constructor Details
-
IncidenceMatrixSparseUndirectedSpecifics
public IncidenceMatrixSparseUndirectedSpecifics(int numVertices, int numEdges, Supplier<Stream<Pair<Integer, Integer>>> edges) Create a new graph from an edge stream- Parameters:
numVertices
- number of verticesnumEdges
- number of edgesedges
- a supplier of an edge stream
-
-
Method Details
-
edgesCount
public long edgesCount()Description copied from interface:SparseGraphSpecifics
Get the number of edges.- Specified by:
edgesCount
in interfaceSparseGraphSpecifics
- Returns:
- the number of edges
-
verticesCount
public long verticesCount()Description copied from interface:SparseGraphSpecifics
Get the number of vertices- Specified by:
verticesCount
in interfaceSparseGraphSpecifics
- Returns:
- the number of vertices
-
degreeOf
Description copied from interface:SparseGraphSpecifics
Returns the degree of the specified vertex.A degree of a vertex in an undirected graph is the number of edges touching that vertex. Edges with same source and target vertices (self-loops) are counted twice.
In directed graphs this method returns the sum of the "in degree" and the "out degree".
- Specified by:
degreeOf
in interfaceSparseGraphSpecifics
- Parameters:
vertex
- vertex whose degree is to be calculated.- Returns:
- the degree of the specified vertex.
-
edgesOf
Description copied from interface:SparseGraphSpecifics
Returns a set of all edges touching the specified vertex. If no edges are touching the specified vertex returns an empty set.- Specified by:
edgesOf
in interfaceSparseGraphSpecifics
- Parameters:
vertex
- the vertex for which a set of touching edges is to be returned.- Returns:
- a set of all edges touching the specified vertex.
-
inDegreeOf
Description copied from interface:SparseGraphSpecifics
Returns the "in degree" of the specified vertex.The "in degree" of a vertex in a directed graph is the number of inward directed edges from that vertex. See http://mathworld.wolfram.com/Indegree.html.
In the case of undirected graphs this method returns the number of edges touching the vertex. Edges with same source and target vertices (self-loops) are counted twice.
- Specified by:
inDegreeOf
in interfaceSparseGraphSpecifics
- Parameters:
vertex
- vertex whose degree is to be calculated.- Returns:
- the degree of the specified vertex.
-
incomingEdgesOf
Description copied from interface:SparseGraphSpecifics
Returns a set of all edges incoming into the specified vertex.In the case of undirected graphs this method returns all edges touching the vertex, thus, some of the returned edges may have their source and target vertices in the opposite order.
- Specified by:
incomingEdgesOf
in interfaceSparseGraphSpecifics
- Parameters:
vertex
- the vertex for which the list of incoming edges to be returned.- Returns:
- a set of all edges incoming into the specified vertex.
-
outDegreeOf
Description copied from interface:SparseGraphSpecifics
Returns the "out degree" of the specified vertex.The "out degree" of a vertex in a directed graph is the number of outward directed edges from that vertex. See http://mathworld.wolfram.com/Outdegree.html.
In the case of undirected graphs this method returns the number of edges touching the vertex. Edges with same source and target vertices (self-loops) are counted twice.
- Specified by:
outDegreeOf
in interfaceSparseGraphSpecifics
- Parameters:
vertex
- vertex whose degree is to be calculated.- Returns:
- the degree of the specified vertex.
-
outgoingEdgesOf
Description copied from interface:SparseGraphSpecifics
Returns a set of all edges outgoing from the specified vertex.In the case of undirected graphs this method returns all edges touching the vertex, thus, some of the returned edges may have their source and target vertices in the opposite order.
- Specified by:
outgoingEdgesOf
in interfaceSparseGraphSpecifics
- Parameters:
vertex
- the vertex for which the list of outgoing edges to be returned.- Returns:
- a set of all edges outgoing from the specified vertex.
-
getType
Description copied from interface:SparseGraphSpecifics
Get the graph type. The graph type can be used to query for additional metadata such as whether the graph supports directed or undirected edges, self-loops, multiple (parallel) edges, weights, etc.- Specified by:
getType
in interfaceSparseGraphSpecifics
- Returns:
- the graph type
-
getEdgeSource
Description copied from interface:SparseGraphSpecifics
Returns the source vertex of an edge. For an undirected graph, source and target are distinguishable designations (but without any mathematical meaning).- Specified by:
getEdgeSource
in interfaceSparseGraphSpecifics
- Parameters:
e
- edge of interest- Returns:
- source vertex
-
getEdgeTarget
Description copied from interface:SparseGraphSpecifics
Returns the target vertex of an edge. For an undirected graph, source and target are distinguishable designations (but without any mathematical meaning).- Specified by:
getEdgeTarget
in interfaceSparseGraphSpecifics
- Parameters:
e
- edge of interest- Returns:
- target vertex
-
getEdge
Returns an edge connecting source vertex to target vertex if such vertices and such edge exist in this graph. Otherwise returnsnull
. If any of the specified vertices isnull
returnsnull
In undirected graphs, the returned edge may have its source and target vertices in the opposite order.
This operation costs $O(d)$ where $d$ is the degree of the source vertex.- Specified by:
getEdge
in interfaceSparseGraphSpecifics
- Parameters:
sourceVertex
- source vertex of the edge.targetVertex
- target vertex of the edge.- Returns:
- an edge connecting source vertex to target vertex.
-
getAllEdges
Returns a set of all edges connecting source vertex to target vertex if such vertices exist in this graph. If any of the vertices does not exist or isnull
, returnsnull
. If both vertices exist but no edges found, returns an empty set.In undirected graphs, some of the returned edges may have their source and target vertices in the opposite order. In simple graphs the returned set is either singleton set or empty set.
This operation costs $O(d)$ where $d$ is the degree of the source vertex.- Specified by:
getAllEdges
in interfaceSparseGraphSpecifics
- Parameters:
sourceVertex
- source vertex of the edge.targetVertex
- target vertex of the edge.- Returns:
- a set of all edges connecting source vertex to target vertex.
-