-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnodecursor.hh
343 lines (312 loc) · 9.52 KB
/
nodecursor.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <[email protected]>
*
* Copyright:
* Guido Tack, 2006
*
* Last modified:
* $Date$ by $Author$
* $Revision$
*
* 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.
*
*/
#ifndef GECODE_GIST_NODECURSOR_HH
#define GECODE_GIST_NODECURSOR_HH
#include "nodecursor_base.hh"
#include <vector>
#include <QTextStream>
class TreeCanvas;
class Execution;
class VisualNode;
/// \brief A cursor that marks failed subtrees as hidden
class HideFailedCursor : public NodeCursor {
private:
bool onlyDirty;
public:
/// Constructor
HideFailedCursor(VisualNode* theNode,
const NodeAllocator& na,
bool onlyDirtyNodes);
/// \name Cursor interface
//@{
/// Test if the cursor may move to the first child node
bool mayMoveDownwards(void) const;
/// Process node
void processCurrentNode(void);
//@}
};
/// \brief A cursor that marks all nodes in the tree as not hidden
class UnhideAllCursor : public NodeCursor {
public:
/// Constructor
UnhideAllCursor(VisualNode* theNode,
const NodeAllocator& na);
/// \name Cursor interface
//@{
/// Process node
void processCurrentNode(void);
//@}
};
/// \brief A cursor that marks all nodes in the tree as not selected
class UnselectAllCursor : public NodeCursor {
public:
/// Constructor
UnselectAllCursor(VisualNode* theNode,
const NodeAllocator& na);
/// \name Cursor interface
//@{
/// Process node
void processCurrentNode(void);
//@}
};
/// \brief A cursor that marks ancestor nodes in the tree as not hidden
class UnhideAncestorsCursor : public NodeCursor {
public:
/// Constructor
UnhideAncestorsCursor(VisualNode* theNode,
const NodeAllocator& na);
/// \name Cursor interface
//@{
/// Test if the cursor may move to the parent node
bool mayMoveUpwards(void) const;
/// Process node
void processCurrentNode(void);
//@}
};
/// \brief A cursor that marks all nodes in the tree as hidden
class HideAllCursor : public NodeCursor {
public:
/// Constructor
HideAllCursor(VisualNode* theNode,
const NodeAllocator& na);
/// \name Cursor interface
//@{
/// Process node
void processCurrentNode(void);
//@}
};
/// \brief A cursor that finds the next solution
class NextSolCursor : public NodeCursor {
private:
/// Whether to search backwards
bool back;
/// Whether the current node is not a solution
bool notOnSol(void) const;
public:
/// Constructor
NextSolCursor(VisualNode* theNode, bool backwards,
const NodeAllocator& na);
/// \name Cursor interface
//@{
/// Do nothing
void processCurrentNode(void);
/// Test if the cursor may move to the parent node
bool mayMoveUpwards(void) const;
/// Test if cursor may move to the first child node
bool mayMoveDownwards(void) const;
/// Move cursor to the first child node
void moveDownwards(void);
/// Test if cursor may move to the first sibling
bool mayMoveSidewards(void) const;
/// Move cursor to the first sibling
void moveSidewards(void);
//@}
};
/// \brief A cursor that finds the next leaf
class NextLeafCursor : public NodeCursor {
private:
/// Whether to search backwards
bool back;
/// Whether the current node is not a leaf
bool notOnLeaf(void) const;
public:
/// Constructor
NextLeafCursor(VisualNode* theNode, bool backwards,
const NodeAllocator& na);
/// \name Cursor interface
//@{
/// Do nothing
void processCurrentNode(void);
/// Test if the cursor may move to the parent node
bool mayMoveUpwards(void) const;
/// Test if cursor may move to the first child node
bool mayMoveDownwards(void) const;
/// Move cursor to the first child node
void moveDownwards(void);
/// Test if cursor may move to the first sibling
bool mayMoveSidewards(void) const;
/// Move cursor to the first sibling
void moveSidewards(void);
//@}
};
/// \brief A cursor that finds the next pentagon
class NextPentagonCursor : public NodeCursor {
private:
/// Whether to search backwards
bool back;
/// Whether the current node is not a pentagon
bool notOnPentagon(void) const;
public:
/// Constructor
NextPentagonCursor(VisualNode* theNode, bool backwards,
const NodeAllocator& na);
/// \name Cursor interface
//@{
/// Do nothing
void processCurrentNode(void);
/// Test if the cursor may move to the parent node
bool mayMoveUpwards(void) const;
/// Test if cursor may move to the first child node
bool mayMoveDownwards(void) const;
/// Move cursor to the first child node
void moveDownwards(void);
/// Test if cursor may move to the first sibling
bool mayMoveSidewards(void) const;
/// Move cursor to the first sibling
void moveSidewards(void);
//@}
};
/// \brief A cursor that collects statistics
class StatCursor : public NodeCursor {
private:
/// Current depth
int curDepth;
public:
/// Depth of the search tree
int depth;
/// Number of failed nodes
int failed;
/// Number of solved nodes
int solved;
/// Number of choice nodes
int choice;
/// Number of open nodes
int open;
/// Constructor
StatCursor(VisualNode* theNode,
const NodeAllocator& na);
/// \name Cursor interface
//@{
/// Collect statistics
void processCurrentNode(void);
/// Move cursor to the first child node
void moveDownwards(void);
/// Move cursor to the parent node
void moveUpwards(void);
//@}
};
class HighlightCursor : public NodeCursor {
public:
// Constructor
HighlightCursor(VisualNode* startNode, const NodeAllocator& na);
// Highlight all the nodes below
void processCurrentNode(void);
};
class UnhighlightCursor : public NodeCursor {
public:
// Constructor
UnhighlightCursor(VisualNode* root, const NodeAllocator& na);
// Unhighlight all the nodes below
void processCurrentNode(void);
};
class CountSolvedCursor : public NodeCursor {
public:
CountSolvedCursor(VisualNode* startNode, const NodeAllocator& na, int &count);
// Count solved leaves and store the nubmer in count variable
void processCurrentNode(void);
private:
int &_count;
};
class GetIndexesCursor : public NodeCursor {
public:
// Constructor
GetIndexesCursor(VisualNode* startNode, const NodeAllocator& na,
std::vector<int>& node_gids);
// Populate node_gids vector with gid of nodes
void processCurrentNode(void);
private:
const NodeAllocator& _na;
std::vector<int>& _node_gids;
};
/// Hide subtrees that are not highlighted
class HideNotHighlightedCursor : public NodeCursor {
protected:
QHash<VisualNode*,bool> onHighlightPath;
public:
/// Constructor
HideNotHighlightedCursor(VisualNode* startNode, const NodeAllocator& na);
/// Process node
void processCurrentNode(void);
/// Test if cursor may move to the first child node
bool mayMoveDownwards(void) const;
};
/// \brief A cursor that labels branches
class BranchLabelCursor : public NodeCursor {
private:
/// The node allocator
NodeAllocator& _na;
/// Current TreeCanvas instance (extract labels from data)
TreeCanvas& _tc;
/// Whether to clear labels
bool _clear;
public:
/// Constructor
BranchLabelCursor(VisualNode* theNode, bool clear,
NodeAllocator& na, TreeCanvas& tc);
/// \name Cursor interface
//@{
void processCurrentNode(void);
//@}
};
class SubtreeCountCursor : public NodeCursor {
public:
std::vector<int> stack;
int threshold;
SubtreeCountCursor(VisualNode *theNode,
int _threshold,
const NodeAllocator& na);
void processCurrentNode(void);
void moveSidewards(void);
void moveUpwards(void);
void moveDownwards(void);
};
class SearchLogCursor : public NodeCursor {
private:
QTextStream& _out;
/// The node allocator
const NodeAllocator& _na;
/// TODO(maxim): should have a reference to the execution here
const Execution& _execution;
public:
SearchLogCursor(VisualNode *theNode,
QTextStream& outputStream,
const NodeAllocator& na,
const Execution& execution);
void processCurrentNode(void);
};
#include "nodecursor.hpp"
#endif