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
## Utility function that returns a random number edges between its arguments `layer_1` and `layer_2`:
127
+
functionrand_ne_interlayer(layer_1, layer_2)
128
+
nv_1 =nv(layer_1)
129
+
nv_2 =nv(layer_2)
130
+
_ne =rand(1: (nv_1 * nv_2 -1) )
131
+
return _ne
132
+
end
133
+
134
+
# Define the random undirected simple Interlayer
135
+
_ne =rand_ne_interlayer(layer_sg, layer_swg)
136
+
interlayer_sg_swg =Interlayer( layer_sg, # The first layer to be connected
137
+
layer_swg, # The second layer to be connected
138
+
_ne, # The number of edges to randomly generate
139
+
SimpleGraph{vertextype}(), # The underlying graph, passed as a null graph
140
+
interlayer_name =:random_interlayer# The name of the interlayer. We will be able to access it as a property of the multilayer graph via its name. This kwarg's default value is given by a combination of the two layers' names.
141
+
)
142
+
# Define a weighted `Interlayer`
143
+
_ne =rand_ne_interlayer(layer_swg, layer_mg)
144
+
interlayer_swg_mg =Interlayer( layer_swg,
145
+
layer_mg,
146
+
_ne,
147
+
SimpleWeightedGraph{vertextype, _weighttype}();
148
+
default_edge_weight = (x,y) ->rand() # Arguments follow the same rules as in Layer
149
+
)
150
+
# Define an `Interlayer` with an underlying `MetaGraph`
transfer_vertex_metadata =true# This boolean kwarg controls whether vertex metadata found in both connected layers are carried over to the vertices of the Interlayer. NB: not all choice of underlying graph may support this feature. Graphs types that don't support metadata or that pose limitations to it may result in errors.
158
+
)
159
+
# Define an `Interlayer` with an underlying `ValGraph` from `SimpleValueGraphs.jl`, with diagonal couplings only:
multilayergraph =MultilayerGraph( layers, # The (ordered) list of layers the multilayer graph will have
240
+
interlayers; # The list of interlayers specified by the user. Note that the user does not need to specify all interlayers, as the unspecified ones will be automatically constructed using the indications given by the `default_interlayers_null_graph` and `default_interlayers_structure` keywords.
241
+
default_interlayers_null_graph =SimpleGraph{vertextype}(), # Sets the underlying graph for the interlayers that are to be automatically specified. Defaults to `SimpleGraph{T}()`, where `T` is the `T` of all the `layers` and `interlayers`. See the `Layer` constructors for more information.
242
+
default_interlayers_structure ="multiplex"# Sets the structure of the interlayers that are to be automatically specified. May be "multiplex" for diagonally coupled interlayers, or "empty" for empty interlayers (no edges). "multiplex". See the `Interlayer` constructors for more information.
243
+
)
244
+
245
+
# The configuration model-like constructor will be responsible for creating the edges, so we need to provide it with empty layers and interlayers.
246
+
# To create empty layers and interlayers, we will empty the above subgraphs, and, for compatibility reasons, we'll remove the ones having a `SimpleWeightedGraph`s. These lines are not necessary to comprehend the tutorial, they may be skipped. Just know that the variables `empty_layers` and `empty_interlayers` are two lists of, respectively, empty layers and interlayers that do not have `SimpleWeightedGraph`s as their underlying graphs
247
+
248
+
empty_layers =deepcopy([layer for layer in layers if!(layer.graph isa SimpleWeightedGraphs.AbstractSimpleWeightedGraph)])
249
+
250
+
empty_layers_names =name.(empty_layers)
251
+
252
+
empty_interlayers =deepcopy([interlayer for interlayer in interlayers ifall(in.(interlayer.layers_names, Ref(empty_layers_names))) &&!(interlayer.graph isa SimpleWeightedGraphs.AbstractSimpleWeightedGraph) ])
253
+
254
+
for layer in empty_layers
255
+
for edge inedges(layer)
256
+
rem_edge!(layer, edge)
257
+
end
258
+
end
259
+
260
+
for interlayer in empty_interlayers
261
+
for edge inedges(interlayer)
262
+
rem_edge!(interlayer, edge)
263
+
end
264
+
end
265
+
266
+
# Construct a multilayer graph that has a normal degree distribution. The support of the distribution must be positive, since negative degrees are not possible
multilayergraph, # the `Multilayer(Di)Graph` which the new layer will be added to;
295
+
new_layer; # the new `Layer` to add to the `multilayergraph`
296
+
default_interlayers_null_graph =SimpleGraph{vertextype}(), # upon addition of a new `Layer`, all the `Interlayer`s between the new and the existing `Layer`s are immediately created. This keyword argument specifies their `null_graph` See the `Layer` constructor for more information. Defaults to `SimpleGraph{T}()`
297
+
default_interlayers_structure ="empty"# The structure of the `Interlayer`s created by default. May either be "multiplex" to have diagonally-coupled only interlayers, or "empty" for empty interlayers. Defaults to "multiplex".
298
+
)
299
+
300
+
# Check that the new layer now exists within the multilayer graph
301
+
has_layer(multilayergraph, :new_layer)
302
+
303
+
# Instantiate a new Interlayer. Notice that its name will be given by default as
304
+
_ne =rand_ne_interlayer(layer_sg, new_layer)
305
+
new_interlayer =Interlayer( layer_sg,
306
+
new_layer,
307
+
_ne,
308
+
SimpleGraph{vertextype}(),
309
+
interlayer_name =:new_interlayer
310
+
)
311
+
312
+
# Modify an existing interlayer with the latter i.e. specify the latter interlayer:
313
+
specify_interlayer!( multilayergraph,
314
+
new_interlayer)
315
+
316
+
# Now the interlayer between `layer_sg` and `new_layer` is `new_interlayer`
317
+
318
+
# Get a layer by name
319
+
multilayergraph.new_layer
320
+
321
+
# Get an Interlayer by name
322
+
multilayergraph.new_interlayer
323
+
324
+
# Get an Interlayer from the names of the two layers that it connects
0 commit comments