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;
}