Changeset 753


Ignore:
Timestamp:
Aug 15, 2007 11:29:58 AM (12 years ago)
Author:
forrest
Message:

dj fixing and fpump changes

Location:
trunk/Cbc/src
Files:
3 edited

Legend:

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

    r750 r753  
    189189    return 0;
    190190  // probably a good idea
    191   if (model_->getSolutionCount()) return 0;
     191  //if (model_->getSolutionCount()) return 0;
    192192  // loop round doing repeated pumps
    193193  double cutoff;
     
    255255  }
    256256  double time1 = CoinCpuTime();
     257  model_->solver()->resolve();
     258  if (cutoff<1.0e50&&false) {
     259    // Fix on djs
     260    double direction = model_->solver()->getObjSense() ;
     261    double gap = cutoff - model_->solver()->getObjValue()*direction ;
     262    double tolerance;
     263    model_->solver()->getDblParam(OsiDualTolerance,tolerance) ;
     264    if (gap>0.0) {
     265      gap += 100.0*tolerance;
     266      model_->solver()->reducedCostFix(gap);
     267    }
     268  }
     269  CoinWarmStartBasis saveBasis;
     270  CoinWarmStartBasis * basis =
     271    dynamic_cast<CoinWarmStartBasis *>(model_->solver()->getWarmStart()) ;
     272  if (basis) {
     273    saveBasis = * basis;
     274    delete basis;
     275  }
     276  double continuousObjectiveValue = model_->solver()->getObjValue()*model_->solver()->getObjSense();
     277  double * firstPerturbedObjective = NULL;
     278  double * firstPerturbedSolution = NULL;
     279  assert (model_->solver()->isProvenOptimal());
    257280  if (when_>=11&&when_<=15) {
    258281    fixInternal = when_ >11&&when_<15;
     
    266289    usedColumn = new char [numberColumns];
    267290    memset(usedColumn,0,numberColumns);
    268     model_->solver()->resolve();
    269     assert (model_->solver()->isProvenOptimal());
    270291    lastSolution = CoinCopyOfArray(model_->solver()->getColSolution(),numberColumns);
    271292  }
     
    281302    // Clone solver - otherwise annoys root node computations
    282303    OsiSolverInterface * solver = model_->solver()->clone();
     304    if (CoinMin(fakeCutoff_,cutoff)<1.0e50) {
     305      // Fix on djs
     306      double direction = solver->getObjSense() ;
     307      double gap = CoinMin(fakeCutoff_,cutoff) - solver->getObjValue()*direction ;
     308      double tolerance;
     309      solver->getDblParam(OsiDualTolerance,tolerance) ;
     310      if (gap>0.0) {
     311        gap += 100.0*tolerance;
     312        solver->reducedCostFix(gap);
     313      }
     314    }
    283315    // if cutoff exists then add constraint
    284316    bool useCutoff = (fabs(cutoff)<1.0e20&&(fakeCutoff_!=COIN_DBL_MAX||numberTries>1));
     
    300332        }
    301333      }
    302       solver->addRow(nel,which,els,-COIN_DBL_MAX,cutoff);
     334      double offset;
     335      solver->getDblParam(OsiObjOffset,offset);
     336#ifdef COIN_DEVELOP
     337      if (offset)
     338        printf("CbcHeuristicFPump obj offset %g\n",offset);
     339#endif
     340      solver->addRow(nel,which,els,-COIN_DBL_MAX,cutoff+offset);
    303341      delete [] which;
    304342      delete [] els;
     
    379417      memcpy(newSolution,solution,numberColumns*sizeof(double));
    380418      int flip;
     419      if (numberPasses==0&&false) {
     420        // always use same seed
     421        CoinSeedRandom(987654321);
     422      }
    381423      returnCode = rounds(solver, newSolution,saveObjective,numberIntegers,integerVariable,
    382424                          pumpPrint,numberPasses,roundExpensive_,defaultRounding_,&flip);
     425      if (numberPasses==0&&false) {
     426        // Make sure random will be different
     427        for (i=1;i<numberTries;i++)
     428          CoinDrand48();
     429      }
    383430      numberPasses++;
    384431      if (returnCode) {
     
    503550            randomX[i] = max(0.0,CoinDrand48()-0.3);
    504551          for (int k=0;k<10;k++) {
    505 #ifdef COIN_DEVELOP
     552#ifdef COIN_DEVELOP_x
    506553            printf("kpass %d\n",k);
    507554#endif
     
    519566              if (numberX[9]<=200)
    520567                break; // not very many changes
    521               target=CoinMax(200.0,0.05*numberX[9]);
     568              target=CoinMax(200.0,CoinMin(0.05*numberX[9],1000.0));
    522569            }
    523570            int iX=-1;
    524571            int iBand=-1;
    525572            for (i=0;i<10;i++) {
    526 #ifdef COIN_DEVELOP
     573#ifdef COIN_DEVELOP_x
    527574              printf("** %d changed at %g\n",numberX[i],factorX[i]);
    528575#endif
     
    691738          if (numberPerturbed>numberColumns)
    692739            solver->setHintParam(OsiDoDualInResolve,true); // dual may be better
     740          if (numberTries>1&&numberPasses==1&&false) {
     741            // use basis from first time
     742            solver->setWarmStart(&saveBasis);
     743            // and objective
     744            solver->setObjective(firstPerturbedObjective);
     745            // and solution
     746            solver->setColSolution(firstPerturbedSolution);
     747          }
    693748          solver->resolve();
     749          if (numberTries==1&&numberPasses==1&&false) {
     750            // save basis
     751            CoinWarmStartBasis * basis =
     752              dynamic_cast<CoinWarmStartBasis *>(solver->getWarmStart()) ;
     753            if (basis) {
     754              saveBasis = * basis;
     755              delete basis;
     756            }
     757            firstPerturbedObjective = CoinCopyOfArray(solver->getObjCoefficients(),numberColumns);
     758            firstPerturbedSolution = CoinCopyOfArray(solver->getColSolution(),numberColumns);
     759          }
    694760          solver->setHintParam(OsiDoDualInResolve,takeHint);
    695761#ifdef COIN_DEVELOP
    696           printf("took %d iterations\n",solver->getIterationCount());
     762          {
     763            double newSolutionValue = -saveOffset;
     764            const double * newSolution = solver->getColSolution();
     765            for (  i=0 ; i<numberColumns ; i++ )
     766              newSolutionValue += saveObjective[i]*newSolution[i];
     767            newSolutionValue *= direction;
     768            printf("took %d iterations - true obj %g\n",solver->getIterationCount(),newSolutionValue);
     769          }
    697770#endif
    698771          assert (solver->isProvenOptimal());
     
    9691042    if (solutionFound) finalReturnCode=1;
    9701043    cutoff = CoinMin(cutoff,solutionValue);
    971     if (numberTries>=maximumRetries_||!solutionFound||exitAll) {
     1044    if (numberTries>=maximumRetries_||!solutionFound||exitAll||cutoff<continuousObjectiveValue+1.0e-7) {
    9721045      break;
    973     } else if (absoluteIncrement_>0.0||relativeIncrement_>0.0) {
     1046    } else {
    9741047      solutionFound=false;
    975       double gap = relativeIncrement_*fabs(solutionValue);
    976       cutoff -= CoinMax(CoinMax(gap,absoluteIncrement_),model_->getCutoffIncrement());
     1048      if (absoluteIncrement_>0.0||relativeIncrement_>0.0) {
     1049        double gap = relativeIncrement_*fabs(solutionValue);
     1050        cutoff -= CoinMax(CoinMax(gap,absoluteIncrement_),model_->getCutoffIncrement());
     1051      } else {
     1052        cutoff -= 0.1*(cutoff-continuousObjectiveValue);
     1053      }
     1054      if (cutoff<continuousObjectiveValue)
     1055        break;
    9771056      sprintf(pumpPrint+strlen(pumpPrint),"Round again with cutoff of %g",cutoff);
    9781057      model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
     
    9831062        memset(usedColumn,0,numberColumns);
    9841063      totalNumberPasses += numberPasses-1;
    985     } else {
    986       break;
    9871064    }
    9881065  }
     
    10321109  delete [] closestSolution;
    10331110  delete [] integerVariable;
     1111  delete [] firstPerturbedObjective;
     1112  delete [] firstPerturbedSolution;
    10341113  sprintf(pumpPrint,"After %.2f seconds - Feasibility pump exiting - took %.2f seconds",
    10351114          model_->getCurrentSeconds(),CoinCpuTime()-time1);
  • trunk/Cbc/src/CbcSolver.cpp

    r750 r753  
    4141#include "OsiChooseVariable.hpp"
    4242#include "OsiAuxInfo.hpp"
    43 //#define USER_HAS_FAKE_CLP
    44 //#define USER_HAS_FAKE_CBC
     43#define USER_HAS_FAKE_CLP
     44#define USER_HAS_FAKE_CBC
    4545//#define CLP_MALLOC_STATISTICS
    4646#ifdef CLP_MALLOC_STATISTICS
     
    15021502      if (i||r) {
    15031503        // also set increment
    1504         double increment = (0.01*i+0.005)*(fabs(value)+1.0e-12);
     1504        //double increment = (0.01*i+0.005)*(fabs(value)+1.0e-12);
     1505        double increment = 0.0;
    15051506        double dextra2 = parameters[whichParam(DEXTRA2,numberParameters,parameters)].doubleValue();
    15061507        if (dextra2)
     
    15591560  if (type==2&&anyToDo) {
    15601561    // Do heuristics
     1562#if 1
    15611563    // clean copy
    15621564    CbcModel model2(*model);
     
    15811583      model->setNumberHeuristicSolutions(1);
    15821584    }
     1585#else
     1586    if (logLevel<=1)
     1587      model->solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
     1588    OsiBabSolver defaultC;
     1589    //solver_->setAuxiliaryInfo(&defaultC);
     1590    model->passInSolverCharacteristics(&defaultC);
     1591    // Save bounds
     1592    int numberColumns = model->solver()->getNumCols();
     1593    model->createContinuousSolver();
     1594    bool cleanModel = !model->numberIntegers()&&!model->numberObjects();
     1595    model->findIntegers(false);
     1596    model->doHeuristicsAtRoot(true);
     1597    if (cleanModel)
     1598      model->zapIntegerInformation(false);
     1599#endif
    15831600    return 0;
    15841601  } else {
     
    20812098          }
    20822099#endif
     2100          lpSolver = clpSolver->getModelPtr();
    20832101          if (!lpSolver->integerInformation()&&!numberSOS&&
    20842102              !clpSolver->numberSOS()&&!model.numberObjects()&&!clpSolver->numberObjects())
     
    22152233              case DJFIX:
    22162234                djFix=value;
    2217                 preSolve=5;
    2218                 defaultSettings=false; // user knows what she is doing
     2235                if (goodModel&&djFix<1.0e20) {
     2236                  // do some fixing
     2237                  clpSolver = dynamic_cast< OsiClpSolverInterface*> (model.solver());
     2238                  clpSolver->initialSolve();
     2239                  lpSolver = clpSolver->getModelPtr();
     2240                  int numberColumns = lpSolver->numberColumns();
     2241                  int i;
     2242                  const char * type = lpSolver->integerInformation();
     2243                  double * lower = lpSolver->columnLower();
     2244                  double * upper = lpSolver->columnUpper();
     2245                  double * solution = lpSolver->primalColumnSolution();
     2246                  double * dj = lpSolver->dualColumnSolution();
     2247                  int numberFixed=0;
     2248                  double dextra4 = parameters[whichParam(DEXTRA4,numberParameters,parameters)].doubleValue();
     2249                  if (dextra4)
     2250                    printf("Multiple for continuous dj fixing is %g\n",dextra4);
     2251                  for (i=0;i<numberColumns;i++) {
     2252                    double djValue = dj[i];
     2253                    if (!type[i])
     2254                      djValue *= dextra4;
     2255                    if (type[i]||dextra4) {
     2256                      double value = solution[i];
     2257                      if (value<lower[i]+1.0e-5&&djValue>djFix) {
     2258                        solution[i]=lower[i];
     2259                        upper[i]=lower[i];
     2260                        numberFixed++;
     2261                      } else if (value>upper[i]-1.0e-5&&djValue<-djFix) {
     2262                        solution[i]=upper[i];
     2263                        lower[i]=upper[i];
     2264                        numberFixed++;
     2265                      }
     2266                    }
     2267                  }
     2268                  sprintf(generalPrint,"%d columns fixed\n",numberFixed);
     2269                  generalMessageHandler->message(CLP_GENERAL,generalMessages)
     2270                    << generalPrint
     2271                    <<CoinMessageEol;
     2272                }
    22192273                break;
    22202274              case GAPRATIO:
     
    33523406                  }
    33533407                }
    3354                 if (djFix<1.0e20) {
    3355                   // do some fixing
    3356                   int numberColumns = modelC->numberColumns();
    3357                   int i;
    3358                   const char * type = modelC->integerInformation();
    3359                   double * lower = modelC->columnLower();
    3360                   double * upper = modelC->columnUpper();
    3361                   double * solution = modelC->primalColumnSolution();
    3362                   double * dj = modelC->dualColumnSolution();
    3363                   int numberFixed=0;
    3364                   for (i=0;i<numberColumns;i++) {
    3365                     if (type[i]) {
    3366                       double value = solution[i];
    3367                       if (value<lower[i]+1.0e-5&&dj[i]>djFix) {
    3368                         solution[i]=lower[i];
    3369                         upper[i]=lower[i];
    3370                         numberFixed++;
    3371                       } else if (value>upper[i]-1.0e-5&&dj[i]<-djFix) {
    3372                         solution[i]=upper[i];
    3373                         lower[i]=upper[i];
    3374                         numberFixed++;
    3375                       }
    3376                     }
    3377                   }
    3378                   sprintf(generalPrint,"%d columns fixed\n",numberFixed);
    3379                   generalMessageHandler->message(CLP_GENERAL,generalMessages)
    3380                     << generalPrint
    3381                     <<CoinMessageEol;
    3382                 }
    3383               }
     3408              }
    33843409              // See if we want preprocessing
    33853410              OsiSolverInterface * saveSolver=NULL;
     
    50055030                int iStat2 = babModel->secondaryStatus();
    50065031                if (!noPrinting) {
    5007                   sprintf(generalPrint,"Result - %s%s objective %.16g after %d nodes and %d iterations - took %.2f seconds",
     5032                  sprintf(generalPrint,"Result - %s%s objective %.16g after %d nodes and %d iterations - took %.2f seconds (total time %.2f)",
    50085033                          statusName[iStat].c_str(),minor[iStat2].c_str(),
    50095034                          babModel->getObjValue(),babModel->getNodeCount(),
    5010                           babModel->getIterationCount(),time2-time1);
     5035                          babModel->getIterationCount(),time2-time1,time2-time0);
    50115036                  generalMessageHandler->message(CLP_GENERAL,generalMessages)
    50125037                    << generalPrint
  • trunk/Cbc/src/CoinSolve.cpp

    r720 r753  
    160160//#############################################################################
    161161// To use USERCBC or USERCLP change 0 to 1 in defines and add in your fake main program(s) and any other code
    162 //#define USER_HAS_FAKE_CBC
    163 //#define USER_HAS_FAKE_CLP
     162#define USER_HAS_FAKE_CBC
     163#define USER_HAS_FAKE_CLP
    164164#ifdef USER_HAS_FAKE_CBC
    165165#endif
Note: See TracChangeset for help on using the changeset viewer.