Generated on Sat Feb 7 2015 02:01:18 for Gecode by doxygen 1.8.9.1
node.hh
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  *
6  * Copyright:
7  * Guido Tack, 2006
8  *
9  * Last modified:
10  * $Date: 2013-07-02 03:35:13 +0200 (Tue, 02 Jul 2013) $ by $Author: tack $
11  * $Revision: 13749 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #ifndef GECODE_GIST_NODE_HH
39 #define GECODE_GIST_NODE_HH
40 
41 #include <gecode/kernel.hh>
42 
43 #include <QHash>
44 #include <QString>
45 
46 namespace Gecode { namespace Gist {
47 
48  class VisualNode;
49 
51  template<class T>
53  private:
55  static const int NodeBlockSize = 1<<14;
57  class Block {
58  public:
60  T b[NodeBlockSize];
62  int best[NodeBlockSize];
63  };
65  Block** b;
67  int n;
69  int cur_b;
71  int cur_t;
73  void allocate(void);
75  bool _bab;
77  QHash<T*,QString> labels;
78  public:
80  NodeAllocatorBase(bool bab);
82  ~NodeAllocatorBase(void);
84  int allocate(int p);
86  int allocate(Space* root);
88  T* operator [](int i) const;
90  T* best(int i) const;
92  void setBest(int i, int b);
94  bool bab(void) const;
96  bool showLabels(void) const;
98  void showLabels(bool b);
100  bool hasLabel(T* n) const;
102  void setLabel(T* n, const QString& l);
104  void clearLabel(T* n);
106  QString getLabel(T* n) const;
107  };
108 
110  class Node {
111  private:
113  enum {
114  UNDET, //< Number of children not determined
115  LEAF, //< Leaf node
116  TWO_CHILDREN, //< Node with at most two children
117  MORE_CHILDREN //< Node with more than two children
118  };
119 
121  void* childrenOrFirstChild;
122 
126  int noOfChildren;
127 
129  int parent;
130 
132  unsigned int getTag(void) const;
134  void setTag(unsigned int tag);
136  void* getPtr(void) const;
138  int getFirstChild(void) const;
139 
140  protected:
142  bool isUndetermined(void) const;
143 
145  int getChild(int n) const;
146  public:
148 
150  Node(int p, bool failed = false);
151 
153  int getParent(void) const;
155  VisualNode* getParent(const NodeAllocator& na) const;
157  VisualNode* getChild(const NodeAllocator& na, int n) const;
158 
160  int getIndex(const NodeAllocator& na) const;
161 
163  bool isRoot(void) const;
164 
166  void setNumberOfChildren(unsigned int n, NodeAllocator& na);
167 
169  unsigned int getNumberOfChildren(void) const;
170 
171  };
172 
173 }}
174 
175 #endif
176 
177 // STATISTICS: gist-any
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
T * operator[](int i) const
Return node for index i.
Definition: node.hpp:93
void setLabel(T *n, const QString &l)
Set label of node n to l.
Definition: node.hpp:136
NodeAllocatorBase< VisualNode > NodeAllocator
Definition: node.hh:147
Base class for nodes of the search tree.
Definition: node.hh:110
Node allocator.
Definition: node.hh:52
unsigned int getNumberOfChildren(void) const
Return the number of children.
Definition: node.hpp:218
NodeAllocatorBase(bool bab)
Constructor.
Definition: node.hpp:54
Computation spaces.
Definition: core.hpp:1362
int getParent(void) const
Return the parent.
Definition: node.hpp:186
QString getLabel(T *n) const
Get label of node n.
Definition: node.hpp:148
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
bool isRoot(void) const
Check if this node is the root of a tree.
Definition: node.hpp:215
bool bab(void) const
Return branch-and-bound flag.
Definition: node.hpp:118
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
void clearLabel(T *n)
Remove label of node n.
Definition: node.hpp:142
Node(int p, bool failed=false)
Construct node with parent p.
Definition: node.hpp:179
bool showLabels(void) const
Return branching label flag.
Definition: node.hpp:124
void setBest(int i, int b)
Set index of best node before i to b.
Definition: node.hpp:110
~NodeAllocatorBase(void)
Destructor.
Definition: node.hpp:63
void setNumberOfChildren(unsigned int n, NodeAllocator &na)
Set the number of children to n and initialize children.
Definition: node.cpp:46
int getIndex(const NodeAllocator &na) const
Return index of this node.
Definition: node.hpp:228
Node class that supports visual layout
Definition: visualnode.hh:129
T * best(int i) const
Return index of best node before i.
Definition: node.hpp:101
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
int getChild(int n) const
Return index of child no n.
Definition: node.hpp:199
bool isUndetermined(void) const
Return whether this node is undetermined.
Definition: node.hpp:196
bool hasLabel(T *n) const
Return whether node n has a label.
Definition: node.hpp:130