Generated on Thu Jul 21 2022 00:00:00 for Gecode by doxygen 1.9.5
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 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34namespace Gecode { namespace Gist {
35
37 Extent::Extent(void) : l(-1), r(-1) {}
38
40 Extent::Extent(int l0, int r0) : l(l0), r(r0) {}
41
42 inline
43 Extent::Extent(int width) {
44 int halfWidth = width / 2;
45 l = 0 - halfWidth;
46 r = 0 + halfWidth;
47 }
48
49 inline void
50 Extent::extend(int deltaL, int deltaR) {
51 l += deltaL; r += deltaR;
52 }
53
54 inline void
55 Extent::move(int delta) {
56 l += delta; r += delta;
57 }
58
59 forceinline int
60 Shape::depth(void) const { return _depth; }
61
62 forceinline void
64 assert(d <= _depth);
65 _depth = d;
66 }
67
68 forceinline const Extent&
69 Shape::operator [](int i) const {
70 assert(i < _depth);
71 return shape[i];
72 }
73
76 assert(i < _depth);
77 return shape[i];
78 }
79
80 inline Shape*
82 assert(d >= 1);
83 Shape* ret;
84 ret =
85 static_cast<Shape*>(heap.ralloc(sizeof(Shape)+(d-1)*sizeof(Extent)));
86 ret->_depth = d;
87 return ret;
88 }
89
90 forceinline void
92 if (shape != hidden && shape != leaf)
93 heap.rfree(shape);
94 }
95
96 forceinline bool
98 if (d > depth())
99 return false;
100 extent = Extent(0,0);
101 for (int i=0; i <= d; i++) {
102 Extent currentExtent = (*this)[i];
103 extent.l += currentExtent.l;
104 extent.r += currentExtent.r;
105 }
106 return true;
107 }
108
109 forceinline void
111 int lastLeft = 0;
112 int lastRight = 0;
113 bb.left = 0;
114 bb.right = 0;
115 for (int i=0; i<depth(); i++) {
116 lastLeft = lastLeft + (*this)[i].l;
117 lastRight = lastRight + (*this)[i].r;
118 bb.left = std::min(bb.left,lastLeft);
119 bb.right = std::max(bb.right,lastRight);
120 }
121 }
122
125 return bb;
126 }
127
128 forceinline bool
130 return getFlag(HIDDEN);
131 }
132
133 forceinline void
135 setFlag(HIDDEN, h);
136 }
137
138 forceinline void
140 if (getStatus() == BRANCH && h)
142 else if (getStatus() == STOP && !h)
144 }
145
146 forceinline int
148
149 forceinline void
151
152 forceinline bool
154 return getFlag(DIRTY);
155 }
156
157 forceinline void
159 setFlag(DIRTY, d);
160 }
161
162 forceinline bool
165 }
166
167 forceinline void
170 }
171
172 forceinline bool
174 return getFlag(MARKED);
175 }
176
177 forceinline void
179 setFlag(MARKED, m);
180 }
181
182 forceinline bool
184 return getFlag(BOOKMARKED);
185 }
186
187 forceinline void
190 }
191
192 forceinline bool
194 return getFlag(ONPATH);
195 }
196
197 forceinline void
199 setFlag(ONPATH, b);
200 }
201
204 return isHidden() ? Shape::hidden : shape;
205 }
206
209
210}}
211
212// STATISTICS: gist-any
NNF * l
Left subtree.
Definition: bool-expr.cpp:240
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
int right
Right coordinate.
Definition: visualnode.hh:57
int left
Left coordinate.
Definition: visualnode.hh:55
Extent representing shape of a tree at one depth level
Definition: visualnode.hh:63
Extent(void)
Default constructor.
Definition: visualnode.hpp:37
int l
Left extent.
Definition: visualnode.hh:66
int r
Right extent.
Definition: visualnode.hh:68
void extend(int deltaL, int deltaR)
Extend extent by deltaL and deltaR.
Definition: visualnode.hpp:50
void move(int delta)
Move extent by delta.
Definition: visualnode.hpp:55
The shape of a subtree.
Definition: visualnode.hh:83
const BoundingBox & getBoundingBox(void) const
Return bounding box.
Definition: visualnode.hpp:124
bool getExtentAtDepth(int depth, Extent &extent)
Return if extent exists at depth, if yes return it in extent.
Definition: visualnode.hpp:97
const Extent & operator[](int i) const
Return extent at depth i.
Definition: visualnode.hpp:69
static Shape * allocate(int d)
Construct shape of depth d.
Definition: visualnode.hpp:81
void computeBoundingBox(void)
Compute bounding box.
Definition: visualnode.hpp:110
int depth(void) const
Return depth of the shape.
Definition: visualnode.hpp:60
static Shape * leaf
Static shape for leaf nodes.
Definition: visualnode.hh:104
static Shape * hidden
Static shape for hidden nodes.
Definition: visualnode.hh:106
static void deallocate(Shape *)
Definition: visualnode.hpp:91
void setDepth(int d)
Set depth of the shape to d (must be smaller than original depth)
Definition: visualnode.hpp:63
void setStatus(NodeStatus s)
Set status to s.
Definition: spacenode.hpp:65
void setFlag(int flag, bool value)
Set status flag.
Definition: spacenode.hpp:37
NodeStatus getStatus(void) const
Return current status of the node.
Definition: spacenode.hpp:71
bool getFlag(int flag) const
Return status flag.
Definition: spacenode.hpp:45
int offset
Relative offset from the parent node.
Definition: visualnode.hh:138
void setOnPath(bool onPath0)
Set whether node is on the path.
Definition: visualnode.hpp:198
int getOffset(void)
Return offset off this node from its parent.
Definition: visualnode.hpp:147
bool isBookmarked(void)
Return whether node is bookmarked.
Definition: visualnode.hpp:183
bool isHidden(void)
Return if node is hidden.
Definition: visualnode.hpp:129
void setBookmarked(bool m)
Set bookmark of this node.
Definition: visualnode.hpp:188
Shape * shape
Shape of this node.
Definition: visualnode.hh:140
void setHidden(bool h)
Set hidden state to h.
Definition: visualnode.hpp:134
bool isMarked(void)
Return whether node is marked.
Definition: visualnode.hpp:173
void setOffset(int n)
Set offset of this node, relative to its parent.
Definition: visualnode.hpp:150
void setDirty(bool d)
Mark node as dirty.
Definition: visualnode.hpp:158
bool childrenLayoutIsDone(void)
Return whether the layout of the node's children has been completed.
Definition: visualnode.hpp:163
BoundingBox getBoundingBox(void)
Return the bounding box.
Definition: visualnode.hpp:208
bool isDirty(void)
Return whether node is marked as dirty.
Definition: visualnode.hpp:153
bool isOnPath(void)
Return whether node is on the path.
Definition: visualnode.hpp:193
void setMarked(bool m)
Set mark of this node.
Definition: visualnode.hpp:178
void setChildrenLayoutDone(bool d)
Mark node whether the layout of the node's children has been completed.
Definition: visualnode.hpp:168
void setStop(bool h)
Set stop state to h.
Definition: visualnode.hpp:139
Shape * getShape(void)
Return the shape of this node.
Definition: visualnode.hpp:203
void rfree(void *p)
Free memory block starting at p.
Definition: heap.hpp:371
void * ralloc(size_t s)
Allocate s bytes from heap.
Definition: heap.hpp:357
Heap heap
The single global heap.
Definition: heap.cpp:44
@ UNSTOP
Node representing ignored stop point.
Definition: spacenode.hh:50
@ STOP
Node representing stop point.
Definition: spacenode.hh:49
@ BRANCH
Node representing a branch.
Definition: spacenode.hh:47
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
#define forceinline
Definition: config.hpp:194