visualnode.hpp
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.
*
*/
namespace Gecode { namespace Gist {
forceinline
Extent::Extent(void) : l(-1), r(-1) {}
forceinline
Extent::Extent(int l0, int r0) : l(l0), r(r0) {}
inline
Extent::Extent(int width) {
int halfWidth = width / 2;
l = 0 - halfWidth;
r = 0 + halfWidth;
}
inline void
Extent::extend(int deltaL, int deltaR) {
l += deltaL; r += deltaR;
}
inline void
Extent::move(int delta) {
l += delta; r += delta;
}
forceinline int
Shape::depth(void) const { return _depth; }
forceinline void
Shape::setDepth(int d) {
assert(d <= _depth);
_depth = d;
}
forceinline const Extent&
Shape::operator [](int i) const {
assert(i < _depth);
return shape[i];
}
forceinline Extent&
Shape::operator [](int i) {
assert(i < _depth);
return shape[i];
}
inline Shape*
Shape::allocate(int d) {
assert(d >= 1);
Shape* ret;
ret =
static_cast<Shape*>(heap.ralloc(sizeof(Shape)+(d-1)*sizeof(Extent)));
ret->_depth = d;
return ret;
}
forceinline void
Shape::deallocate(Shape* shape) {
if (shape != hidden && shape != leaf)
heap.rfree(shape);
}
forceinline bool
Shape::getExtentAtDepth(int d, Extent& extent) {
if (d > depth())
return false;
extent = Extent(0,0);
for (int i=0; i <= d; i++) {
Extent currentExtent = (*this)[i];
extent.l += currentExtent.l;
extent.r += currentExtent.r;
}
return true;
}
forceinline void
Shape::computeBoundingBox(void) {
int lastLeft = 0;
int lastRight = 0;
bb.left = 0;
bb.right = 0;
for (int i=0; i<depth(); i++) {
lastLeft = lastLeft + (*this)[i].l;
lastRight = lastRight + (*this)[i].r;
bb.left = std::min(bb.left,lastLeft);
bb.right = std::max(bb.right,lastRight);
}
}
forceinline const BoundingBox&
Shape::getBoundingBox(void) const {
return bb;
}
forceinline bool
VisualNode::isHidden(void) {
return getFlag(HIDDEN);
}
forceinline void
VisualNode::setHidden(bool h) {
setFlag(HIDDEN, h);
}
forceinline void
VisualNode::setStop(bool h) {
if (getStatus() == BRANCH && h)
setStatus(STOP);
else if (getStatus() == STOP && !h)
setStatus(UNSTOP);
}
forceinline int
VisualNode::getOffset(void) { return offset; }
forceinline void
VisualNode::setOffset(int n) { offset = n; }
forceinline bool
VisualNode::isDirty(void) {
return getFlag(DIRTY);
}
forceinline void
VisualNode::setDirty(bool d) {
setFlag(DIRTY, d);
}
forceinline bool
VisualNode::childrenLayoutIsDone(void) {
return getFlag(CHILDRENLAYOUTDONE);
}
forceinline void
VisualNode::setChildrenLayoutDone(bool d) {
setFlag(CHILDRENLAYOUTDONE, d);
}
forceinline bool
VisualNode::isMarked(void) {
return getFlag(MARKED);
}
forceinline void
VisualNode::setMarked(bool m) {
setFlag(MARKED, m);
}
forceinline bool
VisualNode::isBookmarked(void) {
return getFlag(BOOKMARKED);
}
forceinline void
VisualNode::setBookmarked(bool m) {
setFlag(BOOKMARKED, m);
}
forceinline bool
VisualNode::isOnPath(void) {
return getFlag(ONPATH);
}
forceinline void
VisualNode::setOnPath(bool b) {
setFlag(ONPATH, b);
}
forceinline Shape*
VisualNode::getShape(void) {
return isHidden() ? Shape::hidden : shape;
}
forceinline BoundingBox
VisualNode::getBoundingBox(void) { return getShape()->getBoundingBox(); }
}}
// STATISTICS: gist-any
Gecode::Gist::BoundingBox
Bounding box.
Definition visualnode.hh:52
Gecode::Gist::Extent
Extent representing shape of a tree at one depth level
Definition visualnode.hh:63
Gecode::Gist::Extent::Extent
Extent(void)
Default constructor.
Definition visualnode.hpp:37
Gecode::Gist::Extent::l
int l
Left extent.
Definition visualnode.hh:66
Gecode::Gist::Extent::r
int r
Right extent.
Definition visualnode.hh:68
Gecode::Gist::Extent::extend
void extend(int deltaL, int deltaR)
Extend extent by deltaL and deltaR.
Definition visualnode.hpp:50
Gecode::Gist::Extent::move
void move(int delta)
Move extent by delta.
Definition visualnode.hpp:55
Gecode::Gist::Shape
The shape of a subtree.
Definition visualnode.hh:83
Gecode::Gist::Shape::getBoundingBox
const BoundingBox & getBoundingBox(void) const
Return bounding box.
Definition visualnode.hpp:124
Gecode::Gist::Shape::getExtentAtDepth
bool getExtentAtDepth(int depth, Extent &extent)
Return if extent exists at depth, if yes return it in extent.
Definition visualnode.hpp:97
Gecode::Gist::Shape::operator[]
const Extent & operator[](int i) const
Return extent at depth i.
Definition visualnode.hpp:69
Gecode::Gist::Shape::allocate
static Shape * allocate(int d)
Construct shape of depth d.
Definition visualnode.hpp:81
Gecode::Gist::Shape::computeBoundingBox
void computeBoundingBox(void)
Compute bounding box.
Definition visualnode.hpp:110
Gecode::Gist::Shape::depth
int depth(void) const
Return depth of the shape.
Definition visualnode.hpp:60
Gecode::Gist::Shape::leaf
static Shape * leaf
Static shape for leaf nodes.
Definition visualnode.hh:104
Gecode::Gist::Shape::hidden
static Shape * hidden
Static shape for hidden nodes.
Definition visualnode.hh:106
Gecode::Gist::Shape::deallocate
static void deallocate(Shape *)
Definition visualnode.hpp:91
Gecode::Gist::Shape::setDepth
void setDepth(int d)
Set depth of the shape to d (must be smaller than original depth).
Definition visualnode.hpp:63
Gecode::Gist::SpaceNode::setStatus
void setStatus(NodeStatus s)
Set status to s.
Definition spacenode.hpp:65
Gecode::Gist::SpaceNode::setFlag
void setFlag(int flag, bool value)
Set status flag.
Definition spacenode.hpp:37
Gecode::Gist::SpaceNode::getStatus
NodeStatus getStatus(void) const
Return current status of the node.
Definition spacenode.hpp:71
Gecode::Gist::SpaceNode::getFlag
bool getFlag(int flag) const
Return status flag.
Definition spacenode.hpp:45
Gecode::Gist::VisualNode::offset
int offset
Relative offset from the parent node.
Definition visualnode.hh:138
Gecode::Gist::VisualNode::setOnPath
void setOnPath(bool onPath0)
Set whether node is on the path.
Definition visualnode.hpp:198
Gecode::Gist::VisualNode::ONPATH
@ ONPATH
Definition visualnode.hh:133
Gecode::Gist::VisualNode::MARKED
@ MARKED
Definition visualnode.hh:132
Gecode::Gist::VisualNode::CHILDRENLAYOUTDONE
@ CHILDRENLAYOUTDONE
Definition visualnode.hh:130
Gecode::Gist::VisualNode::HIDDEN
@ HIDDEN
Definition visualnode.hh:131
Gecode::Gist::VisualNode::DIRTY
@ DIRTY
Definition visualnode.hh:129
Gecode::Gist::VisualNode::BOOKMARKED
@ BOOKMARKED
Definition visualnode.hh:134
Gecode::Gist::VisualNode::getOffset
int getOffset(void)
Return offset off this node from its parent.
Definition visualnode.hpp:147
Gecode::Gist::VisualNode::isBookmarked
bool isBookmarked(void)
Return whether node is bookmarked.
Definition visualnode.hpp:183
Gecode::Gist::VisualNode::isHidden
bool isHidden(void)
Return if node is hidden.
Definition visualnode.hpp:129
Gecode::Gist::VisualNode::setBookmarked
void setBookmarked(bool m)
Set bookmark of this node.
Definition visualnode.hpp:188
Gecode::Gist::VisualNode::shape
Shape * shape
Shape of this node.
Definition visualnode.hh:140
Gecode::Gist::VisualNode::setHidden
void setHidden(bool h)
Set hidden state to h.
Definition visualnode.hpp:134
Gecode::Gist::VisualNode::isMarked
bool isMarked(void)
Return whether node is marked.
Definition visualnode.hpp:173
Gecode::Gist::VisualNode::setOffset
void setOffset(int n)
Set offset of this node, relative to its parent.
Definition visualnode.hpp:150
Gecode::Gist::VisualNode::setDirty
void setDirty(bool d)
Mark node as dirty.
Definition visualnode.hpp:158
Gecode::Gist::VisualNode::childrenLayoutIsDone
bool childrenLayoutIsDone(void)
Return whether the layout of the node's children has been completed.
Definition visualnode.hpp:163
Gecode::Gist::VisualNode::getBoundingBox
BoundingBox getBoundingBox(void)
Return the bounding box.
Definition visualnode.hpp:208
Gecode::Gist::VisualNode::isDirty
bool isDirty(void)
Return whether node is marked as dirty.
Definition visualnode.hpp:153
Gecode::Gist::VisualNode::isOnPath
bool isOnPath(void)
Return whether node is on the path.
Definition visualnode.hpp:193
Gecode::Gist::VisualNode::setMarked
void setMarked(bool m)
Set mark of this node.
Definition visualnode.hpp:178
Gecode::Gist::VisualNode::setChildrenLayoutDone
void setChildrenLayoutDone(bool d)
Mark node whether the layout of the node's children has been completed.
Definition visualnode.hpp:168
Gecode::Gist::VisualNode::setStop
void setStop(bool h)
Set stop state to h.
Definition visualnode.hpp:139
Gecode::Gist::VisualNode::getShape
Shape * getShape(void)
Return the shape of this node.
Definition visualnode.hpp:203
Gecode::heap
Heap heap
The single global heap.
Definition heap.cpp:44
Gecode::Gist
The Gecode Interactive Search Tool.
Gecode::Gist::UNSTOP
@ UNSTOP
Node representing ignored stop point.
Definition spacenode.hh:50
Gecode::Gist::STOP
@ STOP
Node representing stop point.
Definition spacenode.hh:49
Gecode::Gist::BRANCH
@ BRANCH
Node representing a branch.
Definition spacenode.hh:47
Gecode
Gecode toplevel namespace
forceinline
#define forceinline
Definition config.hpp:187