home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / SRC / SRCHSTAT.CPP < prev    next >
C/C++ Source or Header  |  1996-07-08  |  5KB  |  144 lines

  1. /****************************************************************************
  2.     $Id: srchstat.cpp 501.0 1995/03/07 12:26:22 RON Exp $
  3.  
  4.     Copyright (c) 1991-95 Tarma Software Research. All rights reserved.
  5.  
  6.     Project:    Tarma Library for C++ V5.0
  7.     Author:    Ron van der Wal
  8.  
  9.     Implementation of class TLSearchStats.
  10.  
  11.     $Log: srchstat.cpp $
  12.     Revision 501.0  1995/03/07 12:26:22  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.10  1995/02/22 12:43:00  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.9  1995/01/18  10:39:34  ron
  18.     Simplified limit setting of per-depth statistics
  19.  
  20.     Revision 1.8  1995/01/12  13:41:29  ron
  21.     Adapted to previous Searcher/ProblemRep model
  22.  
  23.     Revision 1.7  1995/01/08  11:48:09  ron
  24.     Adapted to change in searcher depth type from int32 to int
  25.  
  26.     Revision 1.6  1995/01/06  15:58:27  ron
  27.     Corrected Revision keyword
  28.  
  29.     Revision 1.5  1995/01/05  15:29:33  ron
  30.     Naming and formatting changes
  31.  
  32.     Revision 1.4  1994/11/16  15:43:36  ron
  33.     Added module info; rearranged #include directives
  34.  
  35.     Revision 1.3  1994/10/13  11:53:30  ron
  36.     Moved class declaration to searcher.h
  37.  
  38.     Revision 1.2  1994/10/10  16:55:35  ron
  39.     Moved definition of searcher events to TLSearcher
  40.  
  41.     Revision 1.1  1994/10/07  17:05:35  ron
  42.     Initial revision
  43.  
  44. ****************************************************************************/
  45.  
  46. #include <tlx\501\_build.h>
  47.  
  48. TLX_MODULE_INFO("$Revision: 501.0 $");
  49.  
  50. #include <iostream.h>
  51. #include <iomanip.h>
  52.  
  53. #include <tlx\501\solve\searcher.h>
  54.  
  55. // Template source code
  56.  
  57. #include <tlx\501\template\array.cpp>
  58. #include <tlx\501\template\stats1.cpp>
  59.  
  60. /*-------------------------------------------------------------------------*/
  61.     TLSearchStats::TLSearchStats()
  62.  
  63. /*  Constructor.
  64. ---------------------------------------------------------------------------*/
  65. {
  66. }
  67.  
  68. /*-------------------------------------------------------------------------*/
  69.     int TLSearchStats::DefaultEvents() const
  70.  
  71. /*  Returns the set of search events that the monitor is interested in.
  72. ---------------------------------------------------------------------------*/
  73. {
  74.     return TLSearcher::sePreProcess | TLSearcher::seInitial |
  75.            TLSearcher::seBranch | TLSearcher::seEnter;
  76. }
  77.  
  78. /*-------------------------------------------------------------------------*/
  79.     void TLSearchStats::OnSearchEvent(
  80.         TLSearcher *    aSearcher,
  81.         const Event &    aEvent)
  82.  
  83. /*  Call-back for events handled by this monitor. It updates search
  84.     statistics.
  85. ---------------------------------------------------------------------------*/
  86. {
  87.     TLX_ASSERT_PTR(aSearcher);
  88.  
  89.     switch (aEvent.mCode)
  90.     {
  91.     case TLSearcher::sePreProcess:
  92.     {
  93.         // The preprocess event is used to reset the statistics
  94.         // to resize the level branching array.
  95.  
  96.         mDepth.Clear();
  97.         mBranching.Clear();
  98.         TLX_ASSERT_PTR(aSearcher->GetProblemRep());
  99.         mLevelBranch.SetLimits(0, aSearcher->GetProblemRep()->Size());
  100.         break;
  101.     }
  102.     case TLSearcher::seInitial:
  103.     case TLSearcher::seBranch:
  104.     {
  105.         // The decomposition events are used to track the branching factor
  106.         // at each level, and globally.
  107.  
  108.         mBranching.Add(aEvent.mUint32Parm);
  109.  
  110.         int depth = aSearcher->GetLevel();
  111.         TLX_ASSERT(depth >= mLevelBranch.Mini());
  112.         TLX_ASSERT(depth <= mLevelBranch.Maxi());
  113.         mLevelBranch[depth].Add(aEvent.mUint32Parm);
  114.         break;
  115.     }
  116.     case TLSearcher::seEnter:
  117.         // Whenever a problem is processed, its depth is noted to obtain
  118.         // a measure of the average search depth during the process.
  119.  
  120.         mDepth.Add(aSearcher->GetLevel());
  121.         break;
  122.  
  123.     // default: all others are ignored
  124.     }
  125. }
  126.  
  127. /*-------------------------------------------------------------------------*/
  128.     ostream &TLSearchStats::PrintOn(ostream &os) const
  129.  
  130. /*  Function to print the contents of the monitor on the given stream,
  131.     usually as part of the searcher's ReportStats() processing.
  132. ---------------------------------------------------------------------------*/
  133. {
  134.     os << "Depth statistics : " << mDepth << "\n";
  135.     os << "Overall branching: " << mBranching << "\n";
  136.     os << "Per-level branching for " << mLevelBranch.Size() << " levels:\n";
  137.  
  138.     for (index_t i = mLevelBranch.Mini(); i <= mLevelBranch.Maxi(); i++)
  139.     os << setw(4) << i << " - " << mLevelBranch[i] << "\n";
  140.  
  141.     return os;
  142. }
  143.  
  144.