Пример #1
0
//Sahar: changed the following line
AlpsTreeNode * AlpsNodePool::getBestNode() const {
  const std::vector<AlpsTreeNode *>& pool=candidateList_.getContainer();
  int k;
  int size = static_cast<int> (pool.size());
  double bestQuality = ALPS_OBJ_MAX;
  AlpsTreeNode * bestNode = NULL;
  AlpsTreeNode * node = NULL;

  //Sahar:added:start
  if(size > 0){
      if ((searchStrategy_ == AlpsSearchTypeBestFirst) ||
	  (searchStrategy_ == AlpsSearchTypeBreadthFirst) ||
	  (searchStrategy_ == AlpsSearchTypeHybrid)) {
	  bestNode = pool[0];
      }
      else{
	  for (k = 0; k < size; ++k) {
	      node = pool[k];
	      if (node->getQuality() < bestQuality) {
		  bestQuality = node->getQuality();
		  bestNode = node;
	      }
	  }
      }
  }
  //Sahar:added:end
  return bestNode;
}
Пример #2
0
double AlpsNodePool::getBestKnowledgeValue() const {
  const std::vector<AlpsTreeNode *>& pool=candidateList_.getContainer();
  int k;
  int size = static_cast<int> (pool.size());
  double bestQuality = ALPS_OBJ_MAX;
  AlpsTreeNode * node = NULL;
  for (k = 0; k < size; ++k) {
    node = pool[k];
    if (node->getQuality() < bestQuality) {
      bestQuality = node->getQuality();
    }
  }
  return bestQuality;
}
Пример #3
0
bool DcModel::fathomAllNodes() {
  double feasBound = ALPS_OBJ_MAX;
  double relBound = ALPS_OBJ_MAX;
  double gapVal = ALPS_OBJ_MAX;

  AlpsTreeNode *bestNode = NULL;

  // Compute gap
  feasBound = broker_->getIncumbentValue();
  bestNode = broker_->getBestNode();

  if (bestNode) {
    relBound = bestNode->getQuality();
  }

  if (relBound > ALPS_OBJ_MAX_LESS) {
    currAbsGap_ = currRelGap_ = 0.0;
  }
  else if (feasBound < ALPS_OBJ_MAX_LESS) {
    gapVal = ALPS_MAX(0, feasBound - relBound);
    currAbsGap_ = ALPS_MAX(0, gapVal);
    currRelGap_ = 100 * gapVal / (ALPS_FABS(relBound) + 1.0);
  }
#if 0
  printf("+++ Process %d: currAbsGap_ %g, currRelGap_%g\n",
	 broker_->getProcRank(), currAbsGap_,  currRelGap_);
#endif
  if ( (currAbsGap_ <= optimalAbsGap_ + ALPS_ZERO) ||
       (currRelGap_ <= optimalRelGap_ + ALPS_ZERO) ) {
    return true;
  }
  else {
    return false;
  }
}
Пример #4
0
AlpsTreeNode*
AlpsNodeSelectionHybrid::selectNextNode(AlpsSubTree *subTree)
{
    AlpsTreeNode *node = subTree->activeNode();

    /* Check if dive too deep */
    if (node) {
        if (subTree->getDiveDepth() > 30) {
            /* Too deep, put nodes in dive pool to regular pool. */
            //std::cout << "++++ TOO DEEP: depth " << subTree->getDiveDepth() 
            //       << std::endl;
            subTree->reset();
            node = NULL;
        }
    }
    
    if (node) {
        subTree->incDiveDepth();
        node->setDiving(true);
    }
    else {
        subTree->setDiveDepth(0);
	if (subTree->diveNodePool()->getNumKnowledges() > 0) {
	    node = dynamic_cast<AlpsTreeNode*>(subTree->diveNodePool()->getKnowledge().first); 
	    node->setDiving(false);	    
	    subTree->diveNodePool()->popKnowledge();
	}
	else if (subTree->nodePool()->hasKnowledge()) {
	    node = dynamic_cast<AlpsTreeNode*>(subTree->nodePool()->getKnowledge().first); 
	    node->setDiving(false);
	    subTree->nodePool()->popKnowledge();
	}
	else {
	    assert(0);
	}
        
#if 0
        std::cout << "======= NOTE[" << node->getIndex() 
                  << "]: JUMP : depth = " << node->getDepth() 
                  << ", quality = " << node->getQuality()
                  << ", estimate = " << node->getSolEstimate()
                  << std::endl;
#endif
    }
    
    return node;
}
Пример #5
0
//Shouldn't this method be a member of either the broker or subtree classes?
void 
AlpsModel::nodeLog(AlpsTreeNode *node, bool force) 
{
    int nodeInterval = 
	broker_->getModel()->AlpsPar()->entry(AlpsParams::nodeLogInterval);

    int numNodesProcessed = broker_->getNumNodesProcessed();
    int numNodesPartial  = broker_->getNumNodesPartial();

    AlpsTreeNode *bestNode = NULL;
    
    if ( (broker_->getProcType() != AlpsProcessTypeMaster) &&
         (broker_->getProcType() != AlpsProcessTypeSerial) ) {
        return;
    }

    if ( (broker_->getMsgLevel() > 1) && 
         ( force ||
           (numNodesProcessed % nodeInterval == 0) ) ) {
        
        double feasBound = ALPS_OBJ_MAX, relBound = ALPS_OBJ_MAX;

        if (broker_->getNumKnowledges(AlpsKnowledgeTypeSolution) > 0) {
            feasBound = (broker_->getBestKnowledge(AlpsKnowledgeTypeSolution)).second;
        }

        bestNode = broker_->getBestNode();
        
        if (bestNode) {
            relBound = bestNode->getQuality();
        }

	//Take into account pregnant nodes (processed but not branched)
        getKnowledgeBroker()->messageHandler()->
            message(ALPS_S_NODE_COUNT, getKnowledgeBroker()->messages())
            << numNodesProcessed
	    << numNodesPartial
            << broker_->updateNumNodesLeft() - numNodesPartial
            << relBound
            << feasBound
            << CoinMessageEol;
    }
}