Skip to content

Commit

Permalink
Added better vertex addition/removal options. Removed partitioning ex…
Browse files Browse the repository at this point in the history
…ample from run_examples.
  • Loading branch information
JoeyT1994 committed Dec 13, 2023
1 parent e4d23ff commit 295ccd8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
31 changes: 28 additions & 3 deletions src/abstractnamedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ function union(graph1::AbstractNamedGraph, graph2::AbstractNamedGraph)
return union_graph
end

function insert_vertex!(graph::AbstractNamedGraph, vertex)
function set_vertex!(graph::AbstractNamedGraph, vertex)
add_vertex!(parent_graph(graph))
# Update the vertex list
push!(vertices(graph), vertex)
Expand All @@ -391,16 +391,24 @@ function insert_vertex!(graph::AbstractNamedGraph, vertex)
return graph
end

function insert_vertex!(graph::AbstractNamedGraph, vertex)
if vertex vertices(graph)
error("Duplicate vertices not allowed!")
else
set_vertex!(graph, vertex)
end
end

function add_vertex!(graph::AbstractNamedGraph, vertex)
if vertex vertices(graph)
return false
else
insert_vertex!(graph, vertex)
set_vertex!(graph, vertex)
return true
end
end

function rem_vertex!(graph::AbstractNamedGraph, vertex)
function unset_vertex!(graph::AbstractNamedGraph, vertex)
parent_vertex = vertex_to_parent_vertex(graph, vertex)
rem_vertex!(parent_graph(graph), parent_vertex)

Expand All @@ -420,6 +428,23 @@ function rem_vertex!(graph::AbstractNamedGraph, vertex)
return graph
end

function rem_vertex!(graph::AbstractNamedGraph, vertex)
if vertex vertices(graph)
return false
else
unset_vertex!(graph, vertex)
return true
end
end

function delete_vertex!(graph::AbstractNamedGraph, vertex)
if vertex vertices(graph)
error("vertex not in graph!")
else
unset_vertex!(graph, vertex)
end
end

function add_vertices!(graph::AbstractNamedGraph, vs::Vector)
for vertex in vs
add_vertex!(graph, vertex)
Expand Down
4 changes: 3 additions & 1 deletion test/test_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ using Suppressor
using Test

examples_path = joinpath(pkgdir(NamedGraphs), "examples")
@testset "Run examples: $filename" for filename in readdir(examples_path)
examples_to_exclude = ["partitioning.jl"]
@testset "Run examples: $filename" for filename in
setdiff(readdir(examples_path), examples_to_exclude)
if endswith(filename, ".jl")
@suppress include(joinpath(examples_path, filename))
end
Expand Down

0 comments on commit 295ccd8

Please sign in to comment.