Package com.jgalgo.graph
A graph is a collection of vertices (nodes) and edges (links) between them. The edges may be directed or undirected.
The Graph
object represent a graph, in which vertices and edges are hashable identifiers.
Vertices can be added or removed to/from a graph, and edges can be added or removed between vertices. The
Graph
object also provides methods to query the graph, such as the number of vertices and
edges, and whether a vertex is connected to another vertex, the out-edges or in-edges of a vertex, etc.
Weights can be associated with the vertices or edges of a graph, and the Graph
object
provides methods to add or remove weights to it. When a weight is added to the vertices, it is added to all
vertices of the graph. The weights can be an Object
or any other primitive such as int
,
double
, etc. When weights are added to a graph via the
Graph.addVerticesWeights(String, Class)
or
Graph.addEdgesWeights(String, Class)
methods, a Weights
object is
created and return, which allow setting and getting the weights values by vertex/edge identifier. If the weights type
is primitive, a specific subclass of Weights
such as WeightsInt
,
WeightsDouble
, etc. is returned. These specific primitive weights containers avoid the
overhead of boxing and unboxing primitive values.
Each Graph
object expose an IndexGraph
via the
Graph.indexGraph()
method. An index graph is a graph in which the identifiers of the
vertices are always in the range [0, n)
, where n
is the number of vertices in the graph, and the
identifiers of the edges are always in the range [0, m)
, where m
is the number of edges in the graph.
Index graphs are much more efficient than regular graphs, as simple arrays are enough to store the data (internal and
additional weights) associated with the vertices/edges. When a vertex or edge is removed from an index graph, some
identifiers may change, as it must maintain the invariant that the identifiers are always in the range [0, n)
and [0, m)
. This makes the index graph less convenient to use, but much more efficient. The default graph
implementation uses an index graph internally, and expose it via the Graph.indexGraph()
method. Good written algorithms should accept a regular graph, retrieve its index graph, perform the heavy
computation on the index graph, and translate back the result to the regular graph identifiers. Index graphs should
rarely be used directly by a user.
-
Interface Summary Interface Description EdgeIter<V,E> Iterator used to iterate over graph edges.EdgeSet<V,E> Set of graph edges.Graph<V,E> A discrete graph with vertices and edges.GraphBuilder<V,E> A builder for graphs.GraphFactory<V,E> A factory forGraph
objects.IdBuilder<K> Builder for unique identifiers of vertices or edges in a graph.IdBuilderInt Builder for unique identifiers of vertices or edges in anIntGraph
.IEdgeIter Iterator used to iterate over int graph edges.IEdgeSet Set of int graph edges.IndexGraph A graph whose vertices and edges identifiers are indices.IndexGraphBuilder A builder for Index graphs.IndexGraphBuilder.ReIndexedGraph A result object of re-indexing and building a graph operation.IndexGraphBuilder.ReIndexingMap A map of indices, mapping an original index to a re-indexed index.IndexGraphFactory A factory for Index graphs.IndexIdMap<K> A mapping betweenGraph
IDs toIndexGraph
indices.IndexIntIdMap A mapping betweenIntGraph
IDs toIndexGraph
indices.IndexRemoveListener A listener that will be notified when anIndexGraph
remove a vertex or an edge.IntGraph A discrete graph withint
vertices and edges.IntGraphBuilder A builder for int graphs.IntGraphFactory A factory forIntGraph
objects.IWeightFunction Weight function that maps graph edges or vertices ofIntGraph
to weights.IWeightFunctionInt Weight function that maps graph edges or vertices ofIntGraph
to integer weights.IWeights<T> Weights of int graph vertices or edges.IWeightsBool Specific weights ofboolean
for int graphs.IWeightsByte Specific weights ofbyte
for int graphs.IWeightsChar Specific weights ofchar
for int graphs.IWeightsDouble Specific weights ofdouble
for int graphs.IWeightsFloat Specific weights offloat
for int graphs.IWeightsInt Specific weights ofint
for int graphs.IWeightsLong Specific weights oflong
for int graphs.IWeightsObj<T> Specific weights ofObject
for int graphs.IWeightsShort Specific weights ofshort
for int graphs.WeightFunction<K> Weight function that maps graph edges or vertices to weights.WeightFunctionInt<K> Weight function that maps graph edges or vertices to integer weights.Weights<K,T> Weights of graph vertices or edges.WeightsBool<K> Specific weights ofboolean
.WeightsByte<K> Specific weights ofbyte
.WeightsChar<K> Specific weights ofchar
.WeightsDouble<K> Specific weights ofdouble
.WeightsFloat<K> Specific weights offloat
.WeightsInt<K> Specific weights ofint
.WeightsLong<K> Specific weights oflong
.WeightsObj<K,T> Specific weights ofObject
.WeightsShort<K> Specific weights ofshort
. -
Class Summary Class Description AbstractGraph<V,E> Abstract implementation ofGraph
.Graphs Static methods class for graphs.IndexIdMaps Static methods class for index-id maps.WeightFunctions Static methods class for weight functions. -
Enum Summary Enum Description GraphFactory.Hint Hints for a graph factory. -
Exception Summary Exception Description NoSuchEdgeException Exception thrown when an edge is not found in a graph.NoSuchVertexException Exception thrown when a vertex is not found in a graph.