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_Linear_Expression_inlines_hh
00024 #define PPL_Linear_Expression_inlines_hh 1
00025
00026 #include "Variable.defs.hh"
00027 #include "Coefficient.defs.hh"
00028 #include <stdexcept>
00029
00030 namespace Parma_Polyhedra_Library {
00031
00032 inline dimension_type
00033 Linear_Expression::max_space_dimension() {
00034 return Linear_Row::max_space_dimension();
00035 }
00036
00037 inline
00038 Linear_Expression::Linear_Expression()
00039 : Linear_Row(1, Linear_Row::Flags()) {
00040 }
00041
00042 inline
00043 Linear_Expression::Linear_Expression(dimension_type sz, bool)
00044 : Linear_Row(sz, Linear_Row::Flags()) {
00045 }
00046
00047 inline
00048 Linear_Expression::Linear_Expression(const Variable v)
00049 : Linear_Row(v.space_dimension() <= max_space_dimension()
00050 ? v.id() + 2
00051 : (throw std::length_error("PPL::Linear_Expression::"
00052 "Linear_Expression(v):\n"
00053 "v exceeds the maximum allowed "
00054 "space dimension."),
00055 v.id() + 2)
00056 , Linear_Row::Flags()) {
00057 (*this)[v.id() + 1] = 1;
00058 }
00059
00060 inline
00061 Linear_Expression::Linear_Expression(const Variable v, const Variable w)
00062 : Linear_Row() {
00063 const dimension_type v_space_dim = v.space_dimension();
00064 const dimension_type w_space_dim = w.space_dimension();
00065 const dimension_type space_dim = std::max(v_space_dim, w_space_dim);
00066 if (space_dim > max_space_dimension())
00067 throw std::length_error("PPL::Linear_Expression::"
00068 "Linear_Expression(v, w):\n"
00069 "v or w exceed the maximum allowed "
00070 "space dimension.");
00071 construct(space_dim+1, Linear_Row::Flags());
00072 if (v_space_dim != w_space_dim) {
00073 (*this)[v_space_dim] = 1;
00074 (*this)[w_space_dim] = -1;
00075 }
00076 }
00077
00078 inline
00079 Linear_Expression::Linear_Expression(const Linear_Expression& e)
00080 : Linear_Row(e) {
00081 }
00082
00083 inline
00084 Linear_Expression::~Linear_Expression() {
00085 }
00086
00087 inline
00088 Linear_Expression::Linear_Expression(const Linear_Expression& e,
00089 dimension_type sz)
00090 : Linear_Row(e, sz, sz) {
00091 }
00092
00093 inline
00094 Linear_Expression::Linear_Expression(Coefficient_traits::const_reference n)
00095 : Linear_Row(1, Linear_Row::Flags()) {
00096 (*this)[0] = n;
00097 }
00098
00099 inline dimension_type
00100 Linear_Expression::space_dimension() const {
00101 return size() - 1;
00102 }
00103
00104 inline Coefficient_traits::const_reference
00105 Linear_Expression::coefficient(Variable v) const {
00106 if (v.space_dimension() > space_dimension())
00107 return Coefficient_zero();
00108 return Linear_Row::coefficient(v.id());
00109 }
00110
00111 inline Coefficient_traits::const_reference
00112 Linear_Expression::inhomogeneous_term() const {
00113 return Linear_Row::inhomogeneous_term();
00114 }
00115
00116 inline const Linear_Expression&
00117 Linear_Expression::zero() {
00118 assert(zero_p != 0);
00119 return *zero_p;
00120 }
00121
00122 inline memory_size_type
00123 Linear_Expression::external_memory_in_bytes() const {
00124 return Linear_Row::external_memory_in_bytes();
00125 }
00126
00127 inline memory_size_type
00128 Linear_Expression::total_memory_in_bytes() const {
00129 return Linear_Row::total_memory_in_bytes();
00130 }
00131
00133 inline Linear_Expression
00134 operator+(const Linear_Expression& e) {
00135 return e;
00136 }
00137
00139 inline Linear_Expression
00140 operator+(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00141 return n + e;
00142 }
00143
00145 inline Linear_Expression
00146 operator+(const Variable v, const Variable w) {
00147
00148 return Linear_Expression(v) + Linear_Expression(w);
00149 }
00150
00152 inline Linear_Expression
00153 operator+(const Variable v, const Linear_Expression& e) {
00154
00155 return e + Linear_Expression(v);
00156 }
00157
00159 inline Linear_Expression
00160 operator+(const Linear_Expression& e, const Variable v) {
00161 return v + e;
00162 }
00163
00165 inline Linear_Expression
00166 operator-(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00167 return -n + e;
00168 }
00169
00171 inline Linear_Expression
00172 operator-(const Variable v, const Variable w) {
00173 return Linear_Expression(v, w);
00174 }
00175
00177 inline Linear_Expression
00178 operator-(const Variable v, const Linear_Expression& e) {
00179
00180 return Linear_Expression(v) - e;
00181 }
00182
00184 inline Linear_Expression
00185 operator-(const Linear_Expression& e, const Variable v) {
00186
00187 return e - Linear_Expression(v);
00188 }
00189
00191 inline Linear_Expression
00192 operator*(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00193 return n * e;
00194 }
00195
00197 inline Linear_Expression&
00198 operator+=(Linear_Expression& e, Coefficient_traits::const_reference n) {
00199 e[0] += n;
00200 return e;
00201 }
00202
00204 inline Linear_Expression&
00205 operator-=(Linear_Expression& e, Coefficient_traits::const_reference n) {
00206 e[0] -= n;
00207 return e;
00208 }
00209
00210 inline void
00211 Linear_Expression::swap(Linear_Expression& y) {
00212 Linear_Row::swap(y);
00213 }
00214
00215 inline void
00216 Linear_Expression::ascii_dump(std::ostream& s) const {
00217 Linear_Row::ascii_dump(s);
00218 }
00219
00220 inline bool
00221 Linear_Expression::ascii_load(std::istream& s) {
00222 return Linear_Row::ascii_load(s);
00223 }
00224
00225 }
00226
00227
00228 namespace std {
00229
00231 inline void
00232 swap(Parma_Polyhedra_Library::Linear_Expression& x,
00233 Parma_Polyhedra_Library::Linear_Expression& y) {
00234 x.swap(y);
00235 }
00236
00237 }
00238
00239 #endif // !defined(PPL_Linear_Expression_inlines_hh)