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

  1. /****************************************************************************
  2.     $Id: propfc.cpp 501.0 1995/03/07 12:26:20 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 TLPropagatorFC class. This class implements a
  10.     forward-checking constraint propagation algorithm.
  11.  
  12.     $Log: propfc.cpp $
  13.     Revision 501.0  1995/03/07 12:26:20  RON
  14.     Updated for TLX 5.01
  15.     Revision 1.12  1995/01/31 16:30:22  RON
  16.     Update for release 012
  17.     Added partial support for SunPro C++ compiler
  18.     Revision 1.11  1995/01/06  15:58:12  ron
  19.     Corrected Revision keyword
  20.  
  21.     Revision 1.10  1995/01/05  15:27:10  ron
  22.     Added standard Propagate() functions
  23.  
  24.     Revision 1.9  1994/11/16  15:42:15  ron
  25.     Added module info; rearranged #include directives
  26.  
  27.     Revision 1.8  1994/10/10  16:53:47  ron
  28.     Changed to <tlx\solve\csp.h>
  29.  
  30.     Revision 1.7  1994/10/07  17:03:34  ron
  31.     Changed Unregister...() to Deregister...()
  32.  
  33.     Revision 1.6  1994/09/28  14:20:28  ron
  34.     Removed Macintosh-style #include references
  35.  
  36.     Revision 1.5  1994/09/27  20:22:46  ron
  37.     Changed path separator from / to \
  38.  
  39.     Revision 1.4  1994/09/26  15:45:30  ron
  40.     Adapted to changes in constraint check counting
  41.  
  42.     Revision 1.3  1994/09/13  10:14:10  ron
  43.     Added a call to reset the failed constraint pointer
  44.  
  45.     Revision 1.2  1994/09/06  14:07:02  ron
  46.     Adapted implementation of CheckForward() to general changes in CSP
  47.  
  48.     Revision 1.1  1994/08/16  18:13:08  ron
  49.     Initial revision
  50.  
  51. ****************************************************************************/
  52.  
  53. #include <tlx\501\_build.h>
  54.  
  55. TLX_MODULE_INFO("$Revision: 501.0 $");
  56.  
  57. #include <iostream.h>
  58. #include <tlx\501\solve\csp.h>
  59.  
  60. /*-------------------------------------------------------------------------*/
  61.     TLPropagatorFC::TLPropagatorFC()
  62.  
  63. /*  Constructor. Initializes the propagator.
  64. ---------------------------------------------------------------------------*/
  65. : TLPropagator()
  66. {
  67. }
  68.  
  69. /*-------------------------------------------------------------------------*/
  70.     bool TLPropagatorFC::CheckForward(TLVariable &var)
  71.  
  72. /*  Performs a forward check that starts with the given variable. Only
  73.     the constraints that originate with this variable are evaluated for
  74.     their effects.
  75.  
  76.     The function returns nonzero if the system is consistent, else zero.
  77. ---------------------------------------------------------------------------*/
  78. {
  79.     SetFailedConstraint(0);
  80.     RegisterPropagator();
  81.  
  82.     int32 ccnt = TLConstraint::CheckCount();
  83.     bool result = var.PropagateChanges();
  84.  
  85.     mStats.mCheckCount += TLConstraint::CheckCount() - ccnt;
  86.     DeregisterPropagator();
  87.  
  88.     return result;
  89. }
  90.  
  91. /*-------------------------------------------------------------------------*/
  92.     const char *TLPropagatorFC::Description() const
  93.  
  94. /*  Returns a description of the propagation algorithm.
  95. ---------------------------------------------------------------------------*/
  96. {
  97.     return "Forward check";
  98. }
  99.  
  100. /*-------------------------------------------------------------------------*/
  101.     bool TLPropagatorFC::Propagate(TLVariable *aVar)
  102.  
  103. /*  Standard propagation interface to propagate from the given variable.
  104. ---------------------------------------------------------------------------*/
  105. {
  106.     TLX_ASSERT_PTR(aVar);
  107.  
  108.     return CheckForward(*aVar);
  109. }
  110.  
  111. /*-------------------------------------------------------------------------*/
  112.     bool TLPropagatorFC::Propagate(TLPtrIter<TLVariable> &aIter)
  113.  
  114. /*  Standard propagation interface to propagate from the given list of
  115.     variables.
  116. ---------------------------------------------------------------------------*/
  117. {
  118.     for (aIter.Reset(); aIter.Next(); )
  119.     {
  120.     TLX_ASSERT_PTR(aIter.Peek());
  121.  
  122.     if (!CheckForward(*aIter.Peek()))
  123.         return false;
  124.     }
  125.     return true;
  126. }
  127.