11 #include <ibrcommon/Logger.h>
41 for(predictmap::const_iterator it = _predictmap.begin(); it != _predictmap.end(); ++it)
44 const std::string eid = it->first.getString();
49 const float& f = it->second;
51 ss << f << std::flush;
62 for(predictmap::const_iterator it = _predictmap.begin(); it != _predictmap.end(); ++it)
64 const std::string eid = it->first.getString();
67 const float& f = it->second;
70 ss << f << std::flush;
75 IBRCOMMON_LOGGER_DEBUG_TAG(
"DeliveryPredictabilityMap", 20) <<
"Serialized with " << _predictmap.size() <<
" items." << IBRCOMMON_LOGGER_ENDL;
76 IBRCOMMON_LOGGER_DEBUG_TAG(
"DeliveryPredictabilityMap", 60) << *
this << IBRCOMMON_LOGGER_ENDL;
86 while(elements_read < map_size)
93 std::vector<char> eid_cstr(eid_len.get<
size_t>());
96 stream.read(&eid_cstr[0], eid_cstr.size());
110 std::vector<char> f_cstr(float_len.get<
size_t>());
113 stream.read(&f_cstr[0], f_cstr.size());
116 std::stringstream ss(std::string(f_cstr.begin(), f_cstr.end()));
128 _predictmap[eid] = f;
133 IBRCOMMON_LOGGER_DEBUG_TAG(
"DeliveryPredictabilityMap", 20) <<
"Deserialized with " << _predictmap.size() <<
" items." << IBRCOMMON_LOGGER_ENDL;
134 IBRCOMMON_LOGGER_DEBUG_TAG(
"DeliveryPredictabilityMap", 60) << *
this << IBRCOMMON_LOGGER_ENDL;
140 predictmap::const_iterator it;
141 if ((it = _predictmap.find(neighbor)) != _predictmap.end())
151 _predictmap[neighbor] = value;
161 return _predictmap.size();
171 p_ab = p_encounter_first;
177 for (predictmap::const_iterator it = dpm._predictmap.begin(); it != dpm._predictmap.end(); ++it)
180 const float &p_bc = it->second;
183 if (host_b.
sameHost(host_c))
continue;
188 predictmap::iterator dp_it;
189 if ((dp_it = _predictmap.find(host_c)) != _predictmap.end()) {
190 dp_it->second = max(dp_it->second, p_ab * p_bc * _beta);
192 _predictmap[host_c] = p_ab * p_bc * _beta;
202 if (current_time <= _lastAgingTime)
return;
206 predictmap::iterator it;
207 for(it = _predictmap.begin(); it != _predictmap.end();)
215 it->second *= pow(_gamma, k.
get<
int>());
217 if(it->second < p_first_threshold)
219 _predictmap.erase(it++);
225 _lastAgingTime = current_time;
230 predictmap::const_iterator it;
231 for (it = _predictmap.begin(); it != _predictmap.end(); ++it)
233 stream << it->first.getString() <<
": " << it->second << std::endl;
252 output << absAgingTime;
257 for (predictmap::const_iterator it = _predictmap.begin(); it != _predictmap.end(); ++it)
260 const float &p_value = it->second;
265 output << peer_entry;
268 output.write(static_cast<const char*>((
const char*)&p_value),
sizeof(p_value));
281 input >> absAgingTime;
288 if (monotonic_now >= (absAgingTime - monotonic_diff))
291 _lastAgingTime = absAgingTime - monotonic_diff;
296 _lastAgingTime = monotonic_now;
300 input >> num_entries;
303 while (input.good() && num_entries > 0)
309 input.read(static_cast<char*>((
char*)&p_value),
sizeof(p_value));
void update(const dtn::data::EID &origin, const DeliveryPredictabilityMap &dpm, const float &p_encounter_first)
void store(std::ostream &output) const
static const dtn::data::Number identifier
static dtn::data::EID local
bool sameHost(const std::string &other) const
void set(const dtn::data::EID &neighbor, float value)
This class keeps track of the predictablities to see a specific EID.
virtual std::ostream & serialize(std::ostream &stream) const
virtual dtn::data::Length getLength() const
void toString(std::ostream &stream) const
static dtn::data::Timestamp getTime()
virtual const dtn::data::Number & getIdentifier() const
std::string getString() const
std::ostream & operator<<(std::ostream &stream, const NodeHandshake &hs)
void restore(std::istream &input)
void age(const float &p_first_threshold)
static dtn::data::Timestamp getMonotonicTimestamp()
virtual std::istream & deserialize(std::istream &stream)
dtn::data::SDNV< Size > Number
float get(const dtn::data::EID &neighbor) const
virtual ~DeliveryPredictabilityMap()
DeliveryPredictabilityMap()