node.hh
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Guido Tack, 2006
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef GECODE_GIST_NODE_HH
#define GECODE_GIST_NODE_HH
#include <gecode/kernel.hh>
#include <QHash>
#include <QString>
namespace Gecode { namespace Gist {
class VisualNode;
template<class T>
class NodeAllocatorBase {
private:
static const int NodeBlockSize = 1<<14;
class Block {
public:
T b[NodeBlockSize];
int best[NodeBlockSize];
};
Block** b;
int n;
int cur_b;
int cur_t;
void allocate(void);
bool _bab;
QHash<T*,QString> labels;
public:
NodeAllocatorBase(bool bab);
~NodeAllocatorBase(void);
int allocate(int p);
int allocate(Space* root);
T* operator [](int i) const;
T* best(int i) const;
void setBest(int i, int b);
bool bab(void) const;
bool showLabels(void) const;
void showLabels(bool b);
bool hasLabel(T* n) const;
void setLabel(T* n, const QString& l);
void clearLabel(T* n);
QString getLabel(T* n) const;
};
class Node {
private:
enum {
UNDET, //< Number of children not determined
LEAF, //< Leaf node
TWO_CHILDREN, //< Node with at most two children
MORE_CHILDREN //< Node with more than two children
};
void* childrenOrFirstChild;
int noOfChildren;
int parent;
unsigned int getTag(void) const;
void setTag(unsigned int tag);
void* getPtr(void) const;
int getFirstChild(void) const;
protected:
bool isUndetermined(void) const;
int getChild(int n) const;
public:
typedef NodeAllocatorBase<VisualNode> NodeAllocator;
Node(int p, bool failed = false);
int getParent(void) const;
VisualNode* getParent(const NodeAllocator& na) const;
VisualNode* getChild(const NodeAllocator& na, int n) const;
int getIndex(const NodeAllocator& na) const;
bool isRoot(void) const;
void setNumberOfChildren(unsigned int n, NodeAllocator& na);
unsigned int getNumberOfChildren(void) const;
};
}}
#endif
// STATISTICS: gist-any
Gecode::Gist::NodeAllocatorBase
Node allocator.
Definition node.hh:48
Gecode::Gist::NodeAllocatorBase< VisualNode >::bab
bool bab(void) const
Gecode::Gist::NodeAllocatorBase::best
T * best(int i) const
Return index of best node before i.
Definition node.hpp:97
Gecode::Gist::NodeAllocatorBase::getLabel
QString getLabel(T *n) const
Get label of node n.
Definition node.hpp:144
Gecode::Gist::NodeAllocatorBase::showLabels
bool showLabels(void) const
Return branching label flag.
Definition node.hpp:120
Gecode::Gist::NodeAllocatorBase::operator[]
T * operator[](int i) const
Return node for index i.
Definition node.hpp:89
Gecode::Gist::NodeAllocatorBase::hasLabel
bool hasLabel(T *n) const
Return whether node n has a label.
Definition node.hpp:126
Gecode::Gist::NodeAllocatorBase::setLabel
void setLabel(T *n, const QString &l)
Set label of node n to l.
Definition node.hpp:132
Gecode::Gist::NodeAllocatorBase::allocate
int allocate(Space *root)
Allocate new root node for space root.
Definition node.hpp:78
Gecode::Gist::NodeAllocatorBase::setBest
void setBest(int i, int b)
Set index of best node before i to b.
Definition node.hpp:106
Gecode::Gist::NodeAllocatorBase::showLabels
void showLabels(bool b)
Set branching label flag.
Gecode::Gist::NodeAllocatorBase::NodeAllocatorBase
NodeAllocatorBase(bool bab)
Constructor.
Definition node.hpp:50
Gecode::Gist::NodeAllocatorBase::allocate
int allocate(int p)
Allocate new node with parent p.
Definition node.hpp:67
Gecode::Gist::NodeAllocatorBase::clearLabel
void clearLabel(T *n)
Remove label of node n.
Definition node.hpp:138
Gecode::Gist::NodeAllocatorBase::~NodeAllocatorBase
~NodeAllocatorBase(void)
Destructor.
Definition node.hpp:59
Gecode::Gist::Node::NodeAllocator
NodeAllocatorBase< VisualNode > NodeAllocator
Definition node.hh:143
Gecode::Gist::Node::setNumberOfChildren
void setNumberOfChildren(unsigned int n, NodeAllocator &na)
Set the number of children to n and initialize children.
Definition node.cpp:42
Gecode::Gist::Node::getNumberOfChildren
unsigned int getNumberOfChildren(void) const
Return the number of children.
Definition node.hpp:214
Gecode::Gist::Node::Node
Node(int p, bool failed=false)
Construct node with parent p.
Definition node.hpp:175
Gecode::Gist::Node::getParent
int getParent(void) const
Return the parent.
Definition node.hpp:182
Gecode::Gist::Node::isUndetermined
bool isUndetermined(void) const
Return whether this node is undetermined.
Definition node.hpp:192
Gecode::Gist::Node::getChild
int getChild(int n) const
Return index of child no n.
Definition node.hpp:195
Gecode::Gist::Node::isRoot
bool isRoot(void) const
Check if this node is the root of a tree.
Definition node.hpp:211
Gecode::Gist::Node::getIndex
int getIndex(const NodeAllocator &na) const
Return index of this node.
Definition node.hpp:227
Gecode::Gist::VisualNode
Node class that supports visual layout
Definition visualnode.hh:125
Gecode::Space
Computation spaces.
Definition core.hpp:1742
kernel.hh
Gecode::Gist
The Gecode Interactive Search Tool.
Gecode
Gecode toplevel namespace