Skip to content

Commit 4abd672

Browse files
InterdisciplinaryPhysicsTeampitmonticoneClaudMor
committed
Update tutorial and docstrings
Co-Authored-By: Pietro Monticone <[email protected]> Co-Authored-By: Claudio Moroni <[email protected]>
1 parent 1daa1f6 commit 4abd672

File tree

8 files changed

+32
-57
lines changed

8 files changed

+32
-57
lines changed

docs/src/API.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This page provides a list of exported methods organized by topic and audience. M
88

99
```@docs
1010
Node
11+
id
1112
```
1213

1314
### Vertices
@@ -349,7 +350,7 @@ metadata(he::MultilayerGraphs.HalfEdge)
349350
weight(he::MultilayerGraphs.HalfEdge)
350351
```
351352

352-
# Subgraphs
353+
### Subgraphs
353354

354355
```@docs
355356
has_vertex(subgraph::S, v::T ) where {T,S<:AbstractSubGraph{T}}

docs/src/index.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ CurrentModule = MultilayerGraphs
2222

2323
A multilayer graph is composed of *layers*, i.e. graphs whose vertices represent the same set of nodes (not all nodes need to be represented in every layer), and *interlayers*, i.e. the [bipartite graphs](https://en.wikipedia.org/wiki/Bipartite_graph) that connect vertices in two different layers. Vertices in a multilayer graph are represented using the [`MultilayerVertex`](@ref) struct, while nodes are represented using the [`Node`](@ref) struct.
2424

25-
[`MultilayerGraph`](@ref) and [`MultilayerDiGraph`](@ref) are fully-fledged [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl) extensions. Both structs are designed to allow for layers and interlayers of any type (as long as they are Graphs.jl extensions themselves) and to permit layers and interlayers of different types. However, it is required that all layers and interlayers in [`MultilayerGraph`](@ref) are undirected, and all layers and interlayers in [`MultilayerDiGraph`](@ref) are directed.
25+
`MultilayerGraph` and `MultilayerDiGraph` are fully-fledged [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl) extensions. Both structs are designed to allow for layers and interlayers of any type (as long as they are Graphs.jl extensions themselves) and to permit layers and interlayers of different types. However, it is required that all layers and interlayers in `MultilayerGraph` are undirected, and all layers and interlayers in `MultilayerDiGraph` are directed.
2626

27-
[`MultilayerGraph`](@ref) and [`MultilayerDiGraph`](@ref) support the specification of vertex and edge metadata, provided that the underlying layer or interlayer also supports metadata.
27+
`MultilayerGraph` and `MultilayerDiGraph` support the specification of vertex and edge metadata, provided that the underlying layer or interlayer also supports metadata.
2828

2929
## Installation
3030

@@ -36,7 +36,7 @@ pkg> add MultilayerGraphs
3636

3737
## Tutorial
3838

39-
Here we illustrate how to define, handle and analyse a [`MultilayerGraph`](@ref) (the directed version is completely analogous).
39+
Here we illustrate how to define, handle and analyse a `MultilayerGraph` (the directed version is completely analogous).
4040

4141
```julia
4242
using Revise
@@ -56,7 +56,6 @@ const max_vertices = 7
5656
const min_edges = 1
5757
const max_edges = max_vertices*(max_vertices-1)
5858
const n_nodes = max_vertices
59-
; #hide
6059
```
6160

6261
Next we define nodes:
@@ -76,7 +75,7 @@ const all_nodes = [Node("node_$i") for i in 1:n_nodes]
7675
Node("node_7")
7776
```
7877

79-
And construct `MultilayerVertex`s from these nodes:
78+
You may access (but not modify) the `id` of a `Node` via the [`id`](@ref) function. And construct `MultilayerVertex`s from these nodes:
8079

8180
```julia
8281
## Convert nodes to multilayer vertices without metadata
@@ -106,7 +105,7 @@ multilayervertices_meta[1]
106105
MV(Node("node_1"), :nothing, ("I'm node node_1",))
107106
```
108107

109-
Where `MV` is an alias for `MultilayerVertex`. The first field is the `Node` being represented, the second the (name of) the layer the vertex is represented in (here it is set to `nothing`, since these vertices are yet to be assigned), and the metadata associated to the vertex (no metadata are currently represented via an empty `NamedTuple`). `MultilayerVertex` metadata can be represented via a `Tuple` or a `NamedTuple` (see below for examples).
108+
Where `MV` is an alias for `MultilayerVertex`. The first field is the `Node` being represented (accessible via the [`node`](@ref) function), the second the (name of) the layer the vertex is represented in ((accessible via the [`layer`](@ref) function), here it is set to `nothing`, since these vertices are yet to be assigned), and the metadata associated to the vertex ((accessible via the [`metadata`](@ref) function), no metadata are currently represented via an empty `NamedTuple`). `MultilayerVertex` metadata can be represented via a `Tuple` or a `NamedTuple` (see below for examples).
110109

111110
### Layers
112111

@@ -155,7 +154,6 @@ function _get_srcmv_dstmv_layer(layer::Layer)
155154

156155
return mvs, src_mv, dst_mv
157156
end
158-
; #hide
159157
```
160158

161159
We are now are ready to define some `Layer`s. Every type of graph from the Graphs.jl ecosystem may underlie a `Layer` (or an `Interlayer`). We will construct a few of them, each time with a different number of vertices and edges.
@@ -204,14 +202,13 @@ layer_vg = Layer( :layer_vg,
204202

205203
# Collect all layers in an ordered list. Order will be recorded when instantiating the multilayer graph.
206204
layers = [layer_sg, layer_swg, layer_mg, layer_vg]
207-
; #hide
208205
```
209206

210207
The API that inspects and modifies `Layer`s will be shown below together with that of `Interlayer`s, since they are usually the same. There are of course other constructors that you may discover by typing `?Layer` in the console.
211208

212209
### Interlayers
213210

214-
Now we turn to defining `Interlayer`s. Interlayers are the graphs containing all the edges between vertices is two distinct layers. As before, we need an utility to ease randomization:
211+
Now we turn to defining [`Interlayer`](@ref)s. Interlayers are the graphs containing all the edges between vertices is two distinct layers. As before, we need an utility to ease randomization:
215212

216213

217214
```julia
@@ -240,7 +237,6 @@ function rand_ne_interlayer(layer_1, layer_2)
240237
_ne = rand(_nv:(_nv*(_nv-1)) ÷ 2 )
241238
return _ne
242239
end
243-
; #hide
244240
```
245241

246242
An `Interlayer` is constructed by passing its name, the two `Layer`s it should connect, and the other parameters just like the `Layer`'s constructor. The random constructor reads:
@@ -298,7 +294,6 @@ interlayer_empty_sg_vg = empty_interlayer( layer_sg,
298294

299295
# Collect all interlayers. Even though the list is ordered, order will not matter when instantiating the multilayer graph.
300296
interlayers = [interlayer_sg_swg, interlayer_swg_mg, interlayer_mg_vg, interlayer_multiplex_sg_mg, interlayer_empty_sg_vg]
301-
; #hide
302297
```
303298

304299
Next, we explore the API associated to modify and analyze `Layer`s and `Interlayer`s.
@@ -405,9 +400,9 @@ interlayer_sg_swg_vertices = mv_vertices(interlayer_sg_swg)
405400

406401
The `vertices` command would return an internal representation of the `MultilayerVertex`s. This method, together with others, serves to make `MultilayerGraphs.jl` compatible with the Graphs.jl ecosystem, but it is not meant to be called by the end user. It is, anyway, thought to be used by developers who wish to interface their packages with `MultilayerGraphs.jl` just as with other packages of the `Graphs.jl` ecosystem: a developer-oriented guide will be compiled if there is the need.
407402

408-
In the [API](@ref) page the intended usage of all methods (*end-user* or *developer*) is highlighted.
403+
In the [API](@ref) page the intended usage of all methods ([End-User](@ref) or [Developer](@ref)) is highlighted.
409404

410-
To add a vertex, simply use [`add_vertex!`](@ref). Let us define a vertex with metadata to add. Since nodes may not be represented more than once in layers, we have to define a new node to:
405+
To add a vertex, simply use [`add_vertex!(layer::Layer, mv::MultilayerVertex)`](@ref). Let us define a vertex with metadata to add. Since nodes may not be represented more than once in layers, we have to define a new node to:
411406

412407
```julia
413408
new_node = Node("missing_node")

src/MultilayerGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export
2424
# Node.jl
2525
AbstractNode,
2626
Node,
27+
id,
2728
# abstractvertex.jl
2829
AbstractVertex,
2930
# multilayervertex.jl

src/multilayerdigraph.jl

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,15 @@
22
MultilayerDiGraph{T, U, G <: AbstractGraph{T}} <: AbstractMultilayerGraph{T,U}
33
44
A concrete type that can represent a general multilayer graph. Its internal fields aren't meant to be modified by the user. Please prefer the provided API.
5-
6-
# FIELDS
7-
8-
- `layers::Vector{LayerDescriptor{T,U}}`: vector containing all the layers of the multilayer graph. Their underlying graphs must be all undirected.
9-
- `interlayers::OrderedDict{Set{Symbol},InterlayerDescriptor{T,U}} `: the ordered dictionary containing all the interlayers of the multilayer graph. Their underlying graphs must be all undirected.
10-
- `v_V_associations::Bijection{ T, <: MultilayerVertex}`: A Bijection from Bijections.jl that associates numeric vertices to `MultilayerVertex`s.
11-
- `idx_N_associations::Bijection{ Int64 , Node}`: A Bijection from Bijections.jl that associates Int64 to `Node`s.
12-
- `fadjlist::Vector{Vector{HalfEdge{ <: MultilayerVertex, <: Union{Nothing, U}}}}`: the forward adjacency list of the MultilayerDiGraph. It is a vector of vectors of [`HalfEdge`](@ref)s. Its i-th element are the[`HalfEdge`](@ref)s that originate from `v_V_associations[i]`.
13-
- `v_metadata_dict::Dict{T, <: Union{ <: Tuple, <: NamedTuple}}`: A Dictionary that associates numeric vertices to their metadata
145
"""
156
mutable struct MultilayerDiGraph{T,U} <: AbstractMultilayerDiGraph{T,U}
16-
layers::Vector{LayerDescriptor{T,U}}
17-
interlayers::OrderedDict{Set{Symbol},InterlayerDescriptor{T,U}}
18-
v_V_associations::Bijection{ T, <: MultilayerVertex}
19-
idx_N_associations::Bijection{ Int64 , Node}
20-
fadjlist::Vector{Vector{HalfEdge{ <: MultilayerVertex, <: Union{Nothing, U}}}}
21-
badjlist::Vector{Vector{HalfEdge{ <: MultilayerVertex, <: Union{Nothing, U}}}}
22-
v_metadata_dict::Dict{T, <: Union{ <: Tuple, <: NamedTuple}}
7+
layers::Vector{LayerDescriptor{T,U}} # vector containing all the layers of the multilayer graph. Their underlying graphs must be all undirected.
8+
interlayers::OrderedDict{Set{Symbol},InterlayerDescriptor{T,U}} # the ordered dictionary containing all the interlayers of the multilayer graph. Their underlying graphs must be all undirected.
9+
v_V_associations::Bijection{ T, <: MultilayerVertex} # A Bijection from Bijections.jl that associates numeric vertices to `MultilayerVertex`s.
10+
idx_N_associations::Bijection{ Int64 , Node} # A Bijection from Bijections.jl that associates Int64 to `Node`s.
11+
fadjlist::Vector{Vector{HalfEdge{ <: MultilayerVertex, <: Union{Nothing, U}}}} # the forward adjacency list of the MultilayerDiGraph. It is a vector of vectors of `HalfEdge`s. Its i-th element are the `HalfEdge`s that originate from `v_V_associations[i]`.
12+
badjlist::Vector{Vector{HalfEdge{ <: MultilayerVertex, <: Union{Nothing, U}}}} # the bacward adjacency list of the MultilayerDiGraph. It is a vector of vectors of `HalfEdge`s. Its i-th element are the `HalfEdge`s that insost on `v_V_associations[i]`.
13+
v_metadata_dict::Dict{T, <: Union{ <: Tuple, <: NamedTuple}} # A Dictionary that associates numeric vertices to their metadata
2314
end
2415

2516
# Traits

src/multilayergraph.jl

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,14 @@
22
MultilayerGraph{T, U, G <: AbstractGraph{T}} <: AbstractMultilayerGraph{T,U}
33
44
A concrete type that can represent a general multilayer graph. Its internal fields aren't meant to be modified by the user. Please prefer the provided API.
5-
6-
# FIELDS
7-
8-
- `layers::Vector{LayerDescriptor{T,U}}`: vector containing all the layers of the multilayer graph. Their underlying graphs must be all undirected.
9-
- `interlayers::OrderedDict{Set{Symbol},InterlayerDescriptor{T,U}} `: the ordered dictionary containing all the interlayers of the multilayer graph. Their underlying graphs must be all undirected.
10-
- `v_V_associations::Bijection{ T, <: MultilayerVertex}`: A Bijection from Bijections.jl that associates numeric vertices to `MultilayerVertex`s.
11-
- `idx_N_associations::Bijection{ Int64 , Node}`: A Bijection from Bijections.jl that associates Int64 to `Node`s.
12-
- `fadjlist::Vector{Vector{HalfEdge{ <: MultilayerVertex, <: Union{Nothing, U}}}}`: the forward adjacency list of the MultilayerGraph. It is a vector of vectors of [`HalfEdge`](@ref)s. Its i-th element are the[`HalfEdge`](@ref)s that originate from `v_V_associations[i]`.
13-
- `v_metadata_dict::Dict{T, <: Union{ <: Tuple, <: NamedTuple}}`: A Dictionary that associates numeric vertices to their metadata.
145
"""
156
mutable struct MultilayerGraph{T,U} <: AbstractMultilayerUGraph{T,U}
16-
layers::Vector{LayerDescriptor{T,U}}
17-
interlayers::OrderedDict{Set{Symbol},InterlayerDescriptor{T,U}}
18-
v_V_associations::Bijection{ T, <: MultilayerVertex}
19-
idx_N_associations::Bijection{ Int64 , Node}
20-
fadjlist::Vector{Vector{HalfEdge{ <: MultilayerVertex, <: Union{Nothing, U}}}}
21-
v_metadata_dict::Dict{T, <: Union{ <: Tuple, <: NamedTuple}}
7+
layers::Vector{LayerDescriptor{T,U}} # vector containing all the layers of the multilayer graph. Their underlying graphs must be all undirected.
8+
interlayers::OrderedDict{Set{Symbol},InterlayerDescriptor{T,U}} # the ordered dictionary containing all the interlayers of the multilayer graph. Their underlying graphs must be all undirected.
9+
v_V_associations::Bijection{ T, <: MultilayerVertex} # A Bijection from Bijections.jl that associates numeric vertices to `MultilayerVertex`s.
10+
idx_N_associations::Bijection{ Int64 , Node} # A Bijection from Bijections.jl that associates Int64 to `Node`s.
11+
fadjlist::Vector{Vector{HalfEdge{ <: MultilayerVertex, <: Union{Nothing, U}}}} # the forward adjacency list of the MultilayerGraph. It is a vector of vectors of `HalfEdge`s. Its i-th element are the `HalfEdge`s that originate from `v_V_associations[i]`.
12+
v_metadata_dict::Dict{T, <: Union{ <: Tuple, <: NamedTuple}} # A Dictionary that associates numeric vertices to their metadata.
2213
end
2314

2415
# Traits

src/node.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ abstract type AbstractNode end
99
struct Node <: AbstractNode
1010
1111
A custom concrete type representing a node of a multilayer graph.
12-
13-
# FIELDS
14-
15-
-`id::String`: the node's id i.e. a String stating its name.
1612
"""
1713
struct Node <: AbstractNode
1814
id::String
1915
end
2016

17+
"""
18+
id(n::Node)
19+
20+
Return the id of `n`.
21+
"""
22+
id(n::Node) = n.id
23+
2124
# Base overrides
2225
Base.:(==)(lhs::Node, rhs::Node) = (lhs.id == rhs.id)
2326
Base.isequal(lhs::Node, rhs::Node) = (lhs.id == rhs.id)

src/subgraphs/layer.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ abstract type AbstractLayer{T,U,G} <: AbstractSubGraph{T,U,G} end
1818
mutable struct Layer{T <: Integer, U <: Real, G <: AbstractGraph{T}} <: AbstractLayer{T,U,G}
1919
2020
Represents a layer in a `Multilayer(Di)Graph`.
21-
22-
# FIELDS
23-
24-
- `name::Symbol`: the name of the layer;
25-
- `graph::G`: underlying graph of the layer;
26-
- `forbidden_vertices::Vector{MultilayerVertex}`: nodes of the MultilayerGraph that are not part of this Layer (they will be formally present in the Layer but it will be checked that they aren't adjacent to any other node);
27-
- `forbidden_edges`::Vector{NTuple{2, MultilayerVertex}}: edges that are required not to exist in this Layer.
2821
"""
2922
mutable struct Layer{T<:Integer,U<:Real,G<:AbstractGraph{T}} <: AbstractLayer{T,U,G}
3023
descriptor::LayerDescriptor{T,U,G}

src/vertices/multilayervertex.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A struct representing a vertex of a MultilayerGraph.
1313
# FIELDS
1414
- `node::Node`: the `Node` that the `MultilayerVertex` represents;
1515
- `layer::Union{Nothing, Symbol}`: the name of the `Layer` the `MultilayerVertex` lies in;
16-
- `layer::Symbol`: the layer the `MultilayerVertex` belongs to.
16+
- `metadata::Union{<: NamedTuple, <: Tuple}`: the metadata associated to this `MultilayerVertex`.
1717
1818
# CONSTRUCTORS
1919

0 commit comments

Comments
 (0)