#  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.
#-------------------------------------------------------------------------------

object SubdivisionOfVectors {

rule scip.milp: MIN_WEIGHTS : VECTORS, MAXIMAL_CELLS {
    my $n_vectors = $this->VECTORS->rows();
    my $secT = $this->secondary_cone(); # no normalization etc
    my $secTineqs = new Matrix<Rational>(primitive($secT->INEQUALITIES));
    my $minus_ones = new Vector<Rational>(-ones_vector<Rational>($secTineqs->rows()));
    my $positive_orthant = zero_vector<Rational>|unit_matrix<Rational>($n_vectors);
    my $ineqs = ($minus_ones|$secTineqs) / $positive_orthant; # shifted ineqs intersected with positive orthant
    my $eqs = zero_vector<Rational> | $secT->EQUATIONS;
    my $ilp = new polytope::MixedIntegerLinearProgram<Rational>(LINEAR_OBJECTIVE=>(0|ones_vector<Rational>($n_vectors)));
    my $secTilp = new polytope::Polytope(INEQUALITIES=>$ineqs, EQUATIONS=>$eqs, MILP=>$ilp);
    $secTilp->apply_rule("scip.milp: MILP.MINIMAL_VALUE, MILP.MINIMAL_SOLUTION : MILP.LINEAR_OBJECTIVE, FACETS | INEQUALITIES");
    $this->MIN_WEIGHTS = $secTilp->MILP->MINIMAL_SOLUTION->slice(~[0]);
}

} # object SubdivisionOfVectors



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