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

  1. /****************************************************************************
  2.     $Id: problist.cpp 501.0 1995/03/07 12:26:18 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 TLProblemList.
  10.  
  11.     $Log: problist.cpp $
  12.     Revision 501.0  1995/03/07 12:26:18  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.11  1995/02/28 15:12:22  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.10  1995/01/12  13:40:28  ron
  18.     Small formatting changes
  19.  
  20.     Revision 1.9  1995/01/06  15:56:53  ron
  21.     Adapted to new Searcher/Problem model
  22.  
  23.     Revision 1.8  1995/01/05  15:26:03  ron
  24.     Naming changes
  25.  
  26.     Revision 1.7  1994/11/16  15:41:34  ron
  27.     Added module info; rearranged #include directives
  28.  
  29.     Revision 1.6  1994/10/10  16:52:30  ron
  30.     Changed to <tlx\solve\searcher.h>
  31.  
  32.     Revision 1.5  1994/10/05  18:41:08  ron
  33.     Added support for Watcom C++
  34.  
  35.     Revision 1.4  1994/09/28  14:19:51  ron
  36.     Removed Macintosh-style #include references
  37.  
  38.     Revision 1.3  1994/09/27  20:22:38  ron
  39.     Changed path separator from / to \
  40.  
  41.     Revision 1.2  1994/09/26  15:44:02  ron
  42.     Changed include file references
  43.  
  44.     Revision 1.1  1994/08/16  18:13:06  ron
  45.     Initial revision
  46.  
  47. ****************************************************************************/
  48.  
  49. #include <tlx\501\_build.h>
  50.  
  51. TLX_MODULE_INFO("$Revision: 501.0 $");
  52.  
  53. //-----    System headers
  54.  
  55. #include <iostream.h>
  56. #include <stdio.h>
  57.  
  58. //----- Library headers
  59.  
  60. #include <tlx\501\solve\searcher.h>
  61.  
  62. /*---------------------------------------------------------------------------
  63.     Template instantiations
  64. ---------------------------------------------------------------------------*/
  65.  
  66. #if defined(THINK_CPLUS)
  67.     #include "ptrseq.cpp"
  68.     #pragma template TLPtrSeq<TLProblemState>;
  69. #elif defined(__BORLANDC__) || defined(_MSC_VER) || defined(__SC__) || defined(__WATCOMC__)
  70.     #include <tlx\501\template\ptrseq.cpp>
  71. #elif defined(__SUNPRO_CC)
  72.     #include <tlx\501\template\ptrseq.cpp>
  73. #elif defined(__IBMCPP__)
  74.   #if __IBMCPP__ < 300
  75.     #pragma implementation("tlx\\template\\ptrseq.cpp")
  76.   #else
  77.     #include <tlx\501\template\ptrseq.cpp>
  78.   #endif
  79. #else
  80.     #error Unsupported compiler; contact Tarma Software Research
  81. #endif
  82.  
  83. /*-------------------------------------------------------------------------*/
  84.     TLProblemList::TLProblemList(TLProblemState *aProblem)
  85.  
  86. /*  Constructor. Creates a node list with a single subproblem and no
  87.     ability to expand. Also sets the sequence to be owner of the nodes
  88.     stored in it, and sets the proper sorting function.
  89. ---------------------------------------------------------------------------*/
  90. : TLPtrSeq<TLProblemState>(aProblem)
  91. {
  92.     TLX_ASSERT_PTR(aProblem);
  93.  
  94.     BecomeOwner(true);
  95.     SetCompare(CompareProblems);
  96. }
  97.  
  98. /*-------------------------------------------------------------------------*/
  99.     TLProblemList::TLProblemList(size_t aCap, size_t aDelta)
  100.  
  101. /*  Constructor. Creates a node list with the given initial capacity and
  102.     expansion factor. Also sets the sequence to be owner of the nodes
  103.     stored in it, and sets the proper sorting function.
  104. ---------------------------------------------------------------------------*/
  105. : TLPtrSeq<TLProblemState>(aCap, aDelta)
  106. {
  107.     BecomeOwner(true);
  108.     SetCompare(CompareProblems);
  109. }
  110.  
  111. /*-------------------------------------------------------------------------*/
  112.     int TLProblemList::CompareProblems(
  113.         const void *    aProblem1,
  114.     const void *    aProblem2)
  115.  
  116. /*  Static member function that compares two subproblems by their ranking.
  117.     Returns: < 0 if the first one is less than the second, 0 if they are
  118.     equal, and > 0 if the first one is larger than the second one.
  119. ---------------------------------------------------------------------------*/
  120. {
  121.     double diff = RECAST(const TLProblemState *, aProblem1)->GetRank() -
  122.           RECAST(const TLProblemState *, aProblem2)->GetRank();
  123.  
  124.     return (diff < 0.0) ? -1 : (diff > 0.0) ? 1 : 0;
  125. }
  126.