Generated on Mon Jul 27 2020 00:00:00 for Gecode by doxygen 1.8.18
visualnode.hh
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 
34 #ifndef GECODE_GIST_VISUALNODE_HH
35 #define GECODE_GIST_VISUALNODE_HH
36 
37 #include <gecode/gist/spacenode.hh>
38 #include <gecode/kernel.hh>
39 #include <string>
40 
41 namespace Gecode { namespace Gist {
42 
44  class Layout {
45  public:
46  static const int dist_y = 38;
47  static const int extent = 20;
48  static const int minimalSeparation = 10;
49  };
50 
52  class BoundingBox {
53  public:
55  int left;
57  int right;
59  BoundingBox(void) {}
60  };
61 
63  class Extent {
64  public:
66  int l;
68  int r;
70  Extent(void);
72  Extent(int l0, int r0);
74  Extent(int width);
75 
77  void extend(int deltaL, int deltaR);
79  void move(int delta);
80  };
81 
83  class Shape {
84  private:
86  int _depth;
88  BoundingBox bb;
90  Extent shape[1];
92  Shape(const Shape&);
94  Shape& operator =(const Shape&);
96  Shape(void);
97  public:
99  static Shape* allocate(int d);
100  // Destruct
101  static void deallocate(Shape*);
102 
104  static Shape* leaf;
106  static Shape* hidden;
107 
109  int depth(void) const;
111  void setDepth(int d);
113  void computeBoundingBox(void);
115  const Extent& operator [](int i) const;
117  Extent& operator [](int i);
119  bool getExtentAtDepth(int depth, Extent& extent);
121  const BoundingBox& getBoundingBox(void) const;
122  };
123 
125  class VisualNode : public SpaceNode {
126  protected:
134  BOOKMARKED
135  };
136 
138  int offset;
141 
143  bool containsCoordinateAtDepth(int x, int depth);
144  public:
146  VisualNode(int p);
148  VisualNode(Space* root);
149 
151  bool isHidden(void);
153  void setHidden(bool h);
155  void setStop(bool h);
157  void dirtyUp(const NodeAllocator& na);
159  void layout(const NodeAllocator& na);
161  int getOffset(void);
163  void setOffset(int n);
165  bool isDirty(void);
167  void setDirty(bool d);
169  bool childrenLayoutIsDone(void);
171  void setChildrenLayoutDone(bool d);
173  bool isMarked(void);
175  void setMarked(bool m);
177  bool isBookmarked(void);
179  void setBookmarked(bool m);
181  void pathUp(const NodeAllocator& na);
183  void unPathUp(const NodeAllocator& na);
185  bool isOnPath(void);
187  int getPathAlternative(const NodeAllocator& na);
189  void setOnPath(bool onPath0);
190 
192  void toggleHidden(const NodeAllocator& na);
194  void hideFailed(const NodeAllocator& na, bool onlyDirty=false);
196  void unhideAll(const NodeAllocator& na);
198  void toggleStop(const NodeAllocator& na);
200  void unstopAll(const NodeAllocator& na);
201 
203  Shape* getShape(void);
205  void setShape(Shape* s);
207  void computeShape(const NodeAllocator& na);
211  void changedStatus(const NodeAllocator& na);
213  VisualNode* findNode(const NodeAllocator& na, int x, int y);
214 
216  void labelBranches(NodeAllocator& na,
217  BestNode* curBest, int c_d, int a_d);
219  void labelPath(NodeAllocator& na,
220  BestNode* curBest, int c_d, int a_d);
222  std::string getBranchLabel(NodeAllocator& na,
223  VisualNode* p, const Choice* c,
224  BestNode* curBest, int c_d, int a_d, int alt);
225 
227  std::string toolTip(NodeAllocator& na, BestNode* curBest,
228  int c_d, int a_d);
229 
231  void dispose(void);
232  };
233 
234 }}
235 
236 #include <gecode/gist/node.hpp>
237 #include <gecode/gist/spacenode.hpp>
239 
240 #endif
241 
242 // STATISTICS: gist-any
int left
Left coordinate.
Definition: visualnode.hh:55
@ MARKED
Definition: visualnode.hh:132
int getOffset(void)
Return offset off this node from its parent.
Definition: visualnode.hpp:147
Post propagator for SetVar x
Definition: set.hh:767
VisualNode * findNode(const NodeAllocator &na, int x, int y)
Find a node in this subtree at coordinates x, y.
Definition: visualnode.cpp:249
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
void dirtyUp(const NodeAllocator &na)
Mark all nodes up the path to the parent as dirty.
Definition: visualnode.cpp:102
Shape * shape
Shape of this node.
Definition: visualnode.hh:140
int right
Right coordinate.
Definition: visualnode.hh:57
void computeBoundingBox(void)
Compute bounding box.
Definition: visualnode.hpp:110
void setShape(Shape *s)
Set the shape of this node.
Definition: visualnode.cpp:391
void pathUp(const NodeAllocator &na)
Set all nodes from the node to the root to be on the path.
Definition: visualnode.cpp:127
Node class that supports visual layout
Definition: visualnode.hh:125
static const int minimalSeparation
Definition: visualnode.hh:48
void setBookmarked(bool m)
Set bookmark of this node.
Definition: visualnode.hpp:188
void hideFailed(const NodeAllocator &na, bool onlyDirty=false)
Hide all failed subtrees of this node.
Definition: visualnode.cpp:159
int getPathAlternative(const NodeAllocator &na)
Return the alternative of the child that is on the path (-1 if none)
Definition: visualnode.cpp:144
bool isBookmarked(void)
Return whether node is bookmarked.
Definition: visualnode.hpp:183
Computation spaces.
Definition: core.hpp:1742
bool isOnPath(void)
Return whether node is on the path.
Definition: visualnode.hpp:193
static const int extent
Definition: visualnode.hh:47
void changedStatus(const NodeAllocator &na)
Signal that the status has changed.
Definition: visualnode.cpp:230
Layout parameters
Definition: visualnode.hh:44
bool getExtentAtDepth(int depth, Extent &extent)
Return if extent exists at depth, if yes return it in extent.
Definition: visualnode.hpp:97
static Shape * allocate(int d)
Construct shape of depth d.
Definition: visualnode.hpp:81
Gecode toplevel namespace
std::string toolTip(NodeAllocator &na, BestNode *curBest, int c_d, int a_d)
Return string that is used as a tool tip.
Definition: visualnode.cpp:279
void computeShape(const NodeAllocator &na)
Compute the shape according to the shapes of the children.
Definition: visualnode.cpp:399
void extend(int deltaL, int deltaR)
Extend extent by deltaL and deltaR.
Definition: visualnode.hpp:50
static const int dist_y
Definition: visualnode.hh:46
bool containsCoordinateAtDepth(int x, int depth)
Check if the x at depth depth lies in this subtree.
Definition: visualnode.cpp:233
void setOffset(int n)
Set offset of this node, relative to its parent.
Definition: visualnode.hpp:150
void toggleStop(const NodeAllocator &na)
Do not stop at this node.
Definition: visualnode.cpp:214
void setDirty(bool d)
Mark node as dirty.
Definition: visualnode.hpp:158
void unhideAll(const NodeAllocator &na)
Unhide all nodes in the subtree of this node.
Definition: visualnode.cpp:207
Node allocator.
Definition: node.hh:48
The shape of a subtree.
Definition: visualnode.hh:83
void layout(const NodeAllocator &na)
Compute layout for the subtree of this node.
Definition: visualnode.cpp:113
bool childrenLayoutIsDone(void)
Return whether the layout of the node's children has been completed.
Definition: visualnode.hpp:163
void setMarked(bool m)
Set mark of this node.
Definition: visualnode.hpp:178
bool isMarked(void)
Return whether node is marked.
Definition: visualnode.hpp:173
Extent(void)
Default constructor.
Definition: visualnode.hpp:37
const Extent & operator[](int i) const
Return extent at depth i.
Definition: visualnode.hpp:69
void toggleHidden(const NodeAllocator &na)
Toggle whether this node is hidden.
Definition: visualnode.cpp:153
Static reference to the currently best space.
Definition: spacenode.hh:80
const BoundingBox & getBoundingBox(void) const
Return bounding box.
Definition: visualnode.hpp:124
@ HIDDEN
Definition: visualnode.hh:131
@ BOOKMARKED
Definition: visualnode.hh:134
bool isDirty(void)
Return whether node is marked as dirty.
Definition: visualnode.hpp:153
void setOnPath(bool onPath0)
Set whether node is on the path.
Definition: visualnode.hpp:198
VisualNode(int p)
Construct with parent p.
Definition: visualnode.cpp:69
void dispose(void)
Free allocated memory.
Definition: visualnode.cpp:96
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
BoundingBox getBoundingBox(void)
Return the bounding box.
Definition: visualnode.hpp:208
bool isHidden(void)
Return if node is hidden.
Definition: visualnode.hpp:129
int offset
Relative offset from the parent node.
Definition: visualnode.hh:138
void labelBranches(NodeAllocator &na, BestNode *curBest, int c_d, int a_d)
Create or clear branch labels in subtree.
Definition: visualnode.cpp:166
static const int LASTBIT
Last bit used for SpaceNode flags.
Definition: spacenode.hh:127
void unstopAll(const NodeAllocator &na)
Do not stop at any stop node in the subtree of this node.
Definition: visualnode.cpp:223
void setHidden(bool h)
Set hidden state to h.
Definition: visualnode.hpp:134
Gecode::IntSet d(v, 7)
int r
Right extent.
Definition: visualnode.hh:68
A node of a search tree of Gecode spaces.
Definition: spacenode.hh:89
static Shape * hidden
Static shape for hidden nodes.
Definition: visualnode.hh:106
Bounding box.
Definition: visualnode.hh:52
static Shape * leaf
Static shape for leaf nodes.
Definition: visualnode.hh:104
BoundingBox(void)
Default constructor.
Definition: visualnode.hh:59
void labelPath(NodeAllocator &na, BestNode *curBest, int c_d, int a_d)
Create or clear branch labels on path to root.
Definition: visualnode.cpp:175
void setDepth(int d)
Set depth of the shape to d (must be smaller than original depth)
Definition: visualnode.hpp:63
void move(int delta)
Move extent by delta.
Definition: visualnode.hpp:55
const unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:113
@ DIRTY
Definition: visualnode.hh:129
static void deallocate(Shape *)
Definition: visualnode.hpp:91
const unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance)
Definition: search.hh:115
Gecode::FloatVal c(-8, 8)
std::string getBranchLabel(NodeAllocator &na, VisualNode *p, const Choice *c, BestNode *curBest, int c_d, int a_d, int alt)
Return string that describes the branch.
Definition: visualnode.cpp:284
@ CHILDRENLAYOUTDONE
Definition: visualnode.hh:130
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Choice for performing commit
Definition: core.hpp:1412
void unPathUp(const NodeAllocator &na)
Set all nodes from the node to the root not to be on the path.
Definition: visualnode.cpp:135
Shape * getShape(void)
Return the shape of this node.
Definition: visualnode.hpp:203
Extent representing shape of a tree at one depth level
Definition: visualnode.hh:63
Gecode::IntArgs i({1, 2, 3, 4})
int depth(void) const
Return depth of the shape.
Definition: visualnode.hpp:60
int l
Left extent.
Definition: visualnode.hh:66
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
@ ONPATH
Definition: visualnode.hh:133
VisualNodeFlags
Flags for VisualNodes.
Definition: visualnode.hh:128