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