本文整理汇总了C++中OsiSolverInterface::writeMps方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiSolverInterface::writeMps方法的具体用法?C++ OsiSolverInterface::writeMps怎么用?C++ OsiSolverInterface::writeMps使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiSolverInterface
的用法示例。
在下文中一共展示了OsiSolverInterface::writeMps方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: finalModelX
//.........这里部分代码省略.........
for (int j = buildStart[iColumn]; j < buildStart[iColumn+1]; j++) {
int jRow = buildRow[j];
jRow = lookupRow[jRow];
assert (jRow >= 0 && jRow < nRow);
buildRow[j] = jRow;
}
}
finalModel->addCols(nCreate, buildStart, buildRow, buildElement, NULL, NULL, buildObj);
int numberFinal = finalModel->getNumCols();
for (iColumn = numberOther; iColumn < numberFinal; iColumn++) {
if (markKnapsack[iKnapsack] < 0) {
finalModel->setColUpper(iColumn, maxCoefficient);
finalModel->setInteger(iColumn);
} else {
finalModel->setColUpper(iColumn, maxCoefficient + 1.0);
finalModel->setInteger(iColumn);
}
OsiSimpleInteger * sosObject = new OsiSimpleInteger(finalModel, iColumn);
sosObject->setPriority(1000000);
object[nObj++] = sosObject;
buildRow[iColumn-numberOther] = iColumn;
buildElement[iColumn-numberOther] = 1.0;
}
if (markKnapsack[iKnapsack] < 0) {
// convexity row
finalModel->addRow(numberFinal - numberOther, buildRow, buildElement, 1.0, 1.0);
} else {
int iColumn = markKnapsack[iKnapsack];
int n = numberFinal - numberOther;
buildRow[n] = iColumn;
buildElement[n++] = -fabs(coefficient[iKnapsack]);
// convexity row (sort of)
finalModel->addRow(n, buildRow, buildElement, 0.0, 0.0);
OsiSOS * sosObject = new OsiSOS(finalModel, n - 1, buildRow, NULL, 1);
sosObject->setPriority(iKnapsack + SOSPriority);
// Say not integral even if is (switch off heuristics)
sosObject->setIntegerValued(false);
object[nSOS++] = sosObject;
}
numberOther = numberFinal;
}
finalModel->addObjects(nObj, object);
for (iKnapsack = 0; iKnapsack < nObj; iKnapsack++)
delete object[iKnapsack];
delete [] object;
// Can we move any rows to cuts
const int * cutMarker = coinModel.cutMarker();
if (cutMarker && 0) {
printf("AMPL CUTS OFF until global cuts fixed\n");
cutMarker = NULL;
}
if (cutMarker) {
// Row copy
const CoinPackedMatrix * matrixByRow = finalModel->getMatrixByRow();
const double * elementByRow = matrixByRow->getElements();
const int * column = matrixByRow->getIndices();
const CoinBigIndex * rowStart = matrixByRow->getVectorStarts();
const int * rowLength = matrixByRow->getVectorLengths();
const double * rowLower = finalModel->getRowLower();
const double * rowUpper = finalModel->getRowUpper();
int nDelete = 0;
for (iRow = 0; iRow < numberRows; iRow++) {
if (cutMarker[iRow] && lookupRow[iRow] >= 0) {
int jRow = lookupRow[iRow];
whichRow[nDelete++] = jRow;
int start = rowStart[jRow];
stored.addCut(rowLower[jRow], rowUpper[jRow],
rowLength[jRow], column + start, elementByRow + start);
}
}
finalModel->deleteRows(nDelete, whichRow);
}
knapsackStart[numberKnapsack] = finalModel->getNumCols();
delete [] buildObj;
delete [] buildElement;
delete [] buildStart;
delete [] buildRow;
finalModel->writeMps("full");
}
}
}
delete [] whichKnapsack;
delete [] markRow;
delete [] markKnapsack;
delete [] coefficient;
delete [] linear;
delete [] whichRow;
delete [] lookupRow;
delete si;
si = NULL;
if (!badModel && finalModel) {
finalModel->setDblParam(OsiObjOffset, coinModel.objectiveOffset());
return finalModel;
} else {
delete finalModel;
printf("can't make knapsacks - did you set fixedPriority (extra1)\n");
return NULL;
}
}
示例2: CoinPackedMatrix
int
main(void)
{
// Create a problem pointer. We use the base class here.
OsiSolverInterface *si;
// When we instantiate the object, we need a specific derived class.
si = new OSIXXX;
// Build our own instance from scratch
/*
* This section adapted from Matt Galati's example
* on the COIN-OR Tutorial website.
*
* Problem from Bertsimas, Tsitsiklis page 21
*
* optimal solution: x* = (1,1)
*
* minimize -1 x0 - 1 x1
* s.t 1 x0 + 2 x1 <= 3
* 2 x0 + 1 x1 <= 3
* x0 >= 0
* x1 >= 0
*/
int n_cols = 2;
double *objective = new double[n_cols];//the objective coefficients
double *col_lb = new double[n_cols];//the column lower bounds
double *col_ub = new double[n_cols];//the column upper bounds
//Define the objective coefficients.
//minimize -1 x0 - 1 x1
objective[0] = -1.0;
objective[1] = -1.0;
//Define the variable lower/upper bounds.
// x0 >= 0 => 0 <= x0 <= infinity
// x1 >= 0 => 0 <= x1 <= infinity
col_lb[0] = 0.0;
col_lb[1] = 0.0;
col_ub[0] = si->getInfinity();
col_ub[1] = si->getInfinity();
int n_rows = 2;
double *row_lb = new double[n_rows]; //the row lower bounds
double *row_ub = new double[n_rows]; //the row upper bounds
//Define the constraint matrix.
CoinPackedMatrix *matrix = new CoinPackedMatrix(false,0,0);
matrix->setDimensions(0, n_cols);
//1 x0 + 2 x1 <= 3 => -infinity <= 1 x0 + 2 x2 <= 3
CoinPackedVector row1;
row1.insert(0, 1.0);
row1.insert(1, 2.0);
row_lb[0] = -1.0 * si->getInfinity();
row_ub[0] = 3.0;
matrix->appendRow(row1);
//2 x0 + 1 x1 <= 3 => -infinity <= 2 x0 + 1 x1 <= 3
CoinPackedVector row2;
row2.insert(0, 2.0);
row2.insert(1, 1.0);
row_lb[1] = -1.0 * si->getInfinity();
row_ub[1] = 3.0;
matrix->appendRow(row2);
//load the problem to OSI
si->loadProblem(*matrix, col_lb, col_ub, objective, row_lb, row_ub);
//write the MPS file to a file called example.mps
si->writeMps("example");
// Solve the (relaxation of the) problem
si->initialSolve();
// Check the solution
if ( si->isProvenOptimal() ) {
std::cout << "Found optimal solution!" << std::endl;
std::cout << "Objective value is " << si->getObjValue() << std::endl;
int n = si->getNumCols();
const double *solution;
solution = si->getColSolution();
// We could then print the solution or examine it.
} else {
std::cout << "Didn't find optimal solution." << std::endl;
// Could then check other status functions.
}
return 0;
}
示例3: doBaCParam
//.........这里部分代码省略.........
<< std::hex << ippSolver << std::dec ;
if (ippSolver) {
std::cout
<< ", log level " << ippSolver->messageHandler()->logLevel() ;
}
std::cout << "." << std::endl ;
# endif
/*
ippSolver == 0 is success of a sort --- integer preprocess has found the
problem to be infeasible or unbounded. Need to think about how to indicate
status.
*/
if (!ippSolver) {
std::cout
<< "Integer preprocess says infeasible or unbounded" << std::endl ;
delete preIppSolver ;
ctlBlk->setBaBStatus(&babModel, CbcGenCtlBlk::BACwIPP) ;
return (0) ;
}
# if COIN_CBC_VERBOSITY > 0
else {
std::cout
<< "After integer preprocessing, model has "
<< ippSolver->getNumRows()
<< " rows, " << ippSolver->getNumCols() << " columns, and "
<< ippSolver->getNumElements() << " elements." << std::endl ;
}
# endif
preIppSolver->setHintParam(OsiDoInBranchAndCut, false, OsiHintDo) ;
ippSolver->setHintParam(OsiDoInBranchAndCut, false, OsiHintDo) ;
if (ippAction == CbcGenCtlBlk::IPPSave) {
ippSolver->writeMps("presolved", "mps", 1.0) ;
std::cout
<< "Integer preprocessed model written to `presolved.mps' "
<< "as minimisation problem." << std::endl ;
}
OsiSolverInterface *osiTmp = ippSolver->clone() ;
babModel.assignSolver(osiTmp) ;
babSolver = babModel.solver() ;
# if CBC_TRACK_SOLVERS > 0
std::cout
<< "doBaCParam: clone of IPP solver passed to babModel is "
<< std::hex << babSolver << std::dec
<< ", log level " << babSolver->messageHandler()->logLevel()
<< "." << std::endl ;
# endif
if (!solveRelaxation(&babModel)) {
delete preIppSolver ;
ctlBlk->setBaBStatus(&babModel, CbcGenCtlBlk::BACwIPPRelax) ;
return (0) ;
}
# if COIN_CBC_VERBOSITY > 0
std::cout
<< "doBaCParam: presolved relaxation z = "
<< babSolver->getObjValue() << "." << std::endl ;
# endif
babModel.setMaximumSeconds(timeLeft - (CoinCpuTime() - time1)) ;
didIPP = true ;
}
/*
At this point, babModel and babSolver hold the constraint system we'll use
for B&C (either the original system or the preprocessed system) and we have
a solution to the lp relaxation.