本文整理汇总了C++中OsiRowCut::setLb方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiRowCut::setLb方法的具体用法?C++ OsiRowCut::setLb怎么用?C++ OsiRowCut::setLb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiRowCut
的用法示例。
在下文中一共展示了OsiRowCut::setLb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CbcCutBranchingObject
CbcBranchingObject *
CbcBranchAllDifferent::createCbcBranch(OsiSolverInterface * /*solver*/
, const OsiBranchingInformation * /*info*/,
int /*way*/)
{
// by default way must be -1
//assert (way==-1);
const double * solution = model_->testSolution();
double * values = new double[numberInSet_];
int * which = new int[numberInSet_];
int i;
for (i = 0; i < numberInSet_; i++) {
int iColumn = which_[i];
values[i] = solution[iColumn];
which[i] = iColumn;
}
CoinSort_2(values, values + numberInSet_, which);
double last = -1.0;
double closest = 1.0;
int worst = -1;
for (i = 0; i < numberInSet_; i++) {
if (values[i] - last < closest) {
closest = values[i] - last;
worst = i - 1;
}
last = values[i];
}
assert (closest <= 0.99999);
OsiRowCut down;
down.setLb(-COIN_DBL_MAX);
down.setUb(-1.0);
int pair[2];
double elements[] = {1.0, -1.0};
pair[0] = which[worst];
pair[1] = which[worst+1];
delete [] values;
delete [] which;
down.setRow(2, pair, elements);
// up is same - just with rhs changed
OsiRowCut up = down;
up.setLb(1.0);
up.setUb(COIN_DBL_MAX);
// Say is not a fix type branch
CbcCutBranchingObject * newObject =
new CbcCutBranchingObject(model_, down, up, false);
if (model_->messageHandler()->logLevel() > 1)
printf("creating cut in CbcBranchCut\n");
return newObject;
}
示例2:
// Add a row cut from elements
void
CglStored::addCut(double lb, double ub, int size, const int * colIndices, const double * elements)
{
OsiRowCut rc;
rc.setRow(size,colIndices,elements,false);
rc.setLb(lb);
rc.setUb(ub);
cuts_.insert(rc);
}
示例3: CglCutGenerator
//-------------------------------------------------------------------
// Constructor from file
//-------------------------------------------------------------------
CglStored::CglStored (const char * fileName) :
CglCutGenerator(),
requiredViolation_(1.0e-5),
probingInfo_(NULL),
numberColumns_(0),
bestSolution_(NULL),
bounds_(NULL)
{
FILE * fp = fopen(fileName,"rb");
if (fp) {
#ifndef NDEBUG
size_t numberRead;
#endif
int maxInCut=0;
int * index = NULL;
double * coefficient = NULL;
double rhs[2];
int n=0;
while (n>=0) {
#ifndef NDEBUG
numberRead = fread(&n,sizeof(int),1,fp);
assert (numberRead==1);
#else
fread(&n,sizeof(int),1,fp);
#endif
if (n<0)
break;
if (n>maxInCut) {
maxInCut=n;
delete [] index;
delete [] coefficient;
index = new int [maxInCut];
coefficient = new double [maxInCut];
}
#ifndef NDEBUG
numberRead = fread(rhs,sizeof(double),2,fp);
assert (numberRead==2);
#else
fread(rhs,sizeof(double),2,fp);
#endif
fread(index,sizeof(int),n,fp);
fread(coefficient,sizeof(double),n,fp);
OsiRowCut rc;
rc.setRow(n,index,coefficient,false);
rc.setLb(rhs[0]);
rc.setUb(rhs[1]);
cuts_.insert(rc);
}
delete [] index;
delete [] coefficient;
fclose(fp);
}
}
示例4: scale
/** scale the cut passed as argument*/
void scale(OsiRowCut &cut)
{
double rhs = fabs(cut.lb());
CoinPackedVector row;
row.reserve(cut.row().getNumElements());
for (int i = 0 ; i < cut.row().getNumElements() ; i++)
{
row.insert(cut.row().getIndices()[i], cut.row().getElements()[i]/rhs);
}
cut.setLb(cut.lb()/rhs);
cut.setRow(row);
}
示例5: sizeRowCuts
/* Insert a row cut unless it is a duplicate (CoinRelFltEq)*/
void
OsiCuts::insertIfNotDuplicate( OsiRowCut & rc , CoinRelFltEq treatAsSame)
{
double newLb = rc.lb();
double newUb = rc.ub();
CoinPackedVector vector = rc.row();
int numberElements =vector.getNumElements();
int * newIndices = vector.getIndices();
double * newElements = vector.getElements();
CoinSort_2(newIndices,newIndices+numberElements,newElements);
bool notDuplicate=true;
int numberRowCuts = sizeRowCuts();
for ( int i =0; i<numberRowCuts;i++) {
const OsiRowCut * cutPtr = rowCutPtr(i);
if (cutPtr->row().getNumElements()!=numberElements)
continue;
if (!treatAsSame(cutPtr->lb(),newLb))
continue;
if (!treatAsSame(cutPtr->ub(),newUb))
continue;
const CoinPackedVector * thisVector = &(cutPtr->row());
const int * indices = thisVector->getIndices();
const double * elements = thisVector->getElements();
int j;
for(j=0;j<numberElements;j++) {
if (indices[j]!=newIndices[j])
break;
if (!treatAsSame(elements[j],newElements[j]))
break;
}
if (j==numberElements) {
notDuplicate=false;
break;
}
}
if (notDuplicate) {
OsiRowCut * newCutPtr = new OsiRowCut();
newCutPtr->setLb(newLb);
newCutPtr->setUb(newUb);
newCutPtr->setRow(vector);
rowCutPtrs_.push_back(newCutPtr);
}
}
示例6: CoinError
OsiRowCut *
BlisConstraint::createOsiRowCut()
{
double lower = CoinMax(getLbHard(), getLbSoft());
double upper = CoinMin(getUbHard(), getUbSoft());
OsiRowCut * cut = new OsiRowCut;
if (!cut) {
/* Out of memory. */
throw CoinError("Out of Memory", "Blis_constraintToOsiCut", "NONE");
}
assert(size_ > 0);
cut->setLb(lower);
cut->setUb(upper);
cut->setRow(size_, indices_, values_);
return cut;
}
示例7: generateCuts
//.........这里部分代码省略.........
countcol[icol]++;
}
}
#ifdef CGL_DEBUG
printf("true constraint %d",nrow2);
#endif
nrow2=nrow2>>1;
double rhs=nrow2;
if (!packed) rhs++; // +1 for cover
ii=0;
for (k=0;k<nincut;k++) {
int jcol=candidate[k];
if (countcol[jcol]) {
#ifdef CGL_DEBUG
printf(" %d %d",jcol,countcol[jcol]);
#endif
int ihalf=(countcol[jcol]+bias)>>1;
if (ihalf) {
element[ii]=ihalf;
sum+=solution[jcol]*element[ii];
/*printf("%d %g %g\n",jcol,element[ii],sumall[jcol]);*/
candidate[ii++]=jcol;
}
countcol[jcol]=0;
}
}
#ifdef CGL_DEBUG
printf("\n");
#endif
OsiRowCut rc;
double violation=0.0;
if (packed) {
violation = sum-rhs;
rc.setLb(-COIN_DBL_MAX);
rc.setUb(rhs);
} else {
// other way for cover
violation = rhs-sum;
rc.setUb(COIN_DBL_MAX);
rc.setLb(rhs);
}
if (violation<minimumViolation_) {
#ifdef CGL_DEBUG
printf("why no cut\n");
#endif
good=false;
} else {
if (static_cast<double> (ii) * minimumViolationPer_>violation||
ii>maximumEntries_) {
#ifdef CGL_DEBUG
printf("why no cut\n");
#endif
if (packed) {
// sort and see if we can get down to length
// relax by taking out ones with solution 0.0
nincut=ii;
for (k=0;k<nincut;k++) {
int jcol=candidate[k];
double value = fabs(dj[jcol]);
if (solution[jcol])
value = -solution[jcol];
sortit[k].dj=value;
sortit[k].element=element[k];
sortit[k].sequence=jcol;
}
// sort
示例8: OsiCbcSolverInterfaceUnitTest
//.........这里部分代码省略.........
OSIUNITTEST_ASSERT_ERROR(ei[ 9] == 3, {}, "cbc", "getMatrixByRow: indices");
OSIUNITTEST_ASSERT_ERROR(ei[10] == 6, {}, "cbc", "getMatrixByRow: indices");
OSIUNITTEST_ASSERT_ERROR(ei[11] == 0, {}, "cbc", "getMatrixByRow: indices");
OSIUNITTEST_ASSERT_ERROR(ei[12] == 4, {}, "cbc", "getMatrixByRow: indices");
OSIUNITTEST_ASSERT_ERROR(ei[13] == 7, {}, "cbc", "getMatrixByRow: indices");
#else // OSICBC_TEST_MTX_STRUCTURE
CoinPackedMatrix exmip1Mtx ;
exmip1Mtx.reverseOrderedCopyOf(BuildExmip1Mtx()) ;
OSIUNITTEST_ASSERT_ERROR(exmip1Mtx.isEquivalent(*smP), {}, "cbc", "getMatrixByRow") ;
#endif // OSICBC_TEST_MTX_STRUCTURE
}
// Test adding several cuts, and handling of a coefficient of infinity
// in the constraint matrix.
{
OsiCbcSolverInterface fim;
std::string fn = mpsDir+"exmip1";
fim.readMps(fn.c_str(),"mps");
// exmip1.mps has 2 integer variables with index 2 & 3
fim.initialSolve();
OsiRowCut cuts[3];
// Generate one ineffective cut plus two trivial cuts
int c;
int nc = fim.getNumCols();
int *inx = new int[nc];
for (c=0;c<nc;c++) inx[c]=c;
double *el = new double[nc];
for (c=0;c<nc;c++) el[c]=1.0e-50+((double)c)*((double)c);
cuts[0].setRow(nc,inx,el);
cuts[0].setLb(-100.);
cuts[0].setUb(500.);
cuts[0].setEffectiveness(22);
el[4]=0.0; // to get inf later
for (c=2;c<4;c++) {
el[0]=1.0;
inx[0]=c;
cuts[c-1].setRow(1,inx,el);
cuts[c-1].setLb(1.);
cuts[c-1].setUb(100.);
cuts[c-1].setEffectiveness(c);
}
fim.writeMps("x1.mps");
fim.applyRowCuts(3,cuts);
fim.writeMps("x2.mps");
// resolve - should get message about zero elements
fim.resolve();
fim.writeMps("x3.mps");
// check integer solution
const double * cs = fim.getColSolution();
CoinRelFltEq eq;
OSIUNITTEST_ASSERT_ERROR(eq(cs[2], 1.0), {}, "cbc", "add cuts");
OSIUNITTEST_ASSERT_ERROR(eq(cs[3], 1.0), {}, "cbc", "add cuts");
// check will find invalid matrix
el[0]=1.0/el[4];
inx[0]=0;
cuts[0].setRow(nc,inx,el);
cuts[0].setLb(-100.);
cuts[0].setUb(500.);
cuts[0].setEffectiveness(22);
fim.applyRowCut(cuts[0]);
// resolve - should get message about zero elements
示例9: cgC
//--------------------------------------------------------------------------
// test the simple rounding cut generators methods.
void
CglSimpleRoundingUnitTest(
const OsiSolverInterface * baseSiP,
const std::string mpsDir )
{
// Test default constructor
{
CglSimpleRounding cg;
}
// Test copy & assignment
{
CglSimpleRounding rhs;
{
CglSimpleRounding cg;
CglSimpleRounding cgC(cg);
rhs=cg;
}
}
// Test gcd and gcdn
{
CglSimpleRounding cg;
int v = cg.gcd(122,356);
assert(v==2);
v=cg.gcd(356,122);
assert(v==2);
v=cg.gcd(54,67);
assert(v==1);
v=cg.gcd(67,54);
assert(v==1);
v=cg.gcd(485,485);
assert(v==485);
v=cg.gcd(17*13,17*23);
assert( v==17);
v=cg.gcd(17*13*5,17*23);
assert( v==17);
v=cg.gcd(17*13*23,17*23);
assert(v==17*23);
int a[4] = {12, 20, 32, 400};
v= cg.gcdv(4,a);
assert(v== 4);
int b[4] = {782, 4692, 51, 2754};
v= cg.gcdv(4,b);
assert(v== 17);
int c[4] = {50, 40, 30, 10};
v= cg.gcdv(4,c);
assert(v== 10);
}
// Test generate cuts method on exmip1.5.mps
{
CglSimpleRounding cg;
OsiSolverInterface * siP = baseSiP->clone();
std::string fn = mpsDir+"exmip1.5.mps";
siP->readMps(fn.c_str(),"");
OsiCuts cuts;
cg.generateCuts(*siP,cuts);
// there should be 3 cuts
int nRowCuts = cuts.sizeRowCuts();
assert(nRowCuts==3);
// get the last "sr"=simple rounding cut that was derived
OsiRowCut srRowCut2 = cuts.rowCut(2);
CoinPackedVector srRowCutPV2 = srRowCut2.row();
// this is what the last cut should look like: i.e. the "solution"
const int solSize = 2;
int solCols[solSize]={2,3};
double solCoefs[solSize]={5.0, 4.0};
OsiRowCut solRowCut;
solRowCut.setRow(solSize,solCols,solCoefs);
solRowCut.setLb(-COIN_DBL_MAX);
solRowCut.setUb(2.0);
// Test for equality between the derived cut and the solution cut
// Note: testing two OsiRowCuts are equal invokes testing two
// CoinPackedVectors are equal which invokes testing two doubles
// are equal. Usually not a good idea to test that two doubles are equal,
// but in this cut the "doubles" represent integer values. Also allow that
// different solvers have different orderings in packed vectors, which may
// not match the ordering defined for solRowCut.
assert(srRowCut2.OsiCut::operator==(solRowCut)) ;
assert(srRowCut2.row().isEquivalent(solRowCut.row())) ;
assert(srRowCut2.lb() == solRowCut.lb()) ;
assert(srRowCut2.ub() == solRowCut.ub()) ;
delete siP;
}
// Test generate cuts method on p0033
//.........这里部分代码省略.........
示例10: if
//-------------------------------------------------------------
void
CglZeroHalf::generateCuts(const OsiSolverInterface & si, OsiCuts & cs,
const CglTreeInfo info)
{
if (mnz_) {
int cnum=0,cnzcnt=0;
int *cbeg=NULL, *ccnt=NULL,*cind=NULL,*cval=NULL,*crhs=NULL;
char *csense=NULL;
const double * solution = si.getColSolution();
if ((flags_&1)==0) {
// redo bounds
const double * columnLower = si.getColLower();
const double * columnUpper = si.getColUpper();
int numberColumns = si.getNumCols();
for (int iColumn=0;iColumn<numberColumns;iColumn++) {
if (vlb_[iColumn]!=COIN_INT_MAX) {
int ilo,iup;
double lo = columnLower[iColumn];
if (lo<-COIN_INT_MAX)
lo=-COIN_INT_MAX;
ilo= static_cast<int> (ceil(lo));
double up = columnUpper[iColumn];
if (up>COIN_INT_MAX)
up=COIN_INT_MAX;
iup= static_cast<int> (floor(up));
vlb_[iColumn]=ilo;
vub_[iColumn]=iup;
}
}
}
if (true) {
cutInfo_.sep_012_cut(mr_,mc_,mnz_,
mtbeg_,mtcnt_, mtind_, mtval_,
vlb_, vub_,
mrhs_, msense_,
solution,
info.inTree ? false : true,
&cnum,&cnzcnt,
&cbeg,&ccnt,&cind,&cval,&crhs,&csense);
} else {
int k = 4*mr_+2*mnz_;
int * temp = new int[k];
int * mtbeg = temp;
int * mtcnt = mtbeg + mr_;
int * mtind = mtcnt+mr_;
int * mtval = mtind+mnz_;
int * mrhs = mtval+mnz_;
char * msense = reinterpret_cast<char*> (mrhs+mr_);
int i;
k=0;
int kel=0;
for (i=0;i<mr_;i++) {
int kel2=kel;
int rhs = mrhs_[i];
for (int j=mtbeg_[i];j<mtbeg_[i]+mtcnt_[i];j++) {
int iColumn=mtind_[j];
int value=mtval_[j];
if (vlb_[iColumn]<vub_[iColumn]) {
mtind[kel]=mtind_[j];
mtval[kel++]=mtval_[j];
} else {
rhs -= vlb_[iColumn]*value;
}
}
if (kel>kel2) {
mtcnt[k]=kel-kel2;
mtbeg[k]=kel2;
mrhs[k]=rhs;
msense[k++]=msense_[i];
}
}
if (kel) {
cutInfo_.sep_012_cut(k,mc_,kel,
mtbeg,mtcnt, mtind, mtval,
vlb_, vub_,
mrhs, msense,
solution,
info.inTree ? false : true,
&cnum,&cnzcnt,
&cbeg,&ccnt,&cind,&cval,&crhs,&csense);
}
delete [] temp;
}
if (cnum) {
// add cuts
double * element = new double[mc_];
for (int i=0;i<cnum;i++) {
int n = ccnt[i];
int start = cbeg[i];
for (int j=0;j<n;j++)
element[j]=cval[start+j];
OsiRowCut rc;
if (csense[i]=='L') {
rc.setLb(-COIN_DBL_MAX);
rc.setUb(crhs[i]);
} else if (csense[i]=='G') {
rc.setLb(crhs[i]);
rc.setUb(COIN_DBL_MAX);
} else {
//.........这里部分代码省略.........
示例11: generateCuts
//.........这里部分代码省略.........
slackIndex += ncol;
// compute cut coefficient
flip(rowElem, slackIndex);
cutCoeff = computeCutCoefficient(rowElem, slackIndex);
if (isZero(fabs(cutCoeff))) {
continue;
}
unflipSlack(cutCoeff, slackIndex, cutRhs, slackVal);
eliminateSlack(cutCoeff, slackIndex, cut, cutRhs,
elements, rowStart, indices, rowLength, rowRhs);
#if defined GMI_TRACE
printf("var %d, row %f, cut %f\n", slackIndex, rowElem, cutCoeff);
#endif
}
}
packRow(cut, cutElem, cutIndex, cutNz);
if (cutNz == 0)
continue;
#if defined GMI_TRACE
printvecDBL("final cut:", cutElem, cutIndex, cutNz);
printf("cutRhs: %f\n", cutRhs);
#endif
#if defined TRACK_REJECT || defined TRACK_REJECT_SIMPLE
if (trackRejection) {
numGeneratedCuts++;
}
#endif
if (cleanCut(cutElem, cutIndex, cutNz, cutRhs, xlp) && cutNz > 0) {
OsiRowCut rc;
rc.setRow(cutNz, cutIndex, cutElem);
rc.setLb(-param.getINFINIT());
rc.setUb(cutRhs);
if (!param.getCHECK_DUPLICATES()) {
cs.insert(rc);
}
else{
cs.insertIfNotDuplicate(rc, CoinAbsFltEq(param.getEPS_COEFF()));
}
}
}
#if defined GMI_TRACE
printf("CglGMI::generateCuts() : number of cuts : %d\n", cs.sizeRowCuts());
#endif
#if defined OSI_TABLEAU
solver->disableFactorization();
delete[] basicVars;
delete[] tableauColPart;
delete[] tableauRowPart;
#endif
delete[] colBasisIndex;
delete[] rowBasisIndex;
delete[] cut;
delete[] slackVal;
delete[] cutElem;
delete[] cutIndex;
delete[] listFracBasic;
delete[] cstat;
delete[] rstat;
delete[] isInteger;
示例12: OsiSpxSolverInterfaceUnitTest
//.........这里部分代码省略.........
OSIUNITTEST_ASSERT_ERROR(eq(ev[12], 1.0), {}, "SoPlex", "matrix by row: elements");
OSIUNITTEST_ASSERT_ERROR(eq(ev[13], 1.9), {}, "SoPlex", "matrix by row: elements");
const CoinBigIndex * mi = siC1mbr->getVectorStarts();
OSIUNITTEST_ASSERT_ERROR(mi[0] == 0, {}, "SoPlex", "matrix by row: vector starts");
OSIUNITTEST_ASSERT_ERROR(mi[1] == 5, {}, "SoPlex", "matrix by row: vector starts");
OSIUNITTEST_ASSERT_ERROR(mi[2] == 7, {}, "SoPlex", "matrix by row: vector starts");
OSIUNITTEST_ASSERT_ERROR(mi[3] == 9, {}, "SoPlex", "matrix by row: vector starts");
OSIUNITTEST_ASSERT_ERROR(mi[4] == 11, {}, "SoPlex", "matrix by row: vector starts");
OSIUNITTEST_ASSERT_ERROR(mi[5] == 14, {}, "SoPlex", "matrix by row: vector starts");
const int * ei = siC1mbr->getIndices();
OSIUNITTEST_ASSERT_ERROR(ei[ 0] == 0, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_ERROR(ei[ 1] == 1, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_ERROR(ei[ 2] == 3, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_ERROR(ei[ 3] == 4, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_ERROR(ei[ 4] == 7, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_ERROR(ei[ 5] == 1, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_ERROR(ei[ 6] == 2, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_ERROR(ei[ 7] == 2, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_ERROR(ei[ 8] == 5, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_ERROR(ei[ 9] == 3, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_ERROR(ei[10] == 6, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_ERROR(ei[11] == 0, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_ERROR(ei[12] == 4, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_ERROR(ei[13] == 7, {}, "SoPlex", "matrix by row: indices");
OSIUNITTEST_ASSERT_WARNING(siC1rs == siC1.getRowSense(), {}, "SoPlex", "row sense");
OSIUNITTEST_ASSERT_WARNING(siC1rhs == siC1.getRightHandSide(), {}, "SoPlex", "right hand side");
OSIUNITTEST_ASSERT_WARNING(siC1rr == siC1.getRowRange(), {}, "SoPlex", "row range");
// Change SOPLEX Model by adding free row
OsiRowCut rc;
rc.setLb(-COIN_DBL_MAX);
rc.setUb( COIN_DBL_MAX);
OsiCuts cuts;
cuts.insert(rc);
siC1.applyCuts(cuts);
// Since model was changed, test that cached data is now freed.
OSIUNITTEST_ASSERT_ERROR(siC1.rowrange_ == NULL, {}, "SoPlex", "free cached data after adding row");
OSIUNITTEST_ASSERT_ERROR(siC1.rowsense_ == NULL, {}, "SoPlex", "free cached data after adding row");
OSIUNITTEST_ASSERT_ERROR(siC1.rhs_ == NULL, {}, "SoPlex", "free cached data after adding row");
OSIUNITTEST_ASSERT_ERROR(siC1.matrixByRow_ == NULL, {}, "SoPlex", "free cached data after adding row");
OSIUNITTEST_ASSERT_ERROR(siC1.matrixByCol_ == NULL, {}, "SoPlex", "free cached data after adding row");
OSIUNITTEST_ASSERT_ERROR(siC1.colsol_ == NULL, {}, "SoPlex", "free cached data after adding row");
OSIUNITTEST_ASSERT_ERROR(siC1.rowsol_ == NULL, {}, "SoPlex", "free cached data after adding row");
siC1rs = siC1.getRowSense();
OSIUNITTEST_ASSERT_ERROR(siC1rs[0] == 'G', {}, "SoPlex", "row sense after adding row");
OSIUNITTEST_ASSERT_ERROR(siC1rs[1] == 'L', {}, "SoPlex", "row sense after adding row");
OSIUNITTEST_ASSERT_ERROR(siC1rs[2] == 'E', {}, "SoPlex", "row sense after adding row");
OSIUNITTEST_ASSERT_ERROR(siC1rs[3] == 'R', {}, "SoPlex", "row sense after adding row");
OSIUNITTEST_ASSERT_ERROR(siC1rs[4] == 'R', {}, "SoPlex", "row sense after adding row");
OSIUNITTEST_ASSERT_ERROR(siC1rs[5] == 'N', {}, "SoPlex", "row sense after adding row");
siC1rhs = siC1.getRightHandSide();
OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[0],2.5), {}, "SoPlex", "right hand side after adding row");
OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[1],2.1), {}, "SoPlex", "right hand side after adding row");
OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[2],4.0), {}, "SoPlex", "right hand side after adding row");
OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[3],5.0), {}, "SoPlex", "right hand side after adding row");
OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[4],15.), {}, "SoPlex", "right hand side after adding row");
OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[5],0.0), {}, "SoPlex", "right hand side after adding row");
siC1rr = siC1.getRowRange();
OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[0],0.0), {}, "SoPlex", "row range after adding row");
示例13: generateCuts
//.........这里部分代码省略.........
// delete column for v_0
// endFor
// clean up memory
// return 0;
int * nVectorIndices = new int[n];
CoinIotaN(nVectorIndices, n, 0);
bool haveWarmStart = false;
bool equalObj1, equalObj2;
CoinRelFltEq eq;
double v_0Elements[2] = {-1,1};
double u_0Elements[1] = {1};
CoinWarmStart * warmStart = 0;
double * ustar = new double[m];
CoinFillN(ustar, m, 0.0);
double* alpha = new double[n];
CoinFillN(alpha, n, 0.0);
for (j=0;j<n;j++){
if (!si.isBinary(j)) continue; // Better to ask coneSi? No!
// coneSi has no binInfo.
equalObj1=eq(x[j],0);
equalObj2=eq(x[j],1);
if (equalObj1 || equalObj2) continue;
// IMPROVEME: if (haveWarmStart) check if j attractive;
// AskLL:wanted to declare u_0 and v_0 packedVec outside loop
// and setIndices, but didn't see a method to do that(?)
// (Could "insert". Seems inefficient)
int v_0Indices[2]={j,nPlus1};
int u_0Indices[1]={j};
//
CoinPackedVector v_0(2,v_0Indices,v_0Elements,false);
CoinPackedVector u_0(1,u_0Indices,u_0Elements,false);
#if CGL_DEBUG
const CoinPackedMatrix *see1 = coneSi->getMatrixByRow();
#endif
coneSi->addCol(v_0,-solverINFINITY,solverINFINITY,0);
coneSi->addCol(u_0,-solverINFINITY,solverINFINITY,x[j]);
if(haveWarmStart) {
coneSi->setWarmStart(warmStart);
coneSi->resolve();
}
else {
#if CGL_DEBUG
const CoinPackedMatrix *see2 = coneSi->getMatrixByRow();
#endif
coneSi->initialSolve();
}
if(coneSi->isProvenOptimal()){
warmStart = coneSi->getWarmStart();
haveWarmStart=true;
const double * wstar = coneSi->getColSolution();
CoinDisjointCopyN(wstar, m, ustar);
Atilde->transposeTimes(ustar,alpha);
alpha[j]+=wstar[BNumCols-1];
#if debug
int p;
double sum;
for(p=0;p<n;p++)sum+=alpha[p]*x[p];
if (sum<=beta_){
throw CoinError("Cut not violated",
"cutGeneration",
"CglLiftAndProject");
}
#endif
// add <alpha^T,x> >= beta_ to cutset
OsiRowCut rc;
rc.setRow(n,nVectorIndices,alpha);
rc.setLb(beta_);
rc.setUb(solverINFINITY);
cs.insert(rc);
}
// delete col for u_o and v_0
coneSi->deleteCols(2,delCols);
// clean up memory
}
// clean up
delete [] alpha;
delete [] ustar;
delete [] nVectorIndices;
// BMatrix, BColLowers,BColUppers, BObjective, BRowLowers, BRowUppers
// are all freed by OsiSolverInterface destructor (?)
delete [] BLengths;
delete [] BStarts;
delete [] BIndices;
delete [] BElements;
}
示例14: if
//.........这里部分代码省略.........
int n = vec->getNumElements();
/** First compute violation if it is too small exit */
double violation = aCut.violated(solCut);
if (violation < minViolation_)
return 1;
/** Now relax get dynamic and remove tiny elements */
int offset = 0;
rhs -= 1e-8;
double smallest = 1e100;
double biggest = 0;
for (int i = 0 ; i < n ; i++)
{
double val = fabs(elems[i]);
if (val <= par.getEPS()) //try to remove coef
{
if (val>0 && val<1e-20)
{
offset++;
continue;
throw;
}
if (val==0)
{
offset++;
continue;
}
int & iCol = indices[i];
if (elems[i]>0. && colUpper[iCol] < 10000.)
{
offset++;
rhs -= elems[i] * colUpper[iCol];
elems[i]=0;
}
else if (elems[i]<0. && colLower[iCol] > -10000.)
{
offset++;
rhs -= elems[i] * colLower[iCol];
elems[i]=0.;
}
else
{
#ifdef DEBUG
std::cout<<"Small coefficient : "<<elems[i]<<" bounds : ["<<colLower[iCol]<<", "<<colUpper[iCol]<<std::endl;
#endif
numRejected_[SmallCoefficient]++;
return SmallCoefficient;
}
}
else //Not a small coefficient keep it
{
smallest = std::min(val,smallest);
biggest = std::max (val,biggest);
if (biggest > maxRatio_ * smallest)
{
#ifdef DEBUG
std::cout<<"Whaooo "<<biggest/smallest<<std::endl;
#endif
numRejected_[BigDynamic]++;
return BigDynamic;
}
if (offset) //if offset is zero current values are ok otherwise translate
{
int i2 = i - offset;
indices[i2] = indices[i];
elems[i2] = elems[i];
}
}
}
if ((n - offset) > maxNnz)
{
numRejected_[DenseCut] ++;
return DenseCut;
}
if (offset == n)
{
numRejected_[EmptyCut]++;
return EmptyCut;
}
if (offset)
vec->truncate(n - offset);
indices = vec->getIndices();
elems = vec->getElements();
n = vec->getNumElements();
aCut.setLb(rhs);
violation = aCut.violated(solCut);
if (violation < minViolation_)
{
numRejected_[SmallViolation]++;
return SmallViolation;
}
return NoneAccepted;
}
示例15: eq
//.........这里部分代码省略.........
assert( cover.getElements()[1] == 120.0);
assert( remainder.getNumElements() == 1);
assert( remainder.getIndices()[0] == 2);
assert( remainder.getElements()[0] == 68.0);
// test liftCoverCut
CoinPackedVector cut;
double * rowupper = ekk_rowupper(model);
double cutRhs = cover.getNumElements() - 1.0;
kccg.liftCoverCut(b, krow.getNumElements(),
cover, remainder,
cut);
assert ( cut.getNumElements() == 3 );
assert ( cut.getIndices()[0] == 0 );
assert ( cut.getIndices()[1] == 1 );
assert ( cut.getIndices()[2] == 2 );
assert( cut.getElements()[0] == 1 );
assert( cut.getElements()[1] == 1 );
assert( eq(cut.getElements()[2], 0.087719) );
// test liftAndUncomplementAndAdd
OsiCuts cuts;
kccg.liftAndUncomplementAndAdd(*siP.getRowUpper()[0],krow,b,complement,0,
cover,remainder,cuts);
int sizerowcuts = cuts.sizeRowCuts();
assert ( sizerowcuts== 1 );
OsiRowCut testRowCut = cuts.rowCut(0);
CoinPackedVector testRowPV = testRowCut.row();
OsiRowCut sampleRowCut;
const int sampleSize = 3;
int sampleCols[sampleSize]={0,1,2};
double sampleElems[sampleSize]={1.0,-1.0,-0.087719};
sampleRowCut.setRow(sampleSize,sampleCols,sampleElems);
sampleRowCut.setLb(-DBL_MAX);
sampleRowCut.setUb(-0.087719);
bool equiv = testRowPV.equivalent(sampleRowCut.row(),CoinRelFltEq(1.0e-05) );
assert ( equiv );
#endif
// test find PseudoJohnAndEllisCover
cover.setVector(0,NULL, NULL);
remainder.setVector(0,NULL,NULL);
rind = ( siP->getRowSense()[0] == 'N' ) ? 1 : 0;
int findPJE = kccg.findPseudoJohnAndEllisCover( rind, krow,
b, xstar, cover, remainder );
assert( findPJE == 1 );
assert ( cover.getIndices()[0] == 0 );
assert ( cover.getIndices()[1] == 2 );
assert ( cover.getElements()[0] == 161 );
assert ( cover.getElements()[1] == 68 );
assert ( remainder.getIndices()[0] == 1 );
assert ( remainder.getElements()[0] == 120 );
OsiCuts cuts;
kccg.liftAndUncomplementAndAdd((*siP).getRowUpper()[rind],krow,b, complement, rind,
cover,remainder,cuts);
assert (cuts.sizeRowCuts() == 1 );
OsiRowCut testRowCut = cuts.rowCut(0);
CoinPackedVector testRowPV = testRowCut.row();
const int sampleSize = 3;
int sampleCols[sampleSize]={0,1,2};
double sampleElems[sampleSize]={1.0, -1.0, -1.0};
OsiRowCut sampleRowCut;