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

  1. /****************************************************************************
  2.     $Id: cspmonit.cpp 501.0 1995/03/07 12:26:10 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 TLCSPMonitor.
  10.  
  11.     $Log: cspmonit.cpp $
  12.     Revision 501.0  1995/03/07 12:26:10  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.5  1995/01/31 16:30:06  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.4  1995/01/18  10:37:44  ron
  18.     Simplified limit setting of per-depth statistics
  19.  
  20.     Revision 1.3  1995/01/12  13:38:47  ron
  21.     Adapted to previous Searcher/ProblemRep model
  22.  
  23.     Revision 1.2  1995/01/08  11:44:16  ron
  24.     Changed searcher depth type from int32 to int
  25.  
  26.     Revision 1.1  1995/01/06  15:56:48  ron
  27.     Adapted to new Searcher/Problem model
  28.  
  29. ****************************************************************************/
  30.  
  31. #include <tlx\501\_build.h>
  32.  
  33. TLX_MODULE_INFO("$Revision: 501.0 $");
  34.  
  35. #include <iostream.h>
  36. #include <iomanip.h>
  37.  
  38. #include <tlx\501\solve\stdcsp.h>
  39.  
  40. // Template source code
  41.  
  42. #include <tlx\501\template\array.cpp>
  43. #include <tlx\501\template\stats1.cpp>
  44.  
  45. /*-------------------------------------------------------------------------*/
  46.     TLCSPMonitor::TLCSPMonitor()
  47.  
  48. /*  Constructor.
  49. ---------------------------------------------------------------------------*/
  50. {
  51.     mPrevCount = 0;
  52. }
  53.  
  54. /*-------------------------------------------------------------------------*/
  55.     int TLCSPMonitor::DefaultEvents() const
  56.  
  57. /*  Returns the set of search events that the monitor is interested in.
  58. ---------------------------------------------------------------------------*/
  59. {
  60.     return TLSearcher::sePreProcess | TLSearcher::seProcess;
  61. }
  62.  
  63. /*-------------------------------------------------------------------------*/
  64.     void TLCSPMonitor::OnSearchEvent(
  65.     TLSearcher *    aSearcher,
  66.     const Event &    aEvent)
  67.  
  68. /*  Call-back for events handled by this monitor. It updates search
  69.     statistics.
  70. ---------------------------------------------------------------------------*/
  71. {
  72.     TLX_ASSERT_PTR(aSearcher);
  73.  
  74.     switch (aEvent.mCode)
  75.     {
  76.     case TLSearcher::sePreProcess:
  77.     {
  78.         // The preprocess event is used to reset the statistics
  79.         // to resize the level branching array.
  80.  
  81.         mChecks.Clear();
  82.         TLX_ASSERT_PTR(aSearcher->GetProblemRep());
  83.         mLevelChecks.SetLimits(0, aSearcher->GetProblemRep()->Size());
  84.         mPrevCount = 0;
  85.         break;
  86.     }
  87.     case TLSearcher::seProcess:
  88.     {
  89.         // Whenever a problem is processed, the new number of constraint
  90.         // checks is noted.
  91.  
  92.         int32 newcnt = TLConstraint::CheckCount();
  93.         if (newcnt < mPrevCount)
  94.         {
  95.         TLX_TRACE_WARN(TLX, ("Constraint check count has been reset"));
  96.         mPrevCount = newcnt;
  97.         }
  98.  
  99.         int32 diff = newcnt - mPrevCount;
  100.         mPrevCount    = newcnt;
  101.  
  102.         int depth = aSearcher->GetLevel();
  103.         TLX_ASSERT(depth >= mLevelChecks.Mini());
  104.         TLX_ASSERT(depth <= mLevelChecks.Maxi());
  105.         mChecks.Add(diff);
  106.         mLevelChecks[depth].Add(diff);
  107.         break;
  108.     }
  109.  
  110.     // default: all others are ignored
  111.     }
  112. }
  113.  
  114. /*-------------------------------------------------------------------------*/
  115.     ostream &TLCSPMonitor::PrintOn(ostream &os) const
  116.  
  117. /*  Function to print the contents of the monitor on the given stream,
  118.     usually as part of the searcher's ReportStats() processing.
  119. ---------------------------------------------------------------------------*/
  120. {
  121.     os << "Overall constraint checks: " << mChecks << "\n";
  122.     os << "Per-level checks for " << mLevelChecks.Size() << " levels:\n";
  123.  
  124.     for (index_t i = mLevelChecks.Mini(); i <= mLevelChecks.Maxi(); i++)
  125.     os << setw(4) << i << " - " << mLevelChecks[i] << "\n";
  126.  
  127.     return os;
  128. }
  129.  
  130.