Generated on Fri Oct 19 11:25:00 2018 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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  * Permission is hereby granted, free of charge, to any person obtaining
00014  * a copy of this software and associated documentation files (the
00015  * "Software"), to deal in the Software without restriction, including
00016  * without limitation the rights to use, copy, modify, merge, publish,
00017  * distribute, sublicense, and/or sell copies of the Software, and to
00018  * permit persons to whom the Software is furnished to do so, subject to
00019  * the following conditions:
00020  *
00021  * The above copyright notice and this permission notice shall be
00022  * included in all copies or substantial portions of the Software.
00023  *
00024  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #ifndef GECODE_GIST_SPACENODE_HH
00035 #define GECODE_GIST_SPACENODE_HH
00036 
00037 #include <gecode/gist/node.hh>
00038 #include <gecode/kernel.hh>
00039 
00040 namespace Gecode { namespace Gist {
00041 
00044   enum NodeStatus {
00045     SOLVED,       
00046     FAILED,       
00047     BRANCH,       
00048     UNDETERMINED, 
00049     STOP,         
00050     UNSTOP,       
00051   };
00052 
00053   static const unsigned int FIRSTBIT = 24; //< First free bit in status word
00054   static const unsigned int STATUSMASK = 7<<20; //< Mask for accessing status
00055   static const unsigned int MAXDISTANCE = (1<<20)-1; //< Maximum representable distance
00056   static const unsigned int DISTANCEMASK = (1<<20)-1; //< Mask for accessing distance
00057 
00059   class Statistics : public StatusStatistics {
00060   public:
00062     int solutions;
00064     int failures;
00066     int choices;
00068     int undetermined;
00070     int maxDepth;
00071 
00073     Statistics(void)
00074       : solutions(0), failures(0), choices(0), undetermined(1), maxDepth(0) {}
00075   };
00076 
00077   class SpaceNode;
00078 
00080   class BestNode {
00081   public:
00083     SpaceNode* s;
00085     BestNode(SpaceNode* s0);
00086   };
00087 
00089   class SpaceNode : public Node {
00090   protected:
00096     Space* copy;
00097   protected:
00098     const Choice* choice;
00099 
00106     unsigned int nstatus;
00107 
00109     void setDistance(unsigned int d);
00110 
00112     unsigned int getDistance(void) const;
00113 
00115     void setFlag(int flag, bool value);
00116 
00118     bool getFlag(int flag) const;
00119 
00121     enum SpaceNodeFlags {
00122       HASOPENCHILDREN = FIRSTBIT,
00123       HASFAILEDCHILDREN,
00124       HASSOLVEDCHILDREN
00125     };
00127     static const int LASTBIT = HASSOLVEDCHILDREN;
00128 
00129   private:
00131     void setHasOpenChildren(bool b);
00133     void setHasFailedChildren(bool b);
00135     void setHasSolvedChildren(bool b);
00136 
00138     int recompute(NodeAllocator& na,
00139                   BestNode* curBest, int c_d, int a_d);
00140 
00142     void closeChild(const NodeAllocator& na,
00143                     bool hadFailures, bool hadSolutions);
00144   protected:
00146     void setStatus(NodeStatus s);
00148     void acquireSpace(NodeAllocator& na,
00149                       BestNode* curBest, int c_d, int a_d);
00150   public:
00152     SpaceNode(int p);
00154     SpaceNode(Space* root);
00155 
00157     Space* getSpace(NodeAllocator& na,
00158                     BestNode* curBest, int c_d, int a_d);
00159 
00161     const Space* getWorkingSpace(void) const;
00162 
00164     void purge(const NodeAllocator& na);
00165 
00167     void dispose(void);
00168 
00170     bool isCurrentBest(BestNode* curBest);
00171 
00182     int getNumberOfChildNodes(NodeAllocator& na,
00183                               BestNode* curBest,
00184                               Statistics& stats,
00185                               int c_d, int a_d);
00186 
00188     NodeStatus getStatus(void) const;
00189 
00191     bool isOpen(void);
00193     bool hasFailedChildren(void);
00195     bool hasSolvedChildren(void);
00197     bool hasOpenChildren(void);
00199     int getNoOfOpenChildren(const NodeAllocator& na);
00201     void setNoOfOpenChildren(int n);
00203     bool hasCopy(void);
00205     bool hasWorkingSpace(void);
00206 
00208     int getAlternative(const NodeAllocator& na) const;
00210     const Choice* getChoice(void);
00211   };
00212 
00213 }}
00214 
00215 #endif
00216 
00217 // STATISTICS: gist-any