From 214645d1ade9ac4c1cb93d24eb073e97307df828 Mon Sep 17 00:00:00 2001 From: Lars Kastner Date: Mon, 11 Sep 2023 14:52:42 +0200 Subject: [PATCH] Combinatorics: Print graphs nicely --- src/Combinatorics/Graphs/functions.jl | 37 +++++++++++++++---- .../Polyhedron/standard_constructions.jl | 6 +-- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/Combinatorics/Graphs/functions.jl b/src/Combinatorics/Graphs/functions.jl index 97e2abfd1afd..7de3c59b94ec 100644 --- a/src/Combinatorics/Graphs/functions.jl +++ b/src/Combinatorics/Graphs/functions.jl @@ -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 -{} -{0} -) +Graph{Directed} with 2 nodes and the following edges: +(2, 1) julia> graph_from_adjacency_matrix(Undirected, G) -Graph{Undirected}(pm::graph::Graph -{1} -{0} -) +Graph{Undirected} with 2 nodes and the following edges: +(2, 1) ``` """ @@ -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 diff --git a/src/PolyhedralGeometry/Polyhedron/standard_constructions.jl b/src/PolyhedralGeometry/Polyhedron/standard_constructions.jl index c78d007b4014..9fff4cbfa5ca 100644 --- a/src/PolyhedralGeometry/Polyhedron/standard_constructions.jl +++ b/src/PolyhedralGeometry/Polyhedron/standard_constructions.jl @@ -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 -{} -{} -{} -) +Graph{Undirected} with 3 nodes and no edges julia> S = stable_set_polytope(G) Polyhedron in ambient dimension 3