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

  1. /****************************************************************************
  2.     $Id: srchwdog.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 TLSearchWatchdog.
  10.  
  11.     $Log: srchwdog.cpp $
  12.     Revision 501.0  1995/03/07 12:26:22  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.7  1995/02/22 12:43:06  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.6  1995/01/12  13:41:39  ron
  18.     Added newline to monitor output
  19.  
  20.     Revision 1.5  1995/01/06  15:58:28  ron
  21.     Corrected Revision keyword
  22.  
  23.     Revision 1.4  1995/01/05  15:29:50  ron
  24.     Naming and formatting changes
  25.  
  26.     Revision 1.3  1994/11/16  15:43:44  ron
  27.     Added module info; rearranged #include directives
  28.  
  29.     Revision 1.2  1994/10/13  11:54:26  ron
  30.     Moved class declaration to searcher.h
  31.  
  32.     Revision 1.1  1994/10/10  16:55:55  ron
  33.     Initial revision
  34.  
  35. ****************************************************************************/
  36.  
  37. #include <tlx\501\_build.h>
  38.  
  39. TLX_MODULE_INFO("$Revision: 501.0 $");
  40.  
  41. #include <iostream.h>
  42. #include <iomanip.h>
  43.  
  44. #include <tlx\501\log.h>
  45. #include <tlx\501\solve\searcher.h>
  46.  
  47. /*-------------------------------------------------------------------------*/
  48.     TLSearchWatchdog::TLSearchWatchdog(int32 aMaxCount)
  49.  
  50. /*  Constructor.
  51. ---------------------------------------------------------------------------*/
  52. {
  53.     mProblemCount = 0;
  54.     mMaxProblems  = aMaxCount;
  55. }
  56.  
  57. /*-------------------------------------------------------------------------*/
  58.     int TLSearchWatchdog::DefaultEvents() const
  59.  
  60. /*  Returns the set of search events that the monitor is interested in.
  61. ---------------------------------------------------------------------------*/
  62. {
  63.     return TLSearcher::sePreProcess | TLSearcher::seEnter;
  64. }
  65.  
  66. /*-------------------------------------------------------------------------*/
  67.     void TLSearchWatchdog::OnSearchEvent(
  68.         TLSearcher *    aSearcher,
  69.         const Event &    aEvent)
  70.  
  71. /*  Call-back for events handled by this monitor. It updates the node
  72.     counter and terminates the searcher if expired.
  73. ---------------------------------------------------------------------------*/
  74. {
  75.     TLX_ASSERT_PTR(aSearcher);
  76.  
  77.     switch (aEvent.mCode)
  78.     {
  79.     case TLSearcher::sePreProcess:
  80.     {
  81.         // The preprocess event is used to reset the node count
  82.  
  83.         mProblemCount = 0;
  84.         break;
  85.     }
  86.  
  87.     case TLSearcher::seEnter:
  88.         // Whenever a problem is processed, it is counted. If the maximum
  89.         // number is exceeded, the searcher is terminated.
  90.  
  91.         if (++mProblemCount > mMaxProblems)
  92.         {
  93.         TLX_LOG_ENTRY("Watchdog terminates searcher after %ld problems",
  94.                   mProblemCount);
  95.         aSearcher->Terminate();
  96.         }
  97.         break;
  98.  
  99.     // default: all others are ignored
  100.     }
  101. }
  102.  
  103. /*-------------------------------------------------------------------------*/
  104.     ostream &TLSearchWatchdog::PrintOn(ostream &os) const
  105.  
  106. /*  Function to print the contents of the monitor on the given stream,
  107.     usually as part of the searcher's ReportStats() processing.
  108. ---------------------------------------------------------------------------*/
  109. {
  110.     return os << "Watchdog: " << mProblemCount << " problems counted (max="
  111.         << mMaxProblems << ")\n";
  112. }
  113.  
  114.