本文整理汇总了C++中OsiSolverInterface::setDblParam方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiSolverInterface::setDblParam方法的具体用法?C++ OsiSolverInterface::setDblParam怎么用?C++ OsiSolverInterface::setDblParam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiSolverInterface
的用法示例。
在下文中一共展示了OsiSolverInterface::setDblParam方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pushCbcOsiDbl
int pushCbcOsiDbl (CoinParam *param)
{
assert (param != 0) ;
CbcOsiParam *osiParam = dynamic_cast<CbcOsiParam *>(param) ;
assert (osiParam != 0) ;
OsiSolverInterface *osi = osiParam->obj() ;
assert (osi != 0) ;
double val = osiParam->dblVal() ;
CbcOsiParam::CbcOsiParamCode code = osiParam->paramCode() ;
assert (osi != 0) ;
/*
Setup to return nonfatal/fatal error (1/-1) by default, so that all we need
to do is correct to 0 (no error) if we're successful.
*/
int retval ;
if (CoinParamUtils::isInteractive()) {
retval = 1 ;
} else {
retval = -1 ;
}
/*
Translate the parameter code from CbcOsiParamCode into the correct key for
CbcDblParam.
*/
OsiDblParam key ;
switch (code) {
case CbcOsiParam::PRIMALTOLERANCE: {
key = OsiPrimalTolerance ;
break ;
}
case CbcOsiParam::DUALTOLERANCE: {
key = OsiDualTolerance ; ;
break ;
}
case CbcOsiParam::DUALBOUND: {
key = OsiDualObjectiveLimit ;
break ;
}
default: {
std::cerr << "pushCbcOsiDblParam: no equivalent OsiDblParam for "
<< "parameter code `" << code << "'." << std::endl ;
retval = -1 ;
break ;
}
}
bool setOK = osi->setDblParam(key, val) ;
if (setOK == false) {
retval = -1 ;
}
return (retval) ;
}
示例2: mat
void
HeuristicInnerApproximation::extractInnerApproximation(Bonmin::OsiTMINLPInterface & nlp, OsiSolverInterface &si,
const double * x, bool getObj) {
printf("************ Start extracting inner approx");
int n;
int m;
int nnz_jac_g;
int nnz_h_lag;
Ipopt::TNLP::IndexStyleEnum index_style;
Bonmin::TMINLP2TNLP * problem = nlp.problem();
//Get problem information
problem->get_nlp_info(n, m, nnz_jac_g, nnz_h_lag, index_style);
Bonmin::vector<int> jRow(nnz_jac_g);
Bonmin::vector<int> jCol(nnz_jac_g);
Bonmin::vector<double> jValues(nnz_jac_g);
problem->eval_jac_g(n, NULL, 0, m, nnz_jac_g, jRow(), jCol(), NULL);
if(index_style == Ipopt::TNLP::FORTRAN_STYLE)//put C-style
{
for(int i = 0 ; i < nnz_jac_g ; i++){
jRow[i]--;
jCol[i]--;
}
}
//get Jacobian
problem->eval_jac_g(n, x, 1, m, nnz_jac_g, NULL, NULL,
jValues());
Bonmin::vector<double> g(m);
problem->eval_g(n, x, 1, m, g());
Bonmin::vector<int> nonLinear(m);
//store non linear constraints (which are to be removed from IA)
int numNonLinear = 0;
const double * rowLower = nlp.getRowLower();
const double * rowUpper = nlp.getRowUpper();
const double * colLower = nlp.getColLower();
const double * colUpper = nlp.getColUpper();
assert(m == nlp.getNumRows());
double infty = si.getInfinity();
double nlp_infty = nlp.getInfinity();
Bonmin::vector<Ipopt::TNLP::LinearityType> constTypes(m);
Bonmin::vector<Ipopt::TNLP::LinearityType> varTypes(n);
problem->get_constraints_linearity(m, constTypes());
problem->get_variables_linearity(n, varTypes());
for (int i = 0; i < m; i++) {
if (constTypes[i] == Ipopt::TNLP::NON_LINEAR) {
nonLinear[numNonLinear++] = i;
}
}
Bonmin::vector<double> rowLow(m - numNonLinear);
Bonmin::vector<double> rowUp(m - numNonLinear);
int ind = 0;
for (int i = 0; i < m; i++) {
if (constTypes[i] != Ipopt::TNLP::NON_LINEAR) {
if (rowLower[i] > -nlp_infty) {
// printf("Lower %g ", rowLower[i]);
rowLow[ind] = (rowLower[i]);
} else
rowLow[ind] = -infty;
if (rowUpper[i] < nlp_infty) {
// printf("Upper %g ", rowUpper[i]);
rowUp[ind] = (rowUpper[i]);
} else
rowUp[ind] = infty;
ind++;
}
}
CoinPackedMatrix mat(true, jRow(), jCol(), jValues(), nnz_jac_g);
mat.setDimensions(m, n); // In case matrix was empty, this should be enough
//remove non-linear constraints
mat.deleteRows(numNonLinear, nonLinear());
int numcols = nlp.getNumCols();
Bonmin::vector<double> obj(numcols);
for (int i = 0; i < numcols; i++)
obj[i] = 0.;
si.loadProblem(mat, nlp.getColLower(), nlp.getColUpper(),
obj(), rowLow(), rowUp());
const Bonmin::TMINLP::VariableType* variableType = problem->var_types();
for (int i = 0; i < n; i++) {
if ((variableType[i] == Bonmin::TMINLP::BINARY) || (variableType[i] == Bonmin::TMINLP::INTEGER))
si.setInteger(i);
}
if (getObj) {
bool addObjVar = false;
if (problem->hasLinearObjective()) {
double zero;
Bonmin::vector<double> x0(n, 0.);
problem->eval_f(n, x0(), 1, zero);
si.setDblParam(OsiObjOffset, -zero);
//Copy the linear objective and don't create a dummy variable.
problem->eval_grad_f(n, x, 1, obj());
si.setObjective(obj());
} else {
//.........这里部分代码省略.........
示例3: v
void
CglLandP::generateCuts(const OsiSolverInterface & si, OsiCuts & cs,
const CglTreeInfo info )
{
if ((info.pass == 0) && !info.inTree)
{
numrows_ = si.getNumRows();
}
// scanExtraCuts(cs, si.getColSolution());
Parameters params = params_;
params.rhsWeight = numrows_ + 2;
handler_->message(CUT_GAP, messages_)<<info.pass<<si.getObjValue() <<CoinMessageEol;
if (info.inTree) //put lower pivot limit
{
params.pivotLimit = std::min(params.pivotLimit, params.pivotLimitInTree);
params.countMistakenRc = true;
}
if (params.timeLimit < 0)
{
params.pivotLimit = 0;
}
assert(si.basisIsAvailable());
#ifdef APPEND_ROW
OsiSolverInterface * t_si = si.clone();
if (params.modularize)
{
int new_idx = si.getNumCols();
int v_idx[1] = {new_idx};
double v_val[1] = {-1};
CoinPackedVector v(1, v_idx, v_val, false);
t_si->addCol(CoinPackedVector(), 0, 1, 0);
t_si->setInteger(new_idx);
t_si->addRow(v,0, 0);
t_si->resolve();
}
#else
const OsiSolverInterface * t_si = &si;
#endif
cached_.getData(*t_si);
CglLandPSimplex landpSi(*t_si, cached_, params, validator_);
if (params.generateExtraCuts == CglLandP::AllViolatedMigs)
{
landpSi.genThisBasisMigs(cached_, params);
}
landpSi.setLogLevel(handler_->logLevel());
int nCut = 0;
std::vector<int> indices;
getSortedFractionalIndices(indices,cached_, params);
#ifndef NDEBUG
int numrows = si.getNumRows();
#endif
#ifdef DO_STAT
//Get informations on current optimum
{
OsiSolverInterface * gapTester = si.clone();
gapTester->resolve();
roundsStats_.analyseOptimalBasis(gapTester,info.pass, numrows_);
delete gapTester;
}
#endif
params_.timeLimit += CoinCpuTime();
CoinRelFltEq eq(1e-04);
for (unsigned int i = 0; i < indices.size() && nCut < params.maxCutPerRound &&
nCut < cached_.nBasics_ ; i++)
{
//Check for time limit
int iRow = indices[i];
assert(iRow < numrows);
OsiRowCut cut;
int code=1;
OsiSolverInterface * ncSi = NULL;
if (params.pivotLimit != 0)
{
ncSi = t_si->clone();
landpSi.setSi(ncSi);
ncSi->setDblParam(OsiDualObjectiveLimit, COIN_DBL_MAX);
ncSi->messageHandler()->setLogLevel(0);
}
int generated = 0;
if (params.pivotLimit == 0)
{
generated = landpSi.generateMig(iRow, cut, params);
}
else
{
//.........这里部分代码省略.........
示例4: branch_info
/// OaDecomposition method
double
OaFeasibilityChecker::performOa(OsiCuts & cs, solverManip &lpManip,
BabInfo * babInfo, double &cutoff,const CglTreeInfo & info) const
{
bool isInteger = true;
bool feasible = 1;
OsiSolverInterface * lp = lpManip.si();
OsiBranchingInformation branch_info(lp,false);
//int numcols = lp->getNumCols();
double milpBound = -COIN_DBL_MAX;
int numberPasses = 0;
double * nlpSol = NULL;
int numberCutsBefore = cs.sizeRowCuts();
while (isInteger && feasible ) {
numberPasses++;
//setup the nlp
//Fix the variable which have to be fixed, after having saved the bounds
double * colsol = const_cast<double *>(lp->getColSolution());
branch_info.solution_ = colsol;
fixIntegers(*nlp_,branch_info, parameters_.cbcIntegerTolerance_,objects_, nObjects_);
//Now solve the NLP get the cuts, and intall them in the local LP
nlp_->resolve(txt_id);
if (post_nlp_solve(babInfo, cutoff)) {
//nlp solved and feasible
// Update the cutoff
double ub = nlp_->getObjValue();
cutoff = ub > 0 ? ub *(1 - parameters_.cbcCutoffIncrement_) : ub*(1 + parameters_.cbcCutoffIncrement_);
// Update the lp solver cutoff
lp->setDblParam(OsiDualObjectiveLimit, cutoff);
}
// Get the cuts outer approximation at the current point
nlpSol = const_cast<double *>(nlp_->getColSolution());
const double * toCut = (parameter().addOnlyViolated_)?
colsol:NULL;
if(cut_count_ <= maximum_oa_cuts_ && type_ == OA)
nlp_->getOuterApproximation(cs, nlpSol, 1, toCut,
true);
else {//if (type_ == Benders)
nlp_->getBendersCut(cs, parameter().global_);
}
if(pol_ == DetectCycles)
nlp_->getBendersCut(savedCuts_, parameter().global_);
int numberCuts = cs.sizeRowCuts() - numberCutsBefore;
cut_count_ += numberCuts;
if (numberCuts > 0)
installCuts(*lp, cs, numberCuts);
lp->resolve();
double objvalue = lp->getObjValue();
//milpBound = max(milpBound, lp->getObjValue());
feasible = (lp->isProvenOptimal() &&
!lp->isDualObjectiveLimitReached() && (objvalue<cutoff)) ;
//if value of integers are unchanged then we have to get out
bool changed = true;//if lp is infeasible we don't have to check anything
isInteger = 0;
// if(!fixed)//fathom on bounds
// milpBound = 1e200;
if (feasible) {
changed = isDifferentOnIntegers(*nlp_, objects_, nObjects_,
0.1,
nlp_->getColSolution(), lp->getColSolution());
}
if (changed) {
branch_info.solution_ = lp->getColSolution();
isInteger = integerFeasible(*lp,branch_info, parameters_.cbcIntegerTolerance_,
objects_, nObjects_);
}
else {
isInteger = 0;
// if(!fixed)//fathom on bounds
milpBound = 1e200;
}
#ifdef OA_DEBUG
printf("Obj value after cuts %g, %d rows\n",lp->getObjValue(),
numberCuts) ;
#endif
}
int num_cuts_now = cs.sizeRowCuts();
if(pol_ == KeepAll){
for(int i = numberCutsBefore ; i < num_cuts_now ; i++){
cs.rowCut(i).setEffectiveness(99.9e99);
}
}
#ifdef OA_DEBUG
debug_.printEndOfProcedureDebugMessage(cs, true, cutoff, milpBound, isInteger, feasible, std::cout);
std::cout<<"milpBound found: "<<milpBound<<std::endl;
#endif
return milpBound;
}
示例5: mat
void
HeuristicInnerApproximation::extractInnerApproximation(OsiTMINLPInterface & nlp, OsiSolverInterface &si,
const double * x, bool getObj) {
int n;
int m;
int nnz_jac_g;
int nnz_h_lag;
Ipopt::TNLP::IndexStyleEnum index_style;
TMINLP2TNLP * problem = nlp.problem();
//Get problem information
problem->get_nlp_info(n, m, nnz_jac_g, nnz_h_lag, index_style);
vector<int> jRow(nnz_jac_g);
vector<int> jCol(nnz_jac_g);
vector<double> jValues(nnz_jac_g);
problem->eval_jac_g(n, NULL, 0, m, nnz_jac_g, jRow(), jCol(), NULL);
if(index_style == Ipopt::TNLP::FORTRAN_STYLE)//put C-style
{
for(int i = 0 ; i < nnz_jac_g ; i++){
jRow[i]--;
jCol[i]--;
}
}
//get Jacobian
problem->eval_jac_g(n, x, 1, m, nnz_jac_g, NULL, NULL,
jValues());
vector<double> g(m);
problem->eval_g(n, x, 1, m, g());
vector<int> nonLinear(m);
//store non linear constraints (which are to be removed from IA)
int numNonLinear = 0;
const double * rowLower = nlp.getRowLower();
const double * rowUpper = nlp.getRowUpper();
const double * colLower = nlp.getColLower();
const double * colUpper = nlp.getColUpper();
assert(m == nlp.getNumRows());
double infty = si.getInfinity();
double nlp_infty = nlp.getInfinity();
vector<Ipopt::TNLP::LinearityType> constTypes(m);
problem->get_constraints_linearity(m, constTypes());
for (int i = 0; i < m; i++) {
if (constTypes[i] == Ipopt::TNLP::NON_LINEAR) {
nonLinear[numNonLinear++] = i;
}
}
vector<double> rowLow(m - numNonLinear);
vector<double> rowUp(m - numNonLinear);
int ind = 0;
for (int i = 0; i < m; i++) {
if (constTypes[i] != Ipopt::TNLP::NON_LINEAR) {
if (rowLower[i] > -nlp_infty) {
// printf("Lower %g ", rowLower[i]);
rowLow[ind] = (rowLower[i]);
} else
rowLow[ind] = -infty;
if (rowUpper[i] < nlp_infty) {
// printf("Upper %g ", rowUpper[i]);
rowUp[ind] = (rowUpper[i]);
} else
rowUp[ind] = infty;
ind++;
}
}
CoinPackedMatrix mat(true, jRow(), jCol(), jValues(), nnz_jac_g);
mat.setDimensions(m, n); // In case matrix was empty, this should be enough
//remove non-linear constraints
mat.deleteRows(numNonLinear, nonLinear());
int numcols = nlp.getNumCols();
vector<double> obj(numcols);
for (int i = 0; i < numcols; i++)
obj[i] = 0.;
si.loadProblem(mat, nlp.getColLower(), nlp.getColUpper(),
obj(), rowLow(), rowUp());
const Bonmin::TMINLP::VariableType* variableType = problem->var_types();
for (int i = 0; i < n; i++) {
if ((variableType[i] == TMINLP::BINARY) || (variableType[i]
== TMINLP::INTEGER))
si.setInteger(i);
}
if (getObj) {
bool addObjVar = false;
if (problem->hasLinearObjective()) {
double zero;
vector<double> x0(n, 0.);
problem->eval_f(n, x0(), 1, zero);
si.setDblParam(OsiObjOffset, -zero);
//Copy the linear objective and don't create a dummy variable.
problem->eval_grad_f(n, x, 1, obj());
si.setObjective(obj());
} else {
addObjVar = true;
}
//.........这里部分代码省略.........
示例6: 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;
}
}