Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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
91 Shape::deallocate(Shape* shape) {
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
166
167 forceinline void
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
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
Extent representing shape of a tree at one depth level
Definition visualnode.hh:63
Extent(void)
Default constructor.
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.
void move(int delta)
Move extent by delta.
The shape of a subtree.
Definition visualnode.hh:83
const BoundingBox & getBoundingBox(void) const
Return bounding box.
bool getExtentAtDepth(int depth, Extent &extent)
Return if extent exists at depth, if yes return it in extent.
const Extent & operator[](int i) const
Return extent at depth i.
static Shape * allocate(int d)
Construct shape of depth d.
void computeBoundingBox(void)
Compute bounding box.
int depth(void) const
Return depth of the shape.
static Shape * leaf
Static shape for leaf nodes.
static Shape * hidden
Static shape for hidden nodes.
static void deallocate(Shape *)
void setDepth(int d)
Set depth of the shape to d (must be smaller than original depth)
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.
void setOnPath(bool onPath0)
Set whether node is on the path.
int getOffset(void)
Return offset off this node from its parent.
bool isBookmarked(void)
Return whether node is bookmarked.
bool isHidden(void)
Return if node is hidden.
void setBookmarked(bool m)
Set bookmark of this node.
Shape * shape
Shape of this node.
void setHidden(bool h)
Set hidden state to h.
bool isMarked(void)
Return whether node is marked.
void setOffset(int n)
Set offset of this node, relative to its parent.
void setDirty(bool d)
Mark node as dirty.
bool childrenLayoutIsDone(void)
Return whether the layout of the node's children has been completed.
BoundingBox getBoundingBox(void)
Return the bounding box.
bool isDirty(void)
Return whether node is marked as dirty.
bool isOnPath(void)
Return whether node is on the path.
void setMarked(bool m)
Set mark of this node.
void setChildrenLayoutDone(bool d)
Mark node whether the layout of the node's children has been completed.
void setStop(bool h)
Set stop state to h.
Shape * getShape(void)
Return the shape of this node.
Heap heap
The single global heap.
Definition heap.cpp:44
The Gecode Interactive Search Tool.
@ 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
#define forceinline
Definition config.hpp:194