#  Copyright (c) 1997-2010
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Darmstadt, Germany)
#  http://www.polymake.de
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------
#  $Project: polymake $$Id: tropical_properties.rules 9562 2010-03-12 18:52:58Z smoeser $


object TropicalPolytope {

# @category Basic properties
# Dimension of the tropical projective space which contains the tropical polytope.

property AMBIENT_DIM : Int;


# @category Basic properties
# Input points in homogeneous coordinates.  This is the fixed system of generators with respect
# to which many combinatorial properties are expressed.

property POINTS : Matrix<Scalar> {

   sub canonical { &canonicalize_to_leading_zero; }
}


# @category Basic properties
# Vertices of the tropical convex hull in homogeneous coordinates:
# We normalize by setting the first homogeneous coordinate to zero.

property VERTICES : Matrix<Scalar> {

   sub canonical { &canonicalize_to_leading_zero; }
}

# @category Basic properties
# Pseudovertices are the vertices of the [[ENVELOPE]] (with respect to [[POINTS]]).

property PSEUDOVERTICES : Matrix<Scalar>;


declare permutation PseudoVertexPerm {

# transforming [[PSEUDOVERTICES]] from this into basic object
   property PERMUTATION : Array<Int>;
}

rule PseudoVertexPerm.PERMUTATION : PseudoVertexPerm.PSEUDOVERTICES, PSEUDOVERTICES {
   ### my $cmp=$this->prepare_computations;
   $this->PseudoVertexPerm->PERMUTATION=polytope::find_vertex_permutation($this->PseudoVertexPerm->PSEUDOVERTICES, $this->PSEUDOVERTICES);
}

rule PSEUDOVERTICES : PseudoVertexPerm.PSEUDOVERTICES, PseudoVertexPerm.PERMUTATION {
   $this->PSEUDOVERTICES=permuted_rows($this->PseudoVertexPerm->PSEUDOVERTICES, $this->PseudoVertexPerm->PERMUTATION);
}
weight 1.10;


# @category Basic properties
# Unique names assigned to the [[VERTICES]].
# If specified, they are shown by visualization tools instead of vertex indices.

property VERTEX_LABELS : Array<String>;


# @category Basic properties
# Tropical polytopes have a natural description as the complex of bounded faces of their envelopes.
# This envelope depends on the choice of the [[POINTS]] that generate the tropical polytope.

property ENVELOPE : polytope::Polytope<Scalar>;


# @category Combinatorics
# Tropical polytopes have a natural description as ordinary polytopal complexes. This is the 1-skeleton of such a
# complex.

property PSEUDOVERTEX_GRAPH : objects::Graph;

rule PSEUDOVERTEX_GRAPH.NodePerm.PERMUTATION = PseudoVertexPerm.PERMUTATION;


# @category Basic properties
# Cyclic order of the [[PSEUDOVERTICES]] in the boundary (for dimension 2 only).

property CONVEX_HULL_2D_CYCLIC : Array<Int>;


# @category Basic properties
# Types of [[VERTICES]] relative to [[VERTICES]].

property VERTEX_TYPES : Array<Array<Set>>;


# @category Basic properties
# Types of [[PSEUDOVERTICES]] relative to [[POINTS]].

property PSEUDOVERTEX_TYPES : Array<Array<Set>>;

rule PSEUDOVERTEX_TYPES : PseudoVertexPerm.PSEUDOVERTEX_TYPES, PseudoVertexPerm.PERMUTATION {
   $this->PSEUDOVERTEX_TYPES=permuted($this->PseudoVertexPerm->PSEUDOVERTEX_TYPES, $this->PseudoVertexPerm->PERMUTATION);
}
weight 1.10;

rule PseudoVertexPerm.PERMUTATION : PseudoVertexPerm.PSEUDOVERTEX_TYPES, PSEUDOVERTEX_TYPES {
   $this->PseudoVertexPerm->PERMUTATION=find_permutation($this->PseudoVertexPerm->PSEUDOVERTEX_TYPES, $this->PSEUDOVERTEX_TYPES);
}

# @category Basic properties
# Coarse types of [[PSEUDOVERTICES]] relative to [[POINTS]].

property PSEUDOVERTEX_COARSE_TYPES : Array<Array<Int>>;

rule PSEUDOVERTEX_COARSE_TYPES : PseudoVertexPerm.PSEUDOVERTEX_COARSE_TYPES, PseudoVertexPerm.PERMUTATION {
   $this->PSEUDOVERTEX_COARSE_TYPES=permuted($this->PseudoVertexPerm->PSEUDOVERTEX_COARSE_TYPES, $this->PseudoVertexPerm->PERMUTATION);
}
weight 1.10;

rule PseudoVertexPerm.PERMUTATION : PseudoVertexPerm.PSEUDOVERTEX_COARSE_TYPES, PSEUDOVERTEX_COARSE_TYPES {
   $this->PseudoVertexPerm->PERMUTATION=find_permutation($this->PseudoVertexPerm->PSEUDOVERTEX_COARSE_TYPES, $this->PSEUDOVERTEX_COARSE_TYPES);
}

# @category Basic properties
# Unique names assigned to the [[PSEUDOVERTICES]].
# Can be used as "NodeLabels" in [[VISUAL_PLANAR]].

property PSEUDOVERTEX_LABELS : Array<String>;

# @notest  Rule defined "in stock" - currently without use
rule PSEUDOVERTEX_LABELS : PseudoVertexPerm.PSEUDOVERTEX_LABELS, PseudoVertexPerm.PERMUTATION {
  $this->PSEUDOVERTEX_LABELS=permuted($this->PseudoVertexPerm->PSEUDOVERTEX_LABELS, $this->PseudoVertexPerm->PERMUTATION);
}
weight 1.10;

rule PSEUDOVERTEX_LABELS : PSEUDOVERTEX_TYPES {
   $this->PSEUDOVERTEX_LABELS(temporary)=[ map { join("", @$_) } @{$this->PSEUDOVERTEX_TYPES} ];
}

}


# @category Other
# Return the pseudovertex coordinates dehomogenized and converted to Matrix<Float>;
# to be used as "Coord" for visualization.
# @param TropicalPolytope P source object
# @return Matrix<Float>
user_function pseudovertices_float_coords(TropicalPolytope) {
  my $P=shift;
  dehomogenize_trop(convert_to<Float>($P->PSEUDOVERTICES));
}


# Local Variables:
# mode: perl
# c-basic-offset:3
# End:
