Skip to content

Commit 2d30071

Browse files
InterdisciplinaryPhysicsTeamClaudMorpitmonticone
committed
Update docstrings
Co-Authored-By: Claudio Moroni <[email protected]> Co-Authored-By: Pietro Monticone <[email protected]>
1 parent 744e23e commit 2d30071

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

src/abstractmultilayerdigraph.jl

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# ne
2-
# has_edge
3-
# edges
4-
51
"""
62
AbstractMultilayerDiGraph{T,U} <: AbstractMultilayerGraph{T,U}
73
@@ -48,7 +44,6 @@ function Graphs.rem_vertex!(mg::AbstractMultilayerDiGraph, V::MultilayerVertex)
4844

4945
# Get the v corresponding to V, delete the association and replace it with a MissingVertex. Also substitute the metadata with an empty NamedTuple
5046
v = get_v(mg, V)
51-
5247
forward_halfedges_to_be_deleted = mg.fadjlist[v]
5348

5449
# Loop over the halfedges to be removed in `forward_halfedges_to_be_deleted`, get their v and remove halfedges to `V` in their corresponding arrays
@@ -100,7 +95,6 @@ function Graphs.rem_vertex!(mg::AbstractMultilayerDiGraph, V::MultilayerVertex)
10095
delete!(mg.v_V_associations, v)
10196
delete!(mg.v_metadata_dict, v)
10297
end
103-
10498
return true
10599

106100
end
@@ -112,11 +106,11 @@ end
112106
Return true if `mg` has edge between the `src` and `dst` (does not check edge or vertex metadata).
113107
"""
114108
function Graphs.has_edge(mg::M, src::T, dst::T) where { T,M <: AbstractMultilayerDiGraph{T}}
115-
109+
# Returns true if src is a vertex of mg
116110
has_vertex(mg,src) || return false
111+
# Returns true if dst is a vertex of mg
117112
has_vertex(mg,dst) || return false
118113

119-
120114
halfedges_from_src = mg.fadjlist[src]
121115
halfedges_to_dst = mg.badjlist[dst]
122116

@@ -127,56 +121,55 @@ function Graphs.has_edge(mg::M, src::T, dst::T) where { T,M <: AbstractMultilaye
127121
srcs_v = get_v.(Ref(mg), vertex.(halfedges_to_dst))
128122
return src in srcs_v
129123
end
130-
131124
end
132125

133-
134126
"""
135127
set_weight!(mg::M, src::MultilayerVertex{L1}, dst::MultilayerVertex{L2}, weight::U) where {L1 <: Symbol, L2 <: Symbol, T,U, M <: AbstractMultilayerGraph{T,U}}
136128
137129
Set the weight of the edge between `src` and `dst` to `weight`. Return true if succeeds (i.e. if the edge exists and the underlying graph chosen for the Layer/Interlayer where the edge lies is weighted under the `IsWeighted` trait).
138130
"""
139131
function set_weight!(mg::M, src::MultilayerVertex, dst::MultilayerVertex, weight::U) where { T,U, M <: AbstractMultilayerDiGraph{T,U}}
132+
# Get the subgraph descriptor for the layer containing both src and dst
140133
descriptor = get_subgraph_descriptor(mg, layer(src), layer(dst))
134+
# Check if the subgraph is weighted
141135
is_weighted(descriptor.null_graph) || return false
136+
# Check if an edge exists between src and dst
142137
has_edge(mg, src, dst) || return false
143-
138+
# Get the halfedge from src to dst
144139
halfedges_from_src = mg.fadjlist[get_v(mg, src)]
145140
halfedge_from_src = halfedges_from_src[findfirst(he -> vertex(he) == dst, halfedges_from_src)]
141+
# Set the weight of the halfedge from src to dst
146142
halfedge_from_src.weight = weight
147-
143+
# Get the halfedge from dst to src
148144
halfedges_to_dst = mg.badjlist[get_v(mg, dst)]
149145
halfedge_to_dst = halfedges_to_dst[findfirst(he -> vertex(he) == src, halfedges_to_dst)]
146+
# Set the weight of the halfedge from dst to src
150147
halfedge_to_dst.weight = weight
151-
152148
return true
153-
154149
end
155150

156-
157-
158151
"""
159152
set_metadata!(mg::M, src::MultilayerVertex{L1}, dst::MultilayerVertex{L2}, metadata::U) where {L1 <: Symbol, L2 <: Symbol, T,U, M <: AbstractMultilayerGraph{T,U}}
160153
161154
Set the metadata of the edge between `src` and `dst` to `metadata`. Return true if succeeds (i.e. if the edge exists and the underlying graph chosen for the Layer/Interlayer where the edge lies supports metadata at the edge level under the `IsMeta` trait).
162155
"""
163156
function set_metadata!(mg::M, src::MultilayerVertex, dst::MultilayerVertex, metadata::Union{Tuple, NamedTuple}) where M <: AbstractMultilayerDiGraph
157+
# Get the subgraph descriptor that corresponds to the layer of src and dst
164158
descriptor = get_subgraph_descriptor(mg, layer(src), layer(dst))
159+
# If the subgraph descriptor's null graph is true, then the edge does not exist
165160
is_meta(descriptor.null_graph) || return false
161+
# If the edge does not exist, return false
166162
has_edge(mg, src, dst) || return false
167-
163+
# Set the halfedge from src to dst
168164
halfedges_from_src = mg.fadjlist[get_v(mg, src)]
169165
halfedge_from_src = halfedges_from_src[findfirst(he -> vertex(he) == dst, halfedges_from_src)]
170166
halfedge_from_src.metadata = metadata
171-
167+
# Set the halfedge from dst to src
172168
halfedges_to_dst = mg.badjlist[get_v(mg, dst)]
173169
halfedge_to_dst = halfedges_to_dst[findfirst(he -> vertex(he) == src, halfedges_to_dst)]
174170
halfedge_to_dst.metadata = metadata
175-
176171
return true
177-
178-
end
179-
172+
ends
180173

181174
# Overloads that make AbstractMultilayerDiGraph an extension of Graphs.jl. These are all well-inferred .
182175
"""
@@ -389,18 +382,19 @@ end
389382
return _inneighbors
390383
end
391384

392-
393-
# function get_overlay_monoplex_graph end #approach taken from https://github.com/JuliaGraphs/Graphs.jl/blob/7152d540631219fd51c43ab761ec96f12c27680e/src/core.jl#L124
394385
"""
395386
get_overlay_monoplex_graph(mg::M) where {M<: AbstractMultilayerDiGraph}
396387
Get overlay monoplex graph (i.e. the graph that has the same nodes as `mg` but the link between node `i` and `j` has weight equal to the sum of all edges weights between the various vertices representing `i` and `j` in `mg`, accounting for both layers and interlayers). See [De Domenico et al. (2013)](https://doi.org/10.1103/PhysRevX.3.041022).
397388
"""
398389
function get_overlay_monoplex_graph(mg::M) where {T,U,M<:AbstractMultilayerDiGraph{T,U}}
390+
# Convert the multilayer graph to a weight tensor
399391
wgt = weight_tensor(mg).array
392+
# Sum the weights for each edge in the multilayer graph
400393
projected_overlay_adjacency_matrix = sum([
401394
wgt[:, :, i, i] for i in 1:size(wgt, 3)
402395
])
403396
return SimpleWeightedDiGraph{T,U}(
404397
projected_overlay_adjacency_matrix
405398
)
399+
# Approach taken from https://github.com/JuliaGraphs/Graphs.jl/blob/7152d540631219fd51c43ab761ec96f12c27680e/src/core.jl#L124
406400
end

src/vertices/multilayervertex.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,5 @@ function compare_multilayervertices(V1::MultilayerVertex, V2::MultilayerVertex;
112112
end
113113

114114
# Console print utilities
115-
to_string( x::M) where {S , M <: MultilayerVertex{S}} = "MV($(x.node), :$(x.layer), $(x.metadata))" #{:$S}
115+
to_string( x::M) where {S , M <: MultilayerVertex{S}} = "MV($(x.node), :$(x.layer), $(x.metadata))"
116116
Base.show(io::IO, x::MultilayerVertex) = print(io, to_string(x))

0 commit comments

Comments
 (0)