main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Feb 7 2015 02:01:18 for Gecode by
doxygen
1.8.9.1
gecode
gist
nodevisitor.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: 2010-07-30 17:08:42 +0200 (Fri, 30 Jul 2010) $ by $Author: tack $
11
* $Revision: 11315 $
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
40
template
<
class
Cursor>
41
forceinline
42
NodeVisitor<Cursor>::NodeVisitor
(
const
Cursor& c0) :
c
(c0) {}
43
44
template
<
class
Cursor>
45
forceinline
void
46
NodeVisitor<Cursor>::setCursor
(
const
Cursor& c0) {
c
= c0; }
47
48
template
<
class
Cursor>
49
forceinline
Cursor&
50
NodeVisitor<Cursor>::getCursor
(
void
) {
return
c
; }
51
52
template
<
class
Cursor>
53
forceinline
void
54
PostorderNodeVisitor<Cursor>::moveToLeaf
(
void
) {
55
while
(
c
.mayMoveDownwards()) {
56
c
.moveDownwards();
57
}
58
}
59
60
template
<
class
Cursor>
61
PostorderNodeVisitor<Cursor>::PostorderNodeVisitor
(
const
Cursor& c0)
62
:
NodeVisitor
<Cursor>(c0) {
63
moveToLeaf
();
64
}
65
66
template
<
class
Cursor>
67
forceinline
bool
68
PostorderNodeVisitor<Cursor>::next
(
void
) {
69
c
.processCurrentNode();
70
if
(
c
.mayMoveSidewards()) {
71
c
.moveSidewards();
72
moveToLeaf();
73
}
else
if
(
c
.mayMoveUpwards()) {
74
c
.moveUpwards();
75
}
else
{
76
return
false
;
77
}
78
return
true
;
79
}
80
81
template
<
class
Cursor>
82
forceinline
void
83
PostorderNodeVisitor<Cursor>::run
(
void
) {
84
while
(next()) {}
85
}
86
87
template
<
class
Cursor>
88
forceinline
bool
89
PreorderNodeVisitor<Cursor>::backtrack
(
void
) {
90
while
(!
c
.mayMoveSidewards() &&
c
.mayMoveUpwards()) {
91
c
.moveUpwards();
92
}
93
if
(!
c
.mayMoveUpwards()) {
94
return
false
;
95
}
else
{
96
c
.moveSidewards();
97
}
98
return
true
;
99
}
100
101
template
<
class
Cursor>
102
PreorderNodeVisitor<Cursor>::PreorderNodeVisitor
(
const
Cursor& c0)
103
:
NodeVisitor
<Cursor>(c0) {}
104
105
template
<
class
Cursor>
106
forceinline
bool
107
PreorderNodeVisitor<Cursor>::next
(
void
) {
108
c
.processCurrentNode();
109
if
(
c
.mayMoveDownwards()) {
110
c
.moveDownwards();
111
}
else
if
(
c
.mayMoveSidewards()) {
112
c
.moveSidewards();
113
}
else
{
114
return
backtrack();
115
}
116
return
true
;
117
}
118
119
template
<
class
Cursor>
120
forceinline
void
121
PreorderNodeVisitor<Cursor>::run
(
void
) {
122
while
(next()) {}
123
}
124
}}
125
126
// STATISTICS: gist-any
Gecode::Gist::PostorderNodeVisitor::next
bool next(void)
Move cursor to next node, return true if succeeded.
Definition:
nodevisitor.hpp:68
Gecode::Gist::PreorderNodeVisitor::next
bool next(void)
Move cursor to the next node, return true if succeeded.
Definition:
nodevisitor.hpp:107
Gecode::Gist::NodeVisitor::setCursor
void setCursor(const Cursor &c0)
Reset the cursor object to c0.
Definition:
nodevisitor.hpp:46
Gecode::Gist::PostorderNodeVisitor::run
void run(void)
Execute visitor.
Definition:
nodevisitor.hpp:83
Gecode::Gist::PostorderNodeVisitor::PostorderNodeVisitor
PostorderNodeVisitor(const Cursor &c)
Constructor.
Definition:
nodevisitor.hpp:61
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
Gecode::Gist::PreorderNodeVisitor::PreorderNodeVisitor
PreorderNodeVisitor(const Cursor &c)
Constructor.
Definition:
nodevisitor.hpp:102
Gecode::Gist::NodeVisitor::getCursor
Cursor & getCursor(void)
Return the cursor.
Definition:
nodevisitor.hpp:50
Gecode::Gist::PreorderNodeVisitor::run
void run(void)
Execute visitor.
Definition:
nodevisitor.hpp:121
forceinline
#define forceinline
Definition:
config.hpp:132
Gecode::Gist::PreorderNodeVisitor::backtrack
bool backtrack(void)
Move cursor to next node from a leaf.
Definition:
nodevisitor.hpp:89
Gecode::Gist::PostorderNodeVisitor::moveToLeaf
void moveToLeaf(void)
Move the cursor to the left-most leaf.
Definition:
nodevisitor.hpp:54
Gecode::Gist::NodeVisitor
Base class for a visitor that runs a cursor over a tree.
Definition:
nodevisitor.hh:45
Gecode
Gecode toplevel namespace
Gecode::Gist::NodeVisitor::NodeVisitor
NodeVisitor(const Cursor &c0)
Constructor.
Definition:
nodevisitor.hpp:42