Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
60 changes: 60 additions & 0 deletions src/TropicalGeometry/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,63 @@ function is_tropically_generic(A::MatrixElem{<:TropicalSemiringElem})
return helper(transpose(A),nca,nra)
end
end

@doc raw"""
do_rows_form_polytrope(A::MatrixElem{<:TropicalSemiringElem})

Check if the tropical convex hull of the rows of `A` is ordinarily convex (ie a polytrope)

# Examples
```jldoctest
julia> A = tropical_semiring()[0 0 1; 0 1 0; 0 3 3]
[(0) (0) (1)]
[(0) (1) (0)]
[(0) (3) (3)]

julia> do_rows_form_polytrope(A)
Comment thread
Sami-Halaseh marked this conversation as resolved.
Outdated
true
```
"""
function do_rows_form_polytrope(A::MatrixElem{<:TropicalSemiringElem})
#=Convert the matrix of tropical numbers into matrix of rational numbers in
to pass it into polymake's tropical convex hull function =#
ncA = ncols(A)
nrA = nrows(A)
QQA = zero_matrix(QQ,nrA,ncA)
for i in 1:nrA
for j in 1:ncA
iszero(A[i,j]) && return false
QQA[i,j] += QQ(A[i,j])
end
end
#Compute the tropical convex hull
tempP = Polymake.tropical.Polytope{convention(A)}(POINTS=QQA)
#=Compute the tropical convex hull again, this time with
the minimal generating set of vertices of tropical polytope=#
P = Polymake.tropical.Polytope{convention(A)}(POINTS=tempP.VERTICES)
return length(P.POLYTOPE_MAXIMAL_COVECTORS) == 1
end

@doc raw"""
do_rows_form_polytrope(A::QQMatrix, minOrMax::Union{typeof(min),typeof(max)}=min)

Check if the `minOrMax`-tropical convex hull of the rows of `A` is ordinarily convex (ie a polytrope)

# Examples
```jldoctest
julia> A = QQ[0 0 1; 0 1 0; 0 3 3]
[0 0 1]
[0 1 0]
[0 3 3]

julia> do_rows_form_polytrope(A,min)
Comment thread
Sami-Halaseh marked this conversation as resolved.
Outdated
true
```
"""
function do_rows_form_polytrope(A::QQMatrix, minOrMax::Union{typeof(min),typeof(max)}=min)
tempP = Polymake.tropical.Polytope{minOrMax}(POINTS=A)
#=Compute the tropical convex hull again, this time with
the minimal generating set of vertices of tropical polytope=#
P = Polymake.tropical.Polytope{minOrMax}(POINTS=tempP.VERTICES)
return length(P.POLYTOPE_MAXIMAL_COVECTORS) == 1
end
19 changes: 19 additions & 0 deletions test/TropicalGeometry/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,22 @@ end
@test is_tropically_generic(A) == false
@test is_tropically_generic(transpose(A)) == false
end

@testset "testing for polytropes" begin
Comment thread
Sami-Halaseh marked this conversation as resolved.
A = tropical_semiring()[0 0 1; 0 1 0; 0 3 3]
@test do_rows_form_polytrope(A) == true
B = tropical_semiring()[0 1 0; 0 0 1; 1 0 0]
@test do_rows_form_polytrope(B) == false
C = tropical_semiring()[0 0 1; 0 1 0; 0 3 3; 0 2 3; 0 3 2; 0 0 0]
@test do_rows_form_polytrope(C) == true
D = tropical_semiring()[0 1 0; 0 0 1; 2 1 0]
@test do_rows_form_polytrope(D) == false
E = tropical_semiring()[0 1 0; 0 0 0; 0 -1 0]
@test do_rows_form_polytrope(E) == true
F = tropical_semiring()[0 3 1 4 ;0 -1 -1 3; 0 1 -5 1 ; 0 2 -2 0]
@test do_rows_form_polytrope(F) == true
G = tropical_semiring()[0 3 1 4; 0 -1 -1 3; 0 1 -5 1; 0 2 -2 0; 0 0 -3 2]
@test do_rows_form_polytrope(G) == true
H = tropical_semiring()[0 0 0 0 0; 0 1 2 3 4; 0 2 4 6 8; 0 4 8 12 16; 0 5 10 15 20]
@test do_rows_form_polytrope(H) == false
end