00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef DBM_PFED_H
00011 #define DBM_PFED_H
00012
00013 #include <stdexcept>
00014 #include "dbm/Valuation.h"
00015 #include "dbm/priced.h"
00016 #include "base/slist.h"
00017
00018 namespace dbm
00019 {
00020 class pdbm_t;
00021
00022
00023
00024
00025
00026
00027
00028 class pfed_t
00029 {
00030 public:
00031 typedef std::slist<PDBM>::const_iterator const_iterator;
00032
00033 protected:
00034 typedef std::slist<PDBM>::iterator iterator;
00035
00036 struct pfed_s
00037 {
00038 std::slist<PDBM> zones;
00039 uint32_t count;
00040 cindex_t dim;
00041 };
00042
00043 static std::allocator<pfed_s> alloc;
00044
00045
00046 struct pfed_s *ptr;
00047
00048
00049 void incRef();
00050
00051
00052 void decRef();
00053
00054
00055 void prepare();
00056
00057
00058 iterator beginMutable();
00059
00060
00061 iterator endMutable();
00062
00063
00064
00065
00066
00067 iterator erase(iterator);
00068
00069
00070
00071
00072
00073 void add(const PDBM pdbm, size_t dim);
00074 public:
00075
00076
00077 pfed_t();
00078
00079
00080 explicit pfed_t(cindex_t dim);
00081
00082
00083
00084
00085
00086 pfed_t(const PDBM pdbm, cindex_t dim);
00087
00088
00089 pfed_t(const pfed_t &);
00090
00091
00092
00093
00094
00095 ~pfed_t();
00096
00097
00098
00099
00100
00101
00102 bool constrain(cindex_t i, uint32_t value);
00103
00104
00105
00106
00107
00108
00109
00110 bool constrain(cindex_t i, cindex_t j, raw_t constraint);
00111
00112
00113
00114
00115
00116
00117
00118 bool constrain(cindex_t i, cindex_t j, int32_t b, bool isStrict);
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 bool constrain(const constraint_t *constraints, size_t n);
00130
00131
00132
00133
00134
00135
00136 bool constrain(const constraint_t& c);
00137
00138
00139 int32_t getInfimum() const;
00140
00141
00142
00143
00144
00145
00146 bool satisfies(const constraint_t& c) const;
00147
00148
00149
00150
00151
00152
00153
00154 bool satisfies(cindex_t i, cindex_t j, raw_t constraint) const;
00155
00156
00157 bool isEmpty() const;
00158
00159
00160 bool isUnbounded() const;
00161
00162
00163 uint32_t hash(uint32_t seed) const;
00164
00165
00166 bool contains(const DoubleValuation &v) const;
00167
00168
00169 bool contains(const IntValuation &v) const;
00170
00171
00172 void up();
00173
00174
00175 void up(int32_t rate);
00176
00177
00178 void updateValue(cindex_t clock, uint32_t value);
00179
00180
00181
00182
00183
00184 void updateValueZero(cindex_t clock, int32_t value, cindex_t zero);
00185
00186 void extrapolateMaxBounds(int32_t *max);
00187 void diagonalExtrapolateMaxBounds(int32_t *max);
00188 void diagonalExtrapolateLUBounds(int32_t *lower, int32_t *upper);
00189
00190 void incrementCost(int32_t value);
00191
00192 int32_t getCostOfValuation(const IntValuation &valuation) const;
00193 void relax();
00194
00195 void freeClock(cindex_t clock);
00196
00197
00198
00199
00200
00201 void setZero();
00202
00203
00204
00205
00206
00207 void setInit();
00208
00209
00210
00211
00212 void setEmpty();
00213
00214
00215
00216
00217 const_iterator begin() const;
00218
00219
00220
00221
00222
00223 const_iterator end() const;
00224
00225 bool operator == (const pfed_t &) const;
00226
00227
00228 pfed_t &operator = (const pfed_t &);
00229
00230
00231 pfed_t& operator = (const PDBM);
00232
00233
00234 pfed_t &operator |= (const pfed_t &);
00235
00236
00237 pfed_t &operator |= (const PDBM);
00238
00239
00240 pfed_t &operator -= (const pfed_t &);
00241
00242
00243 pfed_t &operator += (const pfed_t &);
00244
00245
00246 pfed_t &operator &= (const pfed_t &);
00247
00248
00249 bool intersects(const pfed_t &) const;
00250
00251
00252 pfed_t operator & (const pfed_t& b) const;
00253
00254
00255 pfed_t operator - (const pfed_t& b) const;
00256
00257
00258 void down();
00259
00260
00261 int32_t getUpperMinimumCost(cindex_t) const;
00262
00263
00264 void relaxUp();
00265
00266
00267 void getValuation(DoubleValuation& cval, bool *freeC = NULL) const;
00268
00269
00270 void swapClocks(cindex_t, cindex_t);
00271
00272
00273 void splitExtrapolate(const constraint_t *, const constraint_t *,
00274 const int32_t *);
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 relation_t relation(const pfed_t &fed) const;
00289
00290
00291
00292
00293
00294 int32_t getInfimumValuation(IntValuation &valuation, const bool *free = NULL) const;
00295
00296
00297 size_t size() const;
00298
00299
00300 size_t getDimension() const;
00301
00302
00303
00304
00305
00306
00307
00308 void freeUp(cindex_t);
00309
00310
00311
00312
00313
00314
00315
00316 void freeDown(cindex_t);
00317
00318 template <typename Predicate>
00319 void erase_if(Predicate p);
00320
00321 template <typename Predicate>
00322 void erase_if_not(Predicate p);
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 raw_t operator () (cindex_t i, cindex_t j) const;
00333
00334
00335
00336
00337
00338 int32_t getRate(cindex_t) const;
00339
00340
00341
00342
00343
00344 size_t analyzeForMinDBM(uint32_t *bitMatrix) const;
00345
00346
00347
00348
00349
00350 int32_t getOffsetCost() const;
00351
00352
00353
00354
00355
00356 int32_t getSlopeOfDelayTrajectory() const;
00357
00358 void setOffsetCost(int32_t);
00359 void setRate(cindex_t, int32_t);
00360
00361
00362 int32_t *writeToMinDBMWithOffset(bool minimizeGraph,
00363 bool tryConstraints16,
00364 allocator_t c_alloc,
00365 uint32_t offset) const;
00366
00367
00368 static size_t getSizeOfMinDBM(size_t dimension, const int32_t *);
00369
00370 static pfed_t readFromMinDBM(size_t dimension, const int32_t *);
00371
00372
00373 relation_t relation(const int32_t *, raw_t *) const;
00374
00375
00376
00377
00378
00379 bool isOnZeroCycle(cindex_t clock, cindex_t &result) const;
00380
00381 const pfed_t &const_dbmt() const;
00382 };
00383
00384 template <typename Predicate>
00385 inline void pfed_t::erase_if(Predicate p)
00386 {
00387 iterator first = beginMutable();
00388 iterator last = endMutable();
00389 while (first != last)
00390 {
00391 if (p(*first))
00392 {
00393 first = erase(first);
00394 }
00395 else
00396 {
00397 ++first;
00398 }
00399 }
00400 }
00401
00402 template <typename Predicate>
00403 void pfed_t::erase_if_not(Predicate p)
00404 {
00405 iterator first = beginMutable();
00406 iterator last = endMutable();
00407 while (first != last)
00408 {
00409 if (p(*first))
00410 {
00411 ++first;
00412 }
00413 else
00414 {
00415 first = erase(first);
00416 }
00417 }
00418 }
00419
00420
00421 inline pfed_t::pfed_t(const pfed_t &pfed) : ptr(pfed.ptr)
00422 {
00423 incRef();
00424 }
00425
00426 inline pfed_t::~pfed_t()
00427 {
00428 assert(ptr->count > 0);
00429 decRef();
00430 }
00431
00432 inline pfed_t::iterator pfed_t::beginMutable()
00433 {
00434 assert(ptr->count <= 1);
00435 return ptr->zones.begin();
00436 }
00437
00438 inline pfed_t::iterator pfed_t::endMutable()
00439 {
00440 assert(ptr->count <= 1);
00441 return ptr->zones.end();
00442 }
00443
00444 inline pfed_t::const_iterator pfed_t::begin() const
00445 {
00446 return ptr->zones.begin();
00447 }
00448
00449 inline pfed_t::const_iterator pfed_t::end() const
00450 {
00451 return ptr->zones.end();
00452 }
00453
00454 inline size_t pfed_t::getDimension() const
00455 {
00456 return ptr->dim;
00457 }
00458
00459 inline size_t pfed_t::size() const
00460 {
00461 return ptr->zones.size();
00462 }
00463
00464 inline void pfed_t::incRef()
00465 {
00466 ptr->count++;
00467 }
00468
00469
00470 inline bool pfed_t::isEmpty() const
00471 {
00472 return ptr->zones.empty();
00473 }
00474
00475 inline const pfed_t &pfed_t::const_dbmt() const
00476 {
00477 assert(size() == 1);
00478 return *this;
00479 }
00480
00481 inline pfed_t& pfed_t::operator = (const PDBM pdbm)
00482 {
00483 *this = pfed_t(pdbm, ptr->dim);
00484 return *this;
00485 }
00486
00487 inline bool pfed_t::constrain(cindex_t i, cindex_t j, int32_t b, bool isStrict)
00488 {
00489 return constrain(i, j, dbm_boundbool2raw(b, isStrict));
00490 }
00491
00492 inline bool pfed_t::constrain(const constraint_t& c)
00493 {
00494 return constrain(c.i, c.j, c.value);
00495 }
00496
00497 inline bool pfed_t::satisfies(const constraint_t& c) const
00498 {
00499 return satisfies(c.i, c.j, c.value);
00500 }
00501 }
00502
00503 #endif