From b86b6a10373c8c69fe481a43f6a07967205213ec Mon Sep 17 00:00:00 2001 From: Yue Ren Date: Wed, 27 Nov 2024 11:00:12 +0000 Subject: [PATCH] TropicalGeometry: tropical_linear_space from graphs --- docs/src/TropicalGeometry/linear_space.md | 1 + src/TropicalGeometry/linear_space.jl | 28 +++++++++++++++++++++++ test/TropicalGeometry/linear_space.jl | 6 +++++ 3 files changed, 35 insertions(+) diff --git a/docs/src/TropicalGeometry/linear_space.md b/docs/src/TropicalGeometry/linear_space.md index e24400084940..0377a47a62bb 100644 --- a/docs/src/TropicalGeometry/linear_space.md +++ b/docs/src/TropicalGeometry/linear_space.md @@ -18,6 +18,7 @@ In addition to converting from `TropicalVariety`, objects of type `TropicalLinea 4. matrices over a field and a tropical semiring map. - if matrix over `QQ` and tropical semiring map is trivial, uses an implementation of Rincon's algorithm [Rin13](@cite) in `polymake` - for general input, computes minors and uses constructor (2.) +5. graphs ```@docs tropical_linear_space ``` diff --git a/src/TropicalGeometry/linear_space.jl b/src/TropicalGeometry/linear_space.jl index df85b285f466..a8e31cc5f784 100644 --- a/src/TropicalGeometry/linear_space.jl +++ b/src/TropicalGeometry/linear_space.jl @@ -365,6 +365,34 @@ function tropical_linear_space(I::MPolyIdeal, nu::Union{Nothing,TropicalSemiring end +@doc raw""" + tropical_linear_space(G::Graph, nu::TropicalSemiringMap; weighted_polyhedral_complex_only::Bool=false) + +Return the Bergman fan of the graphic matroid of `G` as a tropical linear space, the tropical semiring map `nu` is used to fix the convention. If `weighted_polyhedral_complex==true`, will not cache any extra information. + +# Examples +```jldoctest +julia> G = complete_graph(4) +Undirected graph with 4 nodes and the following edges: +(2, 1)(3, 1)(3, 2)(4, 1)(4, 2)(4, 3) + +julia> tropical_linear_space(G) +Min tropical linear space + +``` +""" +function tropical_linear_space(G::Graph, nu::Union{Nothing,TropicalSemiringMap}=nothing; weighted_polyhedral_complex_only::Bool=false) + M = zero_matrix(QQ,nv(G),ne(G)) + for (i,edge) in enumerate(edges(G)) + M[src(edge),i] = 1 + M[dst(edge),i] = -1 + end + TropG = tropical_linear_space(M,nu;weighted_polyhedral_complex_only=weighted_polyhedral_complex_only) + if !weighted_polyhedral_complex_only + set_attribute!(TropG,:graph,G) + end + return TropG +end ############################################################################### # diff --git a/test/TropicalGeometry/linear_space.jl b/test/TropicalGeometry/linear_space.jl index 537cbe8aeddc..b2f7409a0f9a 100644 --- a/test/TropicalGeometry/linear_space.jl +++ b/test/TropicalGeometry/linear_space.jl @@ -32,4 +32,10 @@ @test issetequal(plueckerVector,tropical_pluecker_vector(TropL)) end + @testset "tropical linear space from graphs" begin + G = complete_graph(3) + TropG = tropical_linear_space(G) + @test f_vector(TropG) == [0,1,3] + end + end