Alps  2.0.2
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AlpsSubTree Class Reference

This class contains the data pertaining to a particular subtree in the search tree. More...

#include <AlpsSubTree.h>

+ Inheritance diagram for AlpsSubTree:
+ Collaboration diagram for AlpsSubTree:

Public Member Functions

 AlpsSubTree ()
 Default constructor. More...
 
 AlpsSubTree (AlpsKnowledgeBroker *kb)
 Useful constructor. More...
 
virtual ~AlpsSubTree ()
 Destructor. More...
 
AlpsTreeNodeactiveNode ()
 Get pointer to active node. More...
 
void setActiveNode (AlpsTreeNode *activeNode)
 Set pointer to active node. More...
 
void createChildren (AlpsTreeNode *parent, std::vector< CoinTriple< AlpsNodeDesc *, AlpsNodeStatus, double > > &children, AlpsNodePool *kidNodePool=NULL)
 Create children nodes from the given parent node. More...
 
query and set member functions
AlpsTreeNodegetRoot () const
 Get the root node of this subtree. More...
 
void setRoot (AlpsTreeNode *r)
 Set the root node of this subtree. More...
 
AlpsNodePoolnodePool ()
 Access the node pool. More...
 
AlpsNodePooldiveNodePool ()
 Access the node pool. More...
 
void setNodePool (AlpsNodePool *np)
 Set node pool. More...
 
void changeNodePool (AlpsNodePool *np)
 Set node pool. More...
 
double getBestKnowledgeValue () const
 Get the quality of the best node in the subtree. More...
 
AlpsTreeNodegetBestNode () const
 Get the "best" node in the subtree. More...
 
double getQuality () const
 Get the quality of this subtree. More...
 
double getSolEstimate () const
 Get the estimated quality of this subtree. More...
 
void incDiveDepth (int num=1)
 Increment dive depth. More...
 
int getDiveDepth ()
 Get dive depth. More...
 
void setDiveDepth (int num)
 Set dive depth. More...
 
double calculateQuality ()
 Calcuate and return the quality of this subtree, which is measured by the quality of the specified number of nodes. More...
 
int nextIndex ()
 
int getNextIndex () const
 Get the index of the next generated node. More...
 
void setNextIndex (int next)
 Set the index of the next generated node. More...
 
int getNumNodes () const
 Return the number of nodes on this subtree. More...
 
void setNodeSelection (AlpsSearchStrategy< AlpsTreeNode * > *nc)
 Set the node comparision rule. More...
 
AlpsSubTreesplitSubTree (int &returnSize, int size=10)
 The function split the subtree and return a subtree of the specified size or available size. More...
 
virtual AlpsReturnStatus exploreSubTree (AlpsTreeNode *root, int nodeLimit, double timeLimit, int &numNodesProcessed, int &numNodesBranched, int &numNodesDiscarded, int &numNodesPartial, int &depth)
 Explore the subtree from root as the root of the subtree for given number of nodes or time, depending on which one reach first. More...
 
AlpsReturnStatus exploreUnitWork (bool leaveAsIt, int unitWork, double unitTime, AlpsExitStatus &solStatus, int &numNodesProcessed, int &numNodesBranched, int &numNodesDiscarded, int &numNodesPartial, int &depth, bool &betterSolution)
 Explore the subtree for certain amount of work/time. More...
 
virtual int rampUp (int minNumNodes, int requiredNumNodes, int &depth, AlpsTreeNode *root=NULL)
 Generate required number (specified by a parameter) of nodes. More...
 
virtual AlpsReturnStatus encode (AlpsEncoded *encoded) const
 Encode the content of this into the given AlpsEncoded object. More...
 
virtual AlpsKnowledgedecode (AlpsEncoded &encoded) const
 Decode the given AlpsEncoded object into a new AlpsKnowledge object and return a pointer to it. More...
 
virtual AlpsReturnStatus decodeToSelf (AlpsEncoded &encoded)
 Decode the given AlpsEncoded object into this. More...
 
virtual AlpsSubTreenewSubTree () const
 Create a AlpsSubtree object dynamically. More...
 
void clearNodePools ()
 Remove nodes in pools in the subtree. More...
 
void nullRootActiveNode ()
 Set root and active node to null. More...
 
bool doDive ()
 Check whether we should keep diving or not. More...
 
void reset ()
 Move nodes in node pool, null active node. More...
 
AlpsEncodedencode () const
 Get encode function defined in Alps. More...
 
virtual AlpsReturnStatus encode (AlpsEncoded *encoded) const
 Get encode function defined in Alps. More...
 
- Public Member Functions inherited from AlpsKnowledge
 AlpsKnowledge ()
 Default constructor. More...
 
 AlpsKnowledge (AlpsKnowledgeType type)
 
 AlpsKnowledge (AlpsKnowledgeType type, AlpsKnowledgeBroker *broker)
 
virtual ~AlpsKnowledge ()
 Destructor. More...
 
AlpsKnowledgeType getType () const
 Get knowledge type. More...
 
void setType (AlpsKnowledgeType t)
 Set knowledge type. More...
 
AlpsKnowledgeBrokerbroker ()
 Get pointer to the knowledge broker. More...
 
const AlpsKnowledgeBrokerbroker () const
 Get pointer to the knowledge broker. More...
 
void setBroker (AlpsKnowledgeBroker *broker)
 Set knowledge broker. More...
 
AlpsEncodedencode () const
 Encode the content of this into an AlpsEncoded object and return a pointer to it. More...
 

Protected Member Functions

void removeDeadNodes (AlpsTreeNode *&node)
 The purpose of this method is to remove nodes that are not needed in the description of the subtree. More...
 
void replaceNode (AlpsTreeNode *oldNode, AlpsTreeNode *newNode)
 This function replaces oldNode with newNode in the tree. More...
 
void fathomAllNodes ()
 Fathom all nodes on this subtree. More...
 

Protected Attributes

AlpsTreeNoderoot_
 The root of the sub tree. More...
 
AlpsNodePoolnodePool_
 A node pool containing the leaf nodes awaiting processing. More...
 
AlpsNodePooldiveNodePool_
 A node pool used when diving. More...
 
AlpsSearchStrategy< AlpsTreeNode * > * diveNodeRule_
 Diving node comparing rule. More...
 
int diveDepth_
 Diving depth. More...
 
AlpsTreeNodeactiveNode_
 This is the node that is currently being processed. More...
 
double quality_
 A quantity indicating how good this subtree is. More...
 

Additional Inherited Members

- Public Attributes inherited from AlpsKnowledge
AlpsKnowledgeBrokerbroker_
 

Detailed Description

This class contains the data pertaining to a particular subtree in the search tree.

In order to improve scalability, we will try to deal with entire subtrees as much as possible. They will be the basic unit of work that will be passed between processes.

Definition at line 51 of file AlpsSubTree.h.

Constructor & Destructor Documentation

◆ AlpsSubTree() [1/2]

AlpsSubTree::AlpsSubTree ( )

Default constructor.

◆ AlpsSubTree() [2/2]

AlpsSubTree::AlpsSubTree ( AlpsKnowledgeBroker kb)

Useful constructor.

◆ ~AlpsSubTree()

virtual AlpsSubTree::~AlpsSubTree ( )
virtual

Destructor.

Member Function Documentation

◆ removeDeadNodes()

void AlpsSubTree::removeDeadNodes ( AlpsTreeNode *&  node)
protected

The purpose of this method is to remove nodes that are not needed in the description of the subtree.

The argument node must have status fathomed. First, the argument node is removed, and then the parent is examined to determine whether it has any children left. If it has none, then this function is called recursively on the parent. This removes all nodes that are no longer needed.

◆ replaceNode()

void AlpsSubTree::replaceNode ( AlpsTreeNode oldNode,
AlpsTreeNode newNode 
)
protected

This function replaces oldNode with newNode in the tree.

◆ fathomAllNodes()

void AlpsSubTree::fathomAllNodes ( )
protected

Fathom all nodes on this subtree.

Set activeNode_ and root_ to NULL.

◆ activeNode()

AlpsTreeNode* AlpsSubTree::activeNode ( )
inline

Get pointer to active node.

Definition at line 112 of file AlpsSubTree.h.

◆ setActiveNode()

void AlpsSubTree::setActiveNode ( AlpsTreeNode activeNode)
inline

Set pointer to active node.

Definition at line 115 of file AlpsSubTree.h.

◆ createChildren()

void AlpsSubTree::createChildren ( AlpsTreeNode parent,
std::vector< CoinTriple< AlpsNodeDesc *, AlpsNodeStatus, double > > &  children,
AlpsNodePool kidNodePool = NULL 
)

Create children nodes from the given parent node.

◆ getRoot()

AlpsTreeNode* AlpsSubTree::getRoot ( ) const
inline

Get the root node of this subtree.

Definition at line 128 of file AlpsSubTree.h.

◆ setRoot()

void AlpsSubTree::setRoot ( AlpsTreeNode r)
inline

Set the root node of this subtree.

Definition at line 131 of file AlpsSubTree.h.

◆ nodePool()

AlpsNodePool* AlpsSubTree::nodePool ( )
inline

Access the node pool.

Definition at line 134 of file AlpsSubTree.h.

◆ diveNodePool()

AlpsNodePool* AlpsSubTree::diveNodePool ( )
inline

Access the node pool.

Definition at line 137 of file AlpsSubTree.h.

◆ setNodePool()

void AlpsSubTree::setNodePool ( AlpsNodePool np)
inline

Set node pool.

Delete previous node pool and nodes in pool if exit.

Definition at line 140 of file AlpsSubTree.h.

◆ changeNodePool()

void AlpsSubTree::changeNodePool ( AlpsNodePool np)
inline

Set node pool.

Delete previous node pool, but not the nodes in pool.

Definition at line 149 of file AlpsSubTree.h.

◆ getBestKnowledgeValue()

double AlpsSubTree::getBestKnowledgeValue ( ) const

Get the quality of the best node in the subtree.

◆ getBestNode()

AlpsTreeNode* AlpsSubTree::getBestNode ( ) const

Get the "best" node in the subtree.

◆ getQuality()

double AlpsSubTree::getQuality ( ) const
inline

Get the quality of this subtree.

Definition at line 168 of file AlpsSubTree.h.

◆ getSolEstimate()

double AlpsSubTree::getSolEstimate ( ) const
inline

Get the estimated quality of this subtree.

Definition at line 171 of file AlpsSubTree.h.

◆ incDiveDepth()

void AlpsSubTree::incDiveDepth ( int  num = 1)
inline

Increment dive depth.

Definition at line 181 of file AlpsSubTree.h.

◆ getDiveDepth()

int AlpsSubTree::getDiveDepth ( )
inline

Get dive depth.

Definition at line 184 of file AlpsSubTree.h.

◆ setDiveDepth()

void AlpsSubTree::setDiveDepth ( int  num)
inline

Set dive depth.

Definition at line 187 of file AlpsSubTree.h.

◆ calculateQuality()

double AlpsSubTree::calculateQuality ( )

Calcuate and return the quality of this subtree, which is measured by the quality of the specified number of nodes.

◆ nextIndex()

int AlpsSubTree::nextIndex ( )

◆ getNextIndex()

int AlpsSubTree::getNextIndex ( ) const

Get the index of the next generated node.

◆ setNextIndex()

void AlpsSubTree::setNextIndex ( int  next)

Set the index of the next generated node.

◆ getNumNodes()

int AlpsSubTree::getNumNodes ( ) const
inline

Return the number of nodes on this subtree.

Definition at line 204 of file AlpsSubTree.h.

◆ setNodeSelection()

void AlpsSubTree::setNodeSelection ( AlpsSearchStrategy< AlpsTreeNode * > *  nc)
inline

Set the node comparision rule.

Definition at line 218 of file AlpsSubTree.h.

◆ splitSubTree()

AlpsSubTree* AlpsSubTree::splitSubTree ( int &  returnSize,
int  size = 10 
)

The function split the subtree and return a subtree of the specified size or available size.

◆ exploreSubTree()

virtual AlpsReturnStatus AlpsSubTree::exploreSubTree ( AlpsTreeNode root,
int  nodeLimit,
double  timeLimit,
int &  numNodesProcessed,
int &  numNodesBranched,
int &  numNodesDiscarded,
int &  numNodesPartial,
int &  depth 
)
virtual

Explore the subtree from root as the root of the subtree for given number of nodes or time, depending on which one reach first.

Only for serial code.

◆ exploreUnitWork()

AlpsReturnStatus AlpsSubTree::exploreUnitWork ( bool  leaveAsIt,
int  unitWork,
double  unitTime,
AlpsExitStatus solStatus,
int &  numNodesProcessed,
int &  numNodesBranched,
int &  numNodesDiscarded,
int &  numNodesPartial,
int &  depth,
bool &  betterSolution 
)

Explore the subtree for certain amount of work/time.

leaveAsIt means exit immediately after reseach limits: do not put activeNode_ in pool, do not move nodes in divePool_ in regular pool.

◆ rampUp()

virtual int AlpsSubTree::rampUp ( int  minNumNodes,
int  requiredNumNodes,
int &  depth,
AlpsTreeNode root = NULL 
)
virtual

Generate required number (specified by a parameter) of nodes.

This function is used by master and hubs.

◆ encode() [1/3]

virtual AlpsReturnStatus AlpsSubTree::encode ( AlpsEncoded encoded) const
virtual

Encode the content of this into the given AlpsEncoded object.

Implementation given in this class can not be used when the memory of data members is not contiguous, i.e., some data members are pointers to heap locations, STL set, map, etc. These type of user application sub-classes should implement their own version of this.

Reimplemented from AlpsKnowledge.

◆ decode()

virtual AlpsKnowledge* AlpsSubTree::decode ( AlpsEncoded encoded) const
virtual

Decode the given AlpsEncoded object into a new AlpsKnowledge object and return a pointer to it.

User application sub-classes should implement this since the returned pointer will point to user sub-class instances.

Implements AlpsKnowledge.

◆ decodeToSelf()

virtual AlpsReturnStatus AlpsSubTree::decodeToSelf ( AlpsEncoded encoded)
virtual

Decode the given AlpsEncoded object into this.

Reimplemented from AlpsKnowledge.

◆ newSubTree()

virtual AlpsSubTree* AlpsSubTree::newSubTree ( ) const
inlinevirtual

Create a AlpsSubtree object dynamically.

Only parallel code need this function.

Definition at line 274 of file AlpsSubTree.h.

◆ clearNodePools()

void AlpsSubTree::clearNodePools ( )
inline

Remove nodes in pools in the subtree.

Do not free memory.

Definition at line 279 of file AlpsSubTree.h.

◆ nullRootActiveNode()

void AlpsSubTree::nullRootActiveNode ( )
inline

Set root and active node to null.

Definition at line 289 of file AlpsSubTree.h.

◆ doDive()

bool AlpsSubTree::doDive ( )
inline

Check whether we should keep diving or not.

Definition at line 295 of file AlpsSubTree.h.

◆ reset()

void AlpsSubTree::reset ( )
inline

Move nodes in node pool, null active node.

Definition at line 300 of file AlpsSubTree.h.

◆ encode() [2/3]

AlpsEncoded* AlpsKnowledge::encode

Get encode function defined in Alps.

◆ encode() [3/3]

virtual AlpsReturnStatus AlpsKnowledge::encode

Get encode function defined in Alps.

Member Data Documentation

◆ root_

AlpsTreeNode* AlpsSubTree::root_
protected

The root of the sub tree.

Definition at line 56 of file AlpsSubTree.h.

◆ nodePool_

AlpsNodePool* AlpsSubTree::nodePool_
protected

A node pool containing the leaf nodes awaiting processing.

Definition at line 59 of file AlpsSubTree.h.

◆ diveNodePool_

AlpsNodePool* AlpsSubTree::diveNodePool_
protected

A node pool used when diving.

Definition at line 62 of file AlpsSubTree.h.

◆ diveNodeRule_

AlpsSearchStrategy<AlpsTreeNode*>* AlpsSubTree::diveNodeRule_
protected

Diving node comparing rule.

Definition at line 65 of file AlpsSubTree.h.

◆ diveDepth_

int AlpsSubTree::diveDepth_
protected

Diving depth.

Definition at line 68 of file AlpsSubTree.h.

◆ activeNode_

AlpsTreeNode* AlpsSubTree::activeNode_
protected

This is the node that is currently being processed.

Note that since this is the worker, there is only one.

Definition at line 75 of file AlpsSubTree.h.

◆ quality_

double AlpsSubTree::quality_
protected

A quantity indicating how good this subtree is.

Definition at line 78 of file AlpsSubTree.h.


The documentation for this class was generated from the following file: