Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "load-stats-face.h" |
| 22 | |
| 23 | namespace ndnSIM |
| 24 | { |
| 25 | |
| 26 | void |
| 27 | LoadStatsFace::Step () |
| 28 | { |
| 29 | m_count.Step (); |
| 30 | m_satisfied.Step (); |
| 31 | m_unsatisfied.Step (); |
| 32 | } |
| 33 | |
| 34 | // |
| 35 | LoadStats::stats_tuple |
| 36 | LoadStatsFace::GetSatisfiedRatio () const |
| 37 | { |
| 38 | return LoadStats::stats_tuple (m_satisfied.GetStats ().get<0> () / std::max (0.01, m_count.GetStats ().get<0> ()), |
| 39 | m_satisfied.GetStats ().get<1> () / std::max (0.01, m_count.GetStats ().get<1> ()), |
| 40 | m_satisfied.GetStats ().get<2> () / std::max (0.01, m_count.GetStats ().get<2> ())); |
| 41 | } |
| 42 | |
| 43 | LoadStats::stats_tuple |
| 44 | LoadStatsFace::GetUnsatisfiedRatio () const |
| 45 | { |
| 46 | return LoadStats::stats_tuple (m_unsatisfied.GetStats ().get<0> () / std::max (0.01, m_count.GetStats ().get<0> ()), |
| 47 | m_unsatisfied.GetStats ().get<1> () / std::max (0.01, m_count.GetStats ().get<1> ()), |
| 48 | m_unsatisfied.GetStats ().get<2> () / std::max (0.01, m_count.GetStats ().get<2> ())); |
| 49 | } |
| 50 | |
| 51 | LoadStatsFace & |
| 52 | LoadStatsFace::operator += (const LoadStatsFace &load) |
| 53 | { |
| 54 | m_count += load.m_count; |
| 55 | m_satisfied += load.m_satisfied; |
| 56 | m_unsatisfied += load.m_unsatisfied; |
| 57 | |
| 58 | return *this; |
| 59 | } |
| 60 | |
Alexander Afanasyev | 0560eec | 2012-07-16 15:44:31 -0700 | [diff] [blame^] | 61 | bool |
| 62 | LoadStatsFace::IsZero () const |
| 63 | { |
| 64 | return m_count.IsZero () && m_satisfied.IsZero () && m_unsatisfied.IsZero (); |
| 65 | } |
| 66 | |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 67 | std::ostream & |
| 68 | operator << (std::ostream &os, const LoadStatsFace &stats) |
| 69 | { |
| 70 | os << stats.m_count << "/" << stats.m_satisfied << "/" << stats.m_unsatisfied; |
| 71 | return os; |
| 72 | } |
| 73 | |
| 74 | } |