Skip to content

Commit

Permalink
fix odd accuracy bug with some cut generators
Browse files Browse the repository at this point in the history
  • Loading branch information
jjhforrest committed Jul 17, 2024
1 parent 842782c commit 4039409
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/CglFlowCover/CglFlowCover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void CglFlowCover::generateCuts(const OsiSolverInterface & si, OsiCuts & cs,
hasCut = generateOneFlowCut(si, rowLen, ind, coef, 'L',
thisRhs, flowCut1, violation);
if (hasCut) { // If find a cut
cs.insertIfNotDuplicate(flowCut1);
cs.insertIfNotDuplicateAndClean(flowCut1,41);
incNumFlowCuts();
if (getNumFlowCuts() >= getMaxNumCuts())
break;
Expand All @@ -309,7 +309,7 @@ void CglFlowCover::generateCuts(const OsiSolverInterface & si, OsiCuts & cs,
hasCut = generateOneFlowCut(si, rowLen, ind, coef, 'G',
thisRhs, flowCut2, violation);
if (hasCut) {
cs.insertIfNotDuplicate(flowCut2);
cs.insertIfNotDuplicateAndClean(flowCut2,42);
incNumFlowCuts();
if (getNumFlowCuts() >= getMaxNumCuts())
break;
Expand All @@ -319,7 +319,7 @@ void CglFlowCover::generateCuts(const OsiSolverInterface & si, OsiCuts & cs,
hasCut = generateOneFlowCut(si, rowLen, ind, coef, sense[iRow],
thisRhs, flowCut3, violation);
if (hasCut) {
cs.insertIfNotDuplicate(flowCut3);
cs.insertIfNotDuplicateAndClean(flowCut3,43);
incNumFlowCuts();
if (getNumFlowCuts() >= getMaxNumCuts())
break;
Expand Down
4 changes: 2 additions & 2 deletions src/CglGMI/CglGMI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,10 +1264,10 @@ void CglGMI::generateCuts(OsiCuts &cs)
rc.setLb(-param.getINFINIT());
rc.setUb(cutRhs);
if (!param.getCHECK_DUPLICATES()) {
cs.insertIfNotDuplicate(rc);
cs.insertIfNotDuplicateAndClean(rc,21);
}
else{
cs.insertIfNotDuplicate(rc, CoinAbsFltEq(param.getEPS_COEFF()));
cs.insertIfNotDuplicateAndClean(rc, 22, CoinAbsFltEq(param.getEPS_COEFF()));
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/CglGomory/CglGomory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1695,13 +1695,13 @@ CglGomory::generateCuts(
if (number>1) {
#if MORE_GOMORY_CUTS<2
nTotalEls -= number;
cs.insertIfNotDuplicate(rc);
cs.insertIfNotDuplicateAndClean(rc,11);
#else
if(number<saveLimit) {
nTotalEls -= number;
cs.insertIfNotDuplicate(rc);
cs.insertIfNotDuplicateAndClean(rc,12);
} else {
longCuts.insertIfNotDuplicate(rc);
longCuts.insertIfNotDuplicateAndClean(rc,13);
}
#endif
} else {
Expand Down Expand Up @@ -1747,7 +1747,7 @@ CglGomory::generateCuts(
rc.setRow(0,cutIndex,packed,false);
rc.setLb(1.0);
rc.setUb(0.0);
cs.insertIfNotDuplicate(rc);
cs.insertIfNotDuplicateAndClean(rc,14);
} else if (lb>lbCol || ub<ubCol) {
if (!intVar[iColumn]) {
// think
Expand Down Expand Up @@ -1776,7 +1776,7 @@ CglGomory::generateCuts(
rc.setRow(number,cutIndex,packed,false);
rc.setLb(bounds[0]);
rc.setUb(bounds[1]);
secondaryCuts.insertIfNotDuplicate(rc);
secondaryCuts.insertIfNotDuplicateAndClean(rc,15);
#endif
}
} else {
Expand Down Expand Up @@ -1877,7 +1877,7 @@ CglGomory::generateCuts(
while (nTotalEls>0) {
for (int i=0;i<numberLong;i++) {
nTotalEls -= longCuts.rowCutPtr(i)->row().getNumElements();
cs.insertIfNotDuplicate(longCuts.rowCut(i));
cs.insertIfNotDuplicateAndClean(longCuts.rowCut(i),16);
numberAdded ++;
if (nTotalEls<=0)
break;
Expand All @@ -1889,7 +1889,7 @@ CglGomory::generateCuts(
while (nTotalEls>0) {
for (int i=0;i<numberInaccurate;i++) {
nTotalEls -= secondaryCuts.rowCutPtr(i)->row().getNumElements();
cs.insertIfNotDuplicate(secondaryCuts.rowCut(i));
cs.insertIfNotDuplicateAndClean(secondaryCuts.rowCut(i),17);
numberAdded ++;
if (nTotalEls<=0)
break;
Expand Down
23 changes: 18 additions & 5 deletions src/CglMixedIntegerRounding2/CglMixedIntegerRounding2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ CglMixedIntegerRounding2::generateCuts(const OsiSolverInterface& si,
// everytime this function is called. Otherwise, just do once.
bool preInit = false;
bool preReso = false;
info_ = &info;
si.getHintParam(OsiDoPresolveInInitial, preInit);
si.getHintParam(OsiDoPresolveInResolve, preReso);
// Deal with MAXAGGR_
int saveMaxAggr = MAXAGGR_;
if (MAXAGGR_==-1) {
if(!info.inTree && info.pass<1000)
if (MAXAGGR_<0) {
if(!info.inTree && info.pass<1000) {
MAXAGGR_=5; // up at root
else
MAXAGGR_=1;
} else {
if (MAXAGGR_==-1)
MAXAGGR_=1;
else
return;
}
}
if (preInit == false && preReso == false && doPreproc_ == -1 ) { // Do once
if (doneInitPre_ == false) {
Expand Down Expand Up @@ -992,6 +997,14 @@ CglMixedIntegerRounding2::generateMirCuts(
if (n>CBC_CHECK_CUT_LENGTH*numRows_)
hasCut = false;
}
#endif
#if 1
if (info_->pass || info_->inTree) {
const CoinPackedVector & row = cMirCut.row();
int n=row.getNumElements();
if (n>0.8*numCols_)
hasCut = false;
}
#endif
if (hasCut) {
// look at cut to see if unstable
Expand All @@ -1017,7 +1030,7 @@ CglMixedIntegerRounding2::generateMirCuts(
printf("(%d,%g) ",columns[i],elements[i]);
printf("<= %g\n",cMirCut.ub());
#endif
cs.insertIfNotDuplicate(cMirCut,tolTest);
cs.insertIfNotDuplicateAndClean(cMirCut,31,tolTest);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/CglMixedIntegerRounding2/CglMixedIntegerRounding2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class CGLLIB_EXPORT CglMixedIntegerRounding2 : public CglCutGenerator {
//@{
/// Set MAXAGGR_
inline void setMAXAGGR_ (int maxaggr) {
if (maxaggr > 0 || maxaggr == -1) {
if (maxaggr > 0 || maxaggr == -1 || maxaggr ==-2) {
MAXAGGR_ = maxaggr;
}
else {
Expand Down Expand Up @@ -412,6 +412,8 @@ class CGLLIB_EXPORT CglMixedIntegerRounding2 : public CglCutGenerator {
char * sense_;
// RHS of rows (modified if ranges)
double * RHS_;
// Pointer to info
const CglTreeInfo *info_;
};

//#############################################################################
Expand Down
4 changes: 2 additions & 2 deletions src/CglRedSplit2/CglRedSplit2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2111,7 +2111,7 @@ int CglRedSplit2::generateCuts(OsiCuts* cs, int maxNumCuts, int* lambda)
}
rc.setUb(tabrowrhs + adjust);
// relax the constraint slightly
buffcs->insertIfNotDuplicate(rc, CoinAbsFltEq(param.getEPS()));
buffcs->insertIfNotDuplicateAndClean(rc, 51, CoinAbsFltEq(param.getEPS()));
numCuts = buffcs->sizeRowCuts() - initNumCuts;
#if CBC_CHECK_CUT_LENGTH
}
Expand All @@ -2137,7 +2137,7 @@ int CglRedSplit2::generateCuts(OsiCuts* cs, int maxNumCuts, int* lambda)
// also delete temp data
if (buffcs){
for (int i = 0; i < numCuts && i < maxNumCuts; ++i){
cs->insertIfNotDuplicate(buffcs->rowCut(quality[i].index),
cs->insertIfNotDuplicateAndClean(buffcs->rowCut(quality[i].index),52,
CoinAbsFltEq(param.getEPS_COEFF()));
}
delete buffcs;
Expand Down
4 changes: 2 additions & 2 deletions src/CglResidualCapacity/CglResidualCapacity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ CglResidualCapacity::generateResCapCuts(
#if CGL_DEBUG
std::cout << "Res. cap. cut generated " << std::endl;
#endif
cs.insertIfNotDuplicate(resCapCut);
cs.insertIfNotDuplicateAndClean(resCapCut,71);
}
}

Expand All @@ -516,7 +516,7 @@ CglResidualCapacity::generateResCapCuts(
#if CGL_DEBUG
std::cout << "Res. cap. cut generated " << std::endl;
#endif
cs.insertIfNotDuplicate(resCapCut);
cs.insertIfNotDuplicateAndClean(resCapCut,72);
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/CglTwomir/CglTwomir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CoinWarmStartBasis;
#define t_min data->cparams.t_min
#define a_max data->cparams.a_max
#define max_elements data->cparams.max_elements

//#define CGL_DEBUG
#ifdef CGL_DEBUG
// Declarations and defines for debug build.

Expand Down Expand Up @@ -81,7 +81,6 @@ void testus( DGG_constraint_t *cut){ //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#endif // CGL_DEBUG


//-------------------------------------------------------------------
// Generate cuts
//-------------------------------------------------------------------
Expand Down Expand Up @@ -407,7 +406,7 @@ void CglTwomir::generateCuts(const OsiSolverInterface & si, OsiCuts & cs,
rowcut.setRow(number, cutIndex, packed);
rowcut.setUb(si.getInfinity());
rowcut.setLb(rhs);
cs.insertIfNotDuplicate(rowcut);
cs.insertIfNotDuplicateAndClean(rowcut,61);
} else {
// singleton row cut!
double lb = rhs;
Expand Down Expand Up @@ -436,7 +435,7 @@ void CglTwomir::generateCuts(const OsiSolverInterface & si, OsiCuts & cs,
rc.setRow(0,cutIndex,packed,false);
rc.setLb(1.0);
rc.setUb(0.0);
cs.insertIfNotDuplicate(rc);
cs.insertIfNotDuplicateAndClean(rc,62);
} else if (lb>lbCol || ub<ubCol) {
if (!isInteger) {
// think
Expand All @@ -461,7 +460,7 @@ void CglTwomir::generateCuts(const OsiSolverInterface & si, OsiCuts & cs,
rowcut.setRow(cut->nz, cut->index, cut->coeff);
rowcut.setUb(si->getInfinity());
rowcut.setLb(cut->rhs);
cs.insertIfNotDuplicate(rowcut);
cs.insertIfNotDuplicateAndClean(rowcut,63);
#endif
}

Expand All @@ -476,7 +475,6 @@ void CglTwomir::generateCuts(const OsiSolverInterface & si, OsiCuts & cs,
#endif
}
}

for ( i=0; i<cut_list.n; i++)
DGG_freeConstraint (cut_list.c[i]);
DGG_list_free (&cut_list);
Expand Down

0 comments on commit 4039409

Please sign in to comment.