00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef PPL_Congruence_inlines_hh
00024 #define PPL_Congruence_inlines_hh 1
00025
00026 #include "Constraint.defs.hh"
00027 #include "Linear_Expression.defs.hh"
00028
00029 #include <sstream>
00030
00031 namespace Parma_Polyhedra_Library {
00032
00033 inline
00034 Congruence::Congruence(const Congruence& cg)
00035 : Row(cg) {
00036 }
00037
00038 inline
00039 Congruence::Congruence(const Congruence& cg,
00040 dimension_type sz, dimension_type capacity)
00041 : Row(cg, sz, capacity) {
00042 }
00043
00044 inline
00045 Congruence::Congruence(const Congruence& cg,
00046 Coefficient_traits::const_reference k)
00047 : Row(cg) {
00048 if (k >= 0)
00049 (*this)[size()-1] *= k;
00050 else
00051 (*this)[size()-1] *= -k;
00052 }
00053
00054 inline
00055 Congruence::~Congruence() {
00056 }
00057
00058 inline const Congruence&
00059 Congruence::zero_dim_integrality() {
00060 static const Congruence zdi(Linear_Expression::zero() %= Coefficient(-1));
00061 return zdi;
00062 }
00063
00064 inline const Congruence&
00065 Congruence::zero_dim_false() {
00066 static const Congruence
00067 zdf((Linear_Expression::zero() %= Coefficient_one()) / 0);
00068 return zdf;
00069 }
00070
00071 inline Congruence&
00072 Congruence::operator=(const Congruence& c) {
00073 Row::operator=(c);
00074 return *this;
00075 }
00076
00078 inline Congruence
00079 operator%=(const Linear_Expression& e,
00080 const Coefficient_traits::const_reference n) {
00081
00082 Linear_Expression diff(e, e.space_dimension() + 2);
00083 diff -= n;
00084 Congruence cg(diff, 1, false);
00085 return cg;
00086 }
00087
00089 inline Congruence
00090 operator/(const Congruence& cg,
00091 const Coefficient_traits::const_reference k) {
00092 Congruence ret (cg, k);
00093 return ret;
00094 }
00095
00097 inline Congruence
00098 operator/(const Constraint& c,
00099 const Coefficient_traits::const_reference m) {
00100 Congruence ret (c);
00101 return ret / m;
00102 }
00103
00104 inline Congruence&
00105 Congruence::operator/=(const Coefficient_traits::const_reference k) {
00106 if (k >= 0)
00107 (*this)[size()-1] *= k;
00108 else
00109 (*this)[size()-1] *= -k;
00110 return *this;
00111 }
00112
00114 inline bool
00115 operator==(const Congruence& x, const Congruence& y) {
00116 Congruence x_temp(x);
00117 Congruence y_temp(y);
00118 x_temp.strong_normalize();
00119 y_temp.strong_normalize();
00120 return static_cast<const Row&>(x_temp) == static_cast<const Row&>(y_temp);
00121 }
00122
00124 inline bool
00125 operator!=(const Congruence& x, const Congruence& y) {
00126 return !(x == y);
00127 }
00128
00129 inline dimension_type
00130 Congruence::max_space_dimension() {
00131
00132
00133 return max_size() - 2;
00134 }
00135
00136 inline dimension_type
00137 Congruence::space_dimension() const {
00138 return size() - 2;
00139 }
00140
00141 inline Coefficient_traits::const_reference
00142 Congruence::coefficient(const Variable v) const {
00143 if (v.space_dimension() > space_dimension())
00144 throw_dimension_incompatible("coefficient(v)", "v", v);
00145 return (*this)[v.id()+1];
00146 }
00147
00148 inline Coefficient_traits::const_reference
00149 Congruence::inhomogeneous_term() const {
00150 return (*this)[0];
00151 }
00152
00153 inline Coefficient_traits::const_reference
00154 Congruence::modulus() const {
00155 assert(size() > 0);
00156 return (*this)[size()-1];
00157 }
00158
00159 inline Coefficient&
00160 Congruence::modulus() {
00161 assert(size() > 0);
00162 return (*this)[size()-1];
00163 }
00164
00165 inline bool
00166 Congruence::is_proper_congruence() const {
00167 return modulus() > 0;
00168 }
00169
00170 inline bool
00171 Congruence::is_equality() const {
00172 return modulus() == 0;
00173 }
00174
00175 inline bool
00176 Congruence::is_equal_at_dimension(dimension_type dim,
00177 const Congruence& cg) const {
00178 return operator[](dim) * cg.modulus() == cg[dim] * modulus();
00179 }
00180
00181 inline void
00182 Congruence::set_is_equality() {
00183 modulus() = 0;
00184 }
00185
00186 inline void
00187 Congruence::negate(dimension_type start, dimension_type end) {
00188 while (start <= end)
00189 neg_assign(operator[](start++));
00190 }
00191
00192 inline memory_size_type
00193 Congruence::external_memory_in_bytes() const {
00194 return Row::external_memory_in_bytes();
00195 }
00196
00197 inline memory_size_type
00198 Congruence::total_memory_in_bytes() const {
00199 return Row::total_memory_in_bytes();
00200 }
00201
00202 inline
00203 Congruence::Congruence(Linear_Expression& le,
00204 Coefficient_traits::const_reference m,
00205 bool capacity) {
00206 Row::swap(static_cast<Row&>(le));
00207 if (capacity)
00208 Row::expand_within_capacity(size()+1);
00209 if (m >= 0)
00210 (*this)[size()-1] = m;
00211 else
00212 (*this)[size()-1] = -m;
00213 }
00214
00215 inline void
00216 Congruence::swap(Congruence& y) {
00217 Row::swap(y);
00218 }
00219
00220 }
00221
00222 namespace std {
00223
00225 inline void
00226 swap(Parma_Polyhedra_Library::Congruence& x,
00227 Parma_Polyhedra_Library::Congruence& y) {
00228 x.swap(y);
00229 }
00230
00231 }
00232
00233 #endif // !defined(PPL_Congruence_inlines_hh)