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