#  Copyright (c) 1997-2021
#  Ewgenij Gawrilow, Michael Joswig, and the polymake team
#  Technische Universität Berlin, Germany
#  https://polymake.org
#
#  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.
#-------------------------------------------------------------------------------

# A rational cone in Q^d.
object Cone<Rational> {

rule lrs.convex_hull.primal: FACETS, LINEAR_SPAN : RAYS | INPUT_RAYS {
   lrs_ch_primal($this, $verbose_lrs);
}
weight 4.10;
precondition : N_RAYS | N_INPUT_RAYS;
incurs FacetPerm;

rule lrs.convex_hull.dual: RAYS, LINEALITY_SPACE, POINTED, LINEALITY_DIM : FACETS | INEQUALITIES {
   lrs_ch_dual($this, $verbose_lrs);
}
weight 4.10;
incurs VertexPerm;

rule lrs.convex_hull.cone.count: N_RAYS, POINTED, LINEALITY_DIM : FACETS | INEQUALITIES {
   lrs_count_vertices($this, false, $verbose_lrs);
}
weight 4.50;


# lrs redundancy checks
# lrs cannot detect generators of the lineality space in INPUT_RAYS
# hence LINEALITY_SPACE must be known in advance
rule lrs.convex_hull.redund: POINTED, RAYS, LINEAR_SPAN : INPUT_RAYS, LINEALITY_SPACE  {
   lrs_get_non_redundant_points($this);
}
weight 3.20;
incurs VertexPerm;

# lrs cannot detect implicit equalities among INEQUALITIES
# hence LINEAR_SPAN must be known in advance
rule lrs.convex_hull.redund: FACETS, LINEALITY_SPACE : INEQUALITIES, LINEAR_SPAN {
   lrs_get_non_redundant_inequalities($this);
}
weight 3.20;
incurs FacetPerm;


# FIXME does this rule work for unbounded polyhedra?
# facet count is the same for cones and polytopes
# corresponding polytope rule below
rule lrs.convex_hull.cone.count: N_FACETS : RAYS | INPUT_RAYS {
   lrs_count_facets($this, $verbose_lrs);
}
weight 4.5;

}


# A pointed polyhedron realized in Q^d.
object Polytope<Rational> {

# the precondition BOUNDED is necessary as the corresponding clients
# requires bounded polyhedra, see comment in lrs_interface.cc
rule lrs.convex_hull.count: N_FACETS : RAYS | INPUT_RAYS {
   lrs_count_facets($this, $verbose_lrs);
}
precondition : BOUNDED;
weight 4.5;
override : SUPER::lrs.convex_hull.cone.count;

rule lrs.convex_hull.count: N_VERTICES, N_BOUNDED_VERTICES, POINTED, LINEALITY_DIM : FACETS | INEQUALITIES {
   lrs_count_vertices($this, false, $verbose_lrs);
}
precondition : FEASIBLE;
weight 4.5;
override : SUPER::lrs.convex_hull.cone.count;

rule lrs.convex_hull.count: N_BOUNDED_VERTICES, POINTED, LINEALITY_DIM : FACETS | INEQUALITIES {
   lrs_count_vertices($this, true, $verbose_lrs);
}
precondition : FEASIBLE;
weight 4.3;

rule lrs.valid_point: VALID_POINT : FACETS | INEQUALITIES {
  lrs_valid_point($this);
}
weight 3.10;


label graph_from_vertices

rule graph_from_vertices : GRAPH.ADJACENCY : RAYS {
   $this->GRAPH->ADJACENCY=graph_from_vertices($this->VERTICES);
}
precondition : BOUNDED;
weight 6.99;

}


# Local Variables:
# cperl-indent-level:3
# mode: perl
# End:
