Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/677 #700

Merged
merged 9 commits into from
Oct 1, 2021
5 changes: 3 additions & 2 deletions docs/doc.main
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@
"PolyhedralGeometry/Polyhedra/constructions.md",
"PolyhedralGeometry/Polyhedra/polymake.md",
"PolyhedralGeometry/Polyhedra/auxiliary.md",
"PolyhedralGeometry/Polyhedra/serialization.md"
"PolyhedralGeometry/Polyhedra/serialization.md",
"PolyhedralGeometry/Polyhedra/visualization.md",
],
"PolyhedralGeometry/cones.md",
"PolyhedralGeometry/fans.md",
"PolyhedralGeometry/graphs.md",
"PolyhedralGeometry/linear_programs.md",
"PolyhedralGeometry/subdivisions_of_points.md"
"PolyhedralGeometry/subdivisions_of_points.md",
],

"Commutative Algebra" => [
Expand Down
2 changes: 2 additions & 0 deletions docs/src/PolyhedralGeometry/Polyhedra/auxiliary.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ isfulldimensional(P::Polyhedron)
isnormal(P::Polyhedron)
issmooth(P::Polyhedron)
lattice_points(P::Polyhedron)
lineality_dim(P::Polyhedron)
lineality_space(P::Polyhedron)
nfacets(P::Polyhedron)
normalized_volume(P::Polyhedron)
nvertices(P::Polyhedron)
polarize(P::Polyhedron)
print_constraints(A::AnyVecOrMat, b::AbstractVector; trivial::Bool = false)
print_constraints(P::Polyhedron; trivial::Bool = false)
rays(P::Polyhedron)
Expand Down
18 changes: 18 additions & 0 deletions docs/src/PolyhedralGeometry/Polyhedra/visualization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```@meta
CurrentModule = Oscar
```

```@setup oscar
using Oscar
```

```@contents
Pages = ["visualization.md"]
```


# Visualization

```@docs
visualize(P::Polyhedron)
```
10 changes: 10 additions & 0 deletions docs/src/PolyhedralGeometry/cones.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,22 @@ load_cone(filename::String)
## Auxiliary functions
```@docs
ambient_dim(C::Cone)
f_vector(C::Cone)
hilbert_basis(C::Cone)
codim(C::Cone)
dim(C::Cone)
dual_cone(C::Cone)
intersect(C0::Cone, C1::Cone)
ispointed(C::Cone)
isfulldimensional(C::Cone)
lineality_dim(C::Cone)
lineality_space(C::Cone)
nfacets(C::Cone)
nrays(C::Cone)
rays(C::Cone)
```

### Visualization
```@docs
visualize(C::Cone)
```
23 changes: 23 additions & 0 deletions docs/src/PolyhedralGeometry/fans.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,26 @@ both polymake and Oscar.
save_polyhedralfan(PF::PolyhedralFan, filename::String)
load_polyhedralfan(filename::String)
```

## Auxiliary functions
```@docs
ambient_dim(PF::PolyhedralFan)
dim(PF::PolyhedralFan)
f_vector(PF::PolyhedralFan)
iscomplete(PF::PolyhedralFan)
ispointed(PF::PolyhedralFan)
isregular(PF::PolyhedralFan)
issmooth(PF::PolyhedralFan)
lineality_dim(PF::PolyhedralFan)
lineality_space(PF::PolyhedralFan)
maximal_cones(PF::PolyhedralFan)
maximal_cones_as_incidence_matrix(PF::PolyhedralFan)
nmaximal_cones(PF::PolyhedralFan)
nrays(PF::PolyhedralFan)
rays(PF::PolyhedralFan)
```

### Visualization
```@docs
visualize(PF::PolyhedralFan)
```
11 changes: 7 additions & 4 deletions src/Polytopes/Cone/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ A polyhedral cone in ambient dimension 2
"""
function Cone(R::Union{VectorIterator{RayVector}, Oscar.MatElem, AbstractMatrix}, L::Union{VectorIterator{RayVector}, Oscar.MatElem, AbstractMatrix, Nothing} = nothing; non_redundant::Bool = false)
RM = matrix_for_polymake(R)
LM = isnothing(L) ? Polymake.Matrix{Polymake.Rational}(undef, 0, size(RM, 2)) : matrix_for_polymake(L)
LM = isnothing(L) || isempty(L) ? Polymake.Matrix{Polymake.Rational}(undef, 0, size(RM, 2)) : matrix_for_polymake(L)

if non_redundant
return Cone(Polymake.polytope.Cone{Polymake.Rational}(RAYS = RM, LINEALITY_SPACE = LM,))
Expand Down Expand Up @@ -96,11 +96,14 @@ julia> rays(C)
[1, 1]
```
"""
function cone_from_inequalities(I::Union{HalfspaceIterator, Oscar.MatElem,AbstractMatrix}; non_redundant::Bool = false)
function cone_from_inequalities(I::Union{HalfspaceIterator, Oscar.MatElem, AbstractMatrix}, E::Union{Nothing, HalfspaceIterator, Oscar.MatElem, AbstractMatrix} = nothing; non_redundant::Bool = false)
IM = -matrix_for_polymake(I)
EM = isnothing(E) || isempty(E) ? Polymake.Matrix{Polymake.Rational}(undef, 0, size(IM, 2)) : matrix_for_polymake(E)

if non_redundant
return Cone(Polymake.polytope.Cone{Polymake.Rational}(FACETS = -matrix_for_polymake(I)))
return Cone(Polymake.polytope.Cone{Polymake.Rational}(FACETS = IM, LINEAR_SPAN = EM))
else
return Cone(Polymake.polytope.Cone{Polymake.Rational}(INEQUALITIES = -matrix_for_polymake(I)))
return Cone(Polymake.polytope.Cone{Polymake.Rational}(INEQUALITIES = -matrix_for_polymake(I), EQUATIONS = EM))
end
end

Expand Down
103 changes: 103 additions & 0 deletions src/Polytopes/Cone/properties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ faces(C::Cone, face_dim::Int) = faces(Cone, C, face_dim)
###############################################################################
## Scalar properties
###############################################################################
@doc Markdown.doc"""
nfacets(C::Cone)

Return the number of facets of a cone `C`.

# Examples
The cone over a square at height one has four facets.
```jldoctest
julia> C = positive_hull([1 0 0; 1 1 0; 1 1 1; 1 0 1])
A polyhedral cone in ambient dimension 3

julia> nfacets(C)
4
```
"""
nfacets(C::Cone) = pm_cone(C).N_FACETS


@doc Markdown.doc"""
nrays(C::Cone)
Expand Down Expand Up @@ -115,6 +132,72 @@ julia> codim(C)
"""
codim(C::Cone) = ambient_dim(C)-dim(C)


@doc Markdown.doc"""
f_vector(C::Cone)

Compute the vector $(f₁,f₂,...,f_{(dim(C)-1))$` where $f_i$ is the number of
faces of $C$ of dimension $i$.

# Examples
Take the cone over a square, then the f-vector of the cone is the same as of the square.
```jldoctest
julia> C = positive_hull([1 0 0; 1 1 0; 1 1 1; 1 0 1])
A polyhedral cone in ambient dimension 3

julia> f_vector(C)
2-element Vector{Polymake.Integer}:
4
4

julia> square = cube(2)
A polyhedron in ambient dimension 2

julia> f_vector(square)
2-element Vector{Int64}:
4
4
```
"""
function f_vector(C::Cone)
pmc = pm_cone(C)
ldim = pmc.LINEALITY_DIM
return vcat(fill(0,ldim),pmc.F_VECTOR)
end


@doc Markdown.doc"""
lineality_dim(C::Cone)

Compute the dimension of the lineality space of $C$, i.e. the largest linear
subspace contained in $C$.

# Examples
A cone is pointed if and only if the dimension of its lineality space is zero.
```jldoctest
julia> C = positive_hull([1 0 0; 1 1 0; 1 1 1; 1 0 1])
A polyhedral cone in ambient dimension 3

julia> ispointed(C)
true

julia> lineality_dim(C)
0

julia> C1 = Cone([1 0],[0 1; 0 -1])
A polyhedral cone in ambient dimension 2

julia> ispointed(C1)
false

julia> lineality_dim(C1)
1
```
"""
lineality_dim(C::Cone) = pm_cone(C).LINEALITY_DIM



###############################################################################
## Boolean properties
###############################################################################
Expand Down Expand Up @@ -234,6 +317,26 @@ julia> lineality_space(UH)
"""
lineality_space(C::Cone) = VectorIterator{RayVector{Polymake.Rational}}(pm_cone(C).LINEALITY_SPACE)

@doc Markdown.doc"""
linear_span(C::Cone)

Return the (linear) hyperplanes generating the linear span of `C`.

# Examples
This 2-dimensional cone in $\mathbb{R}^3$ lives in exactly one hyperplane $H$, with
$H = \{ (x_1, x_2, x_3) | x_3 = 0 \}$.
```jldoctest
julia> c = Cone([1 0 0; 0 1 0]);

julia> linear_span(c)
1-element HalfspaceIterator{Hyperplane}:
The Hyperplane of R^3 described by
1: x₃ = 0

```
"""
linear_span(C::Cone) = HalfspaceIterator{Hyperplane}(C.pm_cone.LINEAR_SPAN)

@doc Markdown.doc"""
hilbert_basis(C::Cone)

Expand Down
56 changes: 56 additions & 0 deletions src/Polytopes/Cone/standard_constructions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
###############################################################################
###############################################################################
### Standard constructions
###############################################################################
###############################################################################
@doc Markdown.doc"""
intersect(C0::Cone, C1::Cone)

Return the intersection $C0 \cap C1$ of `C0` and `C1`.

# Examples
```jldoctest
julia> C0 = positive_hull([1 0])
A polyhedral cone in ambient dimension 2

julia> C1 = positive_hull([0 1])
A polyhedral cone in ambient dimension 2

julia> C01 = intersect(C0, C1)
A polyhedral cone in ambient dimension 2

julia> rays(C01)
0-element VectorIterator{RayVector{Polymake.Rational}}

julia> dim(C01)
0
```
"""
function intersect(C0::Cone, C1::Cone)
return Cone(Polymake.polytope.intersection(pm_cone(C0), pm_cone(C1)))
end


@doc Markdown.doc"""
dual_cone(C::Cone)

Return the dual cone of `C` consisting of all those linear functions that
evaluate positively on all of `C`.

# Examples
```jldoctest
julia> C = positive_hull([1 0; -1 2])
A polyhedral cone in ambient dimension 2

julia> Cv = dual_cone(C)
A polyhedral cone in ambient dimension 2

julia> rays(Cv)
2-element VectorIterator{RayVector{Polymake.Rational}}:
[1, 1/2]
[0, 1]
```
"""
function dual_cone(C::Cone)
return Cone(Polymake.polytope.polarize(pm_cone(C)))
end
Loading