main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
gecode
gist
node.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
* Last modified:
10
* $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11
* $Revision: 14967 $
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
#ifndef GECODE_GIST_NODE_HH
39
#define GECODE_GIST_NODE_HH
40
41
#include <
gecode/kernel.hh
>
42
43
#include <QHash>
44
#include <QString>
45
46
namespace
Gecode
{
namespace
Gist {
47
48
class
VisualNode;
49
51
template
<
class
T>
52
class
NodeAllocatorBase
{
53
private
:
55
static
const
int
NodeBlockSize = 1<<14;
57
class
Block {
58
public
:
60
T
b
[NodeBlockSize];
62
int
best
[NodeBlockSize];
63
};
65
Block** b;
67
int
n;
69
int
cur_b;
71
int
cur_t;
73
void
allocate(
void
);
75
bool
_bab;
77
QHash<T*,QString> labels;
78
public
:
80
NodeAllocatorBase
(
bool
bab
);
82
~NodeAllocatorBase
(
void
);
84
int
allocate(
int
p
);
86
int
allocate(
Space
* root);
88
T*
operator []
(
int
i
)
const
;
90
T*
best
(
int
i
)
const
;
92
void
setBest
(
int
i
,
int
b
);
94
bool
bab
(
void
)
const
;
96
bool
showLabels
(
void
)
const
;
98
void
showLabels
(
bool
b
);
100
bool
hasLabel
(T*
n
)
const
;
102
void
setLabel
(T*
n
,
const
QString&
l
);
104
void
clearLabel
(T*
n
);
106
QString
getLabel
(T*
n
)
const
;
107
};
108
110
class
Node
{
111
private
:
113
enum
{
114
UNDET,
//< Number of children not determined
115
LEAF,
//< Leaf node
116
TWO_CHILDREN,
//< Node with at most two children
117
MORE_CHILDREN
//< Node with more than two children
118
};
119
121
void
* childrenOrFirstChild;
122
126
int
noOfChildren;
127
129
int
parent;
130
132
unsigned
int
getTag(
void
)
const
;
134
void
setTag(
unsigned
int
tag);
136
void
* getPtr(
void
)
const
;
138
int
getFirstChild(
void
)
const
;
139
140
protected
:
142
bool
isUndetermined
(
void
)
const
;
143
145
int
getChild
(
int
n
)
const
;
146
public
:
147
typedef
NodeAllocatorBase<VisualNode>
NodeAllocator
;
148
150
Node
(
int
p
,
bool
failed =
false
);
151
153
int
getParent
(
void
)
const
;
155
VisualNode
*
getParent
(
const
NodeAllocator
& na)
const
;
157
VisualNode
*
getChild
(
const
NodeAllocator
& na,
int
n
)
const
;
158
160
int
getIndex
(
const
NodeAllocator
& na)
const
;
161
163
bool
isRoot
(
void
)
const
;
164
166
void
setNumberOfChildren
(
unsigned
int
n
,
NodeAllocator
& na);
167
169
unsigned
int
getNumberOfChildren
(
void
)
const
;
170
171
};
172
173
}}
174
175
#endif
176
177
// STATISTICS: gist-any
kernel.hh
Gecode::Gist::NodeAllocatorBase::operator[]
T * operator[](int i) const
Return node for index i.
Definition:
node.hpp:93
Gecode::Gist::NodeAllocatorBase::getLabel
QString getLabel(T *n) const
Get label of node n.
Definition:
node.hpp:148
Gecode::Gist::VisualNode
Node class that supports visual layout
Definition:
visualnode.hh:129
Gecode::Gist::NodeAllocatorBase::NodeAllocatorBase
NodeAllocatorBase(bool bab)
Constructor.
Definition:
node.hpp:54
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::Gist::Node::getIndex
int getIndex(const NodeAllocator &na) const
Return index of this node.
Definition:
node.hpp:231
Gecode::Gist::Node::setNumberOfChildren
void setNumberOfChildren(unsigned int n, NodeAllocator &na)
Set the number of children to n and initialize children.
Definition:
node.cpp:46
Gecode::Gist::Node::isRoot
bool isRoot(void) const
Check if this node is the root of a tree.
Definition:
node.hpp:215
Gecode::Gist::NodeAllocatorBase::hasLabel
bool hasLabel(T *n) const
Return whether node n has a label.
Definition:
node.hpp:130
Gecode::Gist::Node
Base class for nodes of the search tree.
Definition:
node.hh:110
Gecode
Gecode toplevel namespace
Gecode::Gist::NodeAllocatorBase::best
T * best(int i) const
Return index of best node before i.
Definition:
node.hpp:101
Gecode::Gist::NodeAllocatorBase::~NodeAllocatorBase
~NodeAllocatorBase(void)
Destructor.
Definition:
node.hpp:63
b
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
Gecode::Gist::NodeAllocatorBase::clearLabel
void clearLabel(T *n)
Remove label of node n.
Definition:
node.hpp:142
Gecode::Gist::NodeAllocatorBase
Node allocator.
Definition:
node.hh:52
Gecode::Gist::Node::Node
Node(int p, bool failed=false)
Construct node with parent p.
Definition:
node.hpp:179
Gecode::Gist::Node::NodeAllocator
NodeAllocatorBase< VisualNode > NodeAllocator
Definition:
node.hh:147
Gecode::Gist::Node::getChild
int getChild(int n) const
Return index of child no n.
Definition:
node.hpp:199
Gecode::Gist::Node::getParent
int getParent(void) const
Return the parent.
Definition:
node.hpp:186
Gecode::Gist::NodeAllocatorBase::setBest
void setBest(int i, int b)
Set index of best node before i to b.
Definition:
node.hpp:110
Gecode::Gist::NodeAllocatorBase::bab
bool bab(void) const
Return branch-and-bound flag.
Definition:
node.hpp:118
Gecode::Gist::Node::getNumberOfChildren
unsigned int getNumberOfChildren(void) const
Return the number of children.
Definition:
node.hpp:218
Gecode::Gist::Node::isUndetermined
bool isUndetermined(void) const
Return whether this node is undetermined.
Definition:
node.hpp:196
l
NNF * l
Left subtree.
Definition:
bool-expr.cpp:244
Gecode::Gist::NodeAllocatorBase::showLabels
bool showLabels(void) const
Return branching label flag.
Definition:
node.hpp:124
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:236
Gecode::Gist::NodeAllocatorBase::setLabel
void setLabel(T *n, const QString &l)
Set label of node n to l.
Definition:
node.hpp:136