Generated on Mon Jul 6 18:09:02 2009 for Gecode by doxygen 1.5.9

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: 2009-02-05 06:02:25 +0100 (Thu, 05 Feb 2009) $ by $Author: tack $
00011  *     $Revision: 8152 $
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 
00047   enum NodeStatus {
00048     SOLVED,       
00049     FAILED,       
00050     BRANCH,       
00051     UNDETERMINED, 
00052     SPECIAL,      
00053     STEP          
00054   };
00055 
00056   static const unsigned int FIRSTBIT = 5; //< First free bit in status word
00057   static const unsigned int STATUSMASK = (1<<(FIRSTBIT-1))-1; //< Mask for accessing status
00058 
00060   class StepDesc {
00061   public:
00062     int noOfSteps;
00063     bool debug;
00064     StepDesc(int steps);
00065     void toggleDebug(void);
00066   };
00067 
00069   class SpecialDesc {
00070   public:
00071     const std::string vn;
00072     const int v;
00073     const int rel;
00074     SpecialDesc(std::string varName, int rel0, int v0);
00075   };
00076 
00078   class Statistics : public StatusStatistics {
00079   public:
00081     int solutions;
00083     int failures;
00085     int choices;
00087     int undetermined;
00089     int maxDepth;
00090 
00092     Statistics(void)
00093       : solutions(0), failures(0), choices(0), undetermined(1), maxDepth(0) {}
00094   };
00095 
00096   class SpaceNode;
00097 
00099   class BestNode {
00100   public:
00102     SpaceNode* s;
00104     BestNode(SpaceNode* s0);
00105   };
00106 
00108   class SpaceNode : public Node {
00109   protected:
00111     Space* copy;
00113     Space* workingSpace;
00114   private:
00116     SpaceNode* ownBest;
00117   protected:
00118     union {
00120       const BranchingDesc* branch;
00122       const SpecialDesc* special;
00124       StepDesc* step;
00125     } desc;
00126 
00128     unsigned int nstatus;
00129 
00131     enum SpaceNodeFlags {
00132       HASOPENCHILDREN = FIRSTBIT,
00133       HASFAILEDCHILDREN,
00134       HASSOLVEDCHILDREN
00135     };
00137     static const int LASTBIT = HASSOLVEDCHILDREN;
00138 
00139   private:
00141     void setHasOpenChildren(bool b);
00143     void setHasFailedChildren(bool b);
00145     void setHasSolvedChildren(bool b);
00147     void setStatus(NodeStatus s);
00148 
00150     int recompute(BestNode* curBest, int c_d, int a_d);
00151 
00153     void closeChild(bool hadFailures, bool hadSolutions);
00154   protected:
00156     void acquireSpace(BestNode* curBest, int c_d, int a_d);
00157   public:
00159     SpaceNode(void);
00161     SpaceNode(Space* root);
00163     ~SpaceNode(void);
00164 
00166     Space* getSpace(BestNode* curBest, int c_d, int a_d);
00167 
00169     const Space* getWorkingSpace(void) const;
00170 
00172     void purge(void);
00173 
00175     bool isCurrentBest(BestNode* curBest);
00176 
00187     int getNumberOfChildNodes(NodeAllocator& na,
00188                               BestNode* curBest,
00189                               Statistics& stats,
00190                               int c_d, int a_d);
00191 
00193     NodeStatus getStatus(void) const;
00195     bool isStepNode(void);
00197     void setSpecialDesc(const SpecialDesc* d);
00199     void setStepDesc(StepDesc* d);
00201     StepDesc* getStepDesc(void);
00202 
00204     bool isOpen(void);
00206     bool hasFailedChildren(void);
00208     bool hasSolvedChildren(void);
00210     bool hasOpenChildren(void);
00212     int getNoOfOpenChildren(void);
00214     void setNoOfOpenChildren(int n);
00216     bool hasCopy(void);
00218     bool hasWorkingSpace(void);
00219 
00221     SpaceNode* getParent(void);
00223     SpaceNode* getChild(int i);
00225     int getAlternative(void);
00226   };
00227 
00228 }}
00229 
00230 #include <gecode/gist/spacenode.hpp>
00231 
00232 #endif
00233 
00234 // STATISTICS: gist-any