예제 #1
0
//#############################################################################
void
MibSSolution::print(std::ostream& os) const
{

    double nearInt = 0.0;
    //int size(localModel_->getNumOrigVars());
    int j(0);


    int uN(localModel_->getUpperDim());
    int lN(localModel_->getLowerDim());
    int index(0);
    int * upperColInd = localModel_->getUpperColInd();
    int * lowerColInd = localModel_->getLowerColInd();

    /*
    for(j = 0; j < size; ++j) {
       if (values_[j] > 1.0e-15 || values_[j] < -1.0e-15) {
     nearInt = floor(values_[j] + 0.5);
     if (ALPS_FABS(nearInt - values_[j]) < 1.0e-6) {
        os << "x[" << j << "] = " << nearInt << std::endl;
     }
     else {
        os << "x[" << j << "] = " << values_[j] << std::endl;
     }
       }
    }
    */

    for(j = 0; j < uN; ++j) {
        index = upperColInd[j];
        if (values_[index] > 1.0e-15 || values_[index] < -1.0e-15) {
            nearInt = floor(values_[index] + 0.5);
            if (ALPS_FABS(nearInt - values_[index]) < 1.0e-6) {
                os << "x[" << j << "] = " << nearInt << std::endl;
            }
            else {
                os << "x[" << j << "] = " << values_[index] << std::endl;
            }
        }
    }

    for(j = 0; j < lN; ++j) {
        index = lowerColInd[j];
        if (values_[index] > 1.0e-15 || values_[index] < -1.0e-15) {
            nearInt = floor(values_[index] + 0.5);
            if (ALPS_FABS(nearInt - values_[index]) < 1.0e-6) {
                os << "y[" << j << "] = " << nearInt << std::endl;
            }
            else {
                os << "y[" << j << "] = " << values_[index] << std::endl;
            }
        }
    }


}
예제 #2
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;
  }
}
예제 #3
0
/** Create a set of candidate branching objects. */
int 
MibSBranchStrategyMaxInf::createCandBranchObjects(int numPassesLeft, double ub)
{

    int numInfs = 0;
    
    int i, col, preferDir, maxInfDir, maxScoreDir;
    
    double score, maxScore = 0.0;
    double infeasibility, maxInf = 0.0;
    
    BlisModel *model = dynamic_cast<BlisModel *>(model_);
    
    BlisObjectInt * intObject = 0;
    BlisObjectInt * maxInfIntObject = 0;
    BlisObjectInt * maxScoreIntObject = 0;

    //MibSObjectInt * intObject = 0;
    //MibSObjectInt * maxInfIntObject = 0;
    //MibSObjectInt * maxScoreIntObject = 0;
    
    int numObjects = model->numObjects();
    
    double *objCoef = model->getObjCoef();

    MibSModel *mibsmodel = dynamic_cast<MibSModel *>(model);
    bool bilevelBranch = mibsmodel->bS_->useBilevelBranching_;

    if(bilevelBranch){    
       //create branch based on bilevel infeasibility
       
       std::cout << "Using Bilevel Branching." << std::endl;



    }
    else{
       //use Blis MaxInf branching
       
       for (i = 0; i < numObjects; ++i) {
	  
	  // TODO: currently all integer object.
	  intObject = dynamic_cast<BlisObjectInt *>(model->objects(i));
	  //intObject = dynamic_cast<MibSObjectInt *>(model->objects(i));
	  infeasibility = intObject->infeasibility(model, preferDir);
	  
	  if (infeasibility) {
	     ++numInfs;
	  
	     if (infeasibility > maxInf) {
		maxInfIntObject = intObject;
		maxInfDir = preferDir;
		maxInf = infeasibility;
	     }
	     
	     col = intObject->columnIndex();
	     score = ALPS_FABS(objCoef[col] * infeasibility);
	     
	     if (score > maxScore) {
		maxScoreIntObject = intObject;
		maxScoreDir = preferDir;
		maxScore = score;
	     }
	  }
       }
       
       assert(numInfs > 0);
       
       if (maxScoreIntObject) {
	  maxInfIntObject = maxScoreIntObject;
	  maxInfDir = maxScoreDir;
       }
    }


    numBranchObjects_ = 1;

    //FIXME: THINK I NEED TO DERIVE MY OWN BRANCHING OBJECT CLASS
    branchObjects_ = new BcpsBranchObject* [1];
    branchObjects_[0] = maxInfIntObject->createBranchObject(model,
                                                            maxInfDir);
    
    return 0;
}
/** Create a set of candidate branching objects. */
int 
BlisBranchStrategyMaxInf::createCandBranchObjects(int numPassesLeft,
						  double ub)
{

    int numInfs = 0;
    
    int i, col, preferDir, maxInfDir = 0, maxScoreDir = 0;
    
    double score, maxScore = 0.0;
    double infeasibility, maxInf = 0.0;
    
    BlisModel *model = dynamic_cast<BlisModel *>(model_);
    
    BlisObjectInt * intObject = 0;
    BlisObjectInt * maxInfIntObject = 0;
    BlisObjectInt * maxScoreIntObject = 0;
    
    int numObjects = model->numObjects();
    
    double *objCoef = model->getObjCoef();
    
    for (i = 0; i < numObjects; ++i) {
	
        // TODO: currently all integer object.
        intObject = dynamic_cast<BlisObjectInt *>(model->objects(i));
        infeasibility = intObject->infeasibility(model, preferDir);
        
        if (infeasibility) {
            ++numInfs;
            
            if (infeasibility > maxInf) {
                maxInfIntObject = intObject;
                maxInfDir = preferDir;
                maxInf = infeasibility;
            }
            
            col = intObject->columnIndex();
            score = ALPS_FABS(objCoef[col] * infeasibility);
            
            if (score > maxScore) {
                maxScoreIntObject = intObject;
                maxScoreDir = preferDir;
                maxScore = score;
            }
        }
    }

    assert(numInfs > 0);
    
    if (maxScoreIntObject) {
        maxInfIntObject = maxInfIntObject;
        maxInfDir = maxScoreDir;
    }
    
    numBranchObjects_ = 1;
    branchObjects_ = new BcpsBranchObject* [1];
    branchObjects_[0] = maxInfIntObject->createBranchObject(model,
                                                            maxInfDir);
    
    return 0;
}