本文整理汇总了C++中OsiSolverInterface::isContinuous方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiSolverInterface::isContinuous方法的具体用法?C++ OsiSolverInterface::isContinuous怎么用?C++ OsiSolverInterface::isContinuous使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiSolverInterface
的用法示例。
在下文中一共展示了OsiSolverInterface::isContinuous方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NoBasisError
void
CglLandP::CachedData::getData(const OsiSolverInterface &si)
{
int nBasics = si.getNumRows();
int nNonBasics = si.getNumCols();
if (basis_ != NULL)
delete basis_;
basis_ = dynamic_cast<CoinWarmStartBasis *> (si.getWarmStart());
if (!basis_)
throw NoBasisError();
if (nBasics_ > 0 || nBasics != nBasics_)
{
delete [] basics_;
basics_ = NULL;
}
if (basics_ == NULL)
{
basics_ = new int[nBasics];
nBasics_ = nBasics;
}
if (nNonBasics_ > 0 || nNonBasics != nNonBasics_)
{
delete [] nonBasics_;
nonBasics_ = NULL;
}
if (nonBasics_ == NULL)
{
nonBasics_ = new int[nNonBasics];
nNonBasics_ = nNonBasics;
}
int n = nBasics + nNonBasics;
if ( nBasics_ + nNonBasics_ > 0 || nBasics_ + nNonBasics_ != n)
{
delete [] colsol_;
delete [] integers_;
integers_ = NULL;
colsol_ = NULL;
slacks_ = NULL;
}
if (colsol_ == NULL)
{
colsol_ = new double[n];
slacks_ = &colsol_[nNonBasics];
}
if (integers_ == NULL)
{
integers_ = new bool[n];
}
const double * rowLower = si.getRowLower();
const double * rowUpper = si.getRowUpper();
//determine which slacks are integer
const CoinPackedMatrix * m = si.getMatrixByCol();
const double * elems = m->getElements();
const int * inds = m->getIndices();
const CoinBigIndex * starts = m->getVectorStarts();
const int * lengths = m->getVectorLengths();
// int numElems = m->getNumElements();
int numCols = m->getNumCols();
assert(numCols == nNonBasics_);
// int numRows = m->getNumRows();
CoinFillN(integers_ ,n, true);
for (int i = 0 ; i < numCols ; i++)
{
if (si.isContinuous(i))
integers_[i] = false;
}
bool * integerSlacks = integers_ + numCols;
for (int i = 0 ; i < nBasics ; i++)
{
if (rowLower[i] > -1e50 && INT_INFEAS(rowLower[i]) > 1e-15)
integerSlacks[i] = false;
if (rowUpper[i] < 1e50 && INT_INFEAS(rowUpper[i]) > 1e-15)
integerSlacks[i] = false;
}
for (int i = 0 ; i < numCols ; i++)
{
CoinBigIndex end = starts[i] + lengths[i];
if (integers_[i])
{
for (CoinBigIndex k=starts[i] ; k < end; k++)
{
if (integerSlacks[inds[k]] && INT_INFEAS(elems[k])>1e-15 )
integerSlacks[inds[k]] = false;
}
}
else
{
for (CoinBigIndex k=starts[i] ; k < end; k++)
{
if (integerSlacks[inds[k]])
integerSlacks[inds[k]] = false;
}
}
}
CoinCopyN(si.getColSolution(), si.getNumCols(), colsol_);
//.........这里部分代码省略.........
示例2: eq
//--------------------------------------------------------------------------
// test EKKsolution methods.
void
CglOddHoleUnitTest(
const OsiSolverInterface * baseSiP,
const std::string mpsDir )
{
CoinRelFltEq eq(0.000001);
// Test default constructor
{
CglOddHole aGenerator;
}
// Test copy & assignment
{
CglOddHole rhs;
{
CglOddHole bGenerator;
CglOddHole cGenerator(bGenerator);
rhs=bGenerator;
}
}
// test on simple case
{
const int nRows=3;
const int nCols=3;
const int nEls=6;
const double elem[]={1.0,1.0,1.0,1.0,1.0,1.0};
const int row[]={0,1,0,2,1,2};
const CoinBigIndex start[]={0,2,4};
const int len[]={2,2,2};
CoinPackedMatrix matrix(true,nRows,nCols,nEls,elem,row,start,len);
const double sol[]={0.5,0.5,0.5};
const double dj[]={0,0,0};
const int which[]={1,1,1};
const int fixed[]={0,0,0};
OsiCuts cs;
CglOddHole test1;
CglTreeInfo info;
info.randomNumberGenerator=NULL;
test1.generateCuts(NULL,matrix,sol,dj,cs,which,fixed,info,true);
CoinPackedVector check;
int index[] = {0,1,2};
double el[] = {1,1,1};
check.setVector(3,index,el);
//assert (cs.sizeRowCuts()==2);
assert (cs.sizeRowCuts()==1);
// sort Elements in increasing order
CoinPackedVector rpv=cs.rowCut(0).row();
rpv.sortIncrIndex();
assert (check==rpv);
}
// Testcase /u/rlh/osl2/mps/scOneInt.mps
// Model has 3 continous, 2 binary, and 1 general
// integer variable.
{
OsiSolverInterface * siP = baseSiP->clone();
std::string fn = mpsDir+"scOneInt";
siP->readMps(fn.c_str(),"mps");
#if 0
CglOddHole cg;
int nCols=siP->getNumCols();
// Test the siP methods for detecting
// variable type
int numCont=0, numBinary=0, numIntNonBinary=0, numInt=0;
for (int thisCol=0; thisCol<nCols; thisCol++) {
if ( siP->isContinuous(thisCol) ) numCont++;
if ( siP->isBinary(thisCol) ) numBinary++;
if ( siP->isIntegerNonBinary(thisCol) ) numIntNonBinary++;
if ( siP->isInteger(thisCol) ) numInt++;
}
assert(numCont==3);
assert(numBinary==2);
assert(numIntNonBinary==1);
assert(numInt==3);
// Test initializeCutGenerator
siP->initialSolve();
assert(xstar !=NULL);
for (i=0; i<nCols; i++){
assert(complement[i]==0);
}
int nRows=siP->getNumRows();
for (i=0; i<nRows; i++){
int vectorsize = siP->getMatrixByRow()->getVectorSize(i);
assert(vectorsize==2);
}
kccg.cleanUpCutGenerator(complement,xstar);
#endif
delete siP;
}
//.........这里部分代码省略.........