home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / SRC / VARAC6.CPP < prev    next >
C/C++ Source or Header  |  1996-01-05  |  5KB  |  161 lines

  1. /****************************************************************************
  2.     $Id: varac6.cpp 501.0 1995/03/07 12:26:26 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 TLVariableAC6.
  10.  
  11.     $Log: varac6.cpp $
  12.     Revision 501.0  1995/03/07 12:26:26  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.8  1995/01/31 16:30:32  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.7  1995/01/06  15:58:40  ron
  18.     Corrected Revision keyword
  19.  
  20.     Revision 1.6  1994/11/16  15:45:35  ron
  21.     Added module info; rearranged #include directives
  22.  
  23.     Revision 1.5  1994/10/10  16:56:57  ron
  24.     Changed to <tlx\solve\ac6.h>
  25.  
  26.     Revision 1.4  1994/09/28  14:47:05  ron
  27.     Removed Macintosh-style #include references
  28.  
  29.     Revision 1.3  1994/09/27  20:23:20  ron
  30.     Changed path separator from / to \
  31.  
  32.     Revision 1.2  1994/09/26  15:50:11  ron
  33.     Changed include file references
  34.  
  35.     Revision 1.1  1994/08/16  18:13:20  ron
  36.     Initial revision
  37.  
  38. ****************************************************************************/
  39.  
  40. #include <tlx\501\_build.h>
  41.  
  42. TLX_MODULE_INFO("$Revision: 501.0 $");
  43.  
  44. #include <tlx\501\solve\ac6.h>
  45.  
  46. /*-------------------------------------------------------------------------*/
  47.     TLVariableAC6::TLVariableAC6(const char *aName, size_t aCap)
  48.  
  49. /*  Constructor. Creates a domain with a given initial capacity.
  50. ---------------------------------------------------------------------------*/
  51. : TLVariable(aName), mDomain(aCap, 50)
  52. {
  53. }
  54.  
  55. /*-------------------------------------------------------------------------*/
  56.     void TLVariableAC6::AddSupport(tVarValue aValue, const VV_Assoc &aVV)
  57.  
  58. /*  Adds the given variable/value pair to the support list of the given
  59.     domain value.
  60. ---------------------------------------------------------------------------*/
  61. {
  62.     TLDomainElement &el = mDomain.GetElement(aValue);
  63.     el.AddSupport(aVV);
  64. }
  65.  
  66. /*-------------------------------------------------------------------------*/
  67.     void TLVariableAC6::AddValue(tVarValue aValue)
  68.  
  69. /*  Adds a value and an empty support list to the domain of the variable.
  70. ---------------------------------------------------------------------------*/
  71. {
  72.     mDomain.Append(TLDomainElement(aValue));
  73. }
  74.  
  75. /*-------------------------------------------------------------------------*/
  76.     void TLVariableAC6::ClearSupport()
  77.  
  78. /*  Clears all support lists of all values in the domain.
  79. ---------------------------------------------------------------------------*/
  80. {
  81.     for (index_t i = mDomain.Mini(); i <= mDomain.Maxi(); i++)
  82.     mDomain.PeekAt(i).ClearSupport();
  83. }
  84.  
  85. /*-------------------------------------------------------------------------*/
  86.     void TLVariableAC6::DiscardDomain(void *aDom)
  87.  
  88. /*  Discards a domain that was previously created by SaveDomain().
  89. ---------------------------------------------------------------------------*/
  90. {
  91.     TLX_ASSERT_PTR(aDom);
  92.     delete (TLDomainAC6 *)aDom;
  93. }
  94.  
  95. /*-------------------------------------------------------------------------*/
  96.     TLConstraintAC6 *TLVariableAC6::FindConstraintTo
  97.     (
  98.         const TLVariableAC6 *    aVar
  99.     ) const
  100.  
  101. /*  Looks through all constraints connected to the variable to find the
  102.     (first) one that is connected to the given variable.
  103. ---------------------------------------------------------------------------*/
  104. {
  105.     TLX_ASSERT_PTR(aVar);
  106.  
  107.     // We assume that all constraints are of type TLConstraintAC6 or
  108.     // derived thereof.
  109.  
  110.     for (index_t i = Constraints().Mini(); i <= Constraints().Maxi(); i++)
  111.     {
  112.     TLConstraintAC6 *con = DYNACAST(TLConstraintAC6 *,
  113.                     Constraints().PeekAt(i));
  114.     TLX_ASSERT_PTR(con);
  115.  
  116.     if (&((const TLConstraintAC6 *)con)->OppositeOf(*this) == aVar)
  117.         return con;
  118.     }
  119.     return 0;
  120. }
  121.  
  122. /*-------------------------------------------------------------------------*/
  123.     void TLVariableAC6::RemoveSupport(tVarValue aValue, const VV_Assoc &aVV)
  124.  
  125. /*  Removes the given variable/value pair from the support list of the
  126.     given domain value.
  127. ---------------------------------------------------------------------------*/
  128. {
  129.     TLDomainElement &el = mDomain.GetElement(aValue);
  130.     el.RemoveSupport(aVV);
  131. }
  132.  
  133. /*-------------------------------------------------------------------------*/
  134.     void TLVariableAC6::RemoveValue(tVarValue aValue)
  135.  
  136. /*  Removes a value (and its support list) from the domain of the variable.
  137. ---------------------------------------------------------------------------*/
  138. {
  139.     mDomain.Remove(TLDomainElement(aValue));
  140. }
  141.  
  142. /*-------------------------------------------------------------------------*/
  143.     void TLVariableAC6::RestoreDomain(void *aDom)
  144.  
  145. /*  Restores a domain that was previously saved by SaveDomain().
  146. ---------------------------------------------------------------------------*/
  147. {
  148.     TLX_ASSERT_PTR(aDom);
  149.     mDomain = *(TLDomainAC6 *)aDom;
  150. }
  151.  
  152. /*-------------------------------------------------------------------------*/
  153.     void *TLVariableAC6::SaveDomain()
  154.  
  155. /*  Saves the domain by creating and returning a copy of it.
  156. ---------------------------------------------------------------------------*/
  157. {
  158.     return new TLDomainAC6(mDomain);
  159. }
  160.  
  161.