Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgSearchStatistics.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SgSearchStatistics.cpp */
00003 //----------------------------------------------------------------------------
00004 
00005 #include "SgSystem.h"
00006 #include "SgSearchStatistics.h"
00007 
00008 #include <iostream>
00009 #include "SgTime.h"
00010 
00011 using namespace std;
00012 
00013 //----------------------------------------------------------------------------
00014 
00015 SgSearchStatistics::SgSearchStatistics()
00016 {
00017     Clear();
00018 }
00019 
00020 SgSearchStatistics::SgSearchStatistics(const SgSearchStatistics& stat)
00021     : m_numNodes(stat.m_numNodes),
00022       m_numEvals(stat.m_numEvals),
00023       m_numMoves(stat.m_numMoves),
00024       m_numPass(stat.m_numPass),
00025       m_depthReached(stat.m_depthReached),
00026       m_timeUsed(stat.m_timeUsed)
00027 {
00028 }
00029 
00030 SgSearchStatistics::~SgSearchStatistics()
00031 {
00032 }
00033 
00034 SgSearchStatistics&
00035 SgSearchStatistics::operator=(const SgSearchStatistics& rhs)
00036 {
00037     if (this != &rhs)
00038     {
00039         m_numNodes = rhs.m_numNodes;
00040         m_numEvals = rhs.m_numEvals;
00041         m_numMoves = rhs.m_numMoves;
00042         m_numPass = rhs.m_numPass;
00043         m_timeUsed = rhs.m_timeUsed;
00044         m_depthReached = rhs.m_depthReached;
00045     }
00046     return *this;
00047 }
00048 
00049 SgSearchStatistics&
00050 SgSearchStatistics::operator+=(const SgSearchStatistics& rhs)
00051 {
00052     m_numNodes += rhs.m_numNodes;
00053     m_numEvals += rhs.m_numEvals;
00054     m_numMoves += rhs.m_numMoves;
00055     m_numPass += rhs.m_numPass;
00056     m_timeUsed += rhs.m_timeUsed;
00057     if (m_depthReached < rhs.m_depthReached)
00058     {
00059         m_depthReached = rhs.m_depthReached;
00060     }
00061     return *this;
00062 }
00063 
00064 void SgSearchStatistics::Clear()
00065 {
00066     m_numNodes = 0;
00067     m_numEvals = 0;
00068     m_numMoves = 0;
00069     m_numPass = 0;
00070     m_timeUsed = 0;
00071     m_depthReached = 0;
00072 }
00073 
00074 SgSearchStatistics* SgSearchStatistics::Duplicate() const
00075 {
00076     return new SgSearchStatistics(*this);
00077 }
00078 
00079 double SgSearchStatistics::NumNodesPerSecond() const
00080 {
00081     double used = TimeUsed();
00082     if (used == 0)
00083         return 0;
00084     return m_numNodes / used;
00085 }
00086 
00087 double SgSearchStatistics::NumEvalsPerSecond() const
00088 {
00089     double used = TimeUsed();
00090     if (used == 0)
00091         return 0;
00092     return m_numEvals / used;
00093 }
00094 
00095 ostream& operator<<(ostream& stream, const SgSearchStatistics &s)
00096 {
00097     stream << "SearchStatistics: "
00098            << s.NumNodes() << " Nodes, "
00099            << s.NumEvals() << " Evals, Time: "
00100            << SgTime::Format(s.TimeUsed())
00101            << " DepthReached: " << s.DepthReached() << ", " 
00102            << s.NumNodesPerSecond() << " Nodes/s, "
00103            << s.NumEvalsPerSecond() << " Evals/s\n";
00104     return stream;
00105 }
00106 
00107 //----------------------------------------------------------------------------
00108 


Sun Mar 13 2011 Doxygen 1.7.1