@@ -3,37 +3,57 @@ using LightGraphs
3
3
using JLD2
4
4
5
5
import Base:
6
- eltype, show, == ,
7
- Tuple, copy, length, size,
8
- issubset, zero, getindex, haskey, setindex!, delete!
6
+ eltype,
7
+ show,
8
+ == ,
9
+ Tuple,
10
+ copy,
11
+ length,
12
+ size,
13
+ issubset,
14
+ zero,
15
+ getindex,
16
+ haskey,
17
+ setindex!,
18
+ delete!
9
19
10
20
import LightGraphs:
11
- AbstractGraph, edgetype, nv,
12
- ne, vertices, edges, is_directed,
13
- add_vertex!, add_edge!, rem_vertex!, rem_edge!,
14
- has_vertex, has_edge, inneighbors, outneighbors,
21
+ AbstractGraph,
22
+ edgetype,
23
+ nv,
24
+ ne,
25
+ vertices,
26
+ edges,
27
+ is_directed,
28
+ add_vertex!,
29
+ add_edge!,
30
+ rem_vertex!,
31
+ rem_edge!,
32
+ has_vertex,
33
+ has_edge,
34
+ inneighbors,
35
+ outneighbors,
15
36
weights,
16
37
induced_subgraph,
17
- loadgraph, savegraph, AbstractGraphFormat,
38
+ loadgraph,
39
+ savegraph,
40
+ AbstractGraphFormat,
18
41
reverse
19
42
20
- import LightGraphs. SimpleGraphs:
21
- SimpleGraph, SimpleDiGraph,
22
- fadj, badj
23
-
24
- export
25
- MetaGraph,
26
- weighttype,
27
- defaultweight,
28
- weightfunction,
29
- MGFormat,
30
- DOTFormat,
31
- reverse
43
+ import LightGraphs. SimpleGraphs: SimpleGraph, SimpleDiGraph, fadj, badj
44
+
45
+ export MetaGraph, weighttype, defaultweight, weightfunction, MGFormat, DOTFormat, reverse
32
46
33
47
include (" metagraph.jl" )
34
48
35
- function show (io:: IO , g:: MetaGraph{<: Any, Label, <: Any, VertexMeta, EdgeMeta} ) where {Label, VertexMeta, EdgeMeta}
36
- print (io, " Meta graph based on a $(g. graph) with vertices indexed by $Label (s), $VertexMeta (s) vertex metadata, $EdgeMeta (s) edge metadata, $(repr (g. gprops)) as graph metadata, and default weight $(g. defaultweight) " )
49
+ function show (
50
+ io:: IO ,
51
+ g:: MetaGraph{<:Any,Label,<:Any,VertexMeta,EdgeMeta} ,
52
+ ) where {Label,VertexMeta,EdgeMeta}
53
+ print (
54
+ io,
55
+ " Meta graph based on a $(g. graph) with vertices indexed by $Label (s), $VertexMeta (s) vertex metadata, $EdgeMeta (s) edge metadata, $(repr (g. gprops)) as graph metadata, and default weight $(g. defaultweight) " ,
56
+ )
37
57
end
38
58
39
59
@inline fadj (g:: MetaGraph , x... ) = fadj (g. graph, x... )
@@ -54,7 +74,7 @@ has_vertex(g::MetaGraph, x...) = has_vertex(g.graph, x...)
54
74
inneighbors (g:: MetaGraph , v:: Integer ) = inneighbors (g. graph, v)
55
75
outneighbors (g:: MetaGraph , v:: Integer ) = fadj (g. graph, v)
56
76
57
- issubset (g:: T , h:: T ) where T <: MetaGraph = issubset (g. graph, h. graph)
77
+ issubset (g:: T , h:: T ) where {T <: MetaGraph } = issubset (g. graph, h. graph)
58
78
59
79
"""
60
80
add_edge!(g, u, v, val)
@@ -105,7 +125,7 @@ function _rem_vertex!(g, label, v)
105
125
delete! (eprops, arrange (g, label, metaindex[n], v, n))
106
126
end
107
127
for n in inneighbors (g, v)
108
- delete! (eprops, arrange (g, metaindex[n], label, n, v))
128
+ delete! (eprops, arrange (g, metaindex[n], label, n, v))
109
129
end
110
130
removed = rem_vertex! (g. graph, v)
111
131
if removed
@@ -130,7 +150,7 @@ function rem_vertex!(g::MetaGraph, v::Integer)
130
150
end
131
151
end
132
152
133
- struct MetaWeights{InnerMetaGraph, U <: Real } <: AbstractMatrix{U}
153
+ struct MetaWeights{InnerMetaGraph,U <: Real } <: AbstractMatrix{U}
134
154
meta_graph:: InnerMetaGraph
135
155
end
136
156
@@ -220,7 +240,7 @@ julia> weighttype(MetaGraph(Graph(), defaultweight = 1.0))
220
240
Float64
221
241
```
222
242
"""
223
- weighttype (g:: MetaGraph{<: Any, <: Any, <: Any, <: Any, <: Any, <: Any, <:Any, Weight} ) where {Weight} =
243
+ weighttype (g:: MetaGraph{<:Any,<: Any,<: Any,<: Any,<: Any,<: Any,<:Any,Weight} ) where {Weight} =
224
244
Weight
225
245
226
246
"""
@@ -255,7 +275,7 @@ julia> defaultweight(MetaGraph(Graph(), defaultweight = 2))
255
275
"""
256
276
defaultweight (g:: MetaGraph ) = g. defaultweight
257
277
258
- function _copy_props! (oldg:: T , newg:: T , vmap) where T <: MetaGraph
278
+ function _copy_props! (oldg:: T , newg:: T , vmap) where {T <: MetaGraph }
259
279
for (newv, oldv) in enumerate (vmap)
260
280
oldl = oldg. metaindex[oldv]
261
281
_, meta = oldg. vprops[oldl]
@@ -267,22 +287,26 @@ function _copy_props!(oldg::T, newg::T, vmap) where T <: MetaGraph
267
287
u, v = Tuple (newe)
268
288
label_1 = metaindex[u]
269
289
label_2 = metaindex[v]
270
- newg. eprops[arrange (newg, label_1, label_2, u, v)] = oldg. eprops[arrange (oldg, label_1, label_2)]
290
+ newg. eprops[arrange (newg, label_1, label_2, u, v)] =
291
+ oldg. eprops[arrange (oldg, label_1, label_2)]
271
292
end
272
293
return nothing
273
294
end
274
295
275
- function induced_subgraph (g:: T , v:: AbstractVector{U} ) where T <: MetaGraph where U <: Integer
296
+ function induced_subgraph (
297
+ g:: T ,
298
+ v:: AbstractVector{U} ,
299
+ ) where {T<: MetaGraph } where {U<: Integer }
276
300
inducedgraph, vmap = induced_subgraph (g. graph, v)
277
- newg =
278
- MetaGraph ( inducedgraph,
279
- empty (g. vprops),
280
- empty (g. eprops),
281
- g. gprops,
282
- g. weightfunction,
283
- g. defaultweight,
284
- empty (g. metaindex)
285
- )
301
+ newg = MetaGraph (
302
+ inducedgraph,
303
+ empty (g. vprops),
304
+ empty (g. eprops),
305
+ g. gprops,
306
+ g. weightfunction,
307
+ g. defaultweight,
308
+ empty (g. metaindex),
309
+ )
286
310
_copy_props! (g, newg, vmap)
287
311
return newg, vmap
288
312
end
293
317
294
318
== (x:: MetaGraph , y:: MetaGraph ) = x. graph == y. graph
295
319
296
- copy (g:: T ) where T <: MetaGraph = deepcopy (g)
320
+ copy (g:: T ) where {T <: MetaGraph } = deepcopy (g)
297
321
298
322
include (" metadigraph.jl" )
299
323
include (" overrides.jl" )
0 commit comments