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

node.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-12 13:38:27 +0200 (Thu, 12 Aug 2010) $ by $Author: zayenz $
00011  *     $Revision: 11349 $
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_NODE_HH
00039 #define GECODE_GIST_NODE_HH
00040 
00041 #include <gecode/kernel.hh>
00042 
00043 namespace Gecode { namespace Gist {
00044 
00045   class VisualNode;
00046 
00048   template<class T>
00049   class NodeAllocatorBase {
00050   private:
00052     static const int NodeBlockSize = 1<<14;
00054     class Block {
00055     public:
00057       T b[NodeBlockSize];
00059       int best[NodeBlockSize];
00060     };
00062     Block** b;
00064     int n;
00066     int cur_b;
00068     int cur_t;
00070     void allocate(void);
00072     bool _bab;
00073   public:
00075     NodeAllocatorBase(bool bab);
00077     ~NodeAllocatorBase(void);
00079     int allocate(int p);
00081     int allocate(Space* root);
00083     T* operator [](int i) const;
00085     T* best(int i) const;
00087     void setBest(int i, int b);
00089     bool bab(void) const;
00090   };
00091 
00093   class Node {
00094   private:
00096     enum {
00097       UNDET, //< Number of children not determined
00098       LEAF,  //< Leaf node
00099       TWO_CHILDREN, //< Node with at most two children
00100       MORE_CHILDREN //< Node with more than two children
00101     };
00102 
00104     void* childrenOrFirstChild;
00105 
00109     int noOfChildren;
00110 
00112     int parent;
00113 
00115     unsigned int getTag(void) const;
00117     void setTag(unsigned int tag);
00119     void* getPtr(void) const;
00121     int getFirstChild(void) const;
00122 
00123   protected:
00125     bool isUndetermined(void) const;
00126 
00128     int getChild(int n) const;
00129   public:
00130     typedef NodeAllocatorBase<VisualNode> NodeAllocator;
00131 
00133     Node(int p, bool failed = false);
00134 
00136     int getParent(void) const;
00138     VisualNode* getParent(const NodeAllocator& na) const;
00140     VisualNode* getChild(const NodeAllocator& na, int n) const;
00141 
00143     int getIndex(const NodeAllocator& na) const;
00144 
00146     bool isRoot(void) const;
00147 
00149     void setNumberOfChildren(unsigned int n, NodeAllocator& na);
00150 
00152     unsigned int getNumberOfChildren(void) const;
00153     
00154   };
00155 
00156 }}
00157 
00158 #endif
00159 
00160 // STATISTICS: gist-any