Skip to content

Commit

Permalink
Merge pull request oscar-system#2786 from oscar-system/lk/graph/print
Browse files Browse the repository at this point in the history
  • Loading branch information
lkastner authored Sep 13, 2023
2 parents 5e93531 + 00b2ef2 commit 3df9a13
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
40 changes: 32 additions & 8 deletions src/Combinatorics/Graphs/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,12 @@ julia> G = ZZ[0 0; 1 0]
[1 0]
julia> graph_from_adjacency_matrix(Directed, G)
Graph{Directed}(pm::graph::Graph<pm::graph::Directed>
{}
{0}
)
Directed graph with 2 nodes and the following edges:
(2, 1)
julia> graph_from_adjacency_matrix(Undirected, G)
Graph{Undirected}(pm::graph::Graph<pm::graph::Undirected>
{1}
{0}
)
Undirected graph with 2 nodes and the following edges:
(2, 1)
```
"""
Expand Down Expand Up @@ -1051,3 +1047,31 @@ Polyhedron in ambient dimension 6
```
"""
fractional_matching_polytope(G::Graph{Undirected}) = polyhedron(Polymake.polytope.fractional_matching_polytope(pm_object(G)))


################################################################################
################################################################################
## Printing
################################################################################
################################################################################
_to_string(::Type{Polymake.Directed}) = "Directed"
_to_string(::Type{Polymake.Undirected}) = "Undirected"

function Base.show(io::IO, ::MIME"text/plain", G::Graph{T}) where {T <: Union{Polymake.Directed, Polymake.Undirected}}
if nedges(G) > 0
println(io, "$(_to_string(T)) graph with $(nvertices(G)) nodes and the following edges:") # at least one new line is needed
for e in edges(G)
print(io, "($(src(e)), $(dst(e)))")
end
else
print(io, "$(_to_string(T)) graph with $(nvertices(G)) nodes and no edges")
end
end

function Base.show(io::IO, G::Graph{T}) where {T <: Union{Polymake.Directed, Polymake.Undirected}}
if get(io, :supercompact, false)
print(io, "$(_to_string(T)) graph")
else
print(io, "$(_to_string(T)) graph with $(nvertices(G)) nodes and $(nedges(G)) edges")
end
end
6 changes: 1 addition & 5 deletions src/PolyhedralGeometry/Polyhedron/standard_constructions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2207,11 +2207,7 @@ The following produces first the standard cube in $3$ dimensions, and then
a bipyramid over the convex hull of the unit vectors.
```jldoctest
julia> G = Graph{Undirected}(3)
Graph{Undirected}(pm::graph::Graph<pm::graph::Undirected>
{}
{}
{}
)
Undirected graph with 3 nodes and no edges
julia> S = stable_set_polytope(G)
Polyhedron in ambient dimension 3
Expand Down

0 comments on commit 3df9a13

Please sign in to comment.