Generated on Sat Feb 7 2015 02:01:19 for Gecode by doxygen 1.8.9.1
visualnode.hpp
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-05-06 09:02:17 +0200 (Mon, 06 May 2013) $ by $Author: tack $
11  * $Revision: 13613 $
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 namespace Gecode { namespace Gist {
39 
41  Extent::Extent(void) : l(-1), r(-1) {}
42 
44  Extent::Extent(int l0, int r0) : l(l0), r(r0) {}
45 
46  inline
47  Extent::Extent(int width) {
48  int halfWidth = width / 2;
49  l = 0 - halfWidth;
50  r = 0 + halfWidth;
51  }
52 
53  inline void
54  Extent::extend(int deltaL, int deltaR) {
55  l += deltaL; r += deltaR;
56  }
57 
58  inline void
59  Extent::move(int delta) {
60  l += delta; r += delta;
61  }
62 
63  forceinline int
64  Shape::depth(void) const { return _depth; }
65 
66  forceinline void
68  assert(d <= _depth);
69  _depth = d;
70  }
71 
72  forceinline const Extent&
73  Shape::operator [](int i) const {
74  assert(i < _depth);
75  return shape[i];
76  }
77 
80  assert(i < _depth);
81  return shape[i];
82  }
83 
84  inline Shape*
86  assert(d >= 1);
87  Shape* ret;
88  ret =
89  static_cast<Shape*>(heap.ralloc(sizeof(Shape)+(d-1)*sizeof(Extent)));
90  ret->_depth = d;
91  return ret;
92  }
93 
94  forceinline void
96  if (shape != hidden && shape != leaf)
97  heap.rfree(shape);
98  }
99 
100  forceinline bool
102  if (d > depth())
103  return false;
104  extent = Extent(0,0);
105  for (int i=0; i <= d; i++) {
106  Extent currentExtent = (*this)[i];
107  extent.l += currentExtent.l;
108  extent.r += currentExtent.r;
109  }
110  return true;
111  }
112 
113  forceinline void
115  int lastLeft = 0;
116  int lastRight = 0;
117  bb.left = 0;
118  bb.right = 0;
119  for (int i=0; i<depth(); i++) {
120  lastLeft = lastLeft + (*this)[i].l;
121  lastRight = lastRight + (*this)[i].r;
122  bb.left = std::min(bb.left,lastLeft);
123  bb.right = std::max(bb.right,lastRight);
124  }
125  }
126 
127  forceinline const BoundingBox&
128  Shape::getBoundingBox(void) const {
129  return bb;
130  }
131 
132  forceinline bool
134  return getFlag(HIDDEN);
135  }
136 
137  forceinline void
139  setFlag(HIDDEN, h);
140  }
141 
142  forceinline void
144  if (getStatus() == BRANCH && h)
145  setStatus(STOP);
146  else if (getStatus() == STOP && !h)
147  setStatus(UNSTOP);
148  }
149 
150  forceinline int
151  VisualNode::getOffset(void) { return offset; }
152 
153  forceinline void
155 
156  forceinline bool
158  return getFlag(DIRTY);
159  }
160 
161  forceinline void
163  setFlag(DIRTY, d);
164  }
165 
166  forceinline bool
168  return getFlag(CHILDRENLAYOUTDONE);
169  }
170 
171  forceinline void
174  }
175 
176  forceinline bool
178  return getFlag(MARKED);
179  }
180 
181  forceinline void
183  setFlag(MARKED, m);
184  }
185 
186  forceinline bool
188  return getFlag(BOOKMARKED);
189  }
190 
191  forceinline void
193  setFlag(BOOKMARKED, m);
194  }
195 
196  forceinline bool
198  return getFlag(ONPATH);
199  }
200 
201  forceinline void
203  setFlag(ONPATH, b);
204  }
205 
208  return isHidden() ? Shape::hidden : shape;
209  }
210 
213 
214 }}
215 
216 // STATISTICS: gist-any
bool isOnPath(void)
Return whether node is on the path.
Definition: visualnode.hpp:197
Node representing stop point.
Definition: spacenode.hh:53
int right
Right coordinate.
Definition: visualnode.hh:61
void setOnPath(bool onPath0)
Set whether node is on the path.
Definition: visualnode.hpp:202
int left
Left coordinate.
Definition: visualnode.hh:59
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
void setMarked(bool m)
Set mark of this node.
Definition: visualnode.hpp:182
int l
Left extent.
Definition: visualnode.hh:70
const FloatNum max
Largest allowed float value.
Definition: float.hh:831
Node representing a branch.
Definition: spacenode.hh:51
void rfree(void *p)
Free memory block starting at p.
Definition: heap.hpp:355
void computeBoundingBox(void)
Compute bounding box.
Definition: visualnode.hpp:114
bool isDirty(void)
Return whether node is marked as dirty.
Definition: visualnode.hpp:157
BoundingBox getBoundingBox(void)
Return the bounding box.
Definition: visualnode.hpp:212
bool isHidden(void)
Return if node is hidden.
Definition: visualnode.hpp:133
void setChildrenLayoutDone(bool d)
Mark node whether the layout of the node's children has been completed.
Definition: visualnode.hpp:172
void setStop(bool h)
Set stop state to h.
Definition: visualnode.hpp:143
void setDirty(bool d)
Mark node as dirty.
Definition: visualnode.hpp:162
void * ralloc(size_t s)
Allocate s bytes from heap.
Definition: heap.hpp:341
int offset
Relative offset from the parent node.
Definition: visualnode.hh:142
void setHidden(bool h)
Set hidden state to h.
Definition: visualnode.hpp:138
static Shape * allocate(int d)
Construct shape of depth d.
Definition: visualnode.hpp:85
void setBookmarked(bool m)
Set bookmark of this node.
Definition: visualnode.hpp:192
void setStatus(NodeStatus s)
Set status to s.
Definition: spacenode.hpp:69
Heap heap
The single global heap.
Definition: heap.cpp:49
Gecode::IntSet d(v, 7)
NodeStatus getStatus(void) const
Return current status of the node.
Definition: spacenode.hpp:75
bool getExtentAtDepth(int depth, Extent &extent)
Return if extent exists at depth, if yes return it in extent.
Definition: visualnode.hpp:101
const FloatNum min
Smallest allowed float value.
Definition: float.hh:833
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
void extend(int deltaL, int deltaR)
Extend extent by deltaL and deltaR.
Definition: visualnode.hpp:54
void setOffset(int n)
Set offset of this node, relative to its parent.
Definition: visualnode.hpp:154
void move(int delta)
Move extent by delta.
Definition: visualnode.hpp:59
Shape * getShape(void)
Return the shape of this node.
Definition: visualnode.hpp:207
void setFlag(int flag, bool value)
Set status flag.
Definition: spacenode.hpp:41
int depth(void) const
Return depth of the shape.
Definition: visualnode.hpp:64
bool childrenLayoutIsDone(void)
Return whether the layout of the node's children has been completed.
Definition: visualnode.hpp:167
Extent(void)
Default constructor.
Definition: visualnode.hpp:41
bool isMarked(void)
Return whether node is marked.
Definition: visualnode.hpp:177
static Shape * hidden
Static shape for hidden nodes.
Definition: visualnode.hh:110
Shape * shape
Shape of this node.
Definition: visualnode.hh:144
bool isBookmarked(void)
Return whether node is bookmarked.
Definition: visualnode.hpp:187
const BoundingBox & getBoundingBox(void) const
Return bounding box.
Definition: visualnode.hpp:128
#define forceinline
Definition: config.hpp:132
int getOffset(void)
Return offset off this node from its parent.
Definition: visualnode.hpp:151
const Extent & operator[](int i) const
Return extent at depth i.
Definition: visualnode.hpp:73
static void deallocate(Shape *)
Definition: visualnode.hpp:95
The shape of a subtree.
Definition: visualnode.hh:87
static Shape * leaf
Static shape for leaf nodes.
Definition: visualnode.hh:108
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
void setDepth(int d)
Set depth of the shape to d (must be smaller than original depth)
Definition: visualnode.hpp:67
bool getFlag(int flag) const
Return status flag.
Definition: spacenode.hpp:49
int r
Right extent.
Definition: visualnode.hh:72
Extent representing shape of a tree at one depth level
Definition: visualnode.hh:67
Node representing ignored stop point.
Definition: spacenode.hh:54