More corrections. Now everything is ready for real tests
diff --git a/utils/load-stats-face.cc b/utils/load-stats-face.cc
index 2e66197..09f3d05 100644
--- a/utils/load-stats-face.cc
+++ b/utils/load-stats-face.cc
@@ -20,9 +20,22 @@
#include "load-stats-face.h"
+#include "ns3/log.h"
+
+#include <boost/mpl/for_each.hpp>
+#include <boost/mpl/range_c.hpp>
+
+using namespace boost::mpl;
+using namespace boost::tuples;
+
+NS_LOG_COMPONENT_DEFINE ("LoadStatsFace");
+
namespace ndnSIM
{
+std::ostream &
+operator << (std::ostream &os, const LoadStats::stats_tuple &tuple);
+
void
LoadStatsFace::Step ()
{
@@ -30,22 +43,47 @@
m_satisfied.Step ();
m_unsatisfied.Step ();
}
-
-//
+
+struct update_retval
+{
+ update_retval (const LoadStats &count, const LoadStats &other, LoadStats::stats_tuple &tuple)
+ : count_ (count)
+ , other_ (other)
+ , tuple_ (tuple) {}
+ const LoadStats &count_;
+ const LoadStats &other_;
+ LoadStats::stats_tuple &tuple_;
+
+ template< typename U >
+ void operator () (U)
+ {
+ if (count_.GetStats ().get<U::value> () < LoadStats::PRECISION)
+ tuple_.get<U::value> () = -1;
+ else
+ tuple_.get<U::value> () = other_.GetStats ().get<U::value> () / count_.GetStats ().get<U::value> ();
+ }
+};
+
LoadStats::stats_tuple
LoadStatsFace::GetSatisfiedRatio () const
{
- return LoadStats::stats_tuple (m_satisfied.GetStats ().get<0> () / std::max (0.01, m_count.GetStats ().get<0> ()),
- m_satisfied.GetStats ().get<1> () / std::max (0.01, m_count.GetStats ().get<1> ()),
- m_satisfied.GetStats ().get<2> () / std::max (0.01, m_count.GetStats ().get<2> ()));
+ LoadStats::stats_tuple retval;
+ for_each< range_c<int, 0, length<LoadStats::stats_tuple>::value> >
+ (update_retval (m_count, m_satisfied, retval));
+
+ NS_LOG_DEBUG (retval.get<0> () << ", " << retval.get<1> () << ", " << retval.get<2> ());
+ return retval;
}
LoadStats::stats_tuple
LoadStatsFace::GetUnsatisfiedRatio () const
{
- return LoadStats::stats_tuple (m_unsatisfied.GetStats ().get<0> () / std::max (0.01, m_count.GetStats ().get<0> ()),
- m_unsatisfied.GetStats ().get<1> () / std::max (0.01, m_count.GetStats ().get<1> ()),
- m_unsatisfied.GetStats ().get<2> () / std::max (0.01, m_count.GetStats ().get<2> ()));
+ LoadStats::stats_tuple retval;
+ for_each< range_c<int, 0, length<LoadStats::stats_tuple>::value> >
+ (update_retval (m_count, m_unsatisfied, retval));
+
+ NS_LOG_DEBUG (retval.get<0> () << ", " << retval.get<1> () << ", " << retval.get<2> ());
+ return retval;
}
LoadStatsFace &
@@ -64,10 +102,42 @@
return m_count.IsZero () && m_satisfied.IsZero () && m_unsatisfied.IsZero ();
}
+struct print_tuple
+{
+ print_tuple (const LoadStats::stats_tuple &tuple, std::ostream &os)
+ : tuple_ (tuple)
+ , os_ (os)
+ {
+ }
+
+ const LoadStats::stats_tuple &tuple_;
+ std::ostream &os_;
+
+ template< typename U >
+ void operator () (U)
+ {
+ os_ << tuple_.get< U::value > () << " ";
+ }
+};
+
+
+std::ostream &
+operator << (std::ostream &os, const LoadStats::stats_tuple &tuple)
+{
+ for_each< range_c<int, 0, length<LoadStats::stats_tuple>::value> >
+ (print_tuple (tuple, os));
+
+ return os;
+}
+
std::ostream &
operator << (std::ostream &os, const LoadStatsFace &stats)
{
- os << stats.m_count << "/" << stats.m_satisfied << "/" << stats.m_unsatisfied;
+ LoadStats::stats_tuple
+ satisfied = stats.GetSatisfiedRatio (),
+ unsatisfied = stats.GetUnsatisfiedRatio ();
+
+ os << "ration satisfied: " << satisfied << "/ unsatisfied: " << unsatisfied;
return os;
}
diff --git a/utils/load-stats.cc b/utils/load-stats.cc
index 8a663e3..66786fd 100644
--- a/utils/load-stats.cc
+++ b/utils/load-stats.cc
@@ -23,22 +23,26 @@
using namespace ns3;
-const double EXP_1 = exp (-5.0/60.0); /* 1/exp(5sec/1min) */
-const double EXP_5 = exp (-5.0/300.0); /* 1/exp(5sec/5min) */
-const double EXP_15 = exp (-5.0/900.0); /* 1/exp(5sec/15min) */
+// const double EXP_1 = (1-2.0/6.0);//exp (-1.0/5.0); /* 1/exp(1sec/5sec) */
+// const double EXP_2 = (1-2.0/31.0);//exp (-1.0/30.0); /* 1/exp(1sec/30sec) */
+// const double EXP_3 = (1-2.0/61.0);//exp (-1.0/60.0); /* 1/exp(1sec/60sec) */
-const double EPSILON = 0.000001;
+const double EXP_1 = exp (-1.0/5.0); /* 1/exp(1sec/5sec) */
+const double EXP_2 = exp (-1.0/30.0); /* 1/exp(1sec/30sec) */
+const double EXP_3 = exp (-1.0/60.0); /* 1/exp(1sec/60sec) */
NS_LOG_COMPONENT_DEFINE ("LoadStats");
namespace ndnSIM
{
+const double LoadStats::PRECISION = 0.1;
+
LoadStats::LoadStats ()
: counter_ (0)
, avg1_ (0)
- , avg5_ (0)
- , avg15_ (0)
+ , avg2_ (0)
+ , avg3_ (0)
{
}
@@ -48,9 +52,9 @@
// NS_LOG_FUNCTION (this);
// do magic
- avg1_ = EXP_1 * avg1_ + (1 - EXP_1) * counter_;
- avg5_ = EXP_1 * avg5_ + (1 - EXP_5) * counter_;
- avg15_ = EXP_1 * avg15_ + (1 - EXP_15) * counter_;
+ avg1_ = EXP_1 * avg1_ + (1 - EXP_1) * counter_;
+ avg2_ = EXP_2 * avg2_ + (1 - EXP_2) * counter_;
+ avg3_ = EXP_3 * avg3_ + (1 - EXP_3) * counter_;
counter_ = 0;
}
@@ -76,22 +80,22 @@
LoadStats::stats_tuple
LoadStats::GetStats () const
{
- return stats_tuple (avg1_, avg5_, avg15_);
+ return stats_tuple (avg1_, avg2_, avg3_);
}
bool
LoadStats::IsZero () const
{
return (counter_ == 0 &&
- avg1_ < EPSILON &&
- avg5_ < EPSILON &&
- avg15_ < EPSILON);
+ avg1_ < PRECISION &&
+ avg2_ < PRECISION &&
+ avg3_ < PRECISION);
}
std::ostream &
operator << (std::ostream &os, const LoadStats &stats)
{
- os << stats.avg1_ << ", " << stats.avg5_ << ", " << stats.avg15_;
+ os << stats.avg1_ << ", " << stats.avg2_ << ", " << stats.avg3_;
return os;
}
diff --git a/utils/load-stats.h b/utils/load-stats.h
index a9f2e5f..0b03ce5 100644
--- a/utils/load-stats.h
+++ b/utils/load-stats.h
@@ -32,6 +32,8 @@
public:
typedef boost::tuple<double, double, double> stats_tuple;
+ static const double PRECISION;
+
LoadStats ();
void
@@ -59,8 +61,8 @@
uint32_t counter_;
double avg1_;
- double avg5_;
- double avg15_;
+ double avg2_;
+ double avg3_;
friend std::ostream &
operator << (std::ostream &os, const LoadStats &stats);