本文整理汇总了C++中OsiSolverInterface::getRowSense方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiSolverInterface::getRowSense方法的具体用法?C++ OsiSolverInterface::getRowSense怎么用?C++ OsiSolverInterface::getRowSense使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiSolverInterface
的用法示例。
在下文中一共展示了OsiSolverInterface::getRowSense方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generateCuts
//-----------------------------------------------------------------------------
// Generate LSGFC cuts
//-------------------------------------------------------------------
void CglFlowCover::generateCuts(const OsiSolverInterface & si, OsiCuts & cs,
const CglTreeInfo info) const
{
static int count=0;
if (getMaxNumCuts() <= 0) return;
if (getNumFlowCuts() >= getMaxNumCuts()) return;
++count;
#if 0
bool preInit = false;
bool preReso = false;
si.getHintParam(OsiDoPresolveInInitial, preInit);
si.getHintParam(OsiDoPresolveInResolve, preReso);
if (preInit == false && preReso == false) { // Do once
if (doneInitPre_ == false) {
flowPreprocess(si);
doneInitPre_ = true;
}
}
else
#endif
int numberRowCutsBefore = cs.sizeRowCuts();
flowPreprocess(si);
CoinPackedMatrix matrixByRow(*si.getMatrixByRow());
const char* sense = si.getRowSense();
const double* rhs = si.getRightHandSide();
const double* elementByRow = matrixByRow.getElements();
const int* colInd = matrixByRow.getIndices();
const CoinBigIndex* rowStart = matrixByRow.getVectorStarts();
const int* rowLength = matrixByRow.getVectorLengths();
int* ind = 0;
double* coef = 0;
int iRow, iCol;
CglFlowRowType rType;
for (iRow = 0; iRow < numRows_; ++iRow) {
rType = getRowType(iRow);
if( ( rType != CGLFLOW_ROW_MIXUB ) &&
( rType != CGLFLOW_ROW_MIXEQ ) &&
( rType != CGLFLOW_ROW_NOBINUB ) &&
( rType != CGLFLOW_ROW_NOBINEQ ) &&
( rType != CGLFLOW_ROW_SUMVARUB ) &&
( rType != CGLFLOW_ROW_SUMVAREQ ) )
continue;
const int sta = rowStart[iRow]; // Start position of iRow
const int rowLen = rowLength[iRow]; // iRow length / non-zero elements
if (ind != 0) { delete [] ind; ind = 0; }
ind = new int [rowLen];
if (coef != 0) { delete [] coef; coef = 0; }
coef = new double [rowLen];
int lastPos = sta + rowLen;
for (iCol = sta; iCol < lastPos; ++iCol) {
ind[iCol - sta] = colInd[iCol];
coef[iCol - sta] = elementByRow[iCol];
}
OsiRowCut flowCut1, flowCut2, flowCut3;
double violation = 0.0;
bool hasCut = false;
if (sense[iRow] == 'E') {
hasCut = generateOneFlowCut(si, rowLen, ind, coef, 'L',
rhs[iRow], flowCut1, violation);
if (hasCut) { // If find a cut
cs.insert(flowCut1);
incNumFlowCuts();
if (getNumFlowCuts() >= getMaxNumCuts())
break;
}
hasCut = false;
hasCut = generateOneFlowCut(si, rowLen, ind, coef, 'G',
rhs[iRow], flowCut2, violation);
if (hasCut) {
cs.insert(flowCut2);
incNumFlowCuts();
if (getNumFlowCuts() >= getMaxNumCuts())
break;
}
}
if (sense[iRow] == 'L' || sense[iRow] == 'G') {
hasCut = generateOneFlowCut(si, rowLen, ind, coef, sense[iRow],
rhs[iRow], flowCut3, violation);
if (hasCut) {
cs.insert(flowCut3);
incNumFlowCuts();
if (getNumFlowCuts() >= getMaxNumCuts())
break;
//.........这里部分代码省略.........
示例2: matrixByRow
//-------------------------------------------------------------------
// Determine row types. Find the VUBS and VLBS.
//-------------------------------------------------------------------
void
CglFlowCover::flowPreprocess(const OsiSolverInterface& si) const
{
CoinPackedMatrix matrixByRow(*si.getMatrixByRow());
int numRows = si.getNumRows();
int numCols = si.getNumCols();
const char* sense = si.getRowSense();
const double* RHS = si.getRightHandSide();
const double* coefByRow = matrixByRow.getElements();
const int* colInds = matrixByRow.getIndices();
const int* rowStarts = matrixByRow.getVectorStarts();
const int* rowLengths = matrixByRow.getVectorLengths();
int iRow = -1;
int iCol = -1;
numCols_ = numCols; // Record col and row numbers for copy constructor
numRows_ = numRows;
if (rowTypes_ != 0) {
delete [] rowTypes_; rowTypes_ = 0;
}
rowTypes_ = new CglFlowRowType [numRows];// Destructor will free memory
// Get integer types
const char * columnType = si.getColType (true);
// Summarize the row type infomation.
int numUNDEFINED = 0;
int numVARUB = 0;
int numVARLB = 0;
int numVAREQ = 0;
int numMIXUB = 0;
int numMIXEQ = 0;
int numNOBINUB = 0;
int numNOBINEQ = 0;
int numSUMVARUB = 0;
int numSUMVAREQ = 0;
int numUNINTERSTED = 0;
int* ind = new int [numCols];
double* coef = new double [numCols];
for (iRow = 0; iRow < numRows; ++iRow) {
int rowLen = rowLengths[iRow];
char sen = sense[iRow];
double rhs = RHS[iRow];
CoinDisjointCopyN(colInds + rowStarts[iRow], rowLen, ind);
CoinDisjointCopyN(coefByRow + rowStarts[iRow], rowLen, coef);
CglFlowRowType rowType = determineOneRowType(si, rowLen, ind, coef,
sen, rhs);
rowTypes_[iRow] = rowType;
switch(rowType) {
case CGLFLOW_ROW_UNDEFINED:
++numUNDEFINED;
break;
case CGLFLOW_ROW_VARUB:
++numVARUB;
break;
case CGLFLOW_ROW_VARLB:
++numVARLB;
break;
case CGLFLOW_ROW_VAREQ:
++numVAREQ;
break;
case CGLFLOW_ROW_MIXUB:
++numMIXUB;
break;
case CGLFLOW_ROW_MIXEQ:
++numMIXEQ;
break;
case CGLFLOW_ROW_NOBINUB:
++numNOBINUB;
break;
case CGLFLOW_ROW_NOBINEQ:
++numNOBINEQ;
break;
case CGLFLOW_ROW_SUMVARUB:
++numSUMVARUB;
break;
case CGLFLOW_ROW_SUMVAREQ:
++numSUMVAREQ;
break;
case CGLFLOW_ROW_UNINTERSTED:
++numUNINTERSTED;
break;
default:
throw CoinError("Unknown row type", "flowPreprocess",
"CglFlowCover");
}
}
delete [] ind; ind = NULL;
//.........这里部分代码省略.........
示例3: eq
//.........这里部分代码省略.........
OsiSolverInterface * siP = baseSiP->clone();
std::string fn(mpsDir+"tp3");
siP->readMps(fn.c_str(),"mps");
// All integer variables should be binary.
// Assert that this is true.
for ( i = 0; i < siP->getNumCols(); i++ )
if ( siP->isInteger(i) )
assert(siP->getColUpper()[i]==1.0 && siP->isBinary(i));
OsiCuts cs;
CoinPackedVector krow;
double b=0;
int nCols=siP->getNumCols();
int * complement=new int [nCols];
double * xstar=new double [nCols];
CglKnapsackCover kccg;
// solve LP relaxation
// a "must" before calling initialization
siP->initialSolve();
double lpRelaxBefore=siP->getObjValue();
std::cout<<"Initial LP value: "<<lpRelaxBefore<<std::endl;
assert( eq(siP->getObjValue(), 97.185) );
double mycs[] = {.627, .667558333333, .038};
siP->setColSolution(mycs);
const double *colsol = siP->getColSolution();
int k;
for (k=0; k<nCols; k++){
xstar[k]=colsol[k];
complement[k]=0;
}
// test deriveAKnapsack
int rind = ( siP->getRowSense()[0] == 'N' ) ? 1 : 0;
const CoinShallowPackedVector reqdBySunCC = siP->getMatrixByRow()->getVector(rind) ;
int deriveaknap = kccg.deriveAKnapsack(*siP, cs, krow,b,complement,xstar,rind,reqdBySunCC);
assert(deriveaknap ==1);
assert(complement[0]==0);
assert(complement[1]==1);
assert(complement[2]==1);
int inx[3] = {0,1,2};
double el[3] = {161, 120, 68};
CoinPackedVector r;
r.setVector(3,inx,el);
assert (krow == r);
//assert (b == 183.0); ????? but x1 and x2 at 1 is valid
// test findGreedyCover
CoinPackedVector cover,remainder;
#if 0
int findgreedy = kccg.findGreedyCover( 0, krow, b, xstar, cover, remainder );
assert( findgreedy == 1 );
int coveri = cover.getNumElements();
assert( cover.getNumElements() == 2);
coveri = cover.getIndices()[0];
assert( cover.getIndices()[0] == 0);
assert( cover.getIndices()[1] == 1);
assert( cover.getElements()[0] == 161.0);
assert( cover.getElements()[1] == 120.0);
assert( remainder.getNumElements() == 1);
assert( remainder.getIndices()[0] == 2);
assert( remainder.getElements()[0] == 68.0);
// test liftCoverCut
CoinPackedVector cut;
double * rowupper = ekk_rowupper(model);