Skip to content

Commit 28e4b69

Browse files
author
Vincent Landau
committed
fix zero function, add add_vertex!
1 parent 6a92e41 commit 28e4b69

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/graph_interface.jl

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import LightGraphs:
55
inneighbors, outneighbors, is_directed, add_edge!
66

77
import SimpleWeightedGraphs:
8-
add_edge!, get_weight
8+
add_edge!, get_weight, add_vertex!, vertices
99

10-
import Base:
11-
eltype, zero
10+
import Base: zero
1211

1312
### LightGraphs interface
1413
nv(g::AbstractSpatialGraph) = nv(g.graph)
@@ -22,8 +21,31 @@ has_vertex(g::AbstractSpatialGraph, v) = has_vertex(g.graph, v)
2221
inneighbors(g::AbstractSpatialGraph, v) = inneighbors(g.graph, v)
2322
outneighbors(g::AbstractSpatialGraph, v) = outneighbors(g.graph, v)
2423
is_directed(g::AbstractSpatialGraph) = is_directed(g.graph)
25-
zero(g::AbstractSpatialGraph) = zero(g.graph)
24+
function Base.zero(g::AbstractRasterGraph)
25+
if g.graph isa SimpleGraph
26+
SimpleRasterGraph(
27+
zero(typeof(g.graph)),
28+
g.vertex_raster
29+
)
30+
elseif g.graph isa SimpleDiGraph
31+
SimpleRasterDiGraph(
32+
zero(typeof(g.graph)),
33+
g.vertex_raster
34+
)
35+
elseif g.graph isa SimpleWeightedGraph
36+
WeightedRasterGraph(
37+
SimpleWeightedGraph{eltype(g.graph), weighttype(g.graph)}(),
38+
g.vertex_raster
39+
)
40+
elseif g.graph isa SimpleWeightedDiGraph
41+
WeightedRasterDiGraph(
42+
SimpleWeightedDiGraph{eltype(g.graph), weighttype(g.graph)}(),
43+
g.vertex_raster
44+
)
45+
end
46+
end
2647
add_edge!(g::AbstractSpatialGraph, a::Integer, b::Integer, c::Number) = add_edge!(g.graph, a, b, c)
48+
add_vertex!(g::AbstractSpatialGraph) = add_vertex!(g.graph)
2749

2850
### SimpleWeightedGraphs
2951
get_weight(g::WeightedRasterGraph, a::Integer, b::Integer) = get_weight(g.graph, a, b)

0 commit comments

Comments
 (0)