spacenode.hh
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Guido Tack, 2006
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef GECODE_GIST_SPACENODE_HH
#define GECODE_GIST_SPACENODE_HH
#include <gecode/gist/node.hh>
#include <gecode/kernel.hh>
namespace Gecode { namespace Gist {
enum NodeStatus {
SOLVED,
FAILED,
BRANCH,
UNDETERMINED,
STOP,
UNSTOP,
};
static const unsigned int FIRSTBIT = 24; //< First free bit in status word
static const unsigned int STATUSMASK = 7<<20; //< Mask for accessing status
static const unsigned int MAXDISTANCE = (1<<20)-1; //< Maximum representable distance
static const unsigned int DISTANCEMASK = (1<<20)-1; //< Mask for accessing distance
class Statistics : public StatusStatistics {
public:
int solutions;
int failures;
int choices;
int undetermined;
int maxDepth;
Statistics(void)
: solutions(0), failures(0), choices(0), undetermined(1), maxDepth(0) {}
};
class SpaceNode;
class BestNode {
public:
SpaceNode* s;
BestNode(SpaceNode* s0);
};
class SpaceNode : public Node {
protected:
Space* copy;
protected:
const Choice* choice;
unsigned int nstatus;
void setDistance(unsigned int d);
unsigned int getDistance(void) const;
void setFlag(int flag, bool value);
bool getFlag(int flag) const;
enum SpaceNodeFlags {
HASOPENCHILDREN = FIRSTBIT,
HASFAILEDCHILDREN,
HASSOLVEDCHILDREN
};
static const int LASTBIT = HASSOLVEDCHILDREN;
private:
void setHasOpenChildren(bool b);
void setHasFailedChildren(bool b);
void setHasSolvedChildren(bool b);
int recompute(NodeAllocator& na,
BestNode* curBest, int c_d, int a_d);
void closeChild(const NodeAllocator& na,
bool hadFailures, bool hadSolutions);
protected:
void setStatus(NodeStatus s);
void acquireSpace(NodeAllocator& na,
BestNode* curBest, int c_d, int a_d);
public:
SpaceNode(int p);
SpaceNode(Space* root);
Space* getSpace(NodeAllocator& na,
BestNode* curBest, int c_d, int a_d);
const Space* getWorkingSpace(void) const;
void purge(const NodeAllocator& na);
void dispose(void);
bool isCurrentBest(BestNode* curBest);
int getNumberOfChildNodes(NodeAllocator& na,
BestNode* curBest,
Statistics& stats,
int c_d, int a_d);
NodeStatus getStatus(void) const;
bool isOpen(void);
bool hasFailedChildren(void);
bool hasSolvedChildren(void);
bool hasOpenChildren(void);
int getNoOfOpenChildren(const NodeAllocator& na);
void setNoOfOpenChildren(int n);
bool hasCopy(void);
bool hasWorkingSpace(void);
int getAlternative(const NodeAllocator& na) const;
const Choice* getChoice(void);
};
}}
#endif
// STATISTICS: gist-any
Gecode::Choice
Choice for performing commit
Definition core.hpp:1412
Gecode::Gist::BestNode
Static reference to the currently best space.
Definition spacenode.hh:80
Gecode::Gist::BestNode::BestNode
BestNode(SpaceNode *s0)
Constructor.
Definition spacenode.cpp:61
Gecode::Gist::BestNode::s
SpaceNode * s
The currently best node found, or NULL.
Definition spacenode.hh:83
Gecode::Gist::Node::NodeAllocator
NodeAllocatorBase< VisualNode > NodeAllocator
Definition node.hh:143
Gecode::Gist::Node::Node
Node(int p, bool failed=false)
Construct node with parent p.
Definition node.hpp:175
Gecode::Gist::SpaceNode
A node of a search tree of Gecode spaces.
Definition spacenode.hh:89
Gecode::Gist::SpaceNode::copy
Space * copy
A copy used for recomputation, or NULL.
Definition spacenode.hh:96
Gecode::Gist::SpaceNode::hasCopy
bool hasCopy(void)
Return whether the node has a copy.
Definition spacenode.hpp:159
Gecode::Gist::SpaceNode::choice
const Choice * choice
Definition spacenode.hh:98
Gecode::Gist::SpaceNode::hasWorkingSpace
bool hasWorkingSpace(void)
Return whether the node has a working space.
Definition spacenode.hpp:164
Gecode::Gist::SpaceNode::getChoice
const Choice * getChoice(void)
Return choice of this node.
Definition spacenode.hpp:181
Gecode::Gist::SpaceNode::SpaceNodeFlags
SpaceNodeFlags
Flags for SpaceNodes.
Definition spacenode.hh:121
Gecode::Gist::SpaceNode::HASFAILEDCHILDREN
@ HASFAILEDCHILDREN
Definition spacenode.hh:123
Gecode::Gist::SpaceNode::HASOPENCHILDREN
@ HASOPENCHILDREN
Definition spacenode.hh:122
Gecode::Gist::SpaceNode::HASSOLVEDCHILDREN
@ HASSOLVEDCHILDREN
Definition spacenode.hh:124
Gecode::Gist::SpaceNode::getWorkingSpace
const Space * getWorkingSpace(void) const
Return working space (if present).
Definition spacenode.hpp:112
Gecode::Gist::SpaceNode::isCurrentBest
bool isCurrentBest(BestNode *curBest)
Return whether this node is the currently best solution.
Definition spacenode.hpp:133
Gecode::Gist::SpaceNode::getDistance
unsigned int getDistance(void) const
Return distance from copy.
Definition spacenode.hpp:84
Gecode::Gist::SpaceNode::setNoOfOpenChildren
void setNoOfOpenChildren(int n)
Set number of open children to n.
Gecode::Gist::SpaceNode::LASTBIT
static const int LASTBIT
Last bit used for SpaceNode flags.
Definition spacenode.hh:127
Gecode::Gist::SpaceNode::nstatus
unsigned int nstatus
Status of the node.
Definition spacenode.hh:106
Gecode::Gist::SpaceNode::setStatus
void setStatus(NodeStatus s)
Set status to s.
Definition spacenode.hpp:65
Gecode::Gist::SpaceNode::hasFailedChildren
bool hasFailedChildren(void)
Return whether the subtree of this node has any failed children.
Definition spacenode.hpp:144
Gecode::Gist::SpaceNode::setFlag
void setFlag(int flag, bool value)
Set status flag.
Definition spacenode.hpp:37
Gecode::Gist::SpaceNode::dispose
void dispose(void)
Free allocated memory.
Definition spacenode.cpp:291
Gecode::Gist::SpaceNode::acquireSpace
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
Gecode::Gist::SpaceNode::getNumberOfChildNodes
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
Gecode::Gist::SpaceNode::hasSolvedChildren
bool hasSolvedChildren(void)
Return whether the subtree of this node has any solved children.
Definition spacenode.hpp:149
Gecode::Gist::SpaceNode::getAlternative
int getAlternative(const NodeAllocator &na) const
Return alternative number of this node.
Definition spacenode.hpp:169
Gecode::Gist::SpaceNode::isOpen
bool isOpen(void)
Return whether this node still has open children.
Definition spacenode.hpp:138
Gecode::Gist::SpaceNode::getStatus
NodeStatus getStatus(void) const
Return current status of the node.
Definition spacenode.hpp:71
Gecode::Gist::SpaceNode::getSpace
Space * getSpace(NodeAllocator &na, BestNode *curBest, int c_d, int a_d)
Return working space. Receiver must delete the space.
Definition spacenode.hpp:98
Gecode::Gist::SpaceNode::SpaceNode
SpaceNode(int p)
Construct node with parent p.
Definition spacenode.hpp:89
Gecode::Gist::SpaceNode::purge
void purge(const NodeAllocator &na)
Clear working space and copy (if present and this is not the root).
Definition spacenode.hpp:120
Gecode::Gist::SpaceNode::getFlag
bool getFlag(int flag) const
Return status flag.
Definition spacenode.hpp:45
Gecode::Gist::SpaceNode::setDistance
void setDistance(unsigned int d)
Set distance from copy.
Definition spacenode.hpp:76
Gecode::Gist::SpaceNode::hasOpenChildren
bool hasOpenChildren(void)
Return whether the subtree of this node has any open children.
Definition spacenode.hpp:154
Gecode::Gist::SpaceNode::getNoOfOpenChildren
int getNoOfOpenChildren(const NodeAllocator &na)
Return number of open children.
Definition spacenode.cpp:369
Gecode::Gist::Statistics
Statistics about the search tree
Definition spacenode.hh:59
Gecode::Gist::Statistics::choices
int choices
Number of choice nodes.
Definition spacenode.hh:66
Gecode::Gist::Statistics::failures
int failures
Number of failures.
Definition spacenode.hh:64
Gecode::Gist::Statistics::solutions
int solutions
Number of solutions.
Definition spacenode.hh:62
Gecode::Gist::Statistics::undetermined
int undetermined
Number of open, undetermined nodes.
Definition spacenode.hh:68
Gecode::Gist::Statistics::Statistics
Statistics(void)
Constructor.
Definition spacenode.hh:73
Gecode::Gist::Statistics::maxDepth
int maxDepth
Maximum depth of the tree.
Definition spacenode.hh:70
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::StatusStatistics::StatusStatistics
StatusStatistics(void)
Initialize.
Definition core.hpp:4694
kernel.hh
Gecode::Gist
The Gecode Interactive Search Tool.
Gecode::Gist::NodeStatus
NodeStatus
Status of nodes in the search tree.
Definition spacenode.hh:44
Gecode::Gist::UNDETERMINED
@ UNDETERMINED
Node that has not been explored yet.
Definition spacenode.hh:48
Gecode::Gist::UNSTOP
@ UNSTOP
Node representing ignored stop point.
Definition spacenode.hh:50
Gecode::Gist::FAILED
@ FAILED
Node representing failure.
Definition spacenode.hh:46
Gecode::Gist::STOP
@ STOP
Node representing stop point.
Definition spacenode.hh:49
Gecode::Gist::SOLVED
@ SOLVED
Node representing a solution.
Definition spacenode.hh:45
Gecode::Gist::BRANCH
@ BRANCH
Node representing a branch.
Definition spacenode.hh:47
Gecode
Gecode toplevel namespace
node.hh