Generated on Fri Jan 10 2020 11:38:25 for Gecode by doxygen 1.8.16
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 
40 namespace Gecode { namespace Gist {
41 
44  enum NodeStatus {
49  STOP,
51  };
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 
59  class Statistics : public StatusStatistics {
60  public:
62  int solutions;
64  int failures;
66  int choices;
70  int maxDepth;
71 
73  Statistics(void)
74  : solutions(0), failures(0), choices(0), undetermined(1), maxDepth(0) {}
75  };
76 
77  class SpaceNode;
78 
80  class BestNode {
81  public:
85  BestNode(SpaceNode* s0);
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 
122  HASOPENCHILDREN = FIRSTBIT,
125  };
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);
148  void acquireSpace(NodeAllocator& na,
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);
201  void setNoOfOpenChildren(int n);
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::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Node that has not been explored yet.
Definition: spacenode.hh:48
bool hasOpenChildren(void)
Return whether the subtree of this node has any open children.
Definition: spacenode.hpp:154
int maxDepth
Maximum depth of the tree.
Definition: spacenode.hh:70
Node representing stop point.
Definition: spacenode.hh:49
bool hasSolvedChildren(void)
Return whether the subtree of this node has any solved children.
Definition: spacenode.hpp:149
const Space * getWorkingSpace(void) const
Return working space (if present).
Definition: spacenode.hpp:112
NodeStatus
Status of nodes in the search tree.
Definition: spacenode.hh:44
NodeStatus getStatus(void) const
Return current status of the node.
Definition: spacenode.hpp:71
void dispose(void)
Free allocated memory.
Definition: spacenode.cpp:291
Computation spaces.
Definition: core.hpp:1742
void acquireSpace(NodeAllocator &na, BestNode *curBest, int c_d, int a_d)
Acquire working space, either from parent or by recomputation.
Definition: spacenode.cpp:156
int failures
Number of failures.
Definition: spacenode.hh:64
void purge(const NodeAllocator &na)
Clear working space and copy (if present and this is not the root).
Definition: spacenode.hpp:120
Space * getSpace(NodeAllocator &na, BestNode *curBest, int c_d, int a_d)
Return working space. Receiver must delete the space.
Definition: spacenode.hpp:98
bool getFlag(int flag) const
Return status flag.
Definition: spacenode.hpp:45
Base class for nodes of the search tree.
Definition: node.hh:106
SpaceNode * s
The currently best node found, or NULL.
Definition: spacenode.hh:83
Gecode toplevel namespace
const Choice * choice
Definition: spacenode.hh:98
bool isOpen(void)
Return whether this node still has open children.
Definition: spacenode.hpp:138
int getNoOfOpenChildren(const NodeAllocator &na)
Return number of open children.
Definition: spacenode.cpp:369
int getAlternative(const NodeAllocator &na) const
Return alternative number of this node.
Definition: spacenode.hpp:169
Definition: spacenode.hh:122
Node allocator.
Definition: node.hh:48
bool hasWorkingSpace(void)
Return whether the node has a working space.
Definition: spacenode.hpp:164
Space * copy
A copy used for recomputation, or NULL.
Definition: spacenode.hh:96
void setNoOfOpenChildren(int n)
Set number of open children to n.
Statistics(void)
Constructor.
Definition: spacenode.hh:73
int getNumberOfChildNodes(NodeAllocator &na, BestNode *curBest, Statistics &stats, int c_d, int a_d)
Compute and return the number of children.
Definition: spacenode.cpp:298
bool isCurrentBest(BestNode *curBest)
Return whether this node is the currently best solution.
Definition: spacenode.hpp:133
int choices
Number of choice nodes.
Definition: spacenode.hh:66
Static reference to the currently best space.
Definition: spacenode.hh:80
int solutions
Number of solutions.
Definition: spacenode.hh:62
unsigned int nstatus
Status of the node.
Definition: spacenode.hh:106
Node representing a branch.
Definition: spacenode.hh:47
const Choice * getChoice(void)
Return choice of this node.
Definition: spacenode.hpp:181
Definition: spacenode.hh:123
Definition: spacenode.hh:124
static const int LASTBIT
Last bit used for SpaceNode flags.
Definition: spacenode.hh:127
bool hasCopy(void)
Return whether the node has a copy.
Definition: spacenode.hpp:159
Gecode::IntSet d(v, 7)
A node of a search tree of Gecode spaces.
Definition: spacenode.hh:89
Statistics about the search tree
Definition: spacenode.hh:59
SpaceNodeFlags
Flags for SpaceNodes.
Definition: spacenode.hh:121
BestNode(SpaceNode *s0)
Constructor.
Definition: spacenode.cpp:61
Statistics for execution of status
Definition: core.hpp:1691
SpaceNode(int p)
Construct node with parent p.
Definition: spacenode.hpp:89
bool hasFailedChildren(void)
Return whether the subtree of this node has any failed children.
Definition: spacenode.hpp:144
const unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:113
void setDistance(unsigned int d)
Set distance from copy.
Definition: spacenode.hpp:76
const unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance)
Definition: search.hh:115
void setStatus(NodeStatus s)
Set status to s.
Definition: spacenode.hpp:65
Node representing ignored stop point.
Definition: spacenode.hh:50
unsigned int getDistance(void) const
Return distance from copy.
Definition: spacenode.hpp:84
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Choice for performing commit
Definition: core.hpp:1412
Node representing failure.
Definition: spacenode.hh:46
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
int undetermined
Number of open, undetermined nodes.
Definition: spacenode.hh:68
void setFlag(int flag, bool value)
Set status flag.
Definition: spacenode.hpp:37
Node representing a solution.
Definition: spacenode.hh:45