本文整理汇总了C++中OsiCuts类的典型用法代码示例。如果您正苦于以下问题:C++ OsiCuts类的具体用法?C++ OsiCuts怎么用?C++ OsiCuts使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OsiCuts类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: selectFractionalBinaries
void
CglClique::generateCuts(const OsiSolverInterface& si, OsiCuts & cs,
const CglTreeInfo info)
{
int i;
bool has_petol_set = petol != -1.0;
if (! has_petol_set)
si.getDblParam(OsiPrimalTolerance, petol);
int numberOriginalRows = si.getNumRows();
if (info.inTree&&justOriginalRows_)
numberOriginalRows = info.formulation_rows;
int numberRowCutsBefore = cs.sizeRowCuts();
// First select which rows/columns we are interested in.
if (!setPacking_) {
selectFractionalBinaries(si);
if (!sp_orig_row_ind) {
selectRowCliques(si,numberOriginalRows);
}
} else {
selectFractionals(si);
delete[] sp_orig_row_ind;
sp_numrows = numberOriginalRows;
//sp_numcols = si.getNumCols();
sp_orig_row_ind = new int[sp_numrows];
for (i = 0; i < sp_numrows; ++i)
sp_orig_row_ind[i] = i;
}
// Just original rows
if (justOriginalRows_&&info.inTree)
sp_numrows = CoinMin(info.formulation_rows,sp_numrows);
createSetPackingSubMatrix(si);
fgraph.edgenum = createNodeNode();
createFractionalGraph();
cl_indices = new int[sp_numcols];
cl_del_indices = new int[sp_numcols];
if (do_row_clique)
find_rcl(cs);
if (do_star_clique)
find_scl(cs);
if (!info.inTree&&((info.options&4)==4||((info.options&8)&&!info.pass))) {
int numberRowCutsAfter = cs.sizeRowCuts();
for (int i=numberRowCutsBefore;i<numberRowCutsAfter;i++)
cs.rowCutPtr(i)->setGloballyValid();
}
delete[] cl_indices; cl_indices = 0;
delete[] cl_del_indices; cl_del_indices = 0;
deleteFractionalGraph();
delete[] node_node; node_node = 0;
deleteSetPackingSubMatrix();
if (! has_petol_set)
petol = -1;
}
示例2:
// Add cuts
void
CglStored::addCut(const OsiCuts & cs)
{
int numberRowCuts = cs.sizeRowCuts();
for (int i=0;i<numberRowCuts;i++) {
cuts_.insert(*cs.rowCutPtr(i));
}
}
示例3: gutsOfCopy
//-------------------------------------------------------------------
void OsiCuts::gutsOfCopy(const OsiCuts& source)
{
assert( sizeRowCuts()==0 );
assert( sizeColCuts()==0 );
assert( sizeCuts()==0 );
int i;
int ne = source.sizeRowCuts();
for (i=0; i<ne; i++) insert( source.rowCut(i) );
ne = source.sizeColCuts();
for (i=0; i<ne; i++) insert( source.colCut(i) );
}
示例4: insert
// LANNEZ SEBASTIEN added Thu May 25 01:22:51 EDT 2006
void OsiCuts::insert(const OsiCuts & cs)
{
for (OsiCuts::const_iterator it = cs.begin (); it != cs.end (); it++)
{
const OsiRowCut * rCut = dynamic_cast <const OsiRowCut * >(*it);
const OsiColCut * cCut = dynamic_cast <const OsiColCut * >(*it);
assert (rCut || cCut);
if (rCut)
insert (*rCut);
else
insert (*cCut);
}
}
示例5: CPX_CutCallback
int CPXPUBLIC CPX_CutCallback(CPXCENVptr xenv, void *cbdata,
int wherefrom, void *cbhandle, int *useraction_p) {
// cout << "Entering CPX Callback\n" << flush;
CPXLPptr nodelp;
CPXgetcallbacknodelp(xenv, cbdata, wherefrom, &nodelp);
CoinCallbacks* ccc = (CoinCallbacks*)cbhandle;
int length = CPXgetnumcols(xenv,nodelp) - 1; //hey, don't ask me! some VERY WIERD PHENOMENON... crap
double objVal;
double* solution = new double[length];
CPXgetcallbacknodeobjval(xenv, cbdata, wherefrom, &objVal);
CPXgetcallbacknodex(xenv, cbdata, wherefrom, solution, 0, length-1);
OsiCuts* cuts = new OsiCuts();
CoinCallbacks::CutReturn ret = ccc->cutCallback(objVal, solution, cuts);
if(ret == CoinCallbacks::CR_AddCuts) {
for(int i = cuts->sizeRowCuts(); i-->0;) {
const OsiRowCut& c = cuts->rowCut(i);
const CoinPackedVector& vec = c.row();
if(c.globallyValid())
/* Old Cplex-Versions did NOT have the last parameter (now set to "false").
* If you compile agains an older CPLEX version, simple *REMOVE*
* ", false"
* from the calls to CPXcutscallbackadd
*/
CPXcutcallbackadd(xenv, cbdata, wherefrom,
vec.getNumElements(), c.rhs(), c.sense(), vec.getIndices(), vec.getElements(), false); //default to non-purgable cuts
else
CPXcutcallbackaddlocal(xenv, cbdata, wherefrom,
vec.getNumElements(), c.rhs(), c.sense(), vec.getIndices(), vec.getElements());
cuts->eraseRowCut(i);
}
if(cuts->sizeColCuts() > 0) {
cerr << "ColCuts currently not supported...\n";
OGDF_THROW_PARAM(LibraryNotSupportedException, lnscFunctionNotImplemented);
}
}
*useraction_p = ( ret == CoinCallbacks::CR_Error) ? CPX_CALLBACK_FAIL :
( ret == CoinCallbacks::CR_AddCuts ) ? CPX_CALLBACK_SET :
CPX_CALLBACK_DEFAULT;
delete cuts;
delete[] solution;
// cout << "Leaving CPX Callback\n" << flush;
return 0; // success
}
示例6: 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);
}
}
示例7: memcpy
/*
Append cuts to the cuts_ array in a nodeInfo. The initial reference count
is set to numberToBranchOn, which will normally be the number of arms
defined for the CbcBranchingObject attached to the CbcNode that owns this
CbcNodeInfo.
*/
void
CbcNodeInfo::addCuts (OsiCuts & cuts, int numberToBranchOn,
/*int * whichGenerator,*/int numberPointingToThis)
{
int numberCuts = cuts.sizeRowCuts();
if (numberCuts) {
int i;
if (!numberCuts_) {
cuts_ = new CbcCountRowCut * [numberCuts];
} else {
CbcCountRowCut ** temp = new CbcCountRowCut * [numberCuts+numberCuts_];
memcpy(temp, cuts_, numberCuts_*sizeof(CbcCountRowCut *));
delete [] cuts_;
cuts_ = temp;
}
for (i = 0; i < numberCuts; i++) {
CbcCountRowCut * thisCut = new CbcCountRowCut(*cuts.rowCutPtr(i),
this, numberCuts_,
-1, numberPointingToThis);
thisCut->increment(numberToBranchOn);
cuts_[numberCuts_++] = thisCut;
#ifdef CBC_DEBUG
#if CBC_DEBUG>1
int n = thisCut->row().getNumElements();
printf("Cut %d has %d entries, rhs %g %g =>", i, n, thisCut->lb(),
thisCut->ub());
int j;
const int * index = thisCut->row().getIndices();
const double * element = thisCut->row().getElements();
for (j = 0; j < n; j++) {
printf(" (%d,%g)", index[j], element[j]);
assert(fabs(element[j]) > 1.00e-12);
}
printf("\n");
#else
int n = thisCut->row().getNumElements();
int j;
const double * element = thisCut->row().getElements();
for (j = 0; j < n; j++) {
assert(fabs(element[j]) > 1.00e-12);
}
#endif
#endif
}
}
}
示例8: isWiped
bool isWiped (OsiCuts &cs) {
if (cs.sizeColCuts () == 0)
//(cs.sizeColCuts () != 1))
return false;
CoinPackedVector
lbs = cs.colCutPtr (cs.sizeColCuts () - 1) -> lbs (),
ubs = cs.colCutPtr (cs.sizeColCuts () - 1) -> ubs ();
return ((lbs.getNumElements () == 1) &&
(ubs.getNumElements () == 1) &&
(*(lbs.getIndices ()) == 0) &&
(*(lbs.getElements ()) == 1.) &&
(*(ubs.getIndices ()) == 0) &&
(*(ubs.getElements ()) == -1.));
}
示例9:
int
Cuts::insertAll(OsiCuts & cs, CoinRelFltEq& eq)
{
int r_val = 0;
for (unsigned int i = 0 ; i < cuts_.size() ; i++)
{
if (cuts_[i] != NULL)
{
cs.insertIfNotDuplicate(*cuts_[i], eq);
delete cuts_[i];
cuts_[i] = NULL;
r_val++;
}
}
return r_val;
}
示例10: WipeMakeInfeas
void WipeMakeInfeas (OsiCuts &cs) {
//for (int i=cs.sizeRowCuts(); i--;) cs. eraseRowCut (i);
//for (int i=cs.sizeColCuts(); i--;) cs. eraseColCut (i);
OsiColCut *infeascut = new OsiColCut;
if (infeascut) {
int i=0;
double upper = -1., lower = +1.;
infeascut -> setLbs (1, &i, &lower);
infeascut -> setUbs (1, &i, &upper);
cs.insert (infeascut);
delete infeascut;
}
}
示例11: equal
void
CglClique::recordClique(const int len, int* indices, OsiCuts& cs)
{
/* transform relative indices into user indices and order them */
for (int j = len - 1; j >= 0; j--)
indices[j] = sp_orig_col_ind[indices[j]];
std::sort(indices, indices + len);
OsiRowCut rowcut;
double* coef = new double[len];
std::fill(coef, coef + len, 1.0);
rowcut.setRow(len, indices, coef);
rowcut.setUb(1.0);
CoinAbsFltEq equal(1.0e-12);
cs.insertIfNotDuplicate(rowcut,equal);
delete[] coef;
}
示例12:
void
CglLandP::scanExtraCuts(OsiCuts& cs, const double * colsol) const
{
int numAdded = 0;
for (int i = extraCuts_.sizeRowCuts() - 1; i > -1 ; i--)
{
double violation = extraCuts_.rowCut(i).violated(colsol);
if (violation > 0.)
{
cs.insert(extraCuts_.rowCut(i));
numAdded++;
// std::cout<<"A cut computed in a previous iteration is violated by "<<violation<<"."<<std::endl;
//extraCuts_.eraseRowCut(i);
}
}
// std::cout<<"Added "<<numAdded<<" previously generated cuts."<<std::endl;
}
示例13:
void
OaDecompositionBase::OaDebug::printEndOfProcedureDebugMessage(const OsiCuts &cs,
bool foundSolution,
double solValue,
double milpBound,
bool isInteger,
bool feasible,
std::ostream & os) const{
std::cout<<"------------------------------------------------------------------"
<<std::endl;
std::cout<<"OA procedure finished"<<std::endl;
std::cout<<"Generated "<<cs.sizeRowCuts()<<std::endl;
if (foundSolution)
std::cout <<"Found NLP-integer feasible solution of value : "<<solValue<<std::endl;
std::cout<<"Current MILP lower bound is : "<<milpBound<<std::endl;
std::cout<<"-------------------------------------------------------------------"<<std::endl;
std::cout<<"Stopped because : isInteger "<<isInteger<<", feasible "<<feasible<<std::endl<<std::endl;
}
示例14: assert
void
LinearCutsGenerator::generateCuts(const OsiSolverInterface &solver, OsiCuts &cs,
const CglTreeInfo info) const {
//const OsiTMINLPInterface * tmp = dynamic_cast<const OsiTMINLPInterface *>(&solver);
OsiTMINLPInterface * nlp = dynamic_cast<OsiTMINLPInterface *>(solver.clone());//const_cast<OsiTMINLPInterface *>(tmp);
assert(nlp);
OuterApprox oa;
//si.writeMps("toto");
int numberRows = nlp->getNumRows();
for(int i = 0 ; i < 5 ; i++){
nlp->resolve();
OsiClpSolverInterface si;
oa(*nlp, &si, solver.getColSolution(), true);
si.resolve();
OsiCuts cuts;
for(std::list<Coin::SmartPtr<CuttingMethod> >::const_iterator i = methods_.begin() ;
i != methods_.end() ; i++){
(*i)->cgl->generateCuts(si, cuts, info);
}
std::vector<OsiRowCut *> mycuts(cuts.sizeRowCuts());
for(int i = 0 ; i < cuts.sizeRowCuts() ; i++){
mycuts[i] = cuts.rowCutPtr(i);
cs.insert(*mycuts[i]);
}
nlp->applyRowCuts(mycuts.size(), const_cast<const OsiRowCut **> (&mycuts[0]));
}
// Take off slack cuts
std::vector<int> kept;
int numberRowsNow = nlp->getNumRows();
int * del = new int [numberRowsNow-numberRows];
nlp->resolve();
const double * activity = nlp->getRowActivity();
const double * lb = nlp->getRowLower();
const double * ub = nlp->getRowUpper();
CoinRelFltEq eq(1e-06);
//int nDelete=0;
for (int i=numberRowsNow -1;i>=numberRows;i--) {
if ( !(eq(activity[i], lb[i]) || eq(activity[i], ub[i])) )
cs.eraseRowCut(i - numberRows);
}
delete [] del;
delete nlp;
}
示例15: if
bool
BlisConGenerator::generateCons(OsiCuts & coinCuts , bool fullScan)
{
bool status = false;
if (strategy_ == -2) {
// This con generator has been disabled.
return false;
}
OsiSolverInterface * solver = model_->solver();
#if defined(BLIS_DEBUG_MORE)
std::cout << "model_->getNodeCount() = " << model_->getNodeCount()
<< std::endl;
#endif
if ( fullScan ||
((strategy_ > 0) && (model_->getNumNodes() % strategy_) == 0) ) {
//--------------------------------------------------
// Start to generate cons ...
//--------------------------------------------------
int j;
double start = CoinCpuTime();
int numConsBefore = coinCuts.sizeCuts();
int numRowsBefore = coinCuts.sizeRowCuts();
assert(generator_ != NULL);
CglProbing* generator = dynamic_cast<CglProbing *>(generator_);
if (!generator) {
generator_->generateCuts(*solver, coinCuts);
}
else {
// It is probing - return tight column bound
CglTreeInfo info;
generator->generateCutsAndModify(*solver, coinCuts, &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 numberColumns = solver->getNumCols();
double primalTolerance = 1.0e-8;
for (j = 0; j < numberColumns; ++j) {
if ( (tightUpper[j] == tightLower[j]) &&
(upper[j] > lower[j]) ) {
// fix column j
solver->setColLower(j, tightLower[j]);
solver->setColUpper(j, tightUpper[j]);
if ( (tightLower[j] > solution[j] + primalTolerance) ||
(tightUpper[j] < solution[j] - primalTolerance) ) {
status = true;
}
}
}
} // EOF probing.
//--------------------------------------------------
// Remove zero length row cuts.
//--------------------------------------------------
int numRowCons = coinCuts.sizeRowCuts();
for (j = numRowsBefore; j < numRowCons; ++j) {
OsiRowCut & rCut = coinCuts.rowCut(j);
int len = rCut.row().getNumElements();
#ifdef BLIS_DEBUG_MORE
std::cout << "Cut " << j<<": length = " << len << std::endl;
#endif
if (len == 0) {
// Empty cuts
coinCuts.eraseRowCut(j);
--j;
--numRowCons;
#ifdef BLIS_DEBUG
std::cout << "WARNING: Empty cut from " << name_ << std::endl;
#endif
}
else if (len < 0) {
#ifdef BLIS_DEBUG
std::cout << "ERROR: Cut length = " << len << std::endl;
#endif
// Error
assert(0);
}
}
//--------------------------------------------------
// Update statistics.
//--------------------------------------------------
++calls_;
numConsGenerated_ += (coinCuts.sizeCuts() - numConsBefore);
time_ += (CoinCpuTime() - start);
if (numConsGenerated_ == 0) {
++noConsCalls_;
//.........这里部分代码省略.........