Ignore:
Timestamp:
Oct 8, 2007 8:19:01 AM (13 years ago)
Author:
forrest
Message:

fixes for bonmin and other stuff

File:
1 edited

Legend:

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

    r809 r819  
    1111#include <cstring>
    1212#include <iostream>
    13 
    1413
    1514#include "CoinPragma.hpp"
     
    449448#endif
    450449  // Set up likely cut generators and defaults
    451   parameters_[whichParam(PREPROCESS,numberParameters_,parameters_)].setCurrentOption("on");
     450  parameters_[whichParam(PREPROCESS,numberParameters_,parameters_)].setCurrentOption("sos");
    452451  parameters_[whichParam(MIPOPTIONS,numberParameters_,parameters_)].setIntValue(128|64|1);
    453452  parameters_[whichParam(MIPOPTIONS,numberParameters_,parameters_)].setIntValue(1);
     
    731730  return new CbcStopNow(*this);
    732731}
    733 //#define NEW_STYLE_SOLVER
     732#define NEW_STYLE_SOLVER
    734733//#undef COIN_HAS_ASL
    735734#ifdef COIN_HAS_ASL
     
    11471146  doAction - 0 just fix in original and return NULL
    11481147             1 return fixed non-presolved solver
    1149              2 return fixed presolved solver
     1148             2 as one but use presolve Inside this
    11501149             3 do heuristics and set best solution
    11511150             4 do BAB and just set best solution
     
    11601159  if (doAction==11&&!lastSolution)
    11611160    lastSolution = model.bestSolution();
    1162   assert ((doAction==1&&!lastSolution)||(doAction==11&&lastSolution));
     1161  assert (((doAction==1||doAction==2)&&!lastSolution)||(doAction==11&&lastSolution));
    11631162  double fractionIntFixed = dextra[3];
    11641163  double fractionFixed = dextra[4];
    11651164  double time1 = CoinCpuTime();
    1166   OsiClpSolverInterface * originalClpSolver = dynamic_cast< OsiClpSolverInterface*> (model.solver());
     1165  OsiSolverInterface * originalSolver = model.solver();
     1166  OsiClpSolverInterface * originalClpSolver = dynamic_cast< OsiClpSolverInterface*> (originalSolver);
    11671167  ClpSimplex * originalLpSolver = originalClpSolver->getModelPtr();
    1168   OsiSolverInterface * solver = model.solver()->clone();
    1169   OsiClpSolverInterface * clpSolver = dynamic_cast< OsiClpSolverInterface*> (solver);
    1170   ClpSimplex * lpSolver = clpSolver->getModelPtr();
     1168  int * originalColumns=NULL;
     1169  OsiClpSolverInterface * clpSolver;
     1170  ClpSimplex * lpSolver;
     1171  ClpPresolve pinfo;
     1172  if (doAction==2) {
     1173    doAction=1;
     1174    lpSolver = pinfo.presolvedModel(*originalLpSolver,1.0e-8,false,10);
     1175    assert (lpSolver);
     1176    clpSolver = new OsiClpSolverInterface(lpSolver,true);
     1177    assert(lpSolver == clpSolver->getModelPtr());
     1178    //int numberColumns = lpSolver->numberColumns();
     1179    int numberColumns = lpSolver->numberColumns();
     1180    originalColumns = CoinCopyOfArray(pinfo.originalColumns(),numberColumns);
     1181  } else {
     1182    OsiSolverInterface * solver = originalSolver->clone();
     1183    clpSolver = dynamic_cast< OsiClpSolverInterface*> (solver);
     1184    lpSolver = clpSolver->getModelPtr();
     1185  }
    11711186  // Tighten bounds
    11721187  lpSolver->tightenPrimalBounds(0.0,11,true);
     1188  int numberColumns = clpSolver->getNumCols() ;
     1189  double * saveColumnLower = CoinCopyOfArray(lpSolver->columnLower(),numberColumns);
     1190  double * saveColumnUpper = CoinCopyOfArray(lpSolver->columnUpper(),numberColumns);
    11731191  //char generalPrint[200];
    11741192  const double *objective = lpSolver->getObjCoefficients() ;
    11751193  double *columnLower = lpSolver->columnLower() ;
    11761194  double *columnUpper = lpSolver->columnUpper() ;
    1177   int numberColumns = solver->getNumCols() ;
    1178   int numberRows = solver->getNumRows();
     1195  int numberRows = clpSolver->getNumRows();
    11791196  int iRow,iColumn;
    11801197
    11811198  // Row copy
    1182   CoinPackedMatrix matrixByRow(*solver->getMatrixByRow());
     1199  CoinPackedMatrix matrixByRow(*clpSolver->getMatrixByRow());
    11831200  const double * elementByRow = matrixByRow.getElements();
    11841201  const int * column = matrixByRow.getIndices();
     
    11871204
    11881205  // Column copy
    1189   CoinPackedMatrix  matrixByCol(*solver->getMatrixByCol());
     1206  CoinPackedMatrix  matrixByCol(*clpSolver->getMatrixByCol());
    11901207  //const double * element = matrixByCol.getElements();
    11911208  const int * row = matrixByCol.getIndices();
     
    11931210  const int * columnLength = matrixByCol.getVectorLengths();
    11941211
    1195   const double * rowLower = solver->getRowLower();
    1196   const double * rowUpper = solver->getRowUpper();
     1212  const double * rowLower = clpSolver->getRowLower();
     1213  const double * rowUpper = clpSolver->getRowUpper();
    11971214
    11981215  // Get maximum size of VUB tree
     
    12491266    fix[iColumn]=-1;
    12501267    if (columnUpper[iColumn] > columnLower[iColumn]+1.0e-8) {
    1251       if (solver->isInteger(iColumn))
     1268      if (clpSolver->isInteger(iColumn))
    12521269        numberInteger++;
    12531270      if (columnLower[iColumn]==0.0) {
     
    13791396                      }
    13801397                    }
    1381                     if (!newBound||(solver->isInteger(kColumn)&&newBound<0.999)) {
     1398                    if (!newBound||(clpSolver->isInteger(kColumn)&&newBound<0.999)) {
    13821399                      // fix to zero
    13831400                      if (!mark[kColumn]) {
     
    14221439                      }
    14231440                    }
    1424                     if (!newBound||(solver->isInteger(kColumn)&&newBound<0.999)) {
     1441                    if (!newBound||(clpSolver->isInteger(kColumn)&&newBound<0.999)) {
    14251442                      // fix to zero
    14261443                      if (!mark[kColumn]) {
     
    14701487          mark[otherColumn[i]]=0;
    14711488        // reset bound unless infeasible
    1472         if (!infeasible||!solver->isInteger(iColumn))
     1489        if (!infeasible||!clpSolver->isInteger(iColumn))
    14731490          columnUpper[iColumn]=saveUpper;
    1474         else if (solver->isInteger(iColumn))
     1491        else if (clpSolver->isInteger(iColumn))
    14751492          columnLower[iColumn]=1.0;
    14761493      }
     
    15491566            for (int i=fixColumn[iColumn];i<fixColumn[iColumn+1];i++) {
    15501567              int jColumn=otherColumn[i];
    1551               if (solver->isInteger(jColumn))
     1568              if (clpSolver->isInteger(jColumn))
    15521569                nFix++;
    15531570            }
     
    15591576          }
    15601577          assert (iFix<nCheck);
    1561           if (solver->isInteger(iColumn)) {
     1578          if (clpSolver->isInteger(iColumn)) {
    15621579            numberInteger++;
    15631580            countsI[iFix]++;
     
    16481665          double * columnUpper = lpSolver->columnUpper();
    16491666          //      lpSolver->dual();
    1650           memcpy(columnLower,originalLpSolver->columnLower(),numberColumns*sizeof(double));
    1651           memcpy(columnUpper,originalLpSolver->columnUpper(),numberColumns*sizeof(double));
     1667          memcpy(columnLower,saveColumnLower,numberColumns*sizeof(double));
     1668          memcpy(columnUpper,saveColumnUpper,numberColumns*sizeof(double));
    16521669          //      lpSolver->dual();
    16531670          int iColumn;
    16541671          for (iColumn=0;iColumn<numberColumns;iColumn++) {
    16551672            if (columnUpper[iColumn] > columnLower[iColumn]+1.0e-8) {
    1656               if (solver->isInteger(iColumn)) {
     1673              if (clpSolver->isInteger(iColumn)) {
    16571674                double value = lastSolution[iColumn];
    16581675                int iValue = (int) (value+0.5);
     
    16661683          }
    16671684          lpSolver->initialSolve(solveOptions);
    1668           memcpy(columnLower,originalLpSolver->columnLower(),numberColumns*sizeof(double));
    1669           memcpy(columnUpper,originalLpSolver->columnUpper(),numberColumns*sizeof(double));
     1685          memcpy(columnLower,saveColumnLower,numberColumns*sizeof(double));
     1686          memcpy(columnUpper,saveColumnUpper,numberColumns*sizeof(double));
    16701687        }
    16711688        for (iColumn=0;iColumn<numberColumns;iColumn++) {
    16721689          if (columnUpper[iColumn] > columnLower[iColumn]+1.0e-8) {
    1673             if (solver->isInteger(iColumn)) {
     1690            if (clpSolver->isInteger(iColumn)) {
    16741691              double value = lastSolution[iColumn];
    16751692              int iValue = (int) (value+0.5);
     
    17341751      }
    17351752      for ( iColumn=0;iColumn<numberColumns;iColumn++) {
    1736         if (!solver->isInteger(iColumn)||fix[iColumn]>kLayer)
     1753        if (!clpSolver->isInteger(iColumn)||fix[iColumn]>kLayer)
    17371754          continue;
    17381755        // skip if fixes nothing
     
    18581875        columnUpper = models[kPass].columnUpper();
    18591876        columnLower[iSmallest]=1.0;
    1860         columnUpper[iSmallest]=originalLpSolver->columnUpper()[iSmallest];
     1877        columnUpper[iSmallest]=saveColumnUpper[iSmallest];
    18611878        *lpSolver=models[kPass];
    18621879        columnLower = lpSolver->columnLower();
     
    18651882        dj = lpSolver->dualColumnSolution();
    18661883        columnLower[iSmallest]=1.0;
    1867         columnUpper[iSmallest]=originalLpSolver->columnUpper()[iSmallest];
     1884        columnUpper[iSmallest]=saveColumnUpper[iSmallest];
    18681885        state[iSmallest]=1;
    18691886        // unfix others
     
    18711888          int jColumn=otherColumn[i];
    18721889          if (state[jColumn]==3) {
    1873             columnUpper[jColumn]=originalLpSolver->columnUpper()[jColumn];
     1890            columnUpper[jColumn]=saveColumnUpper[jColumn];
    18741891            state[jColumn]=-1;
    18751892          }
     
    19001917      double sum1=0.0;
    19011918      for ( iColumn=0;iColumn<numberColumns;iColumn++) {
    1902         if (!solver->isInteger(iColumn)||fix[iColumn]>kLayer)
     1919        if (!clpSolver->isInteger(iColumn)||fix[iColumn]>kLayer)
    19031920          continue;
    19041921        // skip if fixes nothing
    19051922        if (fixColumn[iColumn+1]-fixColumn[iColumn]==0&&doAction<10)
    19061923          continue;
    1907         double value = fullSolution[iColumn];
    19081924        double djValue = dj[iColumn];
    19091925        if (state[iColumn]==1) {
    19101926          assert (columnLower[iColumn]);
    1911           assert (value>0.1);
     1927          assert (fullSolution[iColumn]>0.1);
    19121928          if (djValue>0.0) {
    19131929            //printf("YY dj of %d at %g is %g\n",iColumn,value,djValue);
     
    19191935          }
    19201936        } else if (state[iColumn]==0||state[iColumn]==10) {
    1921           assert (value<0.1);
     1937          assert (fullSolution[iColumn]<0.1);
    19221938          assert (!columnUpper[iColumn]);
    19231939          double otherValue=0.0;
     
    19511967      }
    19521968      CoinSort_2(dsort,dsort+n,sort);
    1953       double * originalColumnLower = originalLpSolver->columnLower();
    1954       double * originalColumnUpper = originalLpSolver->columnUpper();
     1969      double * originalColumnLower = saveColumnLower;
     1970      double * originalColumnUpper = saveColumnUpper;
    19551971      double * lo = CoinCopyOfArray(columnLower,numberColumns);
    19561972      double * up = CoinCopyOfArray(columnUpper,numberColumns);
     
    20282044      for ( iColumn=0;iColumn<numberColumns;iColumn++) {
    20292045        if (columnLower[iColumn]==columnUpper[iColumn]) {
    2030           if (solver->isInteger(iColumn))
     2046          if (clpSolver->isInteger(iColumn))
    20312047            nFixedI++;
    20322048          nFixed++;
     
    20702086  delete [] otherColumn2;
    20712087  delete [] fixColumn2;
    2072   // Basis
    2073   memcpy(originalLpSolver->statusArray(),lpSolver->statusArray(),numberRows+numberColumns);
    2074   memcpy(originalLpSolver->primalColumnSolution(),lpSolver->primalColumnSolution(),numberColumns*sizeof(double));
    2075   memcpy(originalLpSolver->primalRowSolution(),lpSolver->primalRowSolution(),numberRows*sizeof(double));
    2076   // Fix in solver
    2077   columnLower = lpSolver->columnLower();
    2078   columnUpper = lpSolver->columnUpper();
     2088  // See if was presolved
     2089  if (originalColumns) {
     2090    for ( iColumn=0;iColumn<numberColumns;iColumn++) {
     2091      saveColumnLower[iColumn] = columnLower[iColumn];
     2092      saveColumnUpper[iColumn] = columnUpper[iColumn];
     2093    }
     2094    pinfo.postsolve(true);
     2095    columnLower = originalLpSolver->columnLower();
     2096    columnUpper = originalLpSolver->columnUpper();
     2097    double * newColumnLower = lpSolver->columnLower();
     2098    double * newColumnUpper = lpSolver->columnUpper();
     2099    for (iColumn=0;iColumn<numberColumns;iColumn++) {
     2100      int jColumn = originalColumns[iColumn];
     2101      columnLower[jColumn] = CoinMax(columnLower[jColumn],newColumnLower[iColumn]);
     2102      columnUpper[jColumn] = CoinMin(columnUpper[jColumn],newColumnUpper[iColumn]);
     2103    }
     2104    numberColumns = originalLpSolver->numberColumns();
     2105    delete [] originalColumns;
     2106  }
     2107  delete [] saveColumnLower;
     2108  delete [] saveColumnUpper;
     2109  if (!originalColumns) {
     2110    // Basis
     2111    memcpy(originalLpSolver->statusArray(),lpSolver->statusArray(),numberRows+numberColumns);
     2112    memcpy(originalLpSolver->primalColumnSolution(),lpSolver->primalColumnSolution(),numberColumns*sizeof(double));
     2113    memcpy(originalLpSolver->primalRowSolution(),lpSolver->primalRowSolution(),numberRows*sizeof(double));
     2114    // Fix in solver
     2115    columnLower = lpSolver->columnLower();
     2116    columnUpper = lpSolver->columnUpper();
     2117  }
    20792118  double * originalColumnLower = originalLpSolver->columnLower();
    20802119  double * originalColumnUpper = originalLpSolver->columnUpper();
     
    20882127  }
    20892128  printf("%d fixed by vub preprocessing\n",doAction);
    2090   delete solver;
     2129  if (originalColumns) {
     2130    originalLpSolver->initialSolve();
     2131  }
     2132  delete clpSolver;
    20912133  return NULL;
    20922134}
     
    30313073#endif
    30323074  // Set up likely cut generators and defaults
    3033   parameters[whichParam(PREPROCESS,numberParameters,parameters)].setCurrentOption("on");
     3075  parameters[whichParam(PREPROCESS,numberParameters,parameters)].setCurrentOption("sos");
    30343076  parameters[whichParam(MIPOPTIONS,numberParameters,parameters)].setIntValue(128|64|1);
    30353077  parameters[whichParam(MIPOPTIONS,numberParameters,parameters)].setIntValue(1);
     
    34953537        }
    34963538      }
    3497       int returnCode = readAmpl(&info,argc,const_cast<char **>(argv),(void **) (& coinModel));
     3539
     3540      union { void * voidModel; CoinModel * model; } coinModelStart;
     3541      coinModelStart.model=NULL;
     3542      int returnCode = readAmpl(&info,argc, const_cast<char **>(argv),& coinModelStart.voidModel);
     3543      coinModel=coinModelStart.model;
    34983544      if (returnCode)
    34993545        return returnCode;
     
    36673713    int doVector=0;
    36683714    int doSprint=-1;
    3669     int doScaling=1;
     3715    int doScaling=4;
    36703716    // set reasonable defaults
    36713717    int preSolve=5;
    3672     int preProcess=1;
     3718    int preProcess=4;
    36733719    bool useStrategy=false;
    36743720    bool preSolveFile=false;
     
    37293775    CglProbing probingGen;
    37303776    probingGen.setUsingObjective(1);
    3731     probingGen.setMaxPass(3);
    3732     probingGen.setMaxPassRoot(3);
     3777    probingGen.setMaxPass(1);
     3778    probingGen.setMaxPassRoot(1);
    37333779    // Number of unsatisfied variables to look at
    37343780    probingGen.setMaxProbe(10);
     
    42094255              lpSolver->scaling(action);
    42104256              solver->setHintParam(OsiDoScale,action!=0,OsiHintTry);
    4211               doScaling = 1-action;
     4257              doScaling = action;
    42124258              break;
    42134259            case AUTOSCALE:
     
    49134959                if (!dextra[3])
    49144960                  dextra[3] = 0.97;
    4915                 OsiClpSolverInterface * newSolver = fixVubs(model_,extra3,vubAction,generalMessageHandler,
    4916                                                             debugValues,dextra);
    4917                 assert (!newSolver);
     4961                //OsiClpSolverInterface * newSolver =
     4962                fixVubs(model_,extra3,vubAction,generalMessageHandler,
     4963                        debugValues,dextra);
     4964                //assert (!newSolver);
    49184965              }
    49194966              // Actually do heuristics
     
    50005047                  dynamic_cast<OsiClpSolverInterface *>(solver) ;
    50015048                assert (si != NULL);
     5049                si->getModelPtr()->scaling(doScaling);
    50025050                // See if quadratic
    50035051#ifdef COIN_HAS_LINK
     
    54565504                  CglProbing generator1;
    54575505                  generator1.setUsingObjective(1);
    5458                   generator1.setMaxPass(3);
     5506                  generator1.setMaxPass(1);
     5507                  generator1.setMaxPassRoot(1);
    54595508                  generator1.setMaxProbeRoot(saveSolver->getNumCols());
    54605509                  generator1.setMaxElements(100);
     
    60756124                    int numberColumns = babModel_->getNumCols();
    60766125                    // backward pointer to new variables
    6077                     int * newColumn = new int[numberOriginalColumns];
     6126                    // extend arrays in case SOS
     6127                    assert (originalColumns);
     6128                    int n = originalColumns[numberColumns-1]+1;
     6129                    int * newColumn = new int[CoinMax(n,numberColumns)];
    60786130                    int i;
    60796131                    for (i=0;i<numberOriginalColumns;i++)
    60806132                      newColumn[i]=-1;
    6081                     assert (originalColumns);
    60826133                    for (i=0;i<numberColumns;i++)
    60836134                      newColumn[originalColumns[i]]=i;
     
    69336984                CbcStrategyDefault strategy(true,babModel_->numberStrong(),babModel_->numberBeforeTrust());
    69346985                // Set up pre-processing
    6935                 int translate2[]={9999,1,1,3,2,4,5};
     6986                int translate2[]={9999,1,1,3,2,4,5,6,6};
    69366987                if (preProcess)
    6937                   strategy.setupPreProcessing(translate2[preProcess]);
     6988                  strategy.setupPreProcessing(translate2[ preProcess ]);
    69386989                babModel_->setStrategy(strategy);
    69396990#ifdef CBC_THREAD
Note: See TracChangeset for help on using the changeset viewer.