本文整理汇总了C++中OsiSolverInterface::getAuxiliaryInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiSolverInterface::getAuxiliaryInfo方法的具体用法?C++ OsiSolverInterface::getAuxiliaryInfo怎么用?C++ OsiSolverInterface::getAuxiliaryInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiSolverInterface
的用法示例。
在下文中一共展示了OsiSolverInterface::getAuxiliaryInfo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: info
int
NlpSolveHeuristic::solution (double & objectiveValue, double * newSolution) {
int noSolution = 1, maxTime = 2;
// do heuristic the usual way, but if for any reason (time is up, no
// better solution found) there is no improvement, get the best
// solution from the GlobalCutOff object in the pointer to the
// CouenneProblem and return it instead.
//
// Although this should be handled by Cbc, very often this doesn't
// happen.
// int nodeDepth = -1;
const int depth = (model_ -> currentNode ()) ? model_ -> currentNode () -> depth () : 0;
if (depth <= 0)
couenne_ -> Jnlst () -> Printf (J_ERROR, J_COUENNE, "NLP Heuristic: "); fflush (stdout);
try {
if (CoinCpuTime () > couenne_ -> getMaxCpuTime ())
throw maxTime;
OsiSolverInterface * solver = model_ -> solver();
OsiAuxInfo * auxInfo = solver->getAuxiliaryInfo();
Bonmin::BabInfo * babInfo = dynamic_cast <Bonmin::BabInfo *> (auxInfo);
if(babInfo){
babInfo->setHasNlpSolution(false);
if(babInfo->infeasibleNode()){
throw noSolution;
}
}
// if too deep in the BB tree, only run NLP heuristic if
// feasibility is low
bool too_deep = false;
// check depth
if (numberSolvePerLevel_ > -1) {
if (numberSolvePerLevel_ == 0)
throw maxTime;
//if (CoinDrand48 () > pow (2., numberSolvePerLevel_ - depth))
if (CoinDrand48 () > 1. / CoinMax
(1., (double) ((depth - numberSolvePerLevel_) *
(depth - numberSolvePerLevel_))))
too_deep = true;
}
if (too_deep)
throw maxTime;
double *lower = new double [couenne_ -> nVars ()];
double *upper = new double [couenne_ -> nVars ()];
CoinFillN (lower, couenne_ -> nVars (), -COUENNE_INFINITY);
CoinFillN (upper, couenne_ -> nVars (), COUENNE_INFINITY);
CoinCopyN (solver->getColLower(), nlp_ -> getNumCols (), lower);
CoinCopyN (solver->getColUpper(), nlp_ -> getNumCols (), upper);
/*printf ("-- int candidate, before: ");
for (int i=0; i<couenne_ -> nOrig (); i++)
printf ("[%g %g] ", lower [i], upper [i]);
printf ("\n");*/
const double * solution = solver->getColSolution();
OsiBranchingInformation info (solver, true);
const int & numberObjects = model_->numberObjects();
OsiObject ** objects = model_->objects();
double maxInfeasibility = 0;
bool haveRoundedIntVars = false;
for (int i = 0 ; i < numberObjects ; i++) {
CouenneObject * couObj = dynamic_cast <CouenneObject *> (objects [i]);
if (couObj) {
if (too_deep) { // only test infeasibility if BB level is high
int dummy;
double infeas;
maxInfeasibility = CoinMax ( maxInfeasibility, infeas = couObj->infeasibility(&info, dummy));
if (maxInfeasibility > maxNlpInf_){
delete [] lower;
delete [] upper;
throw noSolution;
}
}
} else {
OsiSimpleInteger * intObj = dynamic_cast<OsiSimpleInteger *>(objects[i]);
if (intObj) {
//.........这里部分代码省略.........
示例2: CoinError
/** Standard cut generation methods. */
void
OaDecompositionBase::generateCuts(const OsiSolverInterface &si, OsiCuts & cs,
const CglTreeInfo info) {
if (nlp_ == NULL) {
throw CoinError("Error in cut generator for outer approximation no NLP ipopt assigned", "generateCuts", "OaDecompositionBase");
}
// babInfo is used to communicate with the b-and-b solver (Cbc or Bcp).
BabInfo * babInfo = dynamic_cast<BabInfo *> (si.getAuxiliaryInfo());
assert(babInfo);
assert(babInfo->babPtr());
numSols_ = babInfo->babPtr()->model().getSolutionCount ();
CglTreeInfo info_copy = info;
const CbcNode * node = babInfo->babPtr()->model().currentNode();
info_copy.level = (node == NULL) ? 0 : babInfo->babPtr()->model().currentNode()->depth();
if(babInfo->hasSolution()) numSols_ ++;
if (babInfo)
if (!babInfo->mipFeasible())
return;
//Get the continuous solution
const double *colsol = si.getColSolution();
vector<double> savedColLower(nlp_->getNumCols());
CoinCopyN(nlp_->getColLower(), nlp_->getNumCols(), savedColLower());
vector<double> savedColUpper(nlp_->getNumCols());
CoinCopyN(nlp_->getColUpper(), nlp_->getNumCols(), savedColUpper());
OsiBranchingInformation brInfo(nlp_, false);
brInfo.solution_ = colsol;
//Check integer infeasibility
bool isInteger = integerFeasible(*nlp_, brInfo, parameters_.cbcIntegerTolerance_,
objects_, nObjects_);
//Check nodeNumber if it did not change scan savedCuts_ if one is violated force it and exit
int nodeNumber = babInfo->babPtr()->model().getNodeCount();
if(nodeNumber == currentNodeNumber_){
#ifdef OA_DEBUG
printf("OA decomposition recalled from the same node!\n");
#endif
int numCuts = savedCuts_.sizeRowCuts();
for(int i = 0 ; i < numCuts ; i++){
//Check if cuts off solution
if(savedCuts_.rowCut(i).violated(colsol) > 0.){
#ifdef OA_DEBUG
printf("A violated saved cut has been found\n");
#endif
savedCuts_.rowCut(i).setEffectiveness(9.99e99);
cs.insert(savedCuts_.rowCut(i));
savedCuts_.eraseRowCut(i);
return;
i--; numCuts--;
}
}
}
else {
currentNodeNumber_ = nodeNumber;
savedCuts_.dumpCuts();
}
if (!isInteger) {
if (!doLocalSearch(babInfo))//create sub mip solver.
return;
}
//get the current cutoff
double cutoff;
si.getDblParam(OsiDualObjectiveLimit, cutoff);
// Save solvers state if needed
solverManip * lpManip = NULL;
if (lp_ != NULL) {
assert(lp_ == &si);
lpManip = new solverManip(lp_, true, leaveSiUnchanged_, true, true);
}
else {
lpManip = new solverManip(si);
}
lpManip->setObjects(objects_, nObjects_);
double milpBound = performOa(cs, *lpManip, babInfo, cutoff, info_copy);
if(babInfo->hasSolution()){
babInfo->babPtr()->model().setSolutionCount (numSols_ - 1);
}
//Transmit the bound found by the milp
{
if (milpBound>-1e100)
{
// Also store into solver
if (babInfo)
babInfo->setMipBound(milpBound);
}
} //Clean everything :
//.........这里部分代码省略.........
示例3: generateCuts
void CouenneCutGenerator::generateCuts (const OsiSolverInterface &si,
OsiCuts &cs,
const CglTreeInfo info)
#if CGL_VERSION_MAJOR == 0 && CGL_VERSION_MINOR <= 57
const
#endif
{
// check if out of time or if an infeasibility cut (iis of type 0)
// was added as a result of, e.g., pruning on BT. If so, no need to
// run this.
if (isWiped (cs) ||
(CoinCpuTime () > problem_ -> getMaxCpuTime ()))
return;
#ifdef FM_TRACE_OPTSOL
double currCutOff = problem_->getCutOff();
double bestVal = 1e50;
CouenneRecordBestSol *rs = problem_->getRecordBestSol();
if(rs->getHasSol()) {
bestVal = rs->getVal();
}
if(currCutOff > bestVal) {
//problem_ -> setCutOff (bestVal - 1e-6); // FIXME: don't add numerical constants
problem_ -> setCutOff (bestVal);
int indObj = problem_->Obj(0)->Body()->Index();
if (indObj >= 0) {
OsiColCut *objCut = new OsiColCut;
objCut->setUbs(1, &indObj, &bestVal);
cs.insert(objCut);
delete objCut;
}
}
#endif
#ifdef FM_PRINT_INFO
if((BabPtr_ != NULL) && (info.level >= 0) && (info.pass == 0) &&
(BabPtr_->model().getNodeCount() > lastPrintLine)) {
printLineInfo();
lastPrintLine += 1;
}
#endif
const int infeasible = 1;
int nInitCuts = cs.sizeRowCuts ();
CouNumber
*&realOpt = problem_ -> bestSol (),
*saveOptimum = realOpt;
if (!firstcall_ && realOpt) {
// have a debug optimal solution. Check if current bounds
// contain it, otherwise pretend it does not exist
CouNumber *opt = realOpt;
const CouNumber
*sol = si.getColSolution (),
*lb = si.getColLower (),
*ub = si.getColUpper ();
int objind = problem_ -> Obj (0) -> Body () -> Index ();
for (int j=0, i=problem_ -> nVars (); i--; j++, opt++, lb++, ub++)
if ((j != objind) &&
((*opt < *lb - COUENNE_EPS * (1 + CoinMin (fabs (*opt), fabs (*lb)))) ||
(*opt > *ub + COUENNE_EPS * (1 + CoinMin (fabs (*opt), fabs (*ub)))))) {
jnlst_ -> Printf (J_VECTOR, J_CONVEXIFYING,
"out of bounds, ignore x%d = %g [%g,%g] opt = %g\n",
problem_ -> nVars () - i - 1, *sol, *lb, *ub, *opt);
// optimal point is not in current bounding box,
// pretend realOpt is NULL until we return from this procedure
realOpt = NULL;
break;
}
}
/*static int count = 0;
char fname [20];
sprintf (fname, "relax_%d", count++);
si.writeLp (fname);
printf ("writing %s\n", fname);*/
jnlst_ -> Printf (J_DETAILED, J_CONVEXIFYING,
"generateCuts: level = %d, pass = %d, intree = %d\n",
info.level, info.pass, info.inTree);
Bonmin::BabInfo * babInfo = dynamic_cast <Bonmin::BabInfo *> (si.getAuxiliaryInfo ());
if (babInfo)
babInfo -> setFeasibleNode ();
double now = CoinCpuTime ();
//.........这里部分代码省略.........