src/ell/StatePairCollector.cc
Go to the documentation of this file.00001
00002 #include "ell/StatePairCollector.hh"
00003
00004 #include <biu/assertbiu.hh>
00005
00006
00007
00008
00009 namespace ell {
00010
00011 SPC_Counting::SPC_Counting()
00012 : lastAdded_s1(NULL)
00013 , lastAdded_s2(NULL)
00014 , statePairCount(0)
00015 {
00016 }
00017
00018 SPC_Counting::~SPC_Counting()
00019 {
00020 clearLastAdded();
00021 }
00022
00023
00024
00025 void
00026 SPC_Counting::add(const StatePair& s) {
00027 assertbiu(s.first != NULL, "first of the collected State pair is NULL");
00028 assertbiu(s.second!=NULL, "second of the collected State pair is NULL");
00029
00030
00031 lastAdded_s1 = s.first->clone(lastAdded_s1);
00032 lastAdded_s2 = s.second->clone(lastAdded_s2);
00033
00034 statePairCount++;
00035 }
00036
00037
00038
00039 void
00040 SPC_Counting::add(const State* const s1_, const State*const s2_) {
00041 assertbiu(s1_ != NULL, "first of the collected State pair is NULL");
00042 assertbiu(s2_ != NULL, "second of the collected State pair is NULL");
00043
00044
00045 lastAdded_s1 = s1_->clone(lastAdded_s1);
00046 lastAdded_s2 = s2_->clone(lastAdded_s2);
00047
00048 statePairCount++;
00049 }
00050
00051
00052
00053 size_t
00054 SPC_Counting::size() const {
00055 return statePairCount;
00056 }
00057
00058
00059
00060 const SPC_Counting::StatePair
00061 SPC_Counting::getLastAdded() const {
00062 return StatePair(lastAdded_s1,lastAdded_s2);
00063 }
00064
00065 }
00066
00067
00068
00069
00070
00071 namespace ell {
00072
00073 SPC_Listing::SPC_Listing()
00074 : statePairList()
00075 {}
00076
00077 SPC_Listing::~SPC_Listing()
00078 {
00079
00080 for ( List::iterator it = statePairList.begin();
00081 it != statePairList.end(); it++ )
00082 {
00083 delete it->first;
00084 delete it->second;
00085 }
00086
00087 statePairList.clear();
00088 }
00089
00090
00091
00092 void
00093 SPC_Listing::add(const StatePair& s) {
00094 assertbiu(s.first != NULL, "first of the collected State pair is NULL");
00095 assertbiu(s.second!=NULL, "second of the collected State pair is NULL");
00096
00097 statePairList.push_back(StatePair(s.first->clone(),s.second->clone()));
00098 }
00099
00100
00101
00102 void
00103 SPC_Listing::add(const State* const s1_, const State*const s2_) {
00104 assertbiu(s1_ != NULL, "first of the collected State pair is NULL");
00105 assertbiu(s2_ != NULL, "second of the collected State pair is NULL");
00106
00107 statePairList.push_back(StatePair(s1_->clone(),s2_->clone()));
00108 }
00109
00110
00111
00112 size_t
00113 SPC_Listing::size() const {
00114 return statePairList.size();
00115 }
00116
00117
00118
00119 const SPC_Listing::StatePair
00120 SPC_Listing::getLastAdded() const {
00121 return *(statePairList.rbegin());
00122 }
00123
00125
00126
00127
00128 const SPC_Listing::List&
00129 SPC_Listing::getList() const {
00130 return statePairList;
00131 }
00132
00133
00134 }
00135
00136
00137
00138
00139
00140 namespace ell
00141 {
00142
00143 SPC_Outstream::SPC_Outstream( std::ostream& out_
00144 , const std::string& separator
00145 , const std::string& toAppend)
00146 : SPC_Counting()
00147 , out(out_)
00148 , strSep(separator)
00149 , strAppend(toAppend)
00150 {
00151 }
00152
00153 SPC_Outstream::~SPC_Outstream()
00154 {
00155
00156 out.flush();
00157 }
00158
00159
00160
00161 void
00162 SPC_Outstream::add(const StatePair& s) {
00163 assertbiu(s.first != NULL, "first of the collected State pair is NULL");
00164 assertbiu(s.second!=NULL, "second of the collected State pair is NULL");
00165
00166 SPC_Counting::add(s);
00167
00168 printToStream();
00169 }
00170
00171 void
00172 SPC_Outstream::add(const State* const s1_, const State*const s2_) {
00173 assertbiu(s1_ != NULL, "first of the collected State pair is NULL");
00174 assertbiu(s2_ != NULL, "second of the collected State pair is NULL");
00175
00176 SPC_Counting::add(s1_, s2_);
00177
00178 printToStream();
00179 }
00180
00181 }
00182
00183
00184
00185
00186
00187 namespace ell {
00188
00189 SPC_MinPair::SPC_MinPair( const bool pairsAddedInAscOrder_ )
00190 : SPC_Counting()
00191 , pairsAddedInAscOrder(pairsAddedInAscOrder_)
00192 , minPair_s1(NULL)
00193 , minPair_s2(NULL)
00194 , minPair_max(NULL)
00195 {
00196 }
00197
00198 SPC_MinPair::~SPC_MinPair()
00199 {
00200
00201 clearMinPair();
00202 }
00203
00204
00205
00206 void
00207 SPC_MinPair::add(const StatePair& s) {
00208 assertbiu(s.first != NULL, "first of the collected State pair is NULL");
00209 assertbiu(s.second!=NULL, "second of the collected State pair is NULL");
00210
00211 SPC_Counting::add(s);
00212
00213 checkMinPair();
00214 }
00215
00216 void
00217 SPC_MinPair::add(const State* const s1_, const State*const s2_) {
00218 assertbiu(s1_ != NULL, "first of the collected State pair is NULL");
00219 assertbiu(s2_ != NULL, "second of the collected State pair is NULL");
00220
00221 SPC_Counting::add(s1_, s2_);
00222
00223 checkMinPair();
00224 }
00225
00226
00227
00228 const SPC_Counting::StatePair
00229 SPC_MinPair::getMinPair() const {
00230 return StatePair(minPair_s1,minPair_s2);
00231 }
00232
00233 void
00234 SPC_MinPair::checkMinPair() {
00235
00236
00237
00238 if (pairsAddedInAscOrder && minPair_s1 != NULL) {
00239 return;
00240 }
00241
00242 if ( minPair_s1 == NULL )
00243 {
00244
00245 minPair_s1 = lastAdded_s1->clone();
00246 minPair_s2 = lastAdded_s2->clone();
00247
00248 minPair_max = (minPair_s1->operator <(*minPair_s2))?minPair_s1:minPair_s2;
00249 return;
00250 }
00251
00252 const State* lastMax = (lastAdded_s1->operator <(*lastAdded_s2))?lastAdded_s1:lastAdded_s2;
00253
00254 if ( lastMax->operator <(*minPair_max)) {
00255
00256 minPair_s1 = lastAdded_s1->clone(minPair_s1);
00257 minPair_s2 = lastAdded_s2->clone(minPair_s2);
00258
00259 minPair_max = (lastMax==lastAdded_s1)?minPair_s1:minPair_s2;
00260 }
00261 }
00262
00263 }
00264
00265
00266
00267
00268