本文整理汇总了C++中OsiSolverInterface::getColType方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiSolverInterface::getColType方法的具体用法?C++ OsiSolverInterface::getColType怎么用?C++ OsiSolverInterface::getColType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiSolverInterface
的用法示例。
在下文中一共展示了OsiSolverInterface::getColType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getVubs
//-------------------------------------------------------------------
// Given the model data, a row of the model, and a LP solution,
// this function tries to generate a violated lifted simple generalized
// flow cover.
//-------------------------------------------------------------------
bool
CglFlowCover::generateOneFlowCut( const OsiSolverInterface & si,
const int rowLen,
int* ind,
double* coef,
char sense,
double rhs,
OsiRowCut& flowCut,
double& violation ) const
{
bool generated = false;
const double* xlp = si.getColSolution();
const int numCols = si.getNumCols();
double* up = new double [rowLen];
double* x = new double [rowLen];
double* y = new double [rowLen];
CglFlowColType* sign = new CglFlowColType [rowLen];
int i, j;
double value, LB, UB;
CglFlowVLB VLB;
CglFlowVUB VUB;
static int count=0;
++count;
CGLFLOW_DEBUG=false;
doLift=true;
// Get integer types
const char * columnType = si.getColType ();
for (i = 0; i < rowLen; ++i) {
if ( xlp[ind[i]] - floor(xlp[ind[i]]) > EPSILON_ && ceil(xlp[ind[i]]) - xlp[ind[i]] > EPSILON_ )
break;
}
if (i == rowLen) {
delete [] sign;
delete [] up;
delete [] x;
delete [] y;
return generated;
}
//-------------------------------------------------------------------------
if (sense == 'G') flipRow(rowLen, coef, rhs); // flips everything,
// but the sense
if(CGLFLOW_DEBUG) {
std::cout << "***************************" << std::endl;
std::cout << "Generate Flow cover -- initial constraint, converted to L sense..." << std::endl;
std::cout << "Rhs = " << rhs << std::endl;
std::cout << "coef [var_index]" << " -- " << "xlp[var_index]" << '\t' << "vub_coef[vub_index] vub_lp_value OR var_index_col_ub" << std::endl;
for(int iD = 0; iD < rowLen; ++iD) {
VUB = getVubs(ind[iD]);
std::cout << std::setw(5) << coef[iD] << "[" << std::setw(5) << ind[iD] << "] -- "
<< std::setw(20) << xlp[ind[iD]] << '\t';
if (VUB.getVar() != UNDEFINED_) {
std::cout << std::setw(20) << VUB.getVal() << "[" << std::setw(5) << VUB.getVar() << "]"
<< std::setw(20) << xlp[VUB.getVar()] << std::endl;
}
else
std::cout << std::setw(20) << si.getColUpper()[ind[iD]] << " " << std::setw(20) << 1.0 << std::endl;
}
}
//-------------------------------------------------------------------------
// Generate conservation inequality and capacity equalities from
// the given row.
for (i = 0; i < rowLen; ++i) {
VLB = getVlbs(ind[i]);
LB = ( VLB.getVar() != UNDEFINED_ ) ?
VLB.getVal() : si.getColLower()[ind[i]];
VUB = getVubs(ind[i]);
UB = ( VUB.getVar() != UNDEFINED_ ) ?
VUB.getVal() : si.getColUpper()[ind[i]];
if (LB < -EPSILON_) { // Only consider rows whose variables are all
delete [] sign; // non-negative (LB>= 0).
delete [] up;
delete [] x;
delete [] y;
return generated;
}
if ( columnType[ind[i]]==1 ) { // Binary variable
value = coef[i];
if (value > EPSILON_)
//.........这里部分代码省略.........
示例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: flipRow
//-------------------------------------------------------------------
// Determine the type of a given row
//-------------------------------------------------------------------
CglFlowRowType
CglFlowCover::determineOneRowType(const OsiSolverInterface& si,
int rowLen, int* ind,
double* coef, char sense,
double rhs) const
{
if (rowLen == 0)
return CGLFLOW_ROW_UNDEFINED;
CglFlowRowType rowType = CGLFLOW_ROW_UNDEFINED;
// Get integer types
const char * columnType = si.getColType ();
int numPosBin = 0; // num of positive binary variables
int numNegBin = 0; // num of negative binary variables
int numBin = 0; // num of binary variables
int numPosCol = 0; // num of positive variables
int numNegCol = 0; // num of negative variables
int i;
bool flipped = false;
// Range row will only consider as 'L'
if (sense == 'G') { // Transform to " <= "
flipRow(rowLen, coef, sense, rhs);
flipped = true;
}
// Summarize the variable types of the given row.
for ( i = 0; i < rowLen; ++i ) {
if ( coef[i] < -EPSILON_ ) {
++numNegCol;
if( columnType[ind[i]]==1 )
++numNegBin;
}
else {
++numPosCol;
if( columnType[ind[i]]==1 )
++numPosBin;
}
}
numBin = numNegBin + numPosBin;
if(CGLFLOW_DEBUG) {
std::cout << "numNegBin = " << numNegBin << std::endl;
std::cout << "numPosBin = " << numPosBin << std::endl;
std::cout << "numBin = " << numBin << std::endl;
std::cout << "rowLen = " << rowLen << std::endl;
}
//------------------------------------------------------------------------
// Classify row type based on the types of variables.
// All variables are binary. NOT interested in this type of row right now
if (numBin == rowLen)
rowType = CGLFLOW_ROW_UNINTERSTED;
// All variables are NOT binary
if (rowType == CGLFLOW_ROW_UNDEFINED && numBin == 0) {
if (sense == 'L')
rowType = CGLFLOW_ROW_NOBINUB;
else
rowType = CGLFLOW_ROW_NOBINEQ;
}
// There are binary and other types of variables
if (rowType == CGLFLOW_ROW_UNDEFINED) {
if ((rhs < -EPSILON_) || (rhs > EPSILON_) || (numBin != 1)) {
if (sense == 'L')
rowType = CGLFLOW_ROW_MIXUB;
else
rowType = CGLFLOW_ROW_MIXEQ;
}
else { // EXACTLY one binary
if (rowLen == 2) { // One binary and one other type
if (sense == 'L') {
if (numNegCol == 1 && numNegBin == 1)
rowType = CGLFLOW_ROW_VARUB;
if (numPosCol == 1 && numPosBin == 1)
rowType = CGLFLOW_ROW_VARLB;
}
else
rowType = CGLFLOW_ROW_VAREQ;
}
else { // One binary and 2 or more other types
if (numNegCol==1 && numNegBin==1) {// Binary has neg coef and
if (sense == 'L') // other are positive
rowType = CGLFLOW_ROW_SUMVARUB;
else
rowType = CGLFLOW_ROW_SUMVAREQ;
}
}
}
}
// Still undefined
if (rowType == CGLFLOW_ROW_UNDEFINED) {
//.........这里部分代码省略.........