Ignore:
Timestamp:
Sep 21, 2006 11:29:23 AM (13 years ago)
Author:
pbonami
Message:

Can add linear cut to nonlinear formulation in Ipopt

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/devel/Bonmin/src/OaInterface/IpCbcOACutGenerator.cpp

    r1 r44  
    6060  }
    6161
     62#ifdef 0
     63 //Add tight cuts at LP optimum
     64 int numberCuts = si.getNumRows() - nlp_->getNumRows();
     65 const OsiRowCut ** cuts = new const OsiRowCut*[numberCuts];
     66 int begin = nlp_->getNumRows();
     67 numberCuts = 0;
     68 int end = si.getNumRows();
     69 const double * rowLower = si.getRowLower();
     70 const double * rowUpper = si.getRowUpper();
     71 const CoinPackedMatrix * mat = si.getMatrixByRow();     
     72 const CoinBigIndex * starts = mat->getVectorStarts();
     73 const int * lengths = mat->getVectorLengths();
     74 const double * elements = mat->getElements();
     75 const int * indices = mat->getIndices();
     76 
     77 for(int i = begin ; i < end ; i++, numberCuts++)
     78 {
     79   bool nnzExists=false;
     80   for(int k = starts[i] ; k < starts[i]+lengths[i] ; k++)
     81   {
     82     if(indices[k] == nlp_->getNumCols())
     83     {
     84       nnzExists = true;
     85       char sign = (elements[k]>0.)?'+':'-';
     86       char type='<';
     87       if(rowLower[i]>-1e20) type='>';
     88       std::cout<<"Non zero with sign: "<<sign<<", type: "<<type<<std::endl;
     89     }
     90   }
     91   if(nnzExists)
     92   {
     93      numberCuts--;
     94      continue;
     95   }
     96   else
     97      std::cout<<"No nonzero element"<<std::endl;
     98   int * indsCopy = CoinCopyOfArray(&indices[starts[i]], lengths[i]);
     99   double * elemsCopy = CoinCopyOfArray(&elements[starts[i]], lengths[i]);
     100   cuts[numberCuts] = new OsiRowCut(rowLower[i], rowUpper[i], lengths[i], lengths[i],
     101                           indsCopy, elemsCopy);
     102 }
     103 nlp_->applyRowCuts(numberCuts,cuts);
     104#endif
    62105  //Now solve the NLP get the cuts, reset bounds and get out
    63106
     
    128171    }
    129172  }
     173  nlp_->deleteLastRows(numberCuts);
    130174  delete [] saveColLb;
    131175  delete [] saveColUb;
Note: See TracChangeset for help on using the changeset viewer.