Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
spacenode.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_SPACENODE_HH
35#define GECODE_GIST_SPACENODE_HH
36
37#include <gecode/gist/node.hh>
38#include <gecode/kernel.hh>
39
40namespace Gecode { namespace Gist {
41
52
53 static const unsigned int FIRSTBIT = 24; //< First free bit in status word
54 static const unsigned int STATUSMASK = 7<<20; //< Mask for accessing status
55 static const unsigned int MAXDISTANCE = (1<<20)-1; //< Maximum representable distance
56 static const unsigned int DISTANCEMASK = (1<<20)-1; //< Mask for accessing distance
57
60 public:
71
74 : solutions(0), failures(0), choices(0), undetermined(1), maxDepth(0) {}
75 };
76
77 class SpaceNode;
78
80 class BestNode {
81 public:
86 };
87
89 class SpaceNode : public Node {
90 protected:
97 protected:
98 const Choice* choice;
99
106 unsigned int nstatus;
107
109 void setDistance(unsigned int d);
110
112 unsigned int getDistance(void) const;
113
115 void setFlag(int flag, bool value);
116
118 bool getFlag(int flag) const;
119
127 static const int LASTBIT = HASSOLVEDCHILDREN;
128
129 private:
131 void setHasOpenChildren(bool b);
133 void setHasFailedChildren(bool b);
135 void setHasSolvedChildren(bool b);
136
138 int recompute(NodeAllocator& na,
139 BestNode* curBest, int c_d, int a_d);
140
142 void closeChild(const NodeAllocator& na,
143 bool hadFailures, bool hadSolutions);
144 protected:
146 void setStatus(NodeStatus s);
149 BestNode* curBest, int c_d, int a_d);
150 public:
152 SpaceNode(int p);
154 SpaceNode(Space* root);
155
158 BestNode* curBest, int c_d, int a_d);
159
161 const Space* getWorkingSpace(void) const;
162
164 void purge(const NodeAllocator& na);
165
167 void dispose(void);
168
170 bool isCurrentBest(BestNode* curBest);
171
183 BestNode* curBest,
184 Statistics& stats,
185 int c_d, int a_d);
186
188 NodeStatus getStatus(void) const;
189
191 bool isOpen(void);
193 bool hasFailedChildren(void);
195 bool hasSolvedChildren(void);
197 bool hasOpenChildren(void);
199 int getNoOfOpenChildren(const NodeAllocator& na);
203 bool hasCopy(void);
205 bool hasWorkingSpace(void);
206
208 int getAlternative(const NodeAllocator& na) const;
210 const Choice* getChoice(void);
211 };
212
213}}
214
215#endif
216
217// STATISTICS: gist-any
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
Choice for performing commit
Definition core.hpp:1412
Static reference to the currently best space.
Definition spacenode.hh:80
BestNode(SpaceNode *s0)
Constructor.
Definition spacenode.cpp:61
SpaceNode * s
The currently best node found, or NULL.
Definition spacenode.hh:83
Base class for nodes of the search tree.
Definition node.hh:106
A node of a search tree of Gecode spaces.
Definition spacenode.hh:89
Space * copy
A copy used for recomputation, or NULL.
Definition spacenode.hh:96
bool hasCopy(void)
Return whether the node has a copy.
const Choice * choice
Definition spacenode.hh:98
bool hasWorkingSpace(void)
Return whether the node has a working space.
const Choice * getChoice(void)
Return choice of this node.
SpaceNodeFlags
Flags for SpaceNodes.
Definition spacenode.hh:121
const Space * getWorkingSpace(void) const
Return working space (if present).
bool isCurrentBest(BestNode *curBest)
Return whether this node is the currently best solution.
unsigned int getDistance(void) const
Return distance from copy.
Definition spacenode.hpp:84
void setNoOfOpenChildren(int n)
Set number of open children to n.
static const int LASTBIT
Last bit used for SpaceNode flags.
Definition spacenode.hh:127
unsigned int nstatus
Status of the node.
Definition spacenode.hh:106
void setStatus(NodeStatus s)
Set status to s.
Definition spacenode.hpp:65
bool hasFailedChildren(void)
Return whether the subtree of this node has any failed children.
void setFlag(int flag, bool value)
Set status flag.
Definition spacenode.hpp:37
void dispose(void)
Free allocated memory.
void acquireSpace(NodeAllocator &na, BestNode *curBest, int c_d, int a_d)
Acquire working space, either from parent or by recomputation.
int getNumberOfChildNodes(NodeAllocator &na, BestNode *curBest, Statistics &stats, int c_d, int a_d)
Compute and return the number of children.
bool hasSolvedChildren(void)
Return whether the subtree of this node has any solved children.
int getAlternative(const NodeAllocator &na) const
Return alternative number of this node.
bool isOpen(void)
Return whether this node still has open children.
NodeStatus getStatus(void) const
Return current status of the node.
Definition spacenode.hpp:71
Space * getSpace(NodeAllocator &na, BestNode *curBest, int c_d, int a_d)
Return working space. Receiver must delete the space.
Definition spacenode.hpp:98
SpaceNode(int p)
Construct node with parent p.
Definition spacenode.hpp:89
void purge(const NodeAllocator &na)
Clear working space and copy (if present and this is not the root).
bool getFlag(int flag) const
Return status flag.
Definition spacenode.hpp:45
void setDistance(unsigned int d)
Set distance from copy.
Definition spacenode.hpp:76
bool hasOpenChildren(void)
Return whether the subtree of this node has any open children.
int getNoOfOpenChildren(const NodeAllocator &na)
Return number of open children.
Statistics about the search tree
Definition spacenode.hh:59
int choices
Number of choice nodes.
Definition spacenode.hh:66
int failures
Number of failures.
Definition spacenode.hh:64
int solutions
Number of solutions.
Definition spacenode.hh:62
int undetermined
Number of open, undetermined nodes.
Definition spacenode.hh:68
Statistics(void)
Constructor.
Definition spacenode.hh:73
int maxDepth
Maximum depth of the tree.
Definition spacenode.hh:70
Computation spaces.
Definition core.hpp:1742
Statistics for execution of status
Definition core.hpp:1691
NodeStatus
Status of nodes in the search tree.
Definition spacenode.hh:44
@ UNDETERMINED
Node that has not been explored yet.
Definition spacenode.hh:48
@ UNSTOP
Node representing ignored stop point.
Definition spacenode.hh:50
@ FAILED
Node representing failure.
Definition spacenode.hh:46
@ STOP
Node representing stop point.
Definition spacenode.hh:49
@ SOLVED
Node representing a solution.
Definition spacenode.hh:45
@ BRANCH
Node representing a branch.
Definition spacenode.hh:47
Gecode toplevel namespace