1 /* Scalar_Products class definition. 2 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it> 3 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com) 4 5 This file is part of the Parma Polyhedra Library (PPL). 6 7 The PPL is free software; you can redistribute it and/or modify it 8 under the terms of the GNU General Public License as published by the 9 Free Software Foundation; either version 3 of the License, or (at your 10 option) any later version. 11 12 The PPL is distributed in the hope that it will be useful, but WITHOUT 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software Foundation, 19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. 20 21 For the most up-to-date information see the Parma Polyhedra Library 22 site: http://bugseng.com/products/ppl/ . */ 23 24 #ifndef PPL_Scalar_Products_defs_hh 25 #define PPL_Scalar_Products_defs_hh 1 26 27 #include "Scalar_Products_types.hh" 28 #include "Coefficient_types.hh" 29 #include "Linear_Expression_types.hh" 30 #include "Constraint_types.hh" 31 #include "Generator_types.hh" 32 #include "Congruence_types.hh" 33 #include "Grid_Generator_types.hh" 34 35 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS 36 //! A class implementing various scalar product functions. 37 /*! \ingroup PPL_CXX_interface 38 When computing the scalar product of (Linear_Expression or Constraint or 39 Generator) objects <CODE>x</CODE> and <CODE>y</CODE>, it is assumed 40 that the space dimension of the first object <CODE>x</CODE> is less 41 than or equal to the space dimension of the second object <CODE>y</CODE>. 42 */ 43 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) 44 class Parma_Polyhedra_Library::Scalar_Products { 45 public: 46 //! Computes the scalar product of \p x and \p y and assigns it to \p z. 47 static void assign(Coefficient& z, 48 const Linear_Expression& x, const Linear_Expression& y); 49 50 //! Computes the scalar product of \p c and \p g and assigns it to \p z. 51 static void assign(Coefficient& z, const Constraint& c, const Generator& g); 52 53 //! Computes the scalar product of \p g and \p c and assigns it to \p z. 54 static void assign(Coefficient& z, const Generator& g, const Constraint& c); 55 56 //! Computes the scalar product of \p c and \p g and assigns it to \p z. 57 static void assign(Coefficient& z, 58 const Constraint& c, const Grid_Generator& gg); 59 60 //! Computes the scalar product of \p g and \p cg and assigns it to \p z. 61 static void assign(Coefficient& z, 62 const Grid_Generator& gg, const Congruence& cg); 63 64 //! Computes the scalar product of \p cg and \p g and assigns it to \p z. 65 static void assign(Coefficient& z, 66 const Congruence& cg, const Grid_Generator& gg); 67 68 //! Returns the sign of the scalar product between \p x and \p y. 69 static int sign(const Linear_Expression& x, const Linear_Expression& y); 70 71 //! Returns the sign of the scalar product between \p c and \p g. 72 static int sign(const Constraint& c, const Generator& g); 73 74 //! Returns the sign of the scalar product between \p g and \p c. 75 static int sign(const Generator& g, const Constraint& c); 76 77 //! Returns the sign of the scalar product between \p c and \p g. 78 static int sign(const Constraint& c, const Grid_Generator& g); 79 80 /*! \brief 81 Computes the \e reduced scalar product of \p x and \p y, 82 where the \f$\epsilon\f$ coefficient of \p x is ignored, 83 and assigns the result to \p z. 84 */ 85 static void reduced_assign(Coefficient& z, 86 const Linear_Expression& x, 87 const Linear_Expression& y); 88 89 /*! \brief 90 Computes the \e reduced scalar product of \p c and \p g, 91 where the \f$\epsilon\f$ coefficient of \p c is ignored, 92 and assigns the result to \p z. 93 */ 94 static void reduced_assign(Coefficient& z, 95 const Constraint& c, const Generator& g); 96 97 /*! \brief 98 Computes the \e reduced scalar product of \p g and \p c, 99 where the \f$\epsilon\f$ coefficient of \p g is ignored, 100 and assigns the result to \p z. 101 */ 102 static void reduced_assign(Coefficient& z, 103 const Generator& g, const Constraint& c); 104 105 //! \brief 106 //! Computes the \e reduced scalar product of \p g and \p cg, 107 //! where the \f$\epsilon\f$ coefficient of \p g is ignored, 108 //! and assigns the result to \p z. 109 static void reduced_assign(Coefficient& z, 110 const Grid_Generator& gg, const Congruence& cg); 111 112 /*! \brief 113 Returns the sign of the \e reduced scalar product of \p x and \p y, 114 where the \f$\epsilon\f$ coefficient of \p x is ignored. 115 */ 116 static int reduced_sign(const Linear_Expression& x, 117 const Linear_Expression& y); 118 119 /*! \brief 120 Returns the sign of the \e reduced scalar product of \p c and \p g, 121 where the \f$\epsilon\f$ coefficient of \p c is ignored. 122 */ 123 static int reduced_sign(const Constraint& c, const Generator& g); 124 125 /*! \brief 126 Returns the sign of the \e reduced scalar product of \p g and \p c, 127 where the \f$\epsilon\f$ coefficient of \p g is ignored. 128 */ 129 static int reduced_sign(const Generator& g, const Constraint& c); 130 131 /*! \brief 132 Computes the \e homogeneous scalar product of \p x and \p y, 133 where the inhomogeneous terms are ignored, 134 and assigns the result to \p z. 135 */ 136 static void homogeneous_assign(Coefficient& z, 137 const Linear_Expression& x, 138 const Linear_Expression& y); 139 /*! \brief 140 Computes the \e homogeneous scalar product of \p e and \p g, 141 where the inhomogeneous terms are ignored, 142 and assigns the result to \p z. 143 */ 144 static void homogeneous_assign(Coefficient& z, 145 const Linear_Expression& e, 146 const Generator& g); 147 148 //! \brief 149 //! Computes the \e homogeneous scalar product of \p gg and \p c, 150 //! where the inhomogeneous terms are ignored, 151 //! and assigns the result to \p z. 152 static void homogeneous_assign(Coefficient& z, 153 const Grid_Generator& gg, 154 const Constraint& c); 155 156 //! \brief 157 //! Computes the \e homogeneous scalar product of \p g and \p cg, 158 //! where the inhomogeneous terms are ignored, 159 //! and assigns the result to \p z. 160 static void homogeneous_assign(Coefficient& z, 161 const Grid_Generator& gg, 162 const Congruence& cg); 163 164 //! \brief 165 //! Computes the \e homogeneous scalar product of \p e and \p g, 166 //! where the inhomogeneous terms are ignored, 167 //! and assigns the result to \p z. 168 static void homogeneous_assign(Coefficient& z, 169 const Linear_Expression& e, 170 const Grid_Generator& g); 171 172 /*! \brief 173 Returns the sign of the \e homogeneous scalar product of \p x and \p y, 174 where the inhomogeneous terms are ignored. 175 */ 176 static int homogeneous_sign(const Linear_Expression& x, 177 const Linear_Expression& y); 178 179 /*! \brief 180 Returns the sign of the \e homogeneous scalar product of \p e and \p g, 181 where the inhomogeneous terms are ignored. 182 */ 183 static int homogeneous_sign(const Linear_Expression& e, const Generator& g); 184 185 //! \brief 186 //! Returns the sign of the \e homogeneous scalar product of \p e and \p g, 187 //! where the inhomogeneous terms are ignored, 188 static int homogeneous_sign(const Linear_Expression& e, 189 const Grid_Generator& g); 190 191 //! \brief 192 //! Returns the sign of the \e homogeneous scalar product of \p g and \p c, 193 //! where the inhomogeneous terms are ignored, 194 static int homogeneous_sign(const Grid_Generator& g, const Constraint& c); 195 }; 196 197 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS 198 //! Scalar product sign function object depending on topology. 199 /*! \ingroup PPL_CXX_interface */ 200 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) 201 class Parma_Polyhedra_Library::Topology_Adjusted_Scalar_Product_Sign { 202 public: 203 //! Constructs the function object according to the topology of \p c. 204 Topology_Adjusted_Scalar_Product_Sign(const Constraint& c); 205 206 //! Constructs the function object according to the topology of \p g. 207 Topology_Adjusted_Scalar_Product_Sign(const Generator& g); 208 209 //! Computes the (topology adjusted) scalar product sign of \p c and \p g. 210 int operator()(const Constraint&, const Generator&) const; 211 212 //! Computes the (topology adjusted) scalar product sign of \p g and \p c. 213 int operator()(const Generator&, const Constraint&) const; 214 215 private: 216 //! The type of the scalar product sign function pointer. 217 typedef int (* const SPS_type)(const Linear_Expression&, 218 const Linear_Expression&); 219 220 //! The scalar product sign function pointer. 221 SPS_type sps_fp; 222 }; 223 224 // NOTE: Scalar_Products_inlines.hh is NOT included here, to avoid cyclic 225 // include dependencies. 226 227 #endif // !defined(PPL_Scalar_Products_defs_hh) 228