37 #ifndef __BB_PARA_NODE_POOL_H__ 38 #define __BB_PARA_NODE_POOL_H__ 50 static const double eps = 1.0e-12;
148 virtual bool isEmpty(
176 virtual double getBestDualBoundValue(
183 virtual unsigned int getNumOfGoodNodes(
184 double globalBestBound
191 virtual size_t getNumOfNodes(
198 virtual int removeBoundedNodes(
199 double incumbentValue
205 virtual void updateDualBoundsForSavingNodes(
214 virtual int writeBbParaNodesToCheckpointFile(
215 gzstream::ogzstream &out
224 virtual int removeMergedNodes(
232 virtual const std::string toString(
242 return maxUsageOfPool;
254 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >
ascendingPool;
274 if( ascendingPool.size() > 0 )
276 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >::iterator p;
277 for( p = ascendingPool.begin(); p != ascendingPool.end(); )
279 if( p->second )
delete p->second;
280 ascendingPool.erase(p++);
292 ascendingPool.insert(std::make_pair(paraNode,paraNode));
293 if( maxUsageOfPool < ascendingPool.size() )
295 maxUsageOfPool = ascendingPool.size();
306 return ( ascendingPool.size() == 0 );
317 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >::iterator p;
318 p = ascendingPool.begin();
319 while( p != ascendingPool.end() )
321 if( p->second->getMergeNodeInfo() )
324 if( p->second->getMergingStatus() == 4 )
327 ascendingPool.erase(p++);
338 extracted = p->second;
339 ascendingPool.erase(p);
346 extracted = p->second;
347 ascendingPool.erase(p);
351 assert( ( p == ascendingPool.end() && (!extracted) ) || ( p != ascendingPool.end() && extracted ) );
363 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >::reverse_iterator rp;
364 rp = ascendingPool.rbegin();
366 if( rp != ascendingPool.rend() )
368 assert( !(rp->second->getMergeNodeInfo()) );
369 extracted = rp->second;
371 ascendingPool.erase((rp.base()));
386 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >::iterator p;
387 p = ascendingPool.begin();
388 while( p != ascendingPool.end() )
390 assert( !(p->second->getMergeNodeInfo()) );
394 assert( ( p == ascendingPool.end() && (!node) ) || ( p != ascendingPool.end() && node ) );
407 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >::iterator p;
408 p = ascendingPool.begin();
409 size_t nNodes = ascendingPool.size();
410 if( nNodes == 0 )
return extracted;
415 pos = rand()%
static_cast<int>( nNodes * 0.8 ) + static_cast<int>(nNodes*0.1);
416 if( pos < (static_cast<int>(nNodes*0.1)) || pos > nNodes*0.9 )
418 THROW_LOGICAL_ERROR4(
"Invalid pos in extractNodeRandomly in BbParaNodePool: pos = ", pos,
", nNodes = ", nNodes);
420 for(
int j = 0; j < pos; j++ )
425 assert( p != ascendingPool.end() );
426 if( p == ascendingPool.end() )
428 p = ascendingPool.begin();
430 if( p->second->getMergeNodeInfo() )
433 if( p->second->getMergingStatus() == 4 )
436 ascendingPool.erase(p);
443 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >::iterator pp;
444 pp = ascendingPool.begin();
447 if( dynamic_cast<BbParaNodePtr>(pp->second) == dynamic_cast<BbParaNodePtr>(p->second)->getMergeNodeInfo()->mergedTo->paraNode )
449 extracted = pp->second;
450 ascendingPool.erase(pp);
458 extracted = p->second;
459 ascendingPool.erase(p);
465 extracted = p->second;
466 ascendingPool.erase(p);
471 p = ascendingPool.begin();
472 while( p != ascendingPool.end() )
474 if( p->second->getMergeNodeInfo() )
477 if( p->second->getMergingStatus() == 4 )
480 ascendingPool.erase(p++);
491 extracted = p->second;
492 ascendingPool.erase(p);
499 extracted = p->second;
500 ascendingPool.erase(p);
505 assert( ( p == ascendingPool.end() && (!extracted) ) || ( p != ascendingPool.end() && extracted ) );
515 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >::iterator p;
516 for( p = ascendingPool.begin(); p != ascendingPool.end(); ++p )
518 if( p->second->getAncestor() == 0 )
520 p->second->updateInitialDualBoundToSubtreeDualBound();
531 int writeBbParaNodesToCheckpointFile(
532 gzstream::ogzstream &out
536 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >::iterator p;
537 for( p = ascendingPool.begin(); p != ascendingPool.end(); ++p )
539 if( p->second->getAncestor() == 0 )
541 p->second->write(out);
557 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >::iterator p;
558 p = ascendingPool.begin();
559 if( p != ascendingPool.end() )
561 return p->second->getDualBoundValue();
574 double globalBestBound
596 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >::reverse_iterator rp;
597 for( rp = ascendingPool.rbegin(); rp != ascendingPool.rend() &&
598 ( ( ( rp->second->getDualBoundValue() ) - globalBestBound ) /
599 std::max( fabs(globalBestBound) , 1.0 ) ) > bgap;
604 int num3 = ascendingPool.size() - num2;
618 return ascendingPool.size();
626 double incumbentValue
630 if( ascendingPool.size() > 0 )
632 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >::iterator p;
633 for( p = ascendingPool.begin(); p != ascendingPool.end(); )
636 if( !p->second->getMergeNodeInfo() )
638 if( p->second->getDualBoundValue() > incumbentValue || p->second->getMergingStatus() == 4 )
642 ascendingPool.erase(p++);
653 if( p->second->getDualBoundValue() > incumbentValue || p->second->getMergingStatus() == 4 )
657 ascendingPool.erase(p++);
683 assert( ascendingPool.size() > 0 );
684 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >::iterator p;
685 for( p = ascendingPool.begin(); p != ascendingPool.end() && head; )
688 if( p->second->getMergingStatus() == 2 )
692 for( ; cur; cur=cur->
next )
694 if( p->second == cur->
node )
709 assert( cur == prev->
next );
715 assert( cur == prev->
next );
718 assert( p->second == cur->
node );
723 ascendingPool.erase(p++);
741 std::ostringstream s;
742 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterion >::iterator p;
743 for( p = ascendingPool.begin(); p != ascendingPool.end(); ++p )
745 s << p->second->toString();
756 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterionForCleanUp >
descendingPool;
776 if( descendingPool.size() > 0 )
778 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterionForCleanUp >::iterator p;
779 for( p = descendingPool.begin(); p != descendingPool.end(); )
781 if( p->second )
delete p->second;
782 descendingPool.erase(p++);
794 descendingPool.insert(std::make_pair(paraNode,paraNode));
795 if( maxUsageOfPool < descendingPool.size() )
797 maxUsageOfPool = descendingPool.size();
808 return ( descendingPool.size() == 0 );
819 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterionForCleanUp >::iterator p;
820 p = descendingPool.begin();
821 while( p != descendingPool.end() )
823 if( p->second->getMergeNodeInfo() )
827 extracted = p->second;
828 descendingPool.erase(p);
831 assert( ( p == descendingPool.end() && (!extracted) ) || ( p != descendingPool.end() && extracted ) );
842 std::cerr <<
"***** LOGICAL ERROR : should not be called *****" << std::endl;
854 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterionForCleanUp >::iterator p;
855 p = descendingPool.begin();
856 while( p != descendingPool.end() )
858 if( p->second->getMergeNodeInfo() )
862 extracted = p->second;
863 descendingPool.erase(p);
866 assert( ( p == descendingPool.end() && (!extracted) ) || ( p != descendingPool.end() && extracted ) );
876 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterionForCleanUp >::iterator p;
877 for( p = descendingPool.begin(); p != descendingPool.end(); ++p )
879 if( p->second->getAncestor() == 0 )
881 p->second->updateInitialDualBoundToSubtreeDualBound();
892 int writeBbParaNodesToCheckpointFile(
893 gzstream::ogzstream &out
897 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterionForCleanUp >::iterator p;
898 for( p = descendingPool.begin(); p != descendingPool.end(); ++p )
900 if( p->second->getAncestor() == 0 )
902 p->second->write(out);
918 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterionForCleanUp >::reverse_iterator rp;
919 rp = descendingPool.rbegin();
920 if( rp != descendingPool.rend() )
922 return rp->second->getDualBoundValue();
935 double globalBestBound
944 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterionForCleanUp >::reverse_iterator rp;
945 for( rp = descendingPool.rbegin(); rp != descendingPool.rend() &&
946 ( ( ( rp->second->getDualBoundValue() ) - globalBestBound ) /
947 std::max( fabs(globalBestBound) , 1.0 ) ) < bgap;
962 return descendingPool.size();
970 double incumbentValue
974 if( descendingPool.size() > 0 )
976 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterionForCleanUp >::iterator p;
977 for( p = descendingPool.begin(); p != descendingPool.end(); )
980 if( !p->second->getMergeNodeInfo() )
982 if( p->second->getDualBoundValue() > incumbentValue )
986 descendingPool.erase(p++);
1020 std::ostringstream s;
1021 std::multimap<BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterionForCleanUp >::iterator p;
1022 for( p = descendingPool.begin(); p != descendingPool.end(); ++p )
1024 s << p->second->toString();
1032 #endif // __BB_PARA_NODE_POOL_H__
virtual int getNBoundChanges()=0
get the number of bound changes
representative node for merging
unsigned int getNumOfGoodNodes(double globalBestBound)
get number of good (heavy) BbParaNodes in this pool
#define THROW_LOGICAL_ERROR4(msg1, msg2, msg3, msg4)
BbParaNodePtr extractWorstNode()
extract a BbParaNode object with the lowest priority from this pool
BbParaMergeNodeInfo * getMergeNodeInfo()
get merge node information struct
class BbParaNodeSortCriterionForCleanUp
size_t getNumOfNodes()
get number of BbParaNodes in this pool
virtual ~BbParaNodePool()
destructor
size_t getMaxUsageOfPool()
get maximum usage of this pool
merged node list element stract
int removeMergedNodes(BbParaMergedNodeListElement *head)
remove merged BbParaNodes from this pool
bool isEmpty()
check if this pool is empty or not
bool operator()(const BbParaNodePtr &n1, const BbParaNodePtr &n2) const
()operator
bool operator()(const BbParaNodePtr &n1, const BbParaNodePtr &n2) const
()operator
BbParaNodePtr extractNode()
extract a BbParaNode object from this pool
BbParaNodePool(double inBgap)
constructor
double getBestDualBoundValue()
get best dual bound value of BbParaNode object in this pool
void updateDualBoundsForSavingNodes()
update dual bound values for saving BbParaNodes to checkpoint file
class BbParaNodeSortCriterion
#define THROW_LOGICAL_ERROR1(msg1)
double bgap
gap which can be considered as good
std::multimap< BbParaNodePtr, BbParaNodePtr, BbParaNodeSortCriterionForCleanUp > descendingPool
BbParaMergedNodeListElement * next
pointer to the next ParaMergedNodeListElement
BbParaNode * node
pointer to BbParaNode object
void insert(BbParaNodePtr paraNode)
insert BbParaNode to this pool
size_t maxUsageOfPool
maximum usage of this pool
double getDualBoundValue()
getter of dual bound value
~BbParaNodePoolForCleanUp()
destructor
BbParaDiffSubproblem * getDiffSubproblem()
getter of diffSubproblem
BbParaNodePtr extractNodeRandomly()
extract a BbParaNode object randomly from this pool
checking possibility to merge with the other nodes
int removeBoundedNodes(double incumbentValue)
remove bounded BbParaNodes by given incumbnet value
class BbParaNodePoolForCleanUp
BbParaNodePoolForCleanUp(double inBgap)
constructor
const std::string toString()
stringfy this object