本文整理汇总了C++中OsiSolverInterface::getIterationCount方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiSolverInterface::getIterationCount方法的具体用法?C++ OsiSolverInterface::getIterationCount怎么用?C++ OsiSolverInterface::getIterationCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiSolverInterface
的用法示例。
在下文中一共展示了OsiSolverInterface::getIterationCount方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fixed
/* This is a utility function which does strong branching on
a list of objects and stores the results in OsiHotInfo.objects.
On entry the object sequence is stored in the OsiHotInfo object
and maybe more.
It returns -
-1 - one branch was infeasible both ways
0 - all inspected - nothing can be fixed
1 - all inspected - some can be fixed (returnCriterion==0)
2 - may be returning early - one can be fixed (last one done) (returnCriterion==1)
3 - returning because max time
*/
int
OsiChooseStrong::doStrongBranching( OsiSolverInterface * solver,
OsiBranchingInformation *info,
int numberToDo, int returnCriterion)
{
// Might be faster to extend branch() to return bounds changed
double * saveLower = NULL;
double * saveUpper = NULL;
int numberColumns = solver->getNumCols();
solver->markHotStart();
const double * lower = info->lower_;
const double * upper = info->upper_;
saveLower = CoinCopyOfArray(info->lower_,numberColumns);
saveUpper = CoinCopyOfArray(info->upper_,numberColumns);
numResults_=0;
int returnCode=0;
double timeStart = CoinCpuTime();
for (int iDo=0;iDo<numberToDo;iDo++) {
OsiHotInfo * result = results_ + iDo;
// For now just 2 way
OsiBranchingObject * branch = result->branchingObject();
assert (branch->numberBranches()==2);
/*
Try the first direction. Each subsequent call to branch() performs the
specified branch and advances the branch object state to the next branch
alternative.)
*/
OsiSolverInterface * thisSolver = solver;
if (branch->boundBranch()) {
// ordinary
branch->branch(solver);
// maybe we should check bounds for stupidities here?
solver->solveFromHotStart() ;
} else {
// adding cuts or something
thisSolver = solver->clone();
branch->branch(thisSolver);
// set hot start iterations
int limit;
thisSolver->getIntParam(OsiMaxNumIterationHotStart,limit);
thisSolver->setIntParam(OsiMaxNumIteration,limit);
thisSolver->resolve();
}
// can check if we got solution
// status is 0 finished, 1 infeasible and 2 unfinished and 3 is solution
int status0 = result->updateInformation(thisSolver,info,this);
numberStrongIterations_ += thisSolver->getIterationCount();
if (status0==3) {
// new solution already saved
if (trustStrongForSolution_) {
info->cutoff_ = goodObjectiveValue_;
status0=0;
}
}
if (solver!=thisSolver)
delete thisSolver;
// Restore bounds
for (int j=0;j<numberColumns;j++) {
if (saveLower[j] != lower[j])
solver->setColLower(j,saveLower[j]);
if (saveUpper[j] != upper[j])
solver->setColUpper(j,saveUpper[j]);
}
/*
Try the next direction
*/
thisSolver = solver;
if (branch->boundBranch()) {
// ordinary
branch->branch(solver);
// maybe we should check bounds for stupidities here?
solver->solveFromHotStart() ;
} else {
// adding cuts or something
thisSolver = solver->clone();
branch->branch(thisSolver);
// set hot start iterations
int limit;
thisSolver->getIntParam(OsiMaxNumIterationHotStart,limit);
thisSolver->setIntParam(OsiMaxNumIteration,limit);
thisSolver->resolve();
}
// can check if we got solution
// status is 0 finished, 1 infeasible and 2 unfinished and 3 is solution
int status1 = result->updateInformation(thisSolver,info,this);
numberStrongDone_++;
numberStrongIterations_ += thisSolver->getIterationCount();
if (status1==3) {
//.........这里部分代码省略.........
示例2: CbcSubProblem
//.........这里部分代码省略.........
}
}
}
#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;
}
}
示例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);
}