本文整理汇总了C++中OsiSolverInterface::isAbandoned方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiSolverInterface::isAbandoned方法的具体用法?C++ OsiSolverInterface::isAbandoned怎么用?C++ OsiSolverInterface::isAbandoned使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiSolverInterface
的用法示例。
在下文中一共展示了OsiSolverInterface::isAbandoned方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CbcSubProblem
//.........这里部分代码省略.........
break;
}
}
}
#ifdef DIVE_DEBUG
std::cout << "numberAtBoundFixed = " << numberAtBoundFixed << std::endl;
#endif
double originalBoundBestColumn;
double bestColumnValue;
int whichWay;
if (bestColumn >= 0) {
bestColumnValue = newSolution[bestColumn];
if (bestRound < 0) {
originalBoundBestColumn = upper[bestColumn];
solver->setColUpper(bestColumn, floor(bestColumnValue));
whichWay=0;
} else {
originalBoundBestColumn = lower[bestColumn];
solver->setColLower(bestColumn, ceil(bestColumnValue));
whichWay=1;
}
} else {
break;
}
int originalBestRound = bestRound;
int saveModelOptions = model_->specialOptions();
while (1) {
model_->setSpecialOptions(saveModelOptions | 2048);
solver->resolve();
model_->setSpecialOptions(saveModelOptions);
if (!solver->isAbandoned()&&!solver->isIterationLimitReached()) {
numberSimplexIterations += solver->getIterationCount();
} else {
numberSimplexIterations = maxSimplexIterations + 1;
reasonToStop += 100;
break;
}
if (!solver->isProvenOptimal()) {
if (nodes) {
if (solver->isProvenPrimalInfeasible()) {
if (maxSimplexIterationsAtRoot_!=COIN_INT_MAX) {
// stop now
printf("stopping on first infeasibility\n");
break;
} else if (cuts) {
// can do conflict cut
printf("could do intermediate conflict cut\n");
bool localCut;
OsiRowCut * cut = model_->conflictCut(solver,localCut);
if (cut) {
if (!localCut) {
model_->makePartialCut(cut,solver);
cuts[numberCuts++]=cut;
} else {
delete cut;
}
}
}
} else {
reasonToStop += 10;
break;
}
示例2: if
/* After a CbcModel::resolve this can return a status
-1 no effect
0 treat as optimal
1 as 0 but do not do any more resolves (i.e. no more cuts)
2 treat as infeasible
*/
int
CbcNlpStrategy::status(CbcModel * model, CbcNodeInfo * parent,int whereFrom)
{
OsiSolverInterface * solver = model->solver();//get solver
int feasible = 1;
bool solved = true;
int returnStatus = -1;
BonCbcPartialNodeInfo * bmNodeInfo = dynamic_cast<BonCbcPartialNodeInfo *>(parent);
if (!bmNodeInfo) return -1;
int seqOfInfeasiblesSize = bmNodeInfo->getSequenceOfInfeasiblesSize();
int seqOfUnsolvedSize = bmNodeInfo->getSequenceOfUnsolvedSize();
if (solver->isAbandoned()) {
solved = false;
seqOfUnsolvedSize++;
;
}
else if (solver->isProvenPrimalInfeasible()) {
feasible = 0;
seqOfInfeasiblesSize++;
}
if ((seqOfUnsolvedSize==0) || (maxFailure_ == 0) &&
(maxInfeasible_== 0) || (seqOfInfeasiblesSize==0))
if (feasible && seqOfInfeasiblesSize > 1) {
(*model->messageHandler())<<"Feasible node while father was infeasible."
<<CoinMessageEol;
}
if (solved && seqOfUnsolvedSize > 1) {
(*model->messageHandler())<<"Solved node while father was unsolved."
<<CoinMessageEol;
}
if (seqOfInfeasiblesSize < maxInfeasible_ &&
solved && !feasible) {
(*model->messageHandler())<<"Branching on infeasible node, sequence of infeasibles size "
<<seqOfInfeasiblesSize<<CoinMessageEol;
// Have to make sure that we will branch
OsiTMINLPInterface * ipopt = dynamic_cast<OsiTMINLPInterface *>(solver);
ipopt->forceBranchable();
//change objective value
returnStatus = 0;
}
if (!solved && parent != NULL &&
seqOfUnsolvedSize <= maxFailure_) {
(*model->messageHandler())<<"Branching on unsolved node, sequence of unsolved size "<<seqOfUnsolvedSize<<CoinMessageEol;
// Have to make sure that we will branch
OsiTMINLPInterface * osiMinlp = dynamic_cast<OsiTMINLPInterface *>(solver);
osiMinlp->forceBranchable(); // feasible=1;
returnStatus = 0;
}
if (solver->isAbandoned() && parent != NULL &&
seqOfUnsolvedSize > maxFailure_) {
hasFailed_ = true;
OsiTMINLPInterface * osiMinlp =
dynamic_cast<OsiTMINLPInterface *>(solver);
if (pretendFailIsInfeasible_) {
//force infeasible
osiMinlp->forceInfeasible();
returnStatus = 2;
}
else {
std::string probName;
osiMinlp->getStrParam(OsiProbName,probName);
throw osiMinlp->newUnsolvedError(0, osiMinlp->problem(), probName);
}
}
return returnStatus;
}
示例3: sci_rmps
//Solver function
int sci_rmps(char *fname)
{
//creating a problem pointer using base class of OsiSolverInterface and
//instantiate the object using derived class of ClpSolverInterface
OsiSolverInterface* si = new OsiClpSolverInterface();
// Error management variable
SciErr sciErr;
//data declarations
int *piAddressVarOne = NULL; //pointer used to access argument of the function
char* ptr; //pointer to point to address of file name
double* options_; //options to set maximum iterations
CheckInputArgument(pvApiCtx, 2,2 ); //Check we have exactly two arguments as input or not
CheckOutputArgument(pvApiCtx, 6, 6); //Check we have exactly six arguments on output side or not
//Getting the input arguments from Scilab
//Getting the MPS file path
//Reading mps file
getStringFromScilab(1,&ptr);
std::cout<<ptr;
//get options from Scilab
if(getFixedSizeDoubleMatrixInList(2 , 2 , 1 , 1 , &options_))
{
return 1;
}
//Read the MPS file
si->readMps(ptr);
//setting options for maximum iterations
si->setIntParam(OsiMaxNumIteration,options_[0]);
//Solve the problem
si->initialSolve();
//Quering about the problem
//get number of variables
double numVars_;
numVars_ = si->getNumCols();
//get number of constraint equations
double numCons_;
numCons_ = si->getNumRows();
//Output the solution to Scilab
//get solution for x
const double* xValue = si->getColSolution();
//get objective value
double objValue = si->getObjValue();
//get Status value
double status;
if(si->isProvenOptimal())
status=0;
else if(si->isProvenPrimalInfeasible())
status=1;
else if(si->isProvenDualInfeasible())
status=2;
else if(si->isIterationLimitReached())
status=3;
else if(si->isAbandoned())
status=4;
else if(si->isPrimalObjectiveLimitReached())
status=5;
else if(si->isDualObjectiveLimitReached())
status=6;
//get number of iterations
double iterations = si->getIterationCount();
//get reduced cost
const double* reducedCost = si->getReducedCost();
//get dual vector
const double* dual = si->getRowPrice();
returnDoubleMatrixToScilab(1 , 1 , numVars_ , xValue);
returnDoubleMatrixToScilab(2 , 1 , 1 , &objValue);
returnDoubleMatrixToScilab(3 , 1 , 1 , &status);
returnDoubleMatrixToScilab(4 , 1 , 1 , &iterations);
returnDoubleMatrixToScilab(5 , 1 , numVars_ , reducedCost);
returnDoubleMatrixToScilab(6 , 1 , numCons_ , dual);
free(xValue);
free(dual);
free(reducedCost);
}