Skip to content

Commit

Permalink
Combinatorics: Print graphs nicely
Browse files Browse the repository at this point in the history
  • Loading branch information
lkastner committed Sep 11, 2023
1 parent 5756189 commit 214645d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
37 changes: 29 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}
)
Graph{Directed} 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}
)
Graph{Undirected} with 2 nodes and the following edges:
(2, 1)
```
"""
Expand Down Expand Up @@ -1051,3 +1047,28 @@ Polyhedron in ambient dimension 6
```
"""
fractional_matching_polytope(G::Graph{Undirected}) = polyhedron(Polymake.polytope.fractional_matching_polytope(pm_object(G)))


################################################################################
################################################################################
## Printing
################################################################################
################################################################################
function Base.show(io::IO, ::MIME"text/plain", G::Graph{T}) where {T <: Union{Polymake.Directed, Polymake.Undirected}}
if nedges(G) > 0
println(io, "Graph{$T} 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, "Graph{$T} 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, "Graph{$T}")
else
print(io, "Graph{$T} 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>
{}
{}
{}
)
Graph{Undirected} with 3 nodes and no edges
julia> S = stable_set_polytope(G)
Polyhedron in ambient dimension 3
Expand Down

0 comments on commit 214645d

Please sign in to comment.