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
Modified add_vertex! behavior so that it may automatically add the underlying node, should it be absent, instead of erroring
Refactored multilayer(di)graph.jl's code
Fixed a bug in layer.jl that prevented empty layers from being easily instantiated
Co-Authored-By: Pietro Monticone <38562595+pitmonticone@users.noreply.github.com>
Co-Authored-By: Claudio Moroni <43729990+ClaudMor@users.noreply.github.com>
Add MultilayerVertex `mv` to multilayer graph `mg`. If `add_node` is true and `node(mv)` is not already part of `mg`, then add `node(mv)` to `mg` before adding `mv` to `mg` instead of throwing an error.
176
+
"""
177
+
function Graphs.add_vertex!(mg::AbstractMultilayerGraph, mv::MultilayerVertex; add_node::Bool=true)
178
+
_node =node(mv)
179
+
if add_node &&!has_node(mg, _node)
180
+
add_node!(mg, _node)
181
+
end
182
+
add_vertex_specialized!(mg, mv)
183
+
end
184
+
171
185
# Edges
172
186
"""
173
187
edgetype(::M) where {T,U,M<:AbstractMultilayerGraph{T,U}}
# "empty graph" could be the correct way of calling a graph with no edges: https://math.stackexchange.com/questions/320859/what-is-the-term-for-a-graph-on-n-vertices-with-no-edges
139
58
"""
140
59
MultilayerDiGraph(
141
60
empty_layers::Vector{<:Layer{T,U}},
@@ -286,6 +205,90 @@ function MultilayerDiGraph(
286
205
)
287
206
end
288
207
208
+
# General MultilayerDiGraph Utilities
209
+
fadjlist(mg::MultilayerDiGraph) = mg.fadjlist
210
+
badjlist(mg::MultilayerDiGraph) = mg.badjlist
211
+
212
+
# Nodes
213
+
214
+
# Vertices
215
+
216
+
# Edges
217
+
"""
218
+
add_edge!(mg::M, me::E) where {T,U, M <: AbstractMultilayerDiGraph{T,U}, E <: MultilayerEdge{ <: Union{U,Nothing}}}
219
+
220
+
Add MultilayerEdge `me` to the MultilayerDiGraph `mg`. Return true if succeeds, false otherwise.
221
+
"""
222
+
function Graphs.add_edge!(
223
+
mg::M, me::E
224
+
) where {T,U,M<:AbstractMultilayerDiGraph{T,U},E<:MultilayerEdge{<:Union{U,Nothing}}}
225
+
_src =get_bare_mv(src(me))
226
+
_dst =get_bare_mv(dst(me))
227
+
has_vertex(mg, _src) ||
228
+
throw(ErrorException("Vertex $_src does not belong to the multilayer graph."))
229
+
has_vertex(mg, _dst) ||
230
+
throw(ErrorException("Vertex $_dst does not belong to the multilayer graph."))
# "empty graph" could be the correct way of calling a graph with no edges: https://math.stackexchange.com/questions/320859/what-is-the-term-for-a-graph-on-n-vertices-with-no-edges
290
+
291
+
289
292
# Base overloads
290
293
"""
291
294
Base.getproperty(mg::M, f::Symbol) where { M <: MultilayerDiGraph }
0 commit comments