Ignore:
Timestamp:
Aug 21, 2009 12:19:13 PM (10 years ago)
Author:
forrest
Message:

fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/src/CbcHeuristic.cpp

    r1211 r1212  
    11821182  model_->setSpecialOptions(saveModelOptions);
    11831183  model_->setLogLevel(logLevel);
     1184  if (returnCode==1||returnCode==2) {
     1185    OsiSolverInterface * solverC = model_->continuousSolver();
     1186    if (false&&solverC) {
     1187      const double * lower = solver->getColLower();
     1188      const double * upper = solver->getColUpper();
     1189      const double * lowerC = solverC->getColLower();
     1190      const double * upperC = solverC->getColUpper();
     1191      bool good=true;
     1192      for (int iColumn=0;iColumn<numberColumns;iColumn++) {
     1193        if (solverC->isInteger(iColumn)) {
     1194          if (lower[iColumn]>lowerC[iColumn]&&
     1195              upper[iColumn]<upperC[iColumn]) {
     1196            good=false;
     1197            printf("CUT - can't add\n");
     1198            break;
     1199          }
     1200        }
     1201      }
     1202      if (good) {
     1203        double * cut = new double [numberColumns];
     1204        int * which = new int [numberColumns];
     1205        double rhs=-1.0;
     1206        int n=0;
     1207        for (int iColumn=0;iColumn<numberColumns;iColumn++) {
     1208          if (solverC->isInteger(iColumn)) {
     1209            if (lower[iColumn]==upperC[iColumn]) {
     1210              rhs += lower[iColumn];
     1211              cut[n]=1.0;
     1212              which[n++]=iColumn;
     1213            } else if (upper[iColumn]==lowerC[iColumn]) {
     1214              rhs -= upper[iColumn];
     1215              cut[n]=-1.0;
     1216              which[n++]=iColumn;
     1217            }
     1218          }
     1219        }
     1220        printf("CUT has %d entries\n",n);
     1221        OsiRowCut newCut;
     1222        newCut.setLb(-COIN_DBL_MAX);
     1223        newCut.setUb(rhs);
     1224        newCut.setRow(n,which,cut,false);
     1225        model_->makeGlobalCut(newCut);
     1226        delete [] cut;
     1227        delete [] which;
     1228      }
     1229    }
     1230#ifdef COIN_DEVELOP
     1231    if (status==1)
     1232      printf("heuristic could add cut because infeasible (%s)\n",heuristicName_.c_str());
     1233    else if (status==2)
     1234      printf("heuristic could add cut because optimal (%s)\n",heuristicName_.c_str());
     1235#endif
     1236  }
    11841237  if (reset) {
    11851238    for (int iColumn=0;iColumn<numberColumns;iColumn++) {
     
    11911244#ifdef HISTORY_STATISTICS
    11921245  getHistoryStatistics_=true;
    1193 #endif
    1194 #ifdef COIN_DEVELOP
    1195   if (returnCode==1||returnCode==2) {
    1196     if (status==1)
    1197       printf("heuristic could add cut because infeasible (%s)\n",heuristicName_.c_str());
    1198     else if (status==2)
    1199       printf("heuristic could add cut because optimal (%s)\n",heuristicName_.c_str());
    1200   }
    12011246#endif
    12021247  solver->setHintParam(OsiDoReducePrint,takeHint,strength);
     
    14641509  // Get a copy of original matrix (and by row for rounding);
    14651510  assert(model.solver());
    1466   matrix_ = *model.solver()->getMatrixByCol();
    1467   matrixByRow_ = *model.solver()->getMatrixByRow();
    1468   validate();
     1511  if (model.solver()->getNumRows()) {
     1512    matrix_ = *model.solver()->getMatrixByCol();
     1513    matrixByRow_ = *model.solver()->getMatrixByRow();
     1514    validate();
     1515  }
    14691516  seed_=1;
    14701517}
     
    23122359  // Get a copy of original matrix (and by row for rounding);
    23132360  assert(model_->solver());
    2314   matrix_ = *model_->solver()->getMatrixByCol();
    2315   matrixByRow_ = *model_->solver()->getMatrixByRow();
    2316   // make sure model okay for heuristic
    2317   validate();
     2361  if (model_->solver()->getNumRows()) {
     2362    matrix_ = *model_->solver()->getMatrixByCol();
     2363    matrixByRow_ = *model_->solver()->getMatrixByRow();
     2364    // make sure model okay for heuristic
     2365    validate();
     2366  }
    23182367}
    23192368// Validate model i.e. sets when_ to 0 if necessary (may be NULL)
Note: See TracChangeset for help on using the changeset viewer.