main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Oct 22 2013 00:49:02 for Gecode by
doxygen
1.8.4
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: 2013-07-02 03:35:13 +0200 (Tue, 02 Jul 2013) $ by $Author: tack $
11
* $Revision: 13749 $
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