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

  1. /****************************************************************************
  2.     $Id: constrai.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 the TLConstraint class. This class is the abstract
  10.     base class for all constraints in the CSP framework.
  11.  
  12.     $Log: constrai.cpp $
  13.     Revision 501.0  1995/03/07 12:26:10  RON
  14.     Updated for TLX 5.01
  15.     Revision 1.10  1995/01/31 16:30:06  RON
  16.     Update for release 012
  17.     Added partial support for SunPro C++ compiler
  18.     Revision 1.9  1995/01/13  15:30:45  ron
  19.     Changed activation flag to activation count; this ensures that
  20.     constraints with arity > 1 will remain deactivated until all
  21.     connected variables are free
  22.  
  23.     Revision 1.8  1995/01/06  15:57:31  ron
  24.     Corrected Revision keyword
  25.  
  26.     Revision 1.7  1994/11/16  15:37:45  ron
  27.     Added module info; rearranged #include directives
  28.  
  29.     Revision 1.6  1994/10/10  16:47:20  ron
  30.     Chnaged to <tlx\solve\csp.h>
  31.  
  32.     Revision 1.5  1994/10/05  18:36:31  ron
  33.     Added conditional propagation
  34.  
  35.     Revision 1.4  1994/09/28  14:16:15  ron
  36.     Removed Macintosh-style #include references
  37.  
  38.     Revision 1.3  1994/09/27  20:22:07  ron
  39.     Changed path separator from / to \
  40.  
  41.     Revision 1.2  1994/09/26  15:41:00  ron
  42.     Added static constraint check counter
  43.  
  44.     Revision 1.1  1994/08/16  18:12:56  ron
  45.     Initial revision
  46.  
  47. ****************************************************************************/
  48.  
  49. #include <tlx\501\_build.h>
  50.  
  51. TLX_MODULE_INFO("$Revision: 501.0 $");
  52.  
  53. #include <tlx\501\solve\csp.h>
  54.  
  55. /*---------------------------------------------------------------------------
  56.     Static data members
  57. ---------------------------------------------------------------------------*/
  58.  
  59. int32 TLConstraint::sCheckCount = 0;
  60.  
  61. /*-------------------------------------------------------------------------*/
  62.     TLConstraint::TLConstraint()
  63.  
  64. /*  Constructor. Resets deactivation flag.
  65. ---------------------------------------------------------------------------*/
  66. {
  67.     mDeactiveCount = 0;
  68. }
  69.  
  70. /*-------------------------------------------------------------------------*/
  71.     TLConstraint::~TLConstraint()
  72.  
  73. /*  Destructor. Does nothing, but is declared virtual for derivation.
  74. ---------------------------------------------------------------------------*/
  75. {
  76. }
  77.  
  78. /*-------------------------------------------------------------------------*/
  79.     void TLConstraint::Activate()
  80.  
  81. /*  Undoes a level of deactivation by decrementing the deactivation count.
  82. ---------------------------------------------------------------------------*/
  83. {
  84.     if (--mDeactiveCount < 0)
  85.     {
  86.     TLX_TRACE_WARN(TLX, ("More activations than deactivations"));
  87.     mDeactiveCount = 0;
  88.     }
  89. }
  90.  
  91. /*-------------------------------------------------------------------------*/
  92.     void TLConstraint::Deactivate()
  93.  
  94. /*  Deactivates the constraint by increasing its deactivation count. There
  95.     must be a matching number of activations to make the constraint active
  96.     again.
  97. ---------------------------------------------------------------------------*/
  98. {
  99.     if (mDeactiveCount < INT_MAX)
  100.     ++mDeactiveCount;
  101.     else
  102.     TLX_TRACE_WARN(TLX, ("Maximum number of deactivations exceeded"));
  103. }
  104.  
  105. /*-------------------------------------------------------------------------*/
  106.     bool TLConstraint::PropagateCond(TLVariable *aVar)
  107.  
  108. /*  Constraint propagation function. Will call the Propagate() implementation
  109.     if the constraint is active, else will do nothing. Returns the result
  110.     of Propagate(), or true if the constraint is not active.
  111. ---------------------------------------------------------------------------*/
  112. {
  113.     return IsActive() ? Propagate(aVar) : true;
  114. }
  115.  
  116.