Generated on Tue Apr 18 10:21:45 2017 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: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
00011  *     $Revision: 14967 $
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 #include <QHash>
00044 #include <QString>
00045 
00046 namespace Gecode { namespace Gist {
00047 
00048   class VisualNode;
00049 
00051   template<class T>
00052   class NodeAllocatorBase {
00053   private:
00055     static const int NodeBlockSize = 1<<14;
00057     class Block {
00058     public:
00060       T b[NodeBlockSize];
00062       int best[NodeBlockSize];
00063     };
00065     Block** b;
00067     int n;
00069     int cur_b;
00071     int cur_t;
00073     void allocate(void);
00075     bool _bab;
00077     QHash<T*,QString> labels;
00078   public:
00080     NodeAllocatorBase(bool bab);
00082     ~NodeAllocatorBase(void);
00084     int allocate(int p);
00086     int allocate(Space* root);
00088     T* operator [](int i) const;
00090     T* best(int i) const;
00092     void setBest(int i, int b);
00094     bool bab(void) const;
00096     bool showLabels(void) const;
00098     void showLabels(bool b);
00100     bool hasLabel(T* n) const;
00102     void setLabel(T* n, const QString& l);
00104     void clearLabel(T* n);
00106     QString getLabel(T* n) const;
00107   };
00108 
00110   class Node {
00111   private:
00113     enum {
00114       UNDET, //< Number of children not determined
00115       LEAF,  //< Leaf node
00116       TWO_CHILDREN, //< Node with at most two children
00117       MORE_CHILDREN //< Node with more than two children
00118     };
00119 
00121     void* childrenOrFirstChild;
00122 
00126     int noOfChildren;
00127 
00129     int parent;
00130 
00132     unsigned int getTag(void) const;
00134     void setTag(unsigned int tag);
00136     void* getPtr(void) const;
00138     int getFirstChild(void) const;
00139 
00140   protected:
00142     bool isUndetermined(void) const;
00143 
00145     int getChild(int n) const;
00146   public:
00147     typedef NodeAllocatorBase<VisualNode> NodeAllocator;
00148 
00150     Node(int p, bool failed = false);
00151 
00153     int getParent(void) const;
00155     VisualNode* getParent(const NodeAllocator& na) const;
00157     VisualNode* getChild(const NodeAllocator& na, int n) const;
00158 
00160     int getIndex(const NodeAllocator& na) const;
00161 
00163     bool isRoot(void) const;
00164 
00166     void setNumberOfChildren(unsigned int n, NodeAllocator& na);
00167 
00169     unsigned int getNumberOfChildren(void) const;
00170 
00171   };
00172 
00173 }}
00174 
00175 #endif
00176 
00177 // STATISTICS: gist-any