Skip to content

Commit 373870d

Browse files
InterdisciplinaryPhysicsTeampitmonticoneClaudMor
committed
Update docstrings
Co-Authored-By: Pietro Monticone <38562595+pitmonticone@users.noreply.github.com> Co-Authored-By: Claudio Moroni <43729990+ClaudMor@users.noreply.github.com>
1 parent 1c6cc9f commit 373870d

12 files changed

Lines changed: 87 additions & 24 deletions

docs/src/API.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,39 @@ get_weight(subgraph::AbstractSubGraph, src::MultilayerVertex, dst::MultilayerVer
6060
is_directed(subgraph::AbstractSubGraph)
6161
is_directed(::Type{S}) where {T,U,G,S <: AbstractSubGraph{T,U,G}}
6262
adjacency_matrix(subgraph::AbstractSubGraph)
63-
weights(subgraph::S) where {T,U,S<:AbstractSubGraph{T,U}}
63+
MultilayerGraphs.weights(subgraph::S) where {T,U,S<:AbstractSubGraph{T,U}}
6464
name(subgraph::AbstractSubGraph)
6565
Layer{T <: Integer, U <: Real, G <: AbstractGraph{T}}
6666
Layer(name::Symbol, vertices::Vector{<: MultilayerVertex}, edge_list::Vector{ <: MultilayerEdge}, null_graph::G, weighttype::Type{U}; default_vertex_metadata::Function = mv -> NamedTuple(), default_edge_weight::Function = (src, dst) -> one(U), default_edge_metadata::Function = (src, dst) -> NamedTuple()) where {T <: Integer, U <: Real, G <: AbstractGraph{T}}
67-
Layer(nv::Int64, name::Symbol, graph_type::Type{G}, ne::Int64; U::Union{Type{ <: Real},Nothing} = nothing) where {T <: Union{ <: Integer, AbstractVertex}, G <: AbstractGraph{T}}
67+
68+
Layer(
69+
name::Symbol,
70+
vertices::Vector{ <: MultilayerVertex},
71+
ne::Int64,
72+
null_graph::G,
73+
weighttype::Type{U};
74+
default_vertex_metadata::Function = mv -> NamedTuple(),
75+
default_edge_weight::Function = (src, dst) -> nothing,
76+
default_edge_metadata::Function = (src, dst) -> NamedTuple(),
77+
allow_self_loops::Bool = false
78+
) where {T<:Integer, U <: Real, G<:AbstractGraph{T}}
79+
6880
has_node(layer::Layer, n::Node)
6981
rem_vertex!(layer::Layer, mv::MultilayerVertex)
7082
rem_vertex!(layer::Layer, n::Node)
71-
Interlayer{T<:Integer,U<:Real,G<:AbstractGraph{T}}Interlayer(layer_1::Layer{T,U}, layer_2::Layer{T,U}, ne::Int64, null_graph::G; default_edge_weight::Function = (x,y) -> nothing, default_edge_metadata::Function = (x,y) -> NamedTuple(), name::Symbol = Symbol("interlayer_$(layer_1.name)_$(layer_2.name)"), transfer_vertex_metadata::Bool = false) where {T<:Integer, U <: Union{Nothing, <: Real}, G<:AbstractGraph{T}}
83+
84+
Interlayer{T<:Integer,U<:Real,G<:AbstractGraph{T}}
85+
86+
Interlayer(
87+
layer_1::Layer{T,U},
88+
layer_2::Layer{T,U},
89+
ne::Int64,
90+
null_graph::G;
91+
default_edge_weight::Function = (x,y) -> nothing,
92+
default_edge_metadata::Function = (x,y) -> NamedTuple(),
93+
name::Symbol = Symbol("interlayer_$(layer_1.name)_$(layer_2.name)"),
94+
transfer_vertex_metadata::Bool = false
95+
) where {T<:Integer, U <: Union{Nothing, <: Real}, G<:AbstractGraph{T}}
7296
7397
multiplex_interlayer(
7498
layer_1::Layer{T,U},

src/abstractmultilayerdigraph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ function get_subgraph(mg::M, descriptor::InD) where {T,U, G<: AbstractGraph{T},
345345
end
346346
end
347347

348-
return Interlayer(layer_1_multilayervertices, layer_2_multilayervertices, unique(edge_list), descriptor)
348+
return _Interlayer(layer_1_multilayervertices, layer_2_multilayervertices, unique(edge_list), descriptor)
349349

350350
end
351351

src/abstractmultilayerugraph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ function get_subgraph(mg::M, descriptor::InD) where {T,U, G<: AbstractGraph{T},
313313
end
314314
end
315315

316-
return Interlayer(layer_1_multilayervertices, layer_2_multilayervertices, unique(edge_list), descriptor)
316+
return _Interlayer(layer_1_multilayervertices, layer_2_multilayervertices, unique(edge_list), descriptor)
317317
end
318318

319319
# Graphs.jl's internals extra overrides

src/graphs_extensions/graphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ _get_edge_weight(g::Graphs.SimpleGraphs.AbstractSimpleGraph{T}, src::T, dst::T,
1616
# `_get_edge_metadata` must return NamedTuple() (or maybe `nothing` would be better?) instead of throwing an exception in order for `edges` to consistently work on layers and interlayers
1717
_get_edge_metadata(g::Graphs.SimpleGraphs.AbstractSimpleGraph{T}, src::T, dst::T ) where T = NamedTuple()
1818

19-
weights(g::Graphs.SimpleGraphs.AbstractSimpleGraph{T}) where T = adjacency_matrix(g)
19+
Graphs.weights(g::Graphs.SimpleGraphs.AbstractSimpleGraph{T}) where T = adjacency_matrix(g)

src/graphs_extensions/metagraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ _get_edge_metadata(g::AbstractMetaGraph{T}, src::T, dst::T ) where T = NamedTupl
9999

100100
_set_metadata!(g::AbstractMetaGraph{T}, src::T, dst::T, metadata::NamedTuple) where T = set_props!(g, src, dst, Dict(key => value for (key,value) in pairs(metadata)))
101101

102-
weights(g::AbstractMetaGraph{T}) where T = adjacency_matrix(g)
102+
Graphs.weights(g::AbstractMetaGraph{T}) where T = adjacency_matrix(g)

src/graphs_extensions/simplevaluegraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@ function _set_metadata!(g::SimpleValueGraphs.AbstractValGraph{T}, src::T, dst::T
9898
end
9999
end
100100

101-
weights(g::SimpleValueGraphs.AbstractValGraph{T}) where T = adjacency_matrix(g)
101+
Graphs.weights(g::SimpleValueGraphs.AbstractValGraph{T}) where T = adjacency_matrix(g)

src/graphs_extensions/simpleweightedgraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function SimpleWeightedGraphs.SimpleWeightedDiGraph{T,U}(
124124
return SimpleWeightedDiGraph{T,U}(adjm)
125125
end
126126

127-
weights(g::G) where {T, G <: AbstractSimpleWeightedGraph{T}} = SimpleWeightedGraphs.weights(g)
127+
Graphs.weights(g::G) where {T, G <: AbstractSimpleWeightedGraph{T}} = Graphs.weights(g)
128128

129129
#= function _vertices(g::AbstractSimpleWeightedGraph{T}) where T
130130

src/subgraphs/abstractsubgraph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ Graphs.adjacency_matrix(subgraph::AbstractSubGraph) = adjacency_matrix(subgraph.
338338
339339
Return the weights of `subgraph.graph`, with the eltype converted to `U`.
340340
"""
341-
SimpleWeightedGraphs.weights(subgraph::S) where {T,U,S<:AbstractSubGraph{T,U}} = U.(weights(subgraph.graph))
341+
Graphs.weights(subgraph::S) where {T,U,S<:AbstractSubGraph{T,U}} = U.(weights(subgraph.graph))
342342

343343
# Utilities
344344
"""

src/subgraphs/interlayer.jl

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,34 @@ function _Interlayer(
9898
)
9999
end
100100

101+
"""
102+
Interlayer(
103+
layer_1::Layer{T,U},
104+
layer_2::Layer{T,U},
105+
null_graph::G,
106+
edge_list::Vector{ <: MultilayerEdge{<: Union{U, Nothing}}};
107+
default_edge_weight::Function = (x,y) -> nothing,
108+
default_edge_metadata::Function = (x,y) -> NamedTuple(),
109+
transfer_vertex_metadata::Bool = false,
110+
name::Symbol
111+
) where {T<:Integer, U <: Real, G<:AbstractGraph{T}}
112+
113+
Constructor for Interlayer.
114+
115+
# ARGUMENTS
116+
-`layer_1::Layer{T,U}`: one of the two layers connected by the Interlayer;
117+
-`layer_2::Layer{T,U}`: one of the two layers connected by the Interlayer;
118+
-`ne::Int64`: The number of edges of the Interlayer
119+
`null_graph::G`: the Interlayer's underlying graph type, which must be passed as a null graph. If it is not, an error will be thrown.
120+
121+
# KWARGS
122+
123+
-`default_edge_weight::Function`: Function that takes a pair of `MultilayerVertex`s and returns an edge weight of type `weighttype` or `nothing` (which is compatible with unweighted underlying graphs and corresponds to `one(weighttype)` for weighted underlying graphs). Defaults to `(src, dst) -> nothing`;
124+
-`default_edge_metadata::Function`: Function that takes a pair of `MultilayerVertex`s and returns a `Tuple` or a `NamedTuple` containing the edge metadata, that will be called when `add_edge!(mg,src,dst, args...; kwargs...)` is called without the `metadata` keyword argument, and when generating the edges in this constructor. Defaults to `(src, dst) -> NamedTuple()`;
125+
-`name::Symbol`: The name of the Interlayer. Defaults to Symbol("interlayer_(layer_1.name)_(layer_2.name)");
126+
-`transfer_vertex_metadata::Bool`:if true, 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.;
127+
128+
"""
101129
function Interlayer(
102130
layer_1::Layer{T,U},
103131
layer_2::Layer{T,U},
@@ -220,7 +248,7 @@ end
220248
default_edge_metadata::Function = (x,y) -> NamedTuple(),
221249
222250
transfer_vertex_metadata::Bool = false,
223-
name::Symbol = Symbol("interlayer_$(layer_1.name)_$(layer_2.name)"),
251+
name::Symbol),
224252
225253
) where {L1, L2, T<:Integer, U <: Union{Nothing, <: Real}, G<:AbstractGraph{T}}
226254
@@ -340,7 +368,7 @@ empty_interlayer(
340368
null_graph::G;
341369
default_edge_weight::Function = (x,y) -> nothing,
342370
default_edge_metadata::Function = (x,y) -> NamedTuple(),
343-
name::Symbol = Symbol("interlayer_$(layer_1.name)_$(layer_2.name)"),
371+
name::Symbol),
344372
transfer_vertex_metadata::Bool = false
345373
) where {T<:Integer, U <: Real, G<:AbstractGraph{T}}
346374

src/subgraphs/layer.jl

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,18 @@ function Layer(descriptor::LayerDescriptor{T}, vertices::Vector{<: MultilayerVer
106106
end
107107

108108
"""
109-
Layer(nv::Int64, name::Symbol, graph_type::Type{G}, ne::Int64; U::Union{Type{ <: Real},Nothing} = nothing) where {T <: Union{ <: Integer, AbstractVertex}, G <: AbstractGraph{T}}
109+
Layer(
110+
name::Symbol,
111+
vertices::Vector{ <: MultilayerVertex},
112+
ne::Int64,
113+
null_graph::G,
114+
weighttype::Type{U};
115+
default_vertex_metadata::Function = mv -> NamedTuple(),
116+
default_edge_weight::Function = (src, dst) -> nothing,
117+
default_edge_metadata::Function = (src, dst) -> NamedTuple(),
118+
allow_self_loops::Bool = false
119+
120+
) where {T<:Integer, U <: Real, G<:AbstractGraph{T}}
110121
111122
Return a random `Layer`.
112123
@@ -164,11 +175,11 @@ function Layer(
164175
end
165176

166177
"""
167-
has_node(layer::L, n::Node) where { L <: Layer}
178+
has_node(layer::Layer, n::Node)
168179
169180
Return `true` if `n` is a node of `layer`.
170181
"""
171-
has_node(layer::L, n::Node) where {L<:Layer} = MV(n, layer.name) image(layer.v_V_associations)
182+
has_node(layer::Layer, n::Node) = MV(n, layer.name) image(layer.v_V_associations)
172183

173184

174185
"""
@@ -303,19 +314,19 @@ function Graphs.add_edge!(layer::L, src::MultilayerVertex, dst::MultilayerVertex
303314
# If the edge doesn't exist, add it
304315
# If the user does not specify any arguments, we use the default values
305316
if isempty(args) && length(kwargs) == 2 && issetequal(Set([:weight, :metadata]), Set(keys(kwargs)) )
306-
success = add_edge_standard!(layer, bare_src, bare_dst, weight = values(kwargs).weight, metadata = values(kwargs).metadata)
317+
success = add_edge_standard!(layer, src, dst, weight = values(kwargs).weight, metadata = values(kwargs).metadata)
307318
# If the user only specifies the weight, we use the default metadata
308319
elseif isempty(args) && length(kwargs) == 1 && issetequal(Set([:weight]), Set(keys(kwargs)) )
309-
success = add_edge_standard!(layer, bare_src, bare_dst, weight = values(kwargs).weight, metadata = layer.default_edge_metadata(bare_src, bare_dst))
320+
success = add_edge_standard!(layer, src, dst, weight = values(kwargs).weight, metadata = layer.default_edge_metadata(src, dst))
310321
# If the user only specifies the metadata, we use the default weight
311322
elseif isempty(args) && length(kwargs) == 1 && issetequal(Set([:metadata]), Set(keys(kwargs)) )
312-
success = add_edge_standard!(layer, bare_src, bare_dst, weight = layer.default_edge_weight(bare_src, bare_dst), metadata = values(kwargs).metadata)
323+
success = add_edge_standard!(layer, src, dst, weight = layer.default_edge_weight(src, dst), metadata = values(kwargs).metadata)
313324
# If the user does not specify any arguments, we use the default values
314325
elseif length(args) == length(kwargs) == 0
315-
success = add_edge_standard!(layer, bare_src, bare_dst, weight = layer.default_edge_weight(bare_src, bare_dst), metadata = layer.default_edge_metadata(bare_src, bare_dst))
326+
success = add_edge_standard!(layer, src, dst, weight = layer.default_edge_weight(src, dst), metadata = layer.default_edge_metadata(src, dst))
316327
else
317328
# If the user specifies arguments, we use those instead of the defaults
318-
success = add_edge!(layer.graph, get_v(layer,bare_src), get_v(layer,bare_dst), args...; kwargs... )
329+
success = add_edge!(layer.graph, get_v(layer,src), get_v(layer,dst), args...; kwargs... )
319330
end
320331
return success
321332
else

0 commit comments

Comments
 (0)