Generated on Sat Jan 12 2019 20:58:51 for Gecode by doxygen 1.8.13
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,
124  HASSOLVEDCHILDREN
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 
157  Space* getSpace(NodeAllocator& na,
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 
182  int getNumberOfChildNodes(NodeAllocator& na,
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
Node representing stop point.
Definition: spacenode.hh:49
int solutions
Number of solutions.
Definition: spacenode.hh:62
SpaceNode * s
The currently best node found, or NULL.
Definition: spacenode.hh:83
Static reference to the currently best space.
Definition: spacenode.hh:80
Node representing a branch.
Definition: spacenode.hh:47
unsigned int nstatus
Status of the node.
Definition: spacenode.hh:106
int choices
Number of choice nodes.
Definition: spacenode.hh:66
NodeStatus
Status of nodes in the search tree.
Definition: spacenode.hh:44
Node representing failure.
Definition: spacenode.hh:46
Base class for nodes of the search tree.
Definition: node.hh:106
SpaceNodeFlags
Flags for SpaceNodes.
Definition: spacenode.hh:121
Node allocator.
Definition: node.hh:48
Computation spaces.
Definition: core.hpp:1701
Node that has not been explored yet.
Definition: spacenode.hh:48
Statistics for execution of status
Definition: core.hpp:1650
Gecode::IntSet d(v, 7)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
const unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance) ...
Definition: search.hh:115
Node representing a solution.
Definition: spacenode.hh:45
struct Gecode::@593::NNF::@62::@63 b
For binary nodes (and, or, eqv)
int undetermined
Number of open, undetermined nodes.
Definition: spacenode.hh:68
const Choice * choice
Definition: spacenode.hh:98
Choice for performing commit
Definition: core.hpp:1371
int maxDepth
Maximum depth of the tree.
Definition: spacenode.hh:70
const unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:113
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
Gecode toplevel namespace
int failures
Number of failures.
Definition: spacenode.hh:64
ExecStatus purge(Space &home, Propagator &p, TaskArray< OptTask > &t)
Purge optional tasks that are excluded and possibly rewrite propagator.
Definition: purge.hpp:38
Statistics about the search tree
Definition: spacenode.hh:59
Statistics(void)
Constructor.
Definition: spacenode.hh:73
Node representing ignored stop point.
Definition: spacenode.hh:50