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

  1. /****************************************************************************
  2.     $Id: bbstats.cpp 501.0 1995/03/07 12:26:08 RON Exp $
  3.  
  4.     Copyright (c) 1995 Tarma Software Research. All rights reserved.
  5.  
  6.     Project:    Tarma Library for C++ V5.0
  7.     Author:     Ron van der Wal
  8.     Created:    18-01-95 09:41
  9.  
  10.     Implementation of class TLBBStats.
  11.  
  12.     $Log: bbstats.cpp $
  13.     Revision 501.0  1995/03/07 12:26:08  RON
  14.     Updated for TLX 5.01
  15.     Revision 1.2  1995/01/18 10:37:20  RON
  16.     Update for release 012
  17.     Added partial support for SunPro C++ compiler
  18.     Revision 1.1  1995/01/18  10:37:20  ron
  19.     Initial revision
  20.     
  21. ****************************************************************************/
  22.  
  23. #include <tlx\501\_build.h>
  24.  
  25. TLX_MODULE_INFO("$Revision: 501.0 $");
  26.  
  27. #include <iostream.h>
  28. #include <iomanip.h>
  29.  
  30. #include <tlx\501\solve\searcher.h>
  31.  
  32. // Template source code
  33.  
  34. #include <tlx\501\template\array.cpp>
  35. #include <tlx\501\template\stats1.cpp>
  36.  
  37. /*-------------------------------------------------------------------------*/
  38.     TLBBStats::TLBBStats()
  39.  
  40. /*  Constructor.
  41. ---------------------------------------------------------------------------*/
  42. {
  43. }
  44.  
  45. /*-------------------------------------------------------------------------*/
  46.     int TLBBStats::DefaultEvents() const
  47.  
  48. /*  Returns the set of search events that the monitor is interested in.
  49. ---------------------------------------------------------------------------*/
  50. {
  51.     return TLSearcher::sePreProcess | TLSearcher::seProcess;
  52. }
  53.  
  54. /*-------------------------------------------------------------------------*/
  55.     void TLBBStats::OnSearchEvent(
  56.         TLSearcher *    aSearcher,
  57.         const Event &   aEvent)
  58.  
  59. /*  Call-back for events handled by this monitor. It updates lowerbound
  60.     statistics.
  61. ---------------------------------------------------------------------------*/
  62. {
  63.     TLX_ASSERT_PTR(aSearcher);
  64.  
  65.     switch (aEvent.mCode)
  66.     {
  67.         case TLSearcher::sePreProcess:
  68.         {
  69.             // The preprocess event is used to reset the statistics
  70.             // to resize the level branching array.
  71.  
  72.             mLBounds.Clear();
  73.             TLX_ASSERT_PTR(aSearcher->GetProblemRep());
  74.             mLBDepth.SetLimits(0, aSearcher->GetProblemRep()->Size());
  75.             break;
  76.         }
  77.         case TLSearcher::seProcess:
  78.         {
  79.             // Whenever a problem is processed, its lowerbound is noted to
  80.             // obtain a measure of the lowerbound progress during the process.
  81.  
  82.             int depth = aSearcher->GetLevel();
  83.             TLX_ASSERT(depth >= mLBDepth.Mini());
  84.             TLX_ASSERT(depth <= mLBDepth.Maxi());
  85.  
  86.             TLX_ASSERT_PTR(aEvent.mProblem);
  87.             TLBBInfo *info = DYNACAST(TLBBInfo *,
  88.                                 aEvent.mProblem->GetInfo());
  89.             TLX_ASSERT_PTR(info);
  90.  
  91.             double lb = info->LowerBound();
  92.             mLBounds.Add(lb);
  93.             mLBDepth[depth].Add(lb);
  94.  
  95.             break;
  96.         }
  97.         // default: all others are ignored
  98.     }
  99. }
  100.  
  101. /*-------------------------------------------------------------------------*/
  102.     ostream &TLBBStats::PrintOn(ostream &os) const
  103.  
  104. /*  Function to print the contents of the monitor on the given stream,
  105.     usually as part of the searcher's ReportStats() processing.
  106. ---------------------------------------------------------------------------*/
  107. {
  108.     os << "Overall lowerbounds: " << mLBounds << "\n";
  109.     os << "Per-level lowerbounds for " << mLBDepth.Size() << " levels:\n";
  110.  
  111.     for (index_t i = mLBDepth.Mini(); i <= mLBDepth.Maxi(); i++)
  112.         os << setw(4) << i << " - " << mLBDepth[i] << "\n";
  113.  
  114.     return os;
  115. }
  116.  
  117.