Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/Combinatorics/graphs.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ connectivity(g::Graph{Undirected})
complete_graph(n::Int64)
complete_bipartite_graph(n::Int64, m::Int64)
degree(g::Graph, v::Int)
vertices(g::Graph{T}) where {T <: Union{Directed, Undirected}}
edges(g::Graph{T}) where {T <: Union{Directed, Undirected}}
has_edge(g::Graph{T}, source::Int64, target::Int64) where {T <: Union{Directed, Undirected}}
has_vertex(g::Graph{T}, v::Int64) where {T <: Union{Directed, Undirected}}
Expand Down
11 changes: 0 additions & 11 deletions experimental/AlgebraicStatistics/src/GraphicalModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ import Oscar.vertices
import Oscar.gens
import Base.show

###################################################################################
#
# Additional functions for graphs
#
###################################################################################

function vertices(G::Graph)
E = [[src(e), dst(e)] for e in edges(G)]
sort(unique(reduce(vcat, E)))
end

###################################################################################
#
# Additional functions for matrices
Expand Down
20 changes: 20 additions & 0 deletions src/Combinatorics/Graphs/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,26 @@ function n_vertices(g::Graph{T}) where {T <: Union{Directed, Undirected}}
return Polymake.nv(pm_object(g))
end

@doc raw"""
vertices(g::Graph{T}) where {T <: Union{Directed, Undirected}}

Return the vertex indices of a graph.

# Examples
The edge graph of the cube has eight vertices, numbered 1 to 8.
```jldoctest
julia> c = cube(3);

julia> g = vertex_edge_graph(c);

julia> vertices(g)
1:8
```
"""
function vertices(g::Graph{T}) where {T <: Union{Directed, Undirected}}
return 1:n_vertices(g)
end

@doc raw"""
n_edges(g::Graph{T}) where {T <: Union{Directed, Undirected}}

Expand Down
3 changes: 3 additions & 0 deletions test/Combinatorics/Graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
g = Graph{Directed}(5)
@test n_vertices(g) == 5
@test n_edges(g) == 0
@test vertices(g) == 1:5
Comment thread
lgoettgens marked this conversation as resolved.
add_edge!(g, 1, 2)
@test n_edges(g) == 1
@test has_edge(g, 1, 2)
Expand All @@ -19,8 +20,10 @@
@test !has_vertex(g, 6)
@test add_vertices!(g, 5) == 5
@test n_vertices(g) == 10
@test vertices(g) == 1:10
@test rem_vertices!(g, [2, 4, 6, 11])
@test n_vertices(g) == 7
@test vertices(g) == 1:7

g = Graph{Directed}(4)
add_edge!(g, 1, 2)
Expand Down