本文整理汇总了C++中OsiSolverInterface::getNumCols方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiSolverInterface::getNumCols方法的具体用法?C++ OsiSolverInterface::getNumCols怎么用?C++ OsiSolverInterface::getNumCols使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiSolverInterface
的用法示例。
在下文中一共展示了OsiSolverInterface::getNumCols方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createResult
// Create result
void OsiSolverResult::createResult(const OsiSolverInterface &solver, const double *lowerBefore,
const double *upperBefore)
{
delete[] primalSolution_;
delete[] dualSolution_;
if (solver.isProvenOptimal() && !solver.isDualObjectiveLimitReached()) {
objectiveValue_ = solver.getObjValue() * solver.getObjSense();
CoinWarmStartBasis *basis = dynamic_cast< CoinWarmStartBasis * >(solver.getWarmStart());
assert(basis);
basis_ = *basis;
int numberRows = basis_.getNumArtificial();
int numberColumns = basis_.getNumStructural();
assert(numberColumns == solver.getNumCols());
assert(numberRows == solver.getNumRows());
primalSolution_ = CoinCopyOfArray(solver.getColSolution(), numberColumns);
dualSolution_ = CoinCopyOfArray(solver.getRowPrice(), numberRows);
fixed_.addBranch(-1, numberColumns, lowerBefore, solver.getColLower(),
upperBefore, solver.getColUpper());
} else {
// infeasible
objectiveValue_ = COIN_DBL_MAX;
basis_ = CoinWarmStartBasis();
;
primalSolution_ = NULL;
dualSolution_ = NULL;
}
}
示例2:
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 OsiClpSolverInterface;
// Read in an mps file. This one's from the MIPLIB library.
si->readMps("../../Data/Sample/p0033");
// 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:
/*===========================================================================*
Scan through the variables and select those that are binary and are at a
fractional level.
*===========================================================================*/
void
CglClique::selectFractionalBinaries(const OsiSolverInterface& si)
{
// extract the primal tolerance from the solver
double lclPetol = 0.0;
si.getDblParam(OsiPrimalTolerance, lclPetol);
const int numcols = si.getNumCols();
if (petol<0.0) {
// do all if not too many
int n=0;
for (int i = 0; i < numcols; ++i) {
if (si.isBinary(i))
n++;
}
if (n<5000)
lclPetol=-1.0e-5;
}
const double* x = si.getColSolution();
std::vector<int> fracind;
int i;
for (i = 0; i < numcols; ++i) {
if (si.isBinary(i) && x[i] > lclPetol && x[i] < 1-petol)
fracind.push_back(i);
}
sp_numcols = static_cast<int>(fracind.size());
sp_orig_col_ind = new int[sp_numcols];
sp_colsol = new double[sp_numcols];
for (i = 0; i < sp_numcols; ++i) {
sp_orig_col_ind[i] = fracind[i];
sp_colsol[i] = x[fracind[i]];
}
}
示例4: CoinMax
//-------------------------------------------------------------------
// Generate Stored cuts
//-------------------------------------------------------------------
void
CglStoredUser::generateCuts(const OsiSolverInterface & si, OsiCuts & cs,
const CglTreeInfo info) const
{
// Get basic problem information
const double * solution = si.getColSolution();
if (info.inTree&&info.pass>numberPasses_) {
// only continue if integer feasible
int numberColumns=si.getNumCols();
int i;
const double * colUpper = si.getColUpper();
const double * colLower = si.getColLower();
int numberAway=0;
for (i=0;i<numberColumns;i++) {
double value = solution[i];
// In case slightly away from bounds
value = CoinMax(colLower[i],value);
value = CoinMin(colUpper[i],value);
if (si.isInteger(i)&&fabs(value-fabs(value+0.5))>1.0e-5)
numberAway++;
}
if (numberAway)
return; // let code branch
}
int numberRowCuts = cuts_.sizeRowCuts();
for (int i=0;i<numberRowCuts;i++) {
const OsiRowCut * rowCutPointer = cuts_.rowCutPtr(i);
double violation = rowCutPointer->violated(solution);
if (violation>=requiredViolation_)
cs.insert(*rowCutPointer);
}
}
示例5: consistent
bool OsiRowCut::consistent(const OsiSolverInterface& im) const
{
const CoinPackedVector& r = row();
if ( r.getMaxIndex() >= im.getNumCols() ) return false;
return true;
}
示例6: applyBounds
// Apply bounds
void OsiSolverBranch::applyBounds(OsiSolverInterface &solver, int way) const
{
int base = way + 1;
assert(way == -1 || way == 1);
int numberColumns = solver.getNumCols();
const double *columnLower = solver.getColLower();
int i;
for (i = start_[base]; i < start_[base + 1]; i++) {
int iColumn = indices_[i];
if (iColumn < numberColumns) {
double value = CoinMax(bound_[i], columnLower[iColumn]);
solver.setColLower(iColumn, value);
} else {
int iRow = iColumn - numberColumns;
const double *rowLower = solver.getRowLower();
double value = CoinMax(bound_[i], rowLower[iRow]);
solver.setRowLower(iRow, value);
}
}
const double *columnUpper = solver.getColUpper();
for (i = start_[base + 1]; i < start_[base + 2]; i++) {
int iColumn = indices_[i];
if (iColumn < numberColumns) {
double value = CoinMin(bound_[i], columnUpper[iColumn]);
solver.setColUpper(iColumn, value);
} else {
int iRow = iColumn - numberColumns;
const double *rowUpper = solver.getRowUpper();
double value = CoinMin(bound_[i], rowUpper[iRow]);
solver.setRowUpper(iRow, value);
}
}
}
示例7: printf
/*
* Class: thebeast_osi_OsiSolverJNI
* Method: initialSolve
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_thebeast_osi_OsiSolverJNI_initialSolve
(JNIEnv *, jobject, jint ptr){
OsiSolverInterface* solver = (OsiSolverInterface*) ptr;
printf("pointer %d\n", solver);
printf("cols %d\n", solver->getNumCols());
//pointer->initialSolve();
//((OsiSolverInterface*)ptr)->initialSolve();
}
示例8: SmpsIO
void SmpsIO(const char * const name )
{
SmiScnModel smi;
// read SMPS model from files
// <name>.core, <name>.time, and <name>.stoch
smi.readSmps(name);
// generate OSI solver object
// here we use OsiClp
OsiClpSolverInterface *clp = new OsiClpSolverInterface();
// set solver object for SmiScnModel
smi.setOsiSolverHandle(*clp);
// load solver data
// this step generates the deterministic equivalent
// and returns an OsiSolver object
OsiSolverInterface *osiStoch = smi.loadOsiSolverData();
// set some nice Hints to the OSI solver
osiStoch->setHintParam(OsiDoPresolveInInitial,true);
osiStoch->setHintParam(OsiDoScale,true);
osiStoch->setHintParam(OsiDoCrash,true);
// solve
osiStoch->initialSolve();
// print results
printf("Solved stochastic program %s\n", name);
printf("Number of rows: %d\n",osiStoch->getNumRows());
printf("Number of cols: %d\n",osiStoch->getNumCols());
printf("Optimal value: %g\n",osiStoch->getObjValue());
// print solution to file
string outfilename(name);
const string suffix(".out");
outfilename = outfilename + suffix;
FILE *fp = fopen(outfilename.c_str(),"w");
int numScenarios=smi.getNumScenarios();
for (int i=0 ; i<numScenarios; ++i) {
double *dsoln=NULL;
int numCols=0;
fprintf(fp,"Scenario %d \n",i);
dsoln = smi.getColSolution(i,&numCols);
for (int j=0; j<numCols; j++)
fprintf(fp,"%g \n",dsoln[j]);
free(dsoln);
}
fclose(fp);
}
示例9: consistent
bool OsiColCut::consistent(const OsiSolverInterface& im) const
{
const CoinPackedVector & lb = lbs();
const CoinPackedVector & ub = ubs();
// Test for consistent cut.
if ( lb.getMaxIndex() >= im.getNumCols() ) return false;
if ( ub.getMaxIndex() >= im.getNumCols() ) return false;
return true;
}
示例10: defined
/* Generate cuts for the model data contained in si.
The generated cuts are inserted into and returned in the
collection of cuts cs.
*/
bool
AbcCutGenerator::generateCuts( OsiCuts & cs , bool fullScan)
{
int howOften = whenCutGenerator_;
if (howOften == -100)
return false;
if (howOften > 0)
howOften = howOften % 1000000;
else
howOften = 1;
if (!howOften)
howOften = 1;
bool returnCode = false;
OsiSolverInterface * solver = model_->solver();
#if defined(ABC_DEBUG_MORE)
std::cout << "model_->getNodeCount() = " << model_->getNodeCount()
<< std::endl;
#endif
if (fullScan || (model_->getNodeCount() % howOften) == 0 ) {
CglProbing* generator =
dynamic_cast<CglProbing*>(generator_);
if (!generator) {
generator_->generateCuts(*solver,cs);
} else {
// Probing - return tight column bounds
CglTreeInfo info;
generator->generateCutsAndModify(*solver,cs,&info);
const double * tightLower = generator->tightLower();
const double * lower = solver->getColLower();
const double * tightUpper = generator->tightUpper();
const double * upper = solver->getColUpper();
const double * solution = solver->getColSolution();
int j;
int numberColumns = solver->getNumCols();
double primalTolerance = 1.0e-8;
for (j=0; j<numberColumns; j++) {
if (tightUpper[j] == tightLower[j] &&
upper[j] > lower[j]) {
// fix
solver->setColLower(j, tightLower[j]);
solver->setColUpper(j, tightUpper[j]);
if (tightLower[j] > solution[j] + primalTolerance ||
tightUpper[j] < solution[j] - primalTolerance)
returnCode = true;
}
}
}
}
return returnCode;
}
示例11: point
bool
OaDecompositionBase::OaDebug::checkInteger(const OsiSolverInterface &nlp,
std::ostream & os) const {
const double * colsol = nlp.getColSolution();
int numcols = nlp.getNumCols();
for (int i = 0 ; i < numcols ; i++) {
if (nlp.isInteger(i)) {
if (fabs(colsol[i]) - floor(colsol[i] + 0.5) >
1e-07) {
std::cerr<<"Integer infeasible point (should not be), integer infeasibility for variable "<<i
<<" is, "<<fabs(colsol[i] - floor(colsol[i] + 0.5))<<std::endl;
}
}
return true;
}
}
示例12: CoinMax
// Returns true if current solution satsifies one side of branch
bool
OsiSolverBranch::feasibleOneWay(const OsiSolverInterface & solver) const
{
bool feasible = false;
int numberColumns = solver.getNumCols();
const double * columnLower = solver.getColLower();
const double * columnUpper = solver.getColUpper();
const double * columnSolution = solver.getColSolution();
double primalTolerance;
solver.getDblParam(OsiPrimalTolerance,primalTolerance);
for (int base = 0; base<4; base +=2) {
feasible=true;
int i;
for (i=start_[base];i<start_[base+1];i++) {
int iColumn = indices_[i];
if (iColumn<numberColumns) {
double value = CoinMax(bound_[i],columnLower[iColumn]);
if (columnSolution[iColumn]<value-primalTolerance) {
feasible=false;
break;
}
} else {
abort(); // do later (other stuff messed up anyway - e.g. CBC)
}
}
if (!feasible)
break;
for (i=start_[base+1];i<start_[base+2];i++) {
int iColumn = indices_[i];
if (iColumn<numberColumns) {
double value = CoinMin(bound_[i],columnUpper[iColumn]);
if (columnSolution[iColumn]>value+primalTolerance) {
feasible=false;
break;
}
} else {
abort(); // do later (other stuff messed up anyway - e.g. CBC)
}
}
if (feasible)
break; // OK this way
}
return feasible;
}
示例13: memset
// Redoes data when sequence numbers change
void
CbcBranchToFixLots::redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns)
{
model_ = model;
if (mark_) {
OsiSolverInterface * solver = model_->solver();
int numberColumnsNow = solver->getNumCols();
char * temp = new char[numberColumnsNow];
memset(temp, 0, numberColumnsNow);
for (int i = 0; i < numberColumns; i++) {
int j = originalColumns[i];
temp[i] = mark_[j];
}
delete [] mark_;
mark_ = temp;
}
OsiSolverInterface * solver = model_->solver();
matrixByRow_ = *solver->getMatrixByRow();
}
示例14: assert
// Generate cuts
void
CglFakeClique::generateCuts(const OsiSolverInterface& si, OsiCuts & cs,
const CglTreeInfo info) const
{
if (fakeSolver_) {
assert (si.getNumCols()==fakeSolver_->getNumCols());
fakeSolver_->setColLower(si.getColLower());
fakeSolver_->setColSolution(si.getColSolution());
fakeSolver_->setColUpper(si.getColUpper());
CglClique::generateCuts(*fakeSolver_,cs,info);
if (probing_) {
// get and set branch and bound cutoff
double cutoff;
si.getDblParam(OsiDualObjectiveLimit,cutoff);
fakeSolver_->setDblParam(OsiDualObjectiveLimit,cutoff);
probing_->generateCuts(*fakeSolver_,cs,info);
}
} else {
// just use real solver
CglClique::generateCuts(si,cs,info);
}
}
示例15: uObjSense
//#############################################################################
mcSol
MibSHeuristic::solveSubproblem(double beta)
{
/*
optimize wrt to weighted upper-level objective
over current feasible lp feasible region
*/
MibSModel * model = MibSModel_;
OsiSolverInterface * oSolver = model->getSolver();
//OsiSolverInterface * sSolver = new OsiCbcSolverInterface();
OsiSolverInterface* sSolver = new OsiSymSolverInterface();
//sSolver = oSolver->clone();
//OsiSolverInterface * sSolver = tmpSolver;
//OsiSolverInterface * tmpSolver = new OsiSolverInterface(oSolver);
double uObjSense(oSolver->getObjSense());
double lObjSense(model->getLowerObjSense());
int lCols(model->getLowerDim());
int uCols(model->getUpperDim());
int * lColIndices = model->getLowerColInd();
int * uColIndices = model->getUpperColInd();
double * lObjCoeffs = model->getLowerObjCoeffs();
const double * uObjCoeffs = oSolver->getObjCoefficients();
double etol(etol_);
int tCols(uCols + lCols);
assert(tCols == oSolver->getNumCols());
sSolver->loadProblem(*oSolver->getMatrixByCol(),
oSolver->getColLower(), oSolver->getColUpper(),
oSolver->getObjCoefficients(),
oSolver->getRowLower(), oSolver->getRowUpper());
int j(0);
for(j = 0; j < tCols; j++){
if(oSolver->isInteger(j))
sSolver->setInteger(j);
}
double * nObjCoeffs = new double[tCols];
int i(0), index(0);
CoinZeroN(nObjCoeffs, tCols);
/* Multiply the UL columns of the UL objective by beta */
for(i = 0; i < uCols; i++){
index = uColIndices[i];
if(fabs(uObjCoeffs[index]) > etol)
nObjCoeffs[index] = beta * uObjCoeffs[index] * uObjSense;
else
nObjCoeffs[index] = 0.0;
}
/* Multiply the LL columns of the UL objective by beta */
for(i = 0; i < lCols; i++){
index = lColIndices[i];
if(fabs(uObjCoeffs[index]) > etol)
nObjCoeffs[index] = beta* uObjCoeffs[index] * uObjSense;
else
nObjCoeffs[index] = 0.0;
}
/* Add the LL columns of the LL objective multiplied by (1 - beta) */
for(i = 0; i < lCols; i++){
index = lColIndices[i];
if(fabs(lObjCoeffs[i]) > etol)
nObjCoeffs[index] += (1 - beta) * lObjCoeffs[i] * lObjSense;
}
sSolver->setObjective(nObjCoeffs);
//int i(0);
if(0){
for(i = 0; i < sSolver->getNumCols(); i++){
std::cout << "betaobj " << sSolver->getObjCoefficients()[i] << std::endl;
}
}
if(0){
sSolver->writeLp("afterbeta");
//sSolver->writeMps("afterbeta");
}
if(0){
for(i = 0; i < sSolver->getNumCols(); i++){
std::cout << "obj " << sSolver->getObjCoefficients()[i] << std::endl;
std::cout << "upper " << sSolver->getColUpper()[i] << std::endl;
std::cout << "lower " << sSolver->getColLower()[i] << std::endl;
}
}
if(0){
dynamic_cast<OsiCbcSolverInterface *>
(sSolver)->getModelPtr()->messageHandler()->setLogLevel(0);
//.........这里部分代码省略.........