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_Polyhedra_Powerset_inlines_hh
00024 #define PPL_Polyhedra_Powerset_inlines_hh 1
00025
00026 #include "Constraint.defs.hh"
00027 #include "Constraint_System.defs.hh"
00028 #include "Constraint_System.inlines.hh"
00029 #include "Congruence.defs.hh"
00030 #include "Congruence_System.defs.hh"
00031 #include "Congruence_System.inlines.hh"
00032 #include "C_Polyhedron.defs.hh"
00033 #include "NNC_Polyhedron.defs.hh"
00034 #include <algorithm>
00035 #include <deque>
00036
00037 namespace Parma_Polyhedra_Library {
00038
00039 template <typename PH>
00040 inline dimension_type
00041 Polyhedra_Powerset<PH>::space_dimension() const {
00042 return space_dim;
00043 }
00044
00045 template <typename PH>
00046 inline dimension_type
00047 Polyhedra_Powerset<PH>::max_space_dimension() {
00048 return PH::max_space_dimension();
00049 }
00050
00051 template <typename PH>
00052 inline
00053 Polyhedra_Powerset<PH>::Polyhedra_Powerset(dimension_type num_dimensions,
00054 Degenerate_Element kind)
00055 : Base(), space_dim(num_dimensions) {
00056 Polyhedra_Powerset& x = *this;
00057 if (kind == UNIVERSE)
00058 x.sequence.push_back(Determinate<PH>(PH(num_dimensions, kind)));
00059 assert(x.OK());
00060 }
00061
00062 template <typename PH>
00063 inline
00064 Polyhedra_Powerset<PH>::Polyhedra_Powerset(const Polyhedra_Powerset& y)
00065 : Base(y), space_dim(y.space_dim) {
00066 }
00067
00068 template <typename PH>
00069 inline
00070 Polyhedra_Powerset<PH>::Polyhedra_Powerset(const PH& ph)
00071 : Base(ph), space_dim(ph.space_dimension()) {
00072 }
00073
00074
00075
00076
00077
00078 template <>
00079 template <>
00080 inline
00081 Polyhedra_Powerset<NNC_Polyhedron>
00082 ::Polyhedra_Powerset(const Polyhedra_Powerset<C_Polyhedron>& y)
00083 : Base(), space_dim(y.space_dimension()) {
00084 Polyhedra_Powerset& x = *this;
00085 for (Polyhedra_Powerset<C_Polyhedron>::const_iterator i = y.begin(),
00086 y_end = y.end(); i != y_end; ++i)
00087 x.sequence.push_back(Determinate<NNC_Polyhedron>(
00088 NNC_Polyhedron(i->element()))
00089 );
00090 x.reduced = y.reduced;
00091 assert(x.OK());
00092 }
00093
00094
00095
00096
00097
00098 template <>
00099 template <>
00100 inline
00101 Polyhedra_Powerset<C_Polyhedron>
00102 ::Polyhedra_Powerset(const Polyhedra_Powerset<NNC_Polyhedron>& y)
00103 : Base(), space_dim(y.space_dimension()) {
00104 Polyhedra_Powerset& x = *this;
00105 for (Polyhedra_Powerset<NNC_Polyhedron>::const_iterator i = y.begin(),
00106 y_end = y.end(); i != y_end; ++i)
00107 x.sequence.push_back(Determinate<C_Polyhedron>(
00108 C_Polyhedron(i->element()))
00109 );
00110
00111
00112
00113
00114 x.reduced = false;
00115 assert(x.OK());
00116 }
00117
00118 template <typename PH>
00119 inline
00120 Polyhedra_Powerset<PH>::Polyhedra_Powerset(const Constraint_System& cs)
00121
00122
00123
00124 : Base(), space_dim(cs.space_dimension()) {
00125 Polyhedra_Powerset& x = *this;
00126 x.sequence.push_back(Determinate<PH>(cs));
00127 x.reduced = false;
00128 assert(x.OK());
00129 }
00130
00131 template <typename PH>
00132 inline
00133 Polyhedra_Powerset<PH>::Polyhedra_Powerset(const Congruence_System& cgs)
00134
00135
00136
00137 : Base(), space_dim(cgs.space_dimension()) {
00138 Polyhedra_Powerset& x = *this;
00139 x.sequence.push_back(Determinate<PH>(cgs));
00140 x.reduced = false;
00141 assert(OK());
00142 }
00143
00144 template <typename PH>
00145 inline Polyhedra_Powerset<PH>&
00146 Polyhedra_Powerset<PH>::operator=(const Polyhedra_Powerset& y) {
00147 Polyhedra_Powerset& x = *this;
00148 x.Base::operator=(y);
00149 x.space_dim = y.space_dim;
00150 return x;
00151 }
00152
00153 template <typename PH>
00154 inline void
00155 Polyhedra_Powerset<PH>::swap(Polyhedra_Powerset& y) {
00156 Polyhedra_Powerset& x = *this;
00157 x.Base::swap(y);
00158 std::swap(x.space_dim, y.space_dim);
00159 }
00160
00161 template <typename PH>
00162 template <typename QH>
00163 inline Polyhedra_Powerset<PH>&
00164 Polyhedra_Powerset<PH>::operator=(const Polyhedra_Powerset<QH>& y) {
00165 Polyhedra_Powerset& x = *this;
00166 Polyhedra_Powerset<PH> pps(y);
00167 x.swap(pps);
00168 return x;
00169 }
00170
00171 template <typename PH>
00172 inline void
00173 Polyhedra_Powerset<PH>::intersection_assign(const Polyhedra_Powerset& y) {
00174 Polyhedra_Powerset& x = *this;
00175 x.pairwise_apply_assign
00176 (y, CS::lift_op_assign(std::mem_fun_ref(&PH::intersection_assign)));
00177 }
00178
00179 template <typename PH>
00180 inline void
00181 Polyhedra_Powerset<PH>::time_elapse_assign(const Polyhedra_Powerset& y) {
00182 Polyhedra_Powerset& x = *this;
00183 x.pairwise_apply_assign
00184 (y, CS::lift_op_assign(std::mem_fun_ref(&PH::time_elapse_assign)));
00185 }
00186
00187 template <typename PH>
00188 inline bool
00189 Polyhedra_Powerset<PH>
00190 ::geometrically_covers(const Polyhedra_Powerset& y) const {
00191 const Polyhedra_Powerset<NNC_Polyhedron> xx(*this);
00192 const Polyhedra_Powerset<NNC_Polyhedron> yy(y);
00193 return xx.geometrically_covers(yy);
00194 }
00195
00196 template <typename PH>
00197 inline bool
00198 Polyhedra_Powerset<PH>
00199 ::geometrically_equals(const Polyhedra_Powerset& y) const {
00200 const Polyhedra_Powerset<NNC_Polyhedron> xx(*this);
00201 const Polyhedra_Powerset<NNC_Polyhedron> yy(y);
00202 return xx.geometrically_covers(yy) && yy.geometrically_covers(xx);
00203 }
00204
00205 template <>
00206 inline bool
00207 Polyhedra_Powerset<NNC_Polyhedron>
00208 ::geometrically_equals(const Polyhedra_Powerset& y) const {
00209 const Polyhedra_Powerset& x = *this;
00210 return x.geometrically_covers(y) && y.geometrically_covers(x);
00211 }
00212
00213 template <typename PH>
00214 inline memory_size_type
00215 Polyhedra_Powerset<PH>::external_memory_in_bytes() const {
00216 return Base::external_memory_in_bytes();
00217 }
00218
00219 template <typename PH>
00220 inline memory_size_type
00221 Polyhedra_Powerset<PH>::total_memory_in_bytes() const {
00222 return sizeof(*this) + external_memory_in_bytes();
00223 }
00224
00225 template <>
00226 inline void
00227 Polyhedra_Powerset<C_Polyhedron>
00228 ::poly_difference_assign(const Polyhedra_Powerset& y) {
00229 Polyhedra_Powerset<NNC_Polyhedron> nnc_this(*this);
00230 Polyhedra_Powerset<NNC_Polyhedron> nnc_y(y);
00231 nnc_this.poly_difference_assign(nnc_y);
00232 *this = nnc_this;
00233 }
00234
00236 template <typename PH>
00237 inline bool
00238 check_containment(const PH& ph, const Polyhedra_Powerset<PH>& ps) {
00239 const NNC_Polyhedron pph = NNC_Polyhedron(ph.constraints());
00240 const Polyhedra_Powerset<NNC_Polyhedron> pps(ps);
00241 return check_containment(pph, pps);
00242 }
00243
00245 template <>
00246 inline bool
00247 check_containment(const C_Polyhedron& ph,
00248 const Polyhedra_Powerset<C_Polyhedron>& ps) {
00249 return check_containment(NNC_Polyhedron(ph),
00250 Polyhedra_Powerset<NNC_Polyhedron>(ps));
00251 }
00252
00253 }
00254
00255
00256 namespace std {
00257
00259 template <typename PH>
00260 inline void
00261 swap(Parma_Polyhedra_Library::Polyhedra_Powerset<PH>& x,
00262 Parma_Polyhedra_Library::Polyhedra_Powerset<PH>& y) {
00263 x.swap(y);
00264 }
00265
00266 }
00267
00268 #endif // !defined(PPL_Polyhedra_Powerset_inlines_hh)