Generated on Thu Mar 22 10:39:32 2012 for Gecode by doxygen 1.6.3

spacenode.hh

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2006
00008  *
00009  *  Last modified:
00010  *     $Date: 2010-08-11 15:13:48 +0200 (Wed, 11 Aug 2010) $ by $Author: tack $
00011  *     $Revision: 11343 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  * Permission is hereby granted, free of charge, to any person obtaining
00018  * a copy of this software and associated documentation files (the
00019  * "Software"), to deal in the Software without restriction, including
00020  * without limitation the rights to use, copy, modify, merge, publish,
00021  * distribute, sublicense, and/or sell copies of the Software, and to
00022  * permit persons to whom the Software is furnished to do so, subject to
00023  * the following conditions:
00024  *
00025  * The above copyright notice and this permission notice shall be
00026  * included in all copies or substantial portions of the Software.
00027  *
00028  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #ifndef GECODE_GIST_SPACENODE_HH
00039 #define GECODE_GIST_SPACENODE_HH
00040 
00041 #include <gecode/gist/node.hh>
00042 #include <gecode/kernel.hh>
00043 
00044 namespace Gecode { namespace Gist {
00045 
00048   enum NodeStatus {
00049     SOLVED,       
00050     FAILED,       
00051     BRANCH,       
00052     UNDETERMINED, 
00053     STOP,         
00054     UNSTOP,       
00055   };
00056 
00057   static const unsigned int FIRSTBIT = 24; //< First free bit in status word
00058   static const unsigned int STATUSMASK = 7<<20; //< Mask for accessing status
00059   static const unsigned int MAXDISTANCE = (1<<20)-1; //< Maximum representable distance
00060   static const unsigned int DISTANCEMASK = (1<<20)-1; //< Mask for accessing distance
00061 
00063   class Statistics : public StatusStatistics {
00064   public:
00066     int solutions;
00068     int failures;
00070     int choices;
00072     int undetermined;
00074     int maxDepth;
00075 
00077     Statistics(void)
00078       : solutions(0), failures(0), choices(0), undetermined(1), maxDepth(0) {}
00079   };
00080 
00081   class SpaceNode;
00082 
00084   class BestNode {
00085   public:
00087     SpaceNode* s;
00089     BestNode(SpaceNode* s0);
00090   };
00091 
00093   class SpaceNode : public Node {
00094   protected:
00100     Space* copy;
00101   protected:
00102     const Choice* choice;
00103 
00110     unsigned int nstatus;
00111 
00113     void setDistance(unsigned int d);
00114     
00116     unsigned int getDistance(void) const;
00117 
00119     void setFlag(int flag, bool value);
00120 
00122     bool getFlag(int flag) const;
00123 
00125     enum SpaceNodeFlags {
00126       HASOPENCHILDREN = FIRSTBIT,
00127       HASFAILEDCHILDREN,
00128       HASSOLVEDCHILDREN
00129     };
00131     static const int LASTBIT = HASSOLVEDCHILDREN;
00132 
00133   private:
00135     void setHasOpenChildren(bool b);
00137     void setHasFailedChildren(bool b);
00139     void setHasSolvedChildren(bool b);
00140 
00142     int recompute(NodeAllocator& na,
00143                   BestNode* curBest, int c_d, int a_d);
00144 
00146     void closeChild(const NodeAllocator& na,
00147                     bool hadFailures, bool hadSolutions);
00148   protected:
00150     void setStatus(NodeStatus s);
00152     void acquireSpace(NodeAllocator& na,
00153                       BestNode* curBest, int c_d, int a_d);
00154   public:
00156     SpaceNode(int p);
00158     SpaceNode(Space* root);
00159 
00161     Space* getSpace(NodeAllocator& na,
00162                     BestNode* curBest, int c_d, int a_d);
00163 
00165     const Space* getWorkingSpace(void) const;
00166 
00168     void purge(const NodeAllocator& na);
00169 
00171     void dispose(void);
00172 
00174     bool isCurrentBest(BestNode* curBest);
00175 
00186     int getNumberOfChildNodes(NodeAllocator& na,
00187                               BestNode* curBest,
00188                               Statistics& stats,
00189                               int c_d, int a_d);
00190 
00192     NodeStatus getStatus(void) const;
00193 
00195     bool isOpen(void);
00197     bool hasFailedChildren(void);
00199     bool hasSolvedChildren(void);
00201     bool hasOpenChildren(void);
00203     int getNoOfOpenChildren(const NodeAllocator& na);
00205     void setNoOfOpenChildren(int n);
00207     bool hasCopy(void);
00209     bool hasWorkingSpace(void);
00210 
00212     int getAlternative(const NodeAllocator& na) const;
00214     const Choice* getChoice(void);
00215   };
00216 
00217 }}
00218 
00219 #endif
00220 
00221 // STATISTICS: gist-any