You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+193-5Lines changed: 193 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,25 +39,211 @@ Finally, MultilayerGraphs.jl has been integrated within the [JuliaDynamics](http
39
39
40
40
## Installation
41
41
42
-
Press `]` in the Julia REPL and then
42
+
To install MultilayerGraphs.jl it is sufficient to activate the `pkg` mode by pressing `]` in the Julia REPL and then run the following command:
43
43
44
44
```nothing
45
45
pkg> add MultilayerGraphs
46
46
```
47
47
48
48
## Usage
49
49
50
-
In the package documentation you can find a [tutorial](https://juliagraphs.org/MultilayerGraphs.jl/stable/#Tutorial) that illustrates all its main features and functionalities.
50
+
Here we are going to synthetically illustrate some of the main features of MultilayerGraphs.jl. For a more comprehensive exploration of the package functionalities we strongly recommend consulting the [documentation](https://juliagraphs.org/MultilayerGraphs.jl).
51
+
52
+
Let's begin by importing the necessary dependencies and setting the relevant constants.
53
+
54
+
```julia
55
+
using Distributions, Graphs, SimpleValueGraphs
56
+
using MultilayerGraphs
57
+
58
+
# Set the number of nodes: objects represented by multilayer vertices
59
+
const n_nodes =100
60
+
# Create a list of nodes
61
+
const node_list = [Node("node_$i") for i in1:n_nodes]
62
+
```
63
+
64
+
### Layers and Interlayers
65
+
66
+
We will instantiate layers and interlayers with randomly-selected edges and vertices adopting a variety of techniques. Layers and Interlayers are not immutable, and mostly behave like normal graphs. The user is invited to consult the [API](https://juliagraphs.org/MultilayerGraphs.jl/stable/API/) for further details.
67
+
68
+
Here we define a layer with an underlying simple directed graph using a graph generator-like (or "configuration model"-like) constructor which allows us to specify both the **indegree** and the **outdegree sequences**. Before instantiating each layer we sample the number of its vertices and, optionally, of its edges.
sample(node_list, n_vertices; replace=false), # Nodes represented in the layer
75
+
Truncated(Normal(5, 5), 0, 20), # Indegree sequence distribution
76
+
Truncated(Normal(5, 5), 0, 20) # Outdegree sequence distribution
77
+
)
78
+
```
79
+
80
+
Then we define a layer with an underlying simple weighted directed graph. This is another kind of constructor that allows the user to specify the number of edges to be randomly distributed among vertices.
81
+
82
+
```julia
83
+
n_vertices =rand(1:n_nodes) # Number of vertices
84
+
n_edges =rand(n_vertices:(n_vertices * (n_vertices -1) -1)) # Number of edges
sample(node_list, n_vertices; replace=false), # Nodes represented in the layer
88
+
n_edges; # Number of randomly distributed edges
89
+
default_edge_weight=(src, dst) ->rand() # Function assigning weights to edges
90
+
)
91
+
```
92
+
93
+
Similar constructors, more flexible at the cost of ease of use, enable a finer tuning. The constructor we use below should be necessary only in rare circumstances, e.g. if the equivalent simplified constructor `layer_simplevaldigraph` is not able to infer the correct return types of `default_vertex_metadata` or `default_edge_metadata`, or to use and underlying graph structure that isn't currently supported.
94
+
95
+
```julia
96
+
n_vertices =rand(1:n_nodes) # Number of vertices
97
+
n_edges =rand(n_vertices:(n_vertices * (n_vertices -1) -1)) # Number of edges
98
+
default_vertex_metadata = v -> ("vertex_$(v)_metadata") # Vertex metadata
There are many more constructors the user is encouraged to explore in the package [documentation](https://juliagraphs.org/MultilayerGraphs.jl).
121
+
122
+
The interface of interlayers is very similar to that of layers. It is very important to notice that, in order to define a `Multilayer(Di)Graph`, interlayers don't need to be explicitly constructed by the user since they are automatically identified by the `Multilayer(Di)Graph` constructor, but for more complex interlayers the manual instantiation is required.
123
+
124
+
Here we define an interlayer with an underlying simple directed graph.
125
+
126
+
```julia
127
+
n_vertices_1 =nv(layer_simple_directed) # Number of vertices of layer 1
128
+
n_vertices_2 =nv(layer_simple_directed_weighted) # Number of vertices of layer 2
129
+
n_edges =rand(1:(n_vertices_1 * n_vertices_2 -1)) # Number of interlayer edges
# The automatically specified interlayers will have only diagonal couplings
169
+
)
170
+
171
+
# Layers and interlayer can be accessed as properties using their names
172
+
multilayerdigraph.layer_simplevaldigraph
173
+
```
174
+
175
+
Then we proceed by showing how to add nodes, vertices and edges to a directed multilayer graph. The user may add vertices that do or do not represent nodes which are already present in the multilayergraph. In the latter case, we have to create a node first and then add the vertex representing such node to the multilayer graph. The vertex-level metadata are effectively considered only if the graph underlying the relevant layer or interlayer supports them, otherwise they are discarded. The same holds for edge-level metadata and/or weight.
176
+
177
+
```julia
178
+
# Create a node
179
+
new_node_1 =Node("new_node_1")
180
+
# Add the node to the multilayer graph
181
+
add_node!(multilayerdigraph, new_node_1)
182
+
# Create a vertex representing the node
183
+
new_vertex_1 =MV( # Constructor (alias for "MultilayerVertex")
184
+
new_node_1, # Node represented by the vertex
185
+
:layer_simplevaldigraph, # Layer containing the vertex
186
+
("new_metadata") # Vertex metadata
187
+
)
188
+
# Add the vertex
189
+
add_vertex!(
190
+
multilayerdigraph, # MultilayerDiGraph the vertex will be added to
add_node=true# Add the associated node before adding the vertex
203
+
)
204
+
# Create an edge
205
+
new_edge =MultilayerEdge( # Constructor
206
+
new_vertex_1, # Source vertex
207
+
new_vertex_2, # Destination vertex
208
+
("some_edge_metadata") # Edge metadata
209
+
)
210
+
# Add the edge
211
+
add_edge!(
212
+
multilayerdigraph, # MultilayerDiGraph the edge will be added to
213
+
new_edge # MultilayerVertex to add
214
+
)
215
+
```
216
+
217
+
Finally we illustrate how to compute a few multilayer metrics such as the global clustering coefficient, the overlay clustering coefficient, the multilayer eigenvector centrality, and the multilayer modularity as defined in [De Domenico et al. (2013)](https://doi.org/10.1103/physrevx.3.041022).
-[ ][Implement more general configuration models / graph generators](https://github.com/JuliaGraphs/MultilayerGraphs.jl/issues/33);
55
235
-[ ][Implement graph of layers](https://github.com/JuliaGraphs/MultilayerGraphs.jl/issues/34);
56
236
-[ ][Implement projected monoplex and overlay graphs](https://github.com/JuliaGraphs/MultilayerGraphs.jl/issues/35);
57
237
-[ ][Implement more default multilayer graphs](https://github.com/JuliaGraphs/MultilayerGraphs.jl/issues/36) (e.g. multiplex graphs);
58
238
-[ ][Implement configuration models / graph generators for interlayers](https://github.com/JuliaGraphs/MultilayerGraphs.jl/issues/46);
239
+
-[ ][Implement a fully-fledged multilayer configuration model / graph generator](https://github.com/JuliaGraphs/MultilayerGraphs.jl/issues/48);
59
240
-[ ][Relax the requirement of same `T` and `U` for all `Layer`s and `Interlayer`s that are meant to constitute a `Multilayer(Di)Graph`](https://github.com/JuliaGraphs/MultilayerGraphs.jl/issues/53);
60
-
-[ ][Implement multilayer graph data visualisation functionalities (or a new package)](https://github.com/JuliaGraphs/MultilayerGraphs.jl/issues/54).
241
+
-[ ][Implement multilayer graph data visualisation functionalities](https://github.com/JuliaGraphs/MultilayerGraphs.jl/issues/54);
242
+
-[ ][Infer `weighttype` from `default_edge_weight`](https://github.com/JuliaGraphs/MultilayerGraphs.jl/issues/58);
-[ ][Improve integration with Agents.jl](https://github.com/JuliaGraphs/MultilayerGraphs.jl/issues/61);
245
+
-[ ][Allow configuration models to specify a minimum discrepancy between the sampled (di)graphical sequence(s) and the provided distribution](https://github.com/JuliaGraphs/MultilayerGraphs.jl/issues/62);
246
+
-[ ][Add to `add_layer!` a kwarg that allows the user to specify some new interlayers, skipping the instantiation of the default ones.](https://github.com/JuliaGraphs/MultilayerGraphs.jl/issues/63).
61
247
62
248
## How to Contribute
63
249
@@ -67,7 +253,9 @@ We therefore encourage you to participate in [discussions](https://github.com/Ju
67
253
68
254
## How to Cite
69
255
70
-
If you utilize this package in your project, please consider citing this repository using the citation information provided in [`CITATION.bib`](https://github.com/JuliaGraphs/MultilayerGraphs.jl/blob/main/CITATION.bib). This will help to give appropriate credit to the [contributors](https://github.com/JuliaGraphs/MultilayerGraphs.jl/graphs/contributors) and support the continued development of the package.
256
+
If you utilize this package in your project, please consider citing this repository using the citation information provided in [`CITATION.bib`](https://github.com/JuliaGraphs/MultilayerGraphs.jl/blob/main/CITATION.bib).
257
+
258
+
This will help to give appropriate credit to the [contributors](https://github.com/JuliaGraphs/MultilayerGraphs.jl/graphs/contributors) and support the continued development of the package.
0 commit comments