Graph construction
Graphs.jl provides a number of methods for creating a graph. These include tools for building and modifying graph objects, a wide array of graph generator functions, and the ability to read and write graphs from files (using GraphIO.jl).
Creating graphs
Standard generators
Graphs.jl implements numerous graph generators, including random graph generators, constructors for classic graphs, numerous small graphs with familiar topologies, and random and static graphs embedded in Euclidean space. An empty simple Graph can be constructed using g = SimpleGraph()
and similary g = SimpleDiGraph()
for directed graphs. See Generators for common graphs for a complete list of available templates.
Datasets
Other notorious graphs and integration with the MatrixDepot.jl
package are available in the Datasets
submodule of the companion package LightGraphsExtras.jl. Selected graphs from the Stanford Large Network Dataset Collection may be found in the SNAPDatasets.jl package.
Modifying graphs
Starting from a (possibly empty) graph g
, one can modify it using the following functions:
add_vertex!(g)
adds one vertex tog
add_vertices!(g, n)
addsn
vertices tog
add_edge!(g, s, d)
adds the edge(s, d)
tog
rem_vertex!(g, v)
removes vertexv
fromg
rem_edge!(g, s, d)
removes edge(s, d)
fromg
If an iterator of edges edgelist
is available, then one can directly use SimpleGraphFromIterator(edgelist)
or SimpleDiGraphFromIterator(edgelist)
.
In addition to these core functions, more advanced operators can be found in Operators.