Generated on Sat Feb 7 2015 02:01:18 for Gecode by doxygen 1.8.9.1
spacenode.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-08-12 11:02:06 +0200 (Thu, 12 Aug 2010) $ by $Author: tack $
11  * $Revision: 11347 $
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  forceinline void
41  SpaceNode::setFlag(int flag, bool value) {
42  if (value)
43  nstatus |= 1<<(flag-1);
44  else
45  nstatus &= ~(1<<(flag-1));
46  }
47 
48  forceinline bool
49  SpaceNode::getFlag(int flag) const {
50  return (nstatus & (1<<(flag-1))) != 0;
51  }
52 
53  forceinline void
54  SpaceNode::setHasOpenChildren(bool b) {
56  }
57 
58  forceinline void
59  SpaceNode::setHasFailedChildren(bool b) {
61  }
62 
63  forceinline void
64  SpaceNode::setHasSolvedChildren(bool b) {
66  }
67 
68  forceinline void
70  nstatus &= ~( STATUSMASK );
71  nstatus |= s << 20;
72  }
73 
75  SpaceNode::getStatus(void) const {
76  return static_cast<NodeStatus>((nstatus & STATUSMASK) >> 20);
77  }
78 
79  forceinline void
80  SpaceNode::setDistance(unsigned int d) {
81  if (d > MAXDISTANCE)
82  d = MAXDISTANCE;
83  nstatus &= ~( DISTANCEMASK );
84  nstatus |= d;
85  }
86 
87  forceinline unsigned int
88  SpaceNode::getDistance(void) const {
89  return nstatus & DISTANCEMASK;
90  }
91 
94  : Node(p), copy(NULL), nstatus(0) {
95  choice = NULL;
97  setHasSolvedChildren(false);
98  setHasFailedChildren(false);
99  }
100 
103  BestNode* curBest, int c_d, int a_d) {
104  acquireSpace(na,curBest,c_d,a_d);
105  Space* ret;
106  if (Support::marked(copy)) {
107  ret = static_cast<Space*>(Support::unmark(copy));
108  copy = NULL;
109  } else {
110  ret = copy->clone();
111  }
112  return ret;
113  }
114 
115  forceinline const Space*
117  assert(copy != NULL);
118  if (Support::marked(copy))
119  return static_cast<Space*>(Support::unmark(copy));
120  return copy;
121  }
122 
123  forceinline void
125  if (!isRoot() && (getStatus() != SOLVED || !na.bab())) {
126  // only delete copies from solutions if we are not in BAB
127  if (Support::marked(copy))
128  delete static_cast<Space*>(Support::unmark(copy));
129  else
130  delete copy;
131  copy = NULL;
132  }
133  }
134 
135 
136  forceinline bool
138  return curBest != NULL && curBest->s == this;
139  }
140 
141  forceinline bool
143  return ((getStatus() == UNDETERMINED) ||
145  }
146 
147  forceinline bool
149  return getFlag(HASFAILEDCHILDREN);
150  }
151 
152  forceinline bool
154  return getFlag(HASSOLVEDCHILDREN);
155  }
156 
157  forceinline bool
159  return getFlag(HASOPENCHILDREN);
160  }
161 
162  forceinline bool
164  return copy != NULL;
165  }
166 
167  forceinline bool
169  return copy != NULL && Support::marked(copy);
170  }
171 
172  forceinline int
174  SpaceNode* p = getParent(na);
175  if (p == NULL)
176  return -1;
177  for (int i=p->getNumberOfChildren(); i--;)
178  if (p->getChild(na,i) == this)
179  return i;
180  GECODE_NEVER;
181  return -1;
182  }
183 
184  forceinline const Choice*
186  return choice;
187  }
188 
189 }}
190 
191 // STATISTICS: gist-any
bool hasWorkingSpace(void)
Return whether the node has a working space.
Definition: spacenode.hpp:168
bool marked(void *p)
Check whether p is marked.
SpaceNode * s
The currently best node found, or NULL.
Definition: spacenode.hh:87
Static reference to the currently best space.
Definition: spacenode.hh:84
Space * clone(bool share=true, CloneStatistics &stat=unused_clone) const
Clone space.
Definition: core.hpp:2854
unsigned int nstatus
Status of the node.
Definition: spacenode.hh:110
Space * getSpace(NodeAllocator &na, BestNode *curBest, int c_d, int a_d)
Return working space. Receiver must delete the space.
Definition: spacenode.hpp:102
NodeStatus
Status of nodes in the search tree.
Definition: spacenode.hh:48
bool isCurrentBest(BestNode *curBest)
Return whether this node is the currently best solution.
Definition: spacenode.hpp:137
Base class for nodes of the search tree.
Definition: node.hh:110
Node allocator.
Definition: node.hh:52
unsigned int getNumberOfChildren(void) const
Return the number of children.
Definition: node.hpp:218
bool hasFailedChildren(void)
Return whether the subtree of this node has any failed children.
Definition: spacenode.hpp:148
const Space * getWorkingSpace(void) const
Return working space (if present).
Definition: spacenode.hpp:116
Computation spaces.
Definition: core.hpp:1362
void setStatus(NodeStatus s)
Set status to s.
Definition: spacenode.hpp:69
Node that has not been explored yet.
Definition: spacenode.hh:52
int getAlternative(const NodeAllocator &na) const
Return alternative number of this node.
Definition: spacenode.hpp:173
void setDistance(unsigned int d)
Set distance from copy.
Definition: spacenode.hpp:80
void acquireSpace(NodeAllocator &na, BestNode *curBest, int c_d, int a_d)
Acquire working space, either from parent or by recomputation.
Definition: spacenode.cpp:160
Gecode::IntSet d(v, 7)
const Choice * getChoice(void)
Return choice of this node.
Definition: spacenode.hpp:185
int getParent(void) const
Return the parent.
Definition: node.hpp:186
NodeStatus getStatus(void) const
Return current status of the node.
Definition: spacenode.hpp:75
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
bool isRoot(void) const
Check if this node is the root of a tree.
Definition: node.hpp:215
bool bab(void) const
Return branch-and-bound flag.
Definition: node.hpp:118
Gecode::IntArgs i(4, 1, 2, 3, 4)
const unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance) ...
Definition: search.hh:99
Node representing a solution.
Definition: spacenode.hh:49
unsigned int getDistance(void) const
Return distance from copy.
Definition: spacenode.hpp:88
void * unmark(void *p)
Return unmarked pointer for a marked pointer p.
bool hasOpenChildren(void)
Return whether the subtree of this node has any open children.
Definition: spacenode.hpp:158
void setFlag(int flag, bool value)
Set status flag.
Definition: spacenode.hpp:41
const Choice * choice
Definition: spacenode.hh:102
Choice for performing commit
Definition: core.hpp:1036
#define forceinline
Definition: config.hpp:132
const unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:97
A node of a search tree of Gecode spaces.
Definition: spacenode.hh:93
Space * copy
A copy used for recomputation, or NULL.
Definition: spacenode.hh:100
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
bool hasCopy(void)
Return whether the node has a copy.
Definition: spacenode.hpp:163
Gecode toplevel namespace
bool getFlag(int flag) const
Return status flag.
Definition: spacenode.hpp:49
int getChild(int n) const
Return index of child no n.
Definition: node.hpp:199
bool isOpen(void)
Return whether this node still has open children.
Definition: spacenode.hpp:142
SpaceNode(int p)
Construct node with parent p.
Definition: spacenode.hpp:93
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
bool hasSolvedChildren(void)
Return whether the subtree of this node has any solved children.
Definition: spacenode.hpp:153
void purge(const NodeAllocator &na)
Clear working space and copy (if present and this is not the root).
Definition: spacenode.hpp:124