00001 /* 00002 * Copyright 2007 Baylor University 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "Stats.h" 00018 00019 namespace prophet 00020 { 00021 00022 Stats::~Stats() 00023 { 00024 for (pstats::iterator i = pstats_.begin(); i != pstats_.end(); i++) 00025 { 00026 delete (*i).second; 00027 } 00028 pstats_.clear(); 00029 } 00030 00031 void 00032 Stats::update_stats(const Bundle* b, double p) 00033 { 00034 StatsEntry* se = find(b); 00035 00036 // weed out the oddball 00037 if (se == NULL) return; 00038 00039 // update p_max 00040 if (se->p_max_ < p) se->p_max_ = p; 00041 00042 // update MOPR, Section 3.7, eq. 7 00043 se->mopr_ += (1 - se->mopr_) * p; 00044 00045 // update LMOPR, Section 3.7, eq. 8 00046 se->lmopr_ += p; 00047 00048 // this shouldn't be necessary, since the pointer is already stored 00049 // pstats_[b] = se; 00050 } 00051 00052 double 00053 Stats::get_p_max(const Bundle* b) const 00054 { 00055 if (b == NULL) return 0.0; 00056 return const_cast<Stats*>(this)->find(b)->p_max_; 00057 } 00058 00059 double 00060 Stats::get_mopr(const Bundle* b) const 00061 { 00062 if (b == NULL) return 0.0; 00063 return const_cast<Stats*>(this)->find(b)->mopr_; 00064 } 00065 00066 double 00067 Stats::get_lmopr(const Bundle* b) const 00068 { 00069 if (b == NULL) return 0.0; 00070 return const_cast<Stats*>(this)->find(b)->lmopr_; 00071 } 00072 00073 StatsEntry* 00074 Stats::find(const Bundle* b) 00075 { 00076 if (b == NULL) return NULL; 00077 00078 // search for Stats for Bundle 00079 iterator i = pstats_.lower_bound(b->sequence_num()); 00080 00081 // return it if we find it 00082 if (i != pstats_.end() && !pstats_.key_comp()(b->sequence_num(),i->first)) 00083 return (*i).second; 00084 00085 // otherwise create new zero'd StatsEntry 00086 StatsEntry* se = new StatsEntry(); 00087 00088 // insert into container 00089 pstats_.insert(i,pstats::value_type(b->sequence_num(),se)); 00090 00091 // return new entry 00092 return se; 00093 } 00094 00095 void 00096 Stats::drop_bundle(const Bundle* b) 00097 { 00098 if (b == NULL) return; 00099 00100 iterator i = pstats_.find(b->sequence_num()); 00101 if (i != pstats_.end()) 00102 { 00103 delete (*i).second; 00104 pstats_.erase(i); 00105 dropped_++; 00106 } 00107 } 00108 00109 }; // namespace prophet