API reference
Index
SimpleWeightedGraphs.SimpleWeightedGraphs
SimpleWeightedGraphs.AbstractSimpleWeightedEdge
SimpleWeightedGraphs.AbstractSimpleWeightedGraph
SimpleWeightedGraphs.SWGFormat
SimpleWeightedGraphs.SimpleWeightedDiGraph
SimpleWeightedGraphs.SimpleWeightedDiGraphEdge
SimpleWeightedGraphs.SimpleWeightedEdge
SimpleWeightedGraphs.SimpleWeightedEdge
SimpleWeightedGraphs.SimpleWeightedEdge
SimpleWeightedGraphs.SimpleWeightedEdge
SimpleWeightedGraphs.SimpleWeightedEdge
SimpleWeightedGraphs.SimpleWeightedGraph
SimpleWeightedGraphs.SimpleWeightedGraphEdge
SimpleWeightedGraphs.WDiGraph
SimpleWeightedGraphs.WGraph
Base.getindex
Base.getindex
Base.getindex
Base.getindex
Graphs.LinAlg.adjacency_matrix
Graphs.LinAlg.laplacian_matrix
Graphs.SimpleGraphs.add_edge!
Graphs.SimpleGraphs.add_edge!
Graphs.SimpleGraphs.add_edge!
Graphs.SimpleGraphs.rem_edge!
Graphs.SimpleGraphs.rem_edge!
Graphs.SimpleGraphs.rem_edge!
Graphs.SimpleGraphs.rem_vertex!
Graphs.SimpleGraphs.rem_vertex!
Graphs.cartesian_product
Graphs.connected_components
Graphs.has_edge
Graphs.has_edge
Graphs.induced_subgraph
Graphs.inneighbors
Graphs.loadgraph
Graphs.loadgraphs
Graphs.outneighbors
Graphs.pagerank
Graphs.savegraph
Graphs.savegraph
Graphs.savegraph
Graphs.savegraph
Graphs.savegraph
Graphs.weights
Graphs.weights
SimpleWeightedGraphs._get_nz_index!
SimpleWeightedGraphs.degree_matrix
SimpleWeightedGraphs.get_weight
SimpleWeightedGraphs.loadswg
SimpleWeightedGraphs.loadswg_mult
SimpleWeightedGraphs.saveswg
SimpleWeightedGraphs.saveswg_mult
SimpleWeightedGraphs.weight
SimpleWeightedGraphs.weighttype
Docstrings
SimpleWeightedGraphs.SimpleWeightedGraphs
— ModuleSimpleWeightedGraphs
A package for graphs with edge weights and no self-loops, stored as sparse adjacency matrices.
SimpleWeightedGraphs.AbstractSimpleWeightedEdge
— TypeAbstractSimpleWeightedEdge{T}
Abstract type for weighted edges with endpoints of type T
.
SimpleWeightedGraphs.AbstractSimpleWeightedGraph
— TypeAbstractSimpleWeightedGraph
An abstract type representing a simple graph structure with edge weights.
The only requirement for concrete subtypes is that they should implement a method Graphs.weights(g)
which returns the weighted adjacency matrix.
SimpleWeightedGraphs.SWGFormat
— TypeSWGFormat
The storage format of SimpleWeightedGraph files. Multiple graphs may be present in one file.
For each graph, the file contains a one line header:
"LightGraphs.SimpleWeightedGraph", <num_vertices>, <num_edges>, {"d" | "u"}, <name>[, <ver>, <vdatatype>, <wdatatype>, <graphcode>]
"LightGraphs.SimpleWeightedGraph"
is a fixed string<num_vertices>
is an integer<num_edges>
is an integer"d"
for directed graph,"u"
for undirected (note that this option does not perform any additional edge construction, it's merely used to return the correct type of graph)<name>
is a string<ver>
is an int<vdatatype>
is a string ("UInt8", etc.)<wdatatype>
is a string describing the data type of the weights<graphcode>
is a string.
The header is followed by a list of (comma-delimited) edges, each on a separate line:
<src>,<dst>,<weight>
<src>
is an int giving the source of the edge<dst>
is an int giving the destination of the edge<weight>
is a real giving the weight of the edge
SimpleWeightedGraphs.SimpleWeightedDiGraph
— TypeSimpleWeightedDiGraph{T,U}
A type representing a directed weighted graph with vertices of type T
and edge weights of type U
.
Fields
weights::SparseMatrixCSC{U,T}
: weighted adjacency matrix, indexed by(dst, src)
Iteratively adding/removing vertices or edges is not very efficient for this type of graph: better construct the graph in one shot if possible.
Basic constructors
SimpleWeightedDiGraph() # empty
SimpleWeightedDiGraph(n) # n vertices, no edges
SimpleWeightedDiGraph(graph) # from graph
SimpleWeightedDiGraph(adjmx; permute) # from adjacency matrix, possibly transposed
SimpleWeightedDiGraph(sources, destinations, weights) # from list of edges
Use methods(SimpleWeightedDiGraph)
for the full list of constructors. When building a new graph from a list of edges, be aware that repeating (src, dst)
pairs may lead to undefined behavior (e.g. due to floating point errors during weight addition).
SimpleWeightedGraphs.SimpleWeightedDiGraphEdge
— TypeSimpleWeightedDiGraphEdge
Alias for SimpleWeightedEdge
.
SimpleWeightedGraphs.SimpleWeightedEdge
— TypeSimpleWeightedEdge{T,U}
Concrete struct for a weighted edge with endpoints of type T
and a weight of type U<:Real
.
Fields
src::T
: edge sourcedst::T
: edge destinationweight::U
: edge weight
SimpleWeightedGraphs.SimpleWeightedEdge
— MethodSimpleWeightedEdge(u, v)
Construct a SimpleWeightedEdge
from u
to v
with a default weight of 1.0.
SimpleWeightedGraphs.SimpleWeightedEdge
— MethodSimpleWeightedEdge(u => v)
Construct a SimpleWeightedEdge
from u
to v
with a default weight of 1.0.
SimpleWeightedGraphs.SimpleWeightedEdge
— MethodSimpleWeightedEdge((u, v, w))
Construct a SimpleWeightedEdge
from u
to v
with a weight of w
.
SimpleWeightedGraphs.SimpleWeightedEdge
— MethodSimpleWeightedEdge((u, v))
Construct a SimpleWeightedEdge
from u
to v
with a default weight of 1.0.
SimpleWeightedGraphs.SimpleWeightedGraph
— TypeSimpleWeightedGraph{T, U}
A type representing an undirected weighted graph with vertices of type T
and edge weights of type U
.
Fields
weights::SparseMatrixCSC{U,T}
: weighted adjacency matrix, indexed by(dst, src)
Iteratively adding/removing vertices or edges is not very efficient for this type of graph: better construct the graph in one shot if possible.
Basic constructors
SimpleWeightedGraph() # empty
SimpleWeightedGraph(n) # n vertices, no edges
SimpleWeightedGraph(graph) # from graph
SimpleWeightedGraph(adjmx) # from adjacency matrix
SimpleWeightedGraph(sources, destinations, weights) # from list of edges
Use methods(SimpleWeightedGraph)
for the full list of constructors. When building a new graph from a list of edges, be aware that repeating (src, dst)
pairs may lead to undefined behavior (e.g. due to floating point errors during weight addition).
SimpleWeightedGraphs.SimpleWeightedGraphEdge
— TypeSimpleWeightedGraphEdge
Alias for SimpleWeightedEdge
.
SimpleWeightedGraphs.WDiGraph
— TypeWDiGraph
Alias for SimpleWeightedDiGraph
.
SimpleWeightedGraphs.WGraph
— TypeWGraph
Alias for SimpleWeightedGraph
.
Base.getindex
— Methodg[e, Val(:weight)]
Return the weight of edge e
.
Base.getindex
— Methodg[i, j, Val(:weight)]
Return the weight of edge (i, j)
.
Base.getindex
— Methodg[e, :weight]
Return the weight of edge e
.
Base.getindex
— Methodg[i, j, :weight]
Return the weight of edge (i, j)
.
Graphs.LinAlg.adjacency_matrix
— FunctionGraphs.adjacency_matrix(g, T; dir)
Construct the weighted adjacency matrix, filled with element type T
and considering edge direction dir ∈ [:in, :out, :both]
(default is :out
).
Graphs.LinAlg.laplacian_matrix
— FunctionGraphs.laplacian_matrix(g, T; dir)
Subtract the adjacency matrix to the degree matrix, both filled with element type T
and considering edge direction dir ∈ [:in, :out, :both]
(unlike in Graphs.jl, default is :out
).
Graphs.SimpleGraphs.add_edge!
— MethodGraphs.add_edge!(g, u, v, w)
Add the edge (u, v)
to the graph with a weight of w
.
Graphs.SimpleGraphs.add_edge!
— MethodGraphs.add_edge!(g, u, v)
Add the edge (u, v)
to the graph with a default weight of 1.
Graphs.SimpleGraphs.add_edge!
— MethodGraphs.add_edge!(g, e)
Add the edge e
to the graph, where e
is any object that can be converted into edgetype(g)
.
Graphs.SimpleGraphs.rem_edge!
— MethodGraphs.rem_edge!(g, e)
Remove the edge e
from the graph.
Graphs.SimpleGraphs.rem_edge!
— MethodGraphs.rem_edge!(g, e)
Remove the edge e
from the graph.
Graphs.SimpleGraphs.rem_edge!
— MethodGraphs.rem_edge!(g, u, v)
Remove the edge (u, v)
from the graph.
Graphs.SimpleGraphs.rem_vertex!
— Methodrem_vertex!(g::SimpleWeightedDiGraph, v)
Remove the vertex v
from graph g
. Return false if removal fails (e.g., if vertex is not in the graph) and true otherwise.
This operation has to be performed carefully if one keeps external data structures indexed by edges or vertices in the graph, since internally the removal results in all vertices with indices greater than v
being shifted down one.
Graphs.SimpleGraphs.rem_vertex!
— Methodrem_vertex!(g::SimpleWeightedGraph, v)
Remove the vertex v
from graph g
. Return false if removal fails (e.g., if vertex is not in the graph) and true otherwise.
This operation has to be performed carefully if one keeps external data structures indexed by edges or vertices in the graph, since internally the removal results in all vertices with indices greater than v
being shifted down one.
Graphs.cartesian_product
— MethodGraphs.cartesian_product(g, h)
Compute the weighted cartesian product of two weighted graphs.
It is possible that this is suboptimal, but it is the most trivial extension of the implementation used in Graphs.jl.
Graphs.connected_components
— MethodGraphs.connected_components(g)
Compute the connected components of a weighted graph. Note that an edge with weight 0
will still be counted as an edge if it exists in the sparse weights matrix.
Graphs.has_edge
— MethodGraphs.has_edge(g, u, v)
Check the existence of the edge (u, v)
in the graph.
Graphs.has_edge
— MethodGraphs.has_edge(g, e)
Check the existence of the edge e
in the graph, where e
is any object that can be converted into edgetype(g)
.
Graphs.induced_subgraph
— MethodGraphs.induced_subgraph(g, vlist)
Compute the weighted subgraph induced by a list of vertices.
Return a tuple containing the new graph and the list of vertices.
Graphs.inneighbors
— MethodGraphs.inneighbors(g::SimpleWeightedDiGraph, v)
Return the vector of inneighbors of vertex v
.
This function is less efficient than inneighbors
for directed weighted graphs (it allocates a new vector).
Graphs.loadgraph
— MethodGraphs.loadgraph(io, gname, SWGFormat())
Return a single graph with name gname
loaded from the IO stream io
using SWGFormat
.
Graphs.loadgraphs
— MethodGraphs.loadgraphs(io, SWGFormat())
Return a dictionary of name => graph
pairs loaded from the IO stream io
using SWGFormat
.
Graphs.outneighbors
— MethodGraphs.outneighbors(g::SimpleWeightedDiGraph, v)
Return the vector of outneighbors of vertex v
.
This function is more efficient than inneighbors
for directed weighted graphs.
Graphs.pagerank
— FunctionGraphs.pagerank(g, α=0.85, n=100, ϵ=1.0e-6)
Apply the page rank algorithm on a weighted graph.
Graphs.savegraph
— FunctionGraphs.savegraph(fn, g, gname)
This function needs to be checked
Graphs.savegraph
— MethodGraphs.savegraph(io, g, SWGFormat())
Write a graph g
with default name "graph"
to the IO stream io
using SWGFormat
, and return 1 (number of graphs written).
Graphs.savegraph
— MethodGraphs.savegraph(io, g, gname, SWGFormat())
Write a graph g
with name gname
to the IO stream io
using SWGFormat
, and return 1 (number of graphs written).
Graphs.savegraph
— MethodGraphs.savegraph(io, d, SWGFormat())
Write a dictionary d
of name => graph
pairs to the IO stream io
using SWGFormat
, and return the number of graphs written.
Graphs.savegraph
— MethodGraphs.savegraph(fn, d)
This function needs to be checked
Graphs.weights
— MethodGraphs.weights(g::SimpleWeightedDiGraph)
Return the weighted adjacency matrix, stored as an Adjoint
.
Graphs.weights
— MethodGraphs.weights(g::SimpleWeightedGraph)
Return the weighted adjacency matrix.
SimpleWeightedGraphs._get_nz_index!
— Method_get_nz_index!(mat::SparseMatrixCSC, i, j)
Return the index in nzval of mat[i, j]
. We assume bounds are already checked
See https://github.com/JuliaSparse/SparseArrays.jl/blob/fa547689947fadd6c2f3d09ddfcb5f26536f18c8/src/sparsematrix.jl#L2492 for implementation
SimpleWeightedGraphs.degree_matrix
— Functiondegree_matrix(g, T; dir)
Construct the weighted diagonal degree matrix, filled with element type T
and considering edge direction dir ∈ [:in, :out, :both]
(default is :out
).
SimpleWeightedGraphs.get_weight
— Methodget_weight(g, u, v)
get_weight(g, e)
Retrieve the weight of edge (u, v)
or e
.
SimpleWeightedGraphs.loadswg
— Methodloadswg(io, gname)
Return a single graph with name gname
loaded from the IO stream io
using SWGFormat
.
SimpleWeightedGraphs.loadswg_mult
— Methodloadswg_mult(io)
Return a dictionary of name => graph
pairs loaded from the IO stream io
using SWGFormat
.
SimpleWeightedGraphs.saveswg
— Methodsaveswg(io, g, gname)
Write a graph g
with name gname
to the IO stream io
using SWGFormat
, and return 1 (number of graphs written).
SimpleWeightedGraphs.saveswg_mult
— Methodsaveswg_mult(io, d)
Write a dictionary d
of name => graph
pairs to the IO stream io
using SWGFormat
, and return the number of graphs written.
SimpleWeightedGraphs.weight
— Methodweight(e)
Return the weight of a weighted edge.
SimpleWeightedGraphs.weighttype
— Methodweighttype(g)
Return the subtype of Real
used to represent edge weights.