Generated on Thu Apr 11 13:59:03 2019 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  *  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_NODE_HH
00035 #define GECODE_GIST_NODE_HH
00036 
00037 #include <gecode/kernel.hh>
00038 
00039 #include <QHash>
00040 #include <QString>
00041 
00042 namespace Gecode { namespace Gist {
00043 
00044   class VisualNode;
00045 
00047   template<class T>
00048   class NodeAllocatorBase {
00049   private:
00051     static const int NodeBlockSize = 1<<14;
00053     class Block {
00054     public:
00056       T b[NodeBlockSize];
00058       int best[NodeBlockSize];
00059     };
00061     Block** b;
00063     int n;
00065     int cur_b;
00067     int cur_t;
00069     void allocate(void);
00071     bool _bab;
00073     QHash<T*,QString> labels;
00074   public:
00076     NodeAllocatorBase(bool bab);
00078     ~NodeAllocatorBase(void);
00080     int allocate(int p);
00082     int allocate(Space* root);
00084     T* operator [](int i) const;
00086     T* best(int i) const;
00088     void setBest(int i, int b);
00090     bool bab(void) const;
00092     bool showLabels(void) const;
00094     void showLabels(bool b);
00096     bool hasLabel(T* n) const;
00098     void setLabel(T* n, const QString& l);
00100     void clearLabel(T* n);
00102     QString getLabel(T* n) const;
00103   };
00104 
00106   class Node {
00107   private:
00109     enum {
00110       UNDET, //< Number of children not determined
00111       LEAF,  //< Leaf node
00112       TWO_CHILDREN, //< Node with at most two children
00113       MORE_CHILDREN //< Node with more than two children
00114     };
00115 
00117     void* childrenOrFirstChild;
00118 
00122     int noOfChildren;
00123 
00125     int parent;
00126 
00128     unsigned int getTag(void) const;
00130     void setTag(unsigned int tag);
00132     void* getPtr(void) const;
00134     int getFirstChild(void) const;
00135 
00136   protected:
00138     bool isUndetermined(void) const;
00139 
00141     int getChild(int n) const;
00142   public:
00143     typedef NodeAllocatorBase<VisualNode> NodeAllocator;
00144 
00146     Node(int p, bool failed = false);
00147 
00149     int getParent(void) const;
00151     VisualNode* getParent(const NodeAllocator& na) const;
00153     VisualNode* getChild(const NodeAllocator& na, int n) const;
00154 
00156     int getIndex(const NodeAllocator& na) const;
00157 
00159     bool isRoot(void) const;
00160 
00162     void setNumberOfChildren(unsigned int n, NodeAllocator& na);
00163 
00165     unsigned int getNumberOfChildren(void) const;
00166 
00167   };
00168 
00169 }}
00170 
00171 #endif
00172 
00173 // STATISTICS: gist-any