Go to the documentation of this file.
38 namespace Gecode {
namespace Gist {
42 NodeAllocatorBase<T>::allocate(
void) {
47 n =
static_cast<int>(
n*1.5+1.0);
50 b[cur_b] =
static_cast<Block*
>(
heap.
ralloc(
sizeof(Block)));
59 cur_t = NodeBlockSize-1;
64 for (
int i=cur_b+1;
i--;)
73 if (cur_t==NodeBlockSize)
75 new (&
b[cur_b]->b[cur_t]) T(
p);
76 b[cur_b]->best[cur_t] = -1;
77 return cur_b*NodeBlockSize+cur_t;
84 if (cur_t==NodeBlockSize)
86 new (&
b[cur_b]->b[cur_t]) T(root);
87 b[cur_b]->best[cur_t] = -1;
88 return cur_b*NodeBlockSize+cur_t;
94 assert(
i/NodeBlockSize <
n);
95 assert(
i/NodeBlockSize < cur_b ||
i%NodeBlockSize <= cur_t);
96 return &(
b[
i/NodeBlockSize]->b[
i%NodeBlockSize]);
102 assert(
i/NodeBlockSize <
n);
103 assert(
i/NodeBlockSize < cur_b ||
i%NodeBlockSize <= cur_t);
104 int bi =
b[
i/NodeBlockSize]->best[
i%NodeBlockSize];
105 return bi == -1 ? NULL : (*this)[
bi];
111 assert(
i/NodeBlockSize <
n);
112 assert(
i/NodeBlockSize < cur_b ||
i%NodeBlockSize <= cur_t);
113 b[
i/NodeBlockSize]->best[
i%NodeBlockSize] = best;
125 return !labels.isEmpty();
131 return labels.contains(
n);
149 return labels.value(
n);
153 Node::getTag(
void)
const {
154 return static_cast<unsigned int>
155 (
reinterpret_cast<ptrdiff_t
>(childrenOrFirstChild) & 3);
159 Node::setTag(
unsigned int tag) {
161 assert(getTag() == UNDET);
162 childrenOrFirstChild =
reinterpret_cast<void*
>
163 ( (
reinterpret_cast<ptrdiff_t
>(childrenOrFirstChild) & ~(3)) | tag);
167 Node::getPtr(
void)
const {
168 return reinterpret_cast<void*
>
169 (
reinterpret_cast<ptrdiff_t
>(childrenOrFirstChild) & ~(3));
173 Node::getFirstChild(
void)
const {
174 return static_cast<int>
175 ((
reinterpret_cast<ptrdiff_t
>(childrenOrFirstChild) & ~(3)) >> 2);
180 childrenOrFirstChild = NULL;
182 setTag(failed ? LEAF : UNDET);
192 return parent < 0 ? NULL : na[parent];
200 assert(getTag() != UNDET && getTag() != LEAF);
201 if (getTag() == TWO_CHILDREN) {
202 assert(
n != 1 || noOfChildren <= 0);
203 return n == 0 ? getFirstChild() : -noOfChildren;
205 assert(
n < noOfChildren);
206 return static_cast<int*
>(getPtr())[
n];
224 return (noOfChildren <= 0) ? 2 : 1;
226 return static_cast<unsigned int>(noOfChildren);
234 Node*
p = na[parent];
235 for (
int i=
p->getNumberOfChildren();
i--;)
236 if (
p->getChild(na,
i) ==
this)
237 return p->getChild(
i);
T * operator[](int i) const
Return node for index i.
QString getLabel(T *n) const
Get label of node n.
Node class that supports visual layout
NodeAllocatorBase(bool bab)
Constructor.
Gecode::IntArgs i(4, 1, 2, 3, 4)
void * ralloc(size_t s)
Allocate s bytes from heap.
int getIndex(const NodeAllocator &na) const
Return index of this node.
bool isRoot(void) const
Check if this node is the root of a tree.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
bool hasLabel(T *n) const
Return whether node n has a label.
Base class for nodes of the search tree.
Gecode toplevel namespace
T * best(int i) const
Return index of best node before i.
~NodeAllocatorBase(void)
Destructor.
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
void clearLabel(T *n)
Remove label of node n.
Node(int p, bool failed=false)
Construct node with parent p.
int getChild(int n) const
Return index of child no n.
#define GECODE_NEVER
Assert that this command is never executed.
int getParent(void) const
Return the parent.
Heap heap
The single global heap.
void setBest(int i, int b)
Set index of best node before i to b.
bool bab(void) const
Return branch-and-bound flag.
unsigned int getNumberOfChildren(void) const
Return the number of children.
bool isUndetermined(void) const
Return whether this node is undetermined.
void free(T *b, long unsigned int n)
Delete n objects starting at b.
bool showLabels(void) const
Return branching label flag.
int bab(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for branch-and-bound search of root.
int n
Number of negative literals for node type.
void rfree(void *p)
Free memory block starting at p.
int p
Number of positive literals for node type.
T * realloc(T *b, long unsigned int n, long unsigned int m)
Reallocate block of n objects starting at b to m objects of type T from heap.
void setLabel(T *n, const QString &l)
Set label of node n to l.