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 "Linear_Expression.defs.hh"
00027 #include "Constraint.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
00059 Congruence::Congruence(Linear_Expression& le,
00060 Coefficient_traits::const_reference m) {
00061 Row::swap(static_cast<Row&>(le));
00062 assert(m >= 0);
00063 (*this)[size()-1] = m;
00064 }
00065
00066 inline Congruence
00067 Congruence::create(const Linear_Expression& e,
00068 Coefficient_traits::const_reference n) {
00069
00070 Linear_Expression diff(e, e.space_dimension() + 2);
00071 diff -= n;
00072 Congruence cg(diff, 1);
00073 return cg;
00074 }
00075
00076 inline Congruence
00077 Congruence::create(Coefficient_traits::const_reference n,
00078 const Linear_Expression& e) {
00079
00080 Linear_Expression diff(e, e.space_dimension() + 2);
00081 diff -= n;
00082 Congruence cg(diff, 1);
00083 return cg;
00084 }
00085
00087 inline Congruence
00088 operator%=(const Linear_Expression& e1, const Linear_Expression& e2) {
00089 return Congruence::create(e1, e2);
00090 }
00091
00093 inline Congruence
00094 operator%=(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00095 return Congruence::create(e, n);
00096 }
00097
00099 inline Congruence
00100 operator/(const Congruence& cg, Coefficient_traits::const_reference k) {
00101 Congruence ret(cg, k);
00102 return ret;
00103 }
00104
00105 inline const Congruence&
00106 Congruence::zero_dim_integrality() {
00107 return *zero_dim_integrality_p;
00108 }
00109
00110 inline const Congruence&
00111 Congruence::zero_dim_false() {
00112 return *zero_dim_false_p;
00113 }
00114
00115 inline Congruence&
00116 Congruence::operator=(const Congruence& c) {
00117 Row::operator=(c);
00118 return *this;
00119 }
00120
00122 inline Congruence
00123 operator/(const Constraint& c, Coefficient_traits::const_reference m) {
00124 Congruence ret(c);
00125 return ret / m;
00126 }
00127
00128 inline Congruence&
00129 Congruence::operator/=(Coefficient_traits::const_reference k) {
00130 if (k >= 0)
00131 (*this)[size()-1] *= k;
00132 else
00133 (*this)[size()-1] *= -k;
00134 return *this;
00135 }
00136
00138 inline bool
00139 operator==(const Congruence& x, const Congruence& y) {
00140 Congruence x_temp(x);
00141 Congruence y_temp(y);
00142 x_temp.strong_normalize();
00143 y_temp.strong_normalize();
00144 return static_cast<const Row&>(x_temp) == static_cast<const Row&>(y_temp);
00145 }
00146
00148 inline bool
00149 operator!=(const Congruence& x, const Congruence& y) {
00150 return !(x == y);
00151 }
00152
00153 inline dimension_type
00154 Congruence::max_space_dimension() {
00155
00156
00157 return max_size() - 2;
00158 }
00159
00160 inline dimension_type
00161 Congruence::space_dimension() const {
00162 return size() - 2;
00163 }
00164
00165 inline Coefficient_traits::const_reference
00166 Congruence::coefficient(const Variable v) const {
00167 if (v.space_dimension() > space_dimension())
00168 throw_dimension_incompatible("coefficient(v)", "v", v);
00169 return (*this)[v.id()+1];
00170 }
00171
00172 inline Coefficient_traits::const_reference
00173 Congruence::inhomogeneous_term() const {
00174 return (*this)[0];
00175 }
00176
00177 inline Coefficient_traits::const_reference
00178 Congruence::modulus() const {
00179 assert(size() > 1);
00180 return (*this)[size()-1];
00181 }
00182
00183 inline bool
00184 Congruence::is_proper_congruence() const {
00185 return modulus() > 0;
00186 }
00187
00188 inline bool
00189 Congruence::is_equality() const {
00190 return modulus() == 0;
00191 }
00192
00193 inline bool
00194 Congruence::is_equal_at_dimension(dimension_type dim,
00195 const Congruence& cg) const {
00196 return operator[](dim) * cg.modulus() == cg[dim] * modulus();
00197 }
00198
00199 inline void
00200 Congruence::set_is_equality() {
00201 (*this)[size()-1] = 0;
00202 }
00203
00204 inline void
00205 Congruence::negate(dimension_type start, dimension_type end) {
00206 while (start <= end)
00207 neg_assign(operator[](start++));
00208 }
00209
00210 inline memory_size_type
00211 Congruence::external_memory_in_bytes() const {
00212 return Row::external_memory_in_bytes();
00213 }
00214
00215 inline memory_size_type
00216 Congruence::total_memory_in_bytes() const {
00217 return Row::total_memory_in_bytes();
00218 }
00219
00220 inline void
00221 Congruence::swap(Congruence& y) {
00222 Row::swap(y);
00223 }
00224
00225 }
00226
00227 namespace std {
00228
00230 inline void
00231 swap(Parma_Polyhedra_Library::Congruence& x,
00232 Parma_Polyhedra_Library::Congruence& y) {
00233 x.swap(y);
00234 }
00235
00236 }
00237
00238 #endif // !defined(PPL_Congruence_inlines_hh)