Generated on Sat Feb 7 2015 02:01:18 for Gecode by doxygen 1.8.9.1
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  * Last modified:
10  * $Date: 2010-08-11 15:13:48 +0200 (Wed, 11 Aug 2010) $ by $Author: tack $
11  * $Revision: 11343 $
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_SPACENODE_HH
39 #define GECODE_GIST_SPACENODE_HH
40 
41 #include <gecode/gist/node.hh>
42 #include <gecode/kernel.hh>
43 
44 namespace Gecode { namespace Gist {
45 
48  enum NodeStatus {
53  STOP,
55  };
56 
57  static const unsigned int FIRSTBIT = 24; //< First free bit in status word
58  static const unsigned int STATUSMASK = 7<<20; //< Mask for accessing status
59  static const unsigned int MAXDISTANCE = (1<<20)-1; //< Maximum representable distance
60  static const unsigned int DISTANCEMASK = (1<<20)-1; //< Mask for accessing distance
61 
63  class Statistics : public StatusStatistics {
64  public:
66  int solutions;
68  int failures;
70  int choices;
74  int maxDepth;
75 
77  Statistics(void)
78  : solutions(0), failures(0), choices(0), undetermined(1), maxDepth(0) {}
79  };
80 
81  class SpaceNode;
82 
84  class BestNode {
85  public:
89  BestNode(SpaceNode* s0);
90  };
91 
93  class SpaceNode : public Node {
94  protected:
101  protected:
102  const Choice* choice;
103 
110  unsigned int nstatus;
111 
113  void setDistance(unsigned int d);
114 
116  unsigned int getDistance(void) const;
117 
119  void setFlag(int flag, bool value);
120 
122  bool getFlag(int flag) const;
123 
126  HASOPENCHILDREN = FIRSTBIT,
129  };
131  static const int LASTBIT = HASSOLVEDCHILDREN;
132 
133  private:
135  void setHasOpenChildren(bool b);
137  void setHasFailedChildren(bool b);
139  void setHasSolvedChildren(bool b);
140 
142  int recompute(NodeAllocator& na,
143  BestNode* curBest, int c_d, int a_d);
144 
146  void closeChild(const NodeAllocator& na,
147  bool hadFailures, bool hadSolutions);
148  protected:
150  void setStatus(NodeStatus s);
152  void acquireSpace(NodeAllocator& na,
153  BestNode* curBest, int c_d, int a_d);
154  public:
156  SpaceNode(int p);
158  SpaceNode(Space* root);
159 
162  BestNode* curBest, int c_d, int a_d);
163 
165  const Space* getWorkingSpace(void) const;
166 
168  void purge(const NodeAllocator& na);
169 
171  void dispose(void);
172 
174  bool isCurrentBest(BestNode* curBest);
175 
187  BestNode* curBest,
188  Statistics& stats,
189  int c_d, int a_d);
190 
192  NodeStatus getStatus(void) const;
193 
195  bool isOpen(void);
197  bool hasFailedChildren(void);
199  bool hasSolvedChildren(void);
201  bool hasOpenChildren(void);
203  int getNoOfOpenChildren(const NodeAllocator& na);
205  void setNoOfOpenChildren(int n);
207  bool hasCopy(void);
209  bool hasWorkingSpace(void);
210 
212  int getAlternative(const NodeAllocator& na) const;
214  const Choice* getChoice(void);
215  };
216 
217 }}
218 
219 #endif
220 
221 // STATISTICS: gist-any
Node representing stop point.
Definition: spacenode.hh:53
bool hasWorkingSpace(void)
Return whether the node has a working space.
Definition: spacenode.hpp:168
int solutions
Number of solutions.
Definition: spacenode.hh:66
SpaceNode * s
The currently best node found, or NULL.
Definition: spacenode.hh:87
Static reference to the currently best space.
Definition: spacenode.hh:84
Node representing a branch.
Definition: spacenode.hh:51
BestNode(SpaceNode *s0)
Constructor.
Definition: spacenode.cpp:65
unsigned int nstatus
Status of the node.
Definition: spacenode.hh:110
int choices
Number of choice nodes.
Definition: spacenode.hh:70
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
Node representing failure.
Definition: spacenode.hh:50
Base class for nodes of the search tree.
Definition: node.hh:110
SpaceNodeFlags
Flags for SpaceNodes.
Definition: spacenode.hh:125
Node allocator.
Definition: node.hh:52
static const int LASTBIT
Last bit used for SpaceNode flags.
Definition: spacenode.hh:131
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
Statistics for execution of status
Definition: core.hpp:1310
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
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
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
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
int undetermined
Number of open, undetermined nodes.
Definition: spacenode.hh:72
unsigned int getDistance(void) const
Return distance from copy.
Definition: spacenode.hpp:88
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
int getNoOfOpenChildren(const NodeAllocator &na)
Return number of open children.
Definition: spacenode.cpp:373
const Choice * choice
Definition: spacenode.hh:102
Choice for performing commit
Definition: core.hpp:1036
int maxDepth
Maximum depth of the tree.
Definition: spacenode.hh:74
void dispose(void)
Free allocated memory.
Definition: spacenode.cpp:295
const unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:97
int getNumberOfChildNodes(NodeAllocator &na, BestNode *curBest, Statistics &stats, int c_d, int a_d)
Compute and return the number of children.
Definition: spacenode.cpp:302
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
void setNoOfOpenChildren(int n)
Set number of open children to n.
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
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
int failures
Number of failures.
Definition: spacenode.hh:68
Statistics about the search tree
Definition: spacenode.hh:63
bool hasSolvedChildren(void)
Return whether the subtree of this node has any solved children.
Definition: spacenode.hpp:153
Statistics(void)
Constructor.
Definition: spacenode.hh:77
void purge(const NodeAllocator &na)
Clear working space and copy (if present and this is not the root).
Definition: spacenode.hpp:124
Node representing ignored stop point.
Definition: spacenode.hh:54