API reference
Docstrings
MetaGraphsNext.MetaGraphsNext
— ModuleMetaGraphsNext
A package for graphs with vertex labels and metadata in Julia. Its main export is the MetaGraph
type.
MetaGraphsNext.DOTFormat
— Typestruct DOTFormat <: AbstractGraphFormat end
If all metadata types support pairs
or are Nothing
, you can save MetaGraph
s in DOTFormat
.
MetaGraphsNext.MGFormat
— Typestruct MGFormat <: AbstractGraphFormat end
You can save MetaGraph
s in a MGFormat
, currently based on JLD2
.
MetaGraphsNext.MetaGraph
— TypeMetaGraph{
Code<:Integer,
Graph<:AbstractGraph{Code},
Label,
VertexData,
EdgeData,
GraphData,
WeightFunction,
Weight
} <: AbstractGraph{Code}
A graph type with custom vertex labels containing vertex-, edge- and graph-level metadata.
Vertex labels have type Label
, while vertex (resp. edge, resp. graph) metadata has type VertexData
(resp. EdgeData
, resp. GraphData
). It is recommended not to set Label
to an integer type, so as to avoid confusion between vertex labels (which do not change as the graph evolves) and vertex codes (which have type Code<:Integer
and can change as the graph evolves).
Fields
graph::Graph
: underlying, data-less graph with vertex codes of typeCode
vertex_labels::Dict{Code,Label}
: dictionary mapping vertex codes to vertex labelsvertex_properties::Dict{Label,Tuple{Code,VertexData}}
: dictionary mapping vertex labels to vertex codes & metadataedge_data::Dict{Tuple{Label,Label},EdgeData}
: dictionary mapping edge labels such as(label_u, label_v)
to edge metadatagraph_data::GraphData
: metadata for the graph object as a wholeweight_function::WeightFunction
: function computing edge weight from edge metadata, its output must have the same type asdefault_weight
default_weight::Weight
: default weight used when an edge doesn't exist
MetaGraphsNext.MetaGraph
— MethodMetaGraph(
graph;
label_type,
vertex_data_type=Nothing,
edge_data_type=Nothing,
graph_data=nothing,
weight_function=edge_data -> 1.0,
default_weight=1.0
)
Construct an empty MetaGraph
based on an empty graph
, initializing storage with metadata types given as keyword arguments.
This constructor uses keyword arguments for convenience, which means it is type-unstable.
MetaGraphsNext.MetaGraph
— MethodMetaGraph(
graph,
vertices_description,
edges_description,
graph_data=nothing,
weight_function=edge_data -> 1.0,
default_weight=1.0,
)
Construct a non-empty MetaGraph
based on a non-empty graph
with specified vertex and edge data, given as positional arguments.
The data must be given as follows:
vertices_description
is a vector of pairslabel => data
(the code of a vertex will correspond to its rank in the list)edges_description
is a vector of pairs(label1, label2) => data
Furthermore, these arguments must be coherent with the graph
argument, i.e. describe the same set of vertices and edges.
MetaGraphsNext.MetaGraph
— MethodMetaGraph(
graph,
label_type,
vertex_data_type=Nothing,
edge_data_type=Nothing,
graph_data=nothing,
weight_function=edge_data -> 1.0,
default_weight=1.0
)
Construct an empty MetaGraph
based on an empty graph
, initializing storage with metadata types given as positional arguments.
Base.delete!
— Methoddelete!(meta_graph, label_1, label_2)
Delete edge (label_1, label_2)
.
Base.delete!
— Methoddelete!(meta_graph, label)
Delete vertex label
.
Base.getindex
— Methodgetindex(meta_graph, label_1, label_2)
Return edge metadata for the edge between label_1
and label_2
.
Base.getindex
— Methodgetindex(meta_graph, label)
Return vertex metadata for label
.
Base.getindex
— Methodgetindex(meta_weights::MetaWeights, code_1, code_2)
Get the weight of edge (code_1, code_2)
.
Base.getindex
— Methodgetindex(meta_graph)
Return meta_graph metadata.
Base.haskey
— Methodhaskey(meta_graph, label_1, label_2)
Determine whether a MetaGraph meta_graph
contains an edge from label_1
to label_2
.
The order of label_1
and label_2
only matters if meta_graph
is a digraph.
Base.haskey
— Methodhaskey(meta_graph, label)
Determine whether a MetaGraph meta_graph
contains the vertex label
.
Base.setindex!
— Methodsetindex!(meta_graph, data, label_1, label_2)
Set edge metadata for (label_1, label_2)
to data
.
Base.setindex!
— Methodsetindex!(meta_graph, data, label)
Set vertex metadata for label
to data
.
Graphs.SimpleGraphs.add_edge!
— Methodadd_edge!(meta_graph, label_1, label_2, data)
Add an edge (label_1, label_2)
to MetaGraph meta_graph
with metadata data
. If the EdgeData
type of meta_graph
is Nothing
, data
can be omitted.
Return true
if the edge has been added, false
otherwise. If one of the labels does not exist, nothing happens and false
is returned (the label is not inserted). If (label_1, label_2)
already exists, its data is updated to data
and false
is returned nonetheless.
Graphs.SimpleGraphs.add_vertex!
— Methodadd_vertex!(meta_graph, label, data)
Add a vertex to MetaGraph meta_graph
with label label
having metadata data
. If the VertexData
type of meta_graph
is Nothing
, data
can be omitted.
Return true if the vertex has been added, false in case the label already exists or vertex was not added.
Graphs.weights
— Methodweights(meta_graph)
Return a matrix-like MetaWeights
object containing the edge weights for metagraph meta_graph
.
MetaGraphsNext._copy_props!
— Method_copy_props!(old_meta_graph, new_meta_graph, code_map)
Copy properties from old_meta_graph
to new_meta_graph
following vertex map code_map
.
MetaGraphsNext.all_neighbor_labels
— Methodall_neighbor_labels(meta_graph, label)
Iterate through all labels of all neighbors of the vertex code
with label label
, in the same order as the codes obtained by all_neighbors(meta_graph, code)
.
MetaGraphsNext.arrange
— Functionarrange(graph, label_1, label_2)
Sort two vertex labels in a default order (useful to uniquely express undirected edges). For undirected graphs, the default order is based on the labels themselves to be robust to vertex re-coding, so the labels need to support <
.
MetaGraphsNext.code_for
— Methodcode_for(meta_graph::MetaGraph, label)
Find the vertex code (or index) associated with label label
.
This can be useful to pass to methods inherited from Graphs
. Note, however, that vertex codes can be reassigned after vertex deletion.
MetaGraphsNext.default_weight
— Methoddefault_weight(meta_graph)
Return the default weight for metagraph meta_graph
.
MetaGraphsNext.edge_labels
— Methodedge_labels(meta_graph)
Iterate through all tuples of edge labels, in the same order as the tuples of codes obtained by edges(meta_graph)
.
MetaGraphsNext.get_weight_function
— Methodget_weight_function(meta_graph)
Return the weight function for metagraph meta_graph
.
MetaGraphsNext.inneighbor_labels
— Methodinneighbor_labels(meta_graph, label)
Iterate through all labels of inneighbors of the vertex code
with label label
, in the same order as the codes obtained by inneighbors(meta_graph, code)
.
MetaGraphsNext.label_for
— Methodlabel_for(meta_graph::MetaGraph, code)
Find the label associated with code code
.
This can be useful to interpret the results of methods inherited from Graphs
. Note, however, that vertex codes can be reassigned after vertex deletion.
MetaGraphsNext.labels
— Methodlabels(meta_graph)
Iterate through all vertex labels, in the same order as the codes obtained by vertices(meta_graph)
.
MetaGraphsNext.neighbor_labels
— Methodneighbor_labels(meta_graph, label)
Iterate through all labels of neighbors of the vertex code
with label label
, in the same order as the codes obtained by neighbors(meta_graph, code)
.
MetaGraphsNext.outneighbor_labels
— Methodoutneighbor_labels(meta_graph, label)
Iterate through all labels of outneighbors of the vertex code
with label label
, in the same order as the codes obtained by outneighbors(meta_graph, code)
.
MetaGraphsNext.set_data!
— Methodset_data!(meta_graph, label_1, label_2, data)
Set edge metadata for (label_1, label_2)
to data
.
Return true
if the operation succeeds, and false
if meta_graph
has no such edge.
MetaGraphsNext.set_data!
— Methodset_data!(meta_graph, label, data)
Set vertex metadata for label
to data
.
Return true
if the operation succeeds, and false
if meta_graph
has no such vertex.
MetaGraphsNext.weighttype
— Methodweighttype(meta_graph)
Return the weight type for metagraph meta_graph
.
Base.haskey
— Functionhaskey(meta_graph, label)
Determine whether a MetaGraph meta_graph
contains the vertex label
.
haskey(meta_graph, label_1, label_2)
Determine whether a MetaGraph meta_graph
contains an edge from label_1
to label_2
.
The order of label_1
and label_2
only matters if meta_graph
is a digraph.
Base.getindex
— Functiongetindex(meta_graph)
Return meta_graph metadata.
getindex(meta_graph, label)
Return vertex metadata for label
.
getindex(meta_graph, label_1, label_2)
Return edge metadata for the edge between label_1
and label_2
.
getindex(meta_weights::MetaWeights, code_1, code_2)
Get the weight of edge (code_1, code_2)
.
Base.setindex!
— Functionsetindex!(meta_graph, data, label)
Set vertex metadata for label
to data
.
setindex!(meta_graph, data, label_1, label_2)
Set edge metadata for (label_1, label_2)
to data
.
Base.delete!
— Functiondelete!(meta_graph, label)
Delete vertex label
.
delete!(meta_graph, label_1, label_2)
Delete edge (label_1, label_2)
.
Graphs.SimpleGraphs.add_vertex!
— Functionadd_vertex!(meta_graph, label, data)
Add a vertex to MetaGraph meta_graph
with label label
having metadata data
. If the VertexData
type of meta_graph
is Nothing
, data
can be omitted.
Return true if the vertex has been added, false in case the label already exists or vertex was not added.
Graphs.SimpleGraphs.add_edge!
— Functionadd_edge!(meta_graph, label_1, label_2, data)
Add an edge (label_1, label_2)
to MetaGraph meta_graph
with metadata data
. If the EdgeData
type of meta_graph
is Nothing
, data
can be omitted.
Return true
if the edge has been added, false
otherwise. If one of the labels does not exist, nothing happens and false
is returned (the label is not inserted). If (label_1, label_2)
already exists, its data is updated to data
and false
is returned nonetheless.
Graphs.weights
— Functionweights(meta_graph)
Return a matrix-like MetaWeights
object containing the edge weights for metagraph meta_graph
.
Index
MetaGraphsNext.MetaGraphsNext
MetaGraphsNext.DOTFormat
MetaGraphsNext.MGFormat
MetaGraphsNext.MetaGraph
MetaGraphsNext.MetaGraph
MetaGraphsNext.MetaGraph
MetaGraphsNext.MetaGraph
Base.delete!
Base.delete!
Base.delete!
Base.getindex
Base.getindex
Base.getindex
Base.getindex
Base.getindex
Base.haskey
Base.haskey
Base.haskey
Base.setindex!
Base.setindex!
Base.setindex!
Graphs.SimpleGraphs.add_edge!
Graphs.SimpleGraphs.add_edge!
Graphs.SimpleGraphs.add_vertex!
Graphs.SimpleGraphs.add_vertex!
Graphs.weights
Graphs.weights
MetaGraphsNext._copy_props!
MetaGraphsNext.all_neighbor_labels
MetaGraphsNext.arrange
MetaGraphsNext.code_for
MetaGraphsNext.default_weight
MetaGraphsNext.edge_labels
MetaGraphsNext.get_weight_function
MetaGraphsNext.inneighbor_labels
MetaGraphsNext.label_for
MetaGraphsNext.labels
MetaGraphsNext.neighbor_labels
MetaGraphsNext.outneighbor_labels
MetaGraphsNext.set_data!
MetaGraphsNext.set_data!
MetaGraphsNext.weighttype