1 /* Copyright (c) 1997-2021
2 Ewgenij Gawrilow, Michael Joswig, and the polymake team
3 Technische Universität Berlin, Germany
4 https://polymake.org
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version: http://www.gnu.org/licenses/gpl.txt.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 --------------------------------------------------------------------------------
16 */
17
18 #include "polymake/client.h"
19 #include "polymake/tropical/double_description.h"
20 #include "polymake/polytope/hasse_diagram.h"
21
22
23 namespace polymake { namespace tropical {
24
25 template<typename Scalar>
monomial_cone_lattice(const Matrix<Scalar> & m)26 BigObject monomial_cone_lattice(const Matrix<Scalar>& m)
27 {
28 BigObject H("Lattice<BasicDecoration, Nonsequential>");
29 H = polytope::hasse_diagram(tropical::monomial_dual_description(m).second, m.cols());
30 return H;
31 }
32
33 template <typename Addition, typename Scalar>
V_trop_input(BigObject p)34 Matrix<TropicalNumber<Addition, Scalar>> V_trop_input(BigObject p)
35 {
36 const std::pair<Matrix<TropicalNumber<Addition,Scalar>>,Matrix<TropicalNumber<Addition,Scalar>>> Ineq = p.lookup("INEQUALITIES");
37 Matrix<TropicalNumber<Addition, Scalar> > extremals(extremals_from_halfspaces(Ineq.first,Ineq.second));
38 if (extremals.rows() == 0)
39 throw std::runtime_error("the inequalities form an infeasible system");
40 return extremals;
41 }
42
43 FunctionTemplate4perl("V_trop_input<Addition,Scalar>(Polytope<Addition,Scalar>)");
44
45 UserFunctionTemplate4perl("# @category Tropical operations"
46 "# computes the VIF of a monomial tropical cone "
47 "# given by generators "
48 "# @param Matrix M the exponent vectors of the generators. "
49 "# @return Lattice<BasicDecoration, Nonsequential>",
50 "monomial_cone_lattice(Matrix)");
51
52 FunctionTemplate4perl("monoextremals(Matrix, Matrix, Vector)");
53
54 FunctionTemplate4perl("extremals_from_generators(Matrix)");
55
56 FunctionTemplate4perl("extremals_from_halfspaces(Matrix,Matrix)");
57
58 FunctionTemplate4perl("matrixPair2splitApices(Matrix,Matrix)");
59
60 UserFunctionTemplate4perl("# @category Tropical operations"
61 "# This computes the __extremal generators__ of a tropical cone "
62 "# given by generators //G// intersected with one inequality //a//x ~ //b//x."
63 "# Here, ~ is <= for min and >= for max."
64 "# @param Matrix<TropicalNumber> G"
65 "# @param Vector<TropicalNumber> a"
66 "# @param Vector<TropicalNumber> b"
67 "# @return Matrix<TropicalNumber> extrls"
68 "# @example"
69 "# > $G = new Matrix<TropicalNumber<Min>>([[0,0,2],[0,4,0],[0,3,1]]);"
70 "# > $a = new Vector<TropicalNumber<Min>>(['inf','inf',-2]);"
71 "# > $b = new Vector<TropicalNumber<Min>>([0,-1,'inf']);"
72 "# > print intersection_extremals($G,$a,$b);"
73 "# | 0 0 1"
74 "# | 0 4 0"
75 "# | 0 3 1",
76 "intersection_extremals(Matrix, Vector, Vector)");
77
78 UserFunctionTemplate4perl("# @category Tropical operations"
79 "# compute the dual description of "
80 "# a monomial tropical cone. "
81 "# @param Matrix monomial_generators"
82 "# @return Pair<Matrix, IncidenceMatrix<>>",
83 "monomial_dual_description(Matrix)");
84
85 UserFunctionTemplate4perl("# @category Tropical operations"
86 "# Reformulate the description of an "
87 "# inequality system given by two matrices"
88 "# to the description by apices and infeasible sectors "
89 "# @param Matrix<TropicalNumber> G"
90 "# @param Matrix<TropicalNumber> A"
91 "# @return Pair<Matrix<TropicalNumber>, Array<Set<Int>>> signed_apices",
92 "matrixPair2apexSet(Matrix, Matrix)");
93
94 UserFunctionTemplate4perl("# @category Tropical operations"
95 "# Check if a point is contained in "
96 "# all tropical halfspaces given by "
97 "# their apices and the infeasible sectors "
98 "# @param Matrix<TropicalNumber> apices"
99 "# @param Array<Set<Int>> sectors"
100 "# @return Bool",
101 "is_contained(Vector, Matrix, Array)");
102 } }
103