本文整理汇总了C++中OsiSolverInterface::addRows方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiSolverInterface::addRows方法的具体用法?C++ OsiSolverInterface::addRows怎么用?C++ OsiSolverInterface::addRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiSolverInterface
的用法示例。
在下文中一共展示了OsiSolverInterface::addRows方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: problem_convert_to_osi
void* problem_convert_to_osi(Problem *p)
{
int i;
double rowLb, rowUb;
OsiSolverInterface *solver = new OsiClpSolverInterface();
CoinBuild cb;
solver->setIntParam(OsiNameDiscipline, 2);
solver->messageHandler()->setLogLevel(0);
solver->setHintParam(OsiDoReducePrint,true,OsiHintTry);
for(i = 0; i < p->numCols; i++)
{
solver->addCol(0, NULL, NULL, p->colLb[i], p->colUb[i], p->objCoef[i]);
solver->setColName(i, p->colName[i]);
if(p->colType[i] == CONTINUOUS)
solver->setContinuous(i);
else
solver->setInteger(i);
}
for(i = 0; i < p->numRows; i++)
{
switch(p->rowSense[i])
{
case 'E':
rowLb = p->rhs[i];
rowUb = p->rhs[i];
break;
case 'L':
rowLb = -p->infty;
rowUb = p->rhs[i];
break;
case 'G':
rowLb = p->rhs[i];
rowUb = p->infty;
break;
default:
fprintf(stderr, "Error: invalid type of constraint!\n");
exit(EXIT_FAILURE);
}
cb.addRow(p->rowNElements[i], p->idxsByRow[i], p->coefsByRow[i], rowLb, rowUb);
}
solver->addRows(cb);
for(i = 0; i < p->numRows; i++)
solver->setRowName(i, p->rowName[i]);
return solver;
}
示例2: main
int main (int argc, const char *argv[])
{
/* Define your favorite OsiSolver.
CbcModel clones the solver so use solver1 up to the time you pass it
to CbcModel then use a pointer to cloned solver (model.solver())
*/
OsiClpSolverInterface solver1;
/* From now on we can build model in a solver independent way.
You can add rows one at a time but for large problems this is slow so
this example uses CoinBuild or CoinModel
*/
OsiSolverInterface * solver = &solver1;
// Data (is exmip1.mps in Mps/Sample
// Objective
double objValue[]={1.0,2.0,0.0,0.0,0.0,0.0,0.0,-1.0};
// Lower bounds for columns
double columnLower[]={2.5,0.0,0.0,0.0,0.5,0.0,0.0,0.0};
// Upper bounds for columns
double columnUpper[]={COIN_DBL_MAX,4.1,1.0,1.0,4.0,
COIN_DBL_MAX,COIN_DBL_MAX,4.3};
// Lower bounds for row activities
double rowLower[]={2.5,-COIN_DBL_MAX,-COIN_DBL_MAX,1.8,3.0};
// Upper bounds for row activities
double rowUpper[]={COIN_DBL_MAX,2.1,4.0,5.0,15.0};
// Matrix stored packed
int column[] = {0,1,3,4,7,
1,2,
2,5,
3,6,
4,7};
double element[] = {3.0,1.0,-2.0,-1.0,-1.0,
2.0,1.1,
1.0,1.0,
2.8,-1.2,
1.0,1.9};
int starts[]={0,5,7,9,11,13};
// Integer variables (note upper bound already 1.0)
int whichInt[]={2,3};
int numberRows=(int) (sizeof(rowLower)/sizeof(double));
int numberColumns=(int) (sizeof(columnLower)/sizeof(double));
#define BUILD 2
#if BUILD==1
// Using CoinBuild
// First do columns (objective and bounds)
int i;
// We are not adding elements
for (i=0;i<numberColumns;i++) {
solver->addCol(0,NULL,NULL,columnLower[i],columnUpper[i],
objValue[i]);
}
// mark as integer
for (i=0;i<(int) (sizeof(whichInt)/sizeof(int));i++)
solver->setInteger(whichInt[i]);
// Now build rows
CoinBuild build;
for (i=0;i<numberRows;i++) {
int startRow = starts[i];
int numberInRow = starts[i+1]-starts[i];
build.addRow(numberInRow,column+startRow,element+startRow,
rowLower[i],rowUpper[i]);
}
// add rows into solver
solver->addRows(build);
#else
/* using CoinModel - more flexible but still beta.
Can do exactly same way but can mix and match much more.
Also all operations are on building object
*/
CoinModel build;
// First do columns (objective and bounds)
int i;
for (i=0;i<numberColumns;i++) {
build.setColumnBounds(i,columnLower[i],columnUpper[i]);
build.setObjective(i,objValue[i]);
}
// mark as integer
for (i=0;i<(int) (sizeof(whichInt)/sizeof(int));i++)
build.setInteger(whichInt[i]);
// Now build rows
for (i=0;i<numberRows;i++) {
int startRow = starts[i];
int numberInRow = starts[i+1]-starts[i];
build.addRow(numberInRow,column+startRow,element+startRow,
rowLower[i],rowUpper[i]);
}
// add rows into solver
solver->loadFromCoinModel(build);
#endif
// Pass to solver
CbcModel model(*solver);
model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
// Set up some cut generators and defaults
// Probing first as gets tight bounds on continuous
//.........这里部分代码省略.........