Ignore:
Timestamp:
Nov 5, 2009 10:57:25 AM (10 years ago)
Author:
forrest
Message:

Creating new stable branch 2.4 from trunk (rev 1270)

Location:
stable/2.4
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable/2.4

    • Property svn:externals
      •  

        old new  
        77CoinUtils         https://projects.coin-or.org/svn/CoinUtils/stable/2.5/CoinUtils
        88Cgl               https://projects.coin-or.org/svn/Cgl/stable/0.54/Cgl
        9 Clp               https://projects.coin-or.org/svn/Clp/stable/1.10/Clp
         9Clp               https://projects.coin-or.org/svn/Clp/stable/1.11/Clp
        1010Osi               https://projects.coin-or.org/svn/Osi/stable/0.100/Osi
        1111Vol               https://projects.coin-or.org/svn/Vol/stable/1.1/Vol
  • stable/2.4/Cbc/src/CbcHeuristicFPump.cpp

    r1132 r1271  
     1/* $Id$ */
    12// Copyright (C) 2004, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    1819#include "CbcHeuristicFPump.hpp"
    1920#include "CbcBranchActual.hpp"
     21#include "CbcBranchDynamic.hpp"
    2022#include "CoinHelperFunctions.hpp"
    2123#include "CoinWarmStartBasis.hpp"
     
    3739   artificialCost_(COIN_DBL_MAX),
    3840   iterationRatio_(0.0),
     41   reducedCostMultiplier_(1.0),
    3942   maximumPasses_(100),
    4043   maximumRetries_(1),
     
    6063   artificialCost_(COIN_DBL_MAX),
    6164   iterationRatio_(0.0),
     65   reducedCostMultiplier_(1.0),
    6266   maximumPasses_(100),
    6367   maximumRetries_(1),
     
    124128  else
    125129    fprintf(fp,"4  heuristicFPump.setDefaultRounding(%g);\n",defaultRounding_);
    126   fprintf(fp,"3  cbcModel->addHeuristic(&heuristicFPump);\n");
    127130  if (initialWeight_!=other.initialWeight_)
    128131    fprintf(fp,"3  heuristicFPump.setInitialWeight(%g);\n",initialWeight_);
     
    133136  else
    134137    fprintf(fp,"4  heuristicFPump.setWeightFactor(%g);\n",weightFactor_);
     138  if (artificialCost_!=other.artificialCost_)
     139    fprintf(fp,"3  heuristicFPump.setArtificialCost(%g);\n",artificialCost_);
     140  else
     141    fprintf(fp,"4  heuristicFPump.setArtificialCost(%g);\n",artificialCost_);
     142  if (iterationRatio_!=other.iterationRatio_)
     143    fprintf(fp,"3  heuristicFPump.setIterationRatio(%g);\n",iterationRatio_);
     144  else
     145    fprintf(fp,"4  heuristicFPump.setIterationRatio(%g);\n",iterationRatio_);
     146  if (reducedCostMultiplier_!=other.reducedCostMultiplier_)
     147    fprintf(fp,"3  heuristicFPump.setReducedCostMultiplier(%g);\n",reducedCostMultiplier_);
     148  else
     149    fprintf(fp,"4  heuristicFPump.setReducedCostMultiplier(%g);\n",reducedCostMultiplier_);
     150  fprintf(fp,"3  cbcModel->addHeuristic(&heuristicFPump);\n");
    135151}
    136152
     
    149165  artificialCost_(rhs.artificialCost_),
    150166  iterationRatio_(rhs.iterationRatio_),
     167  reducedCostMultiplier_(rhs.reducedCostMultiplier_),
    151168  maximumPasses_(rhs.maximumPasses_),
    152169  maximumRetries_(rhs.maximumRetries_),
     
    173190    artificialCost_ = rhs.artificialCost_;
    174191    iterationRatio_ = rhs.iterationRatio_;
     192    reducedCostMultiplier_ = rhs.reducedCostMultiplier_;
    175193    maximumPasses_ = rhs.maximumPasses_;
    176194    maximumRetries_ = rhs.maximumRetries_;
     
    184202// Resets stuff if model changes
    185203void
    186 CbcHeuristicFPump::resetModel(CbcModel * model)
     204CbcHeuristicFPump::resetModel(CbcModel * )
    187205{
    188206}
     
    197215                         double * betterSolution)
    198216{
     217  startTime_=CoinCpuTime();
    199218  numCouldRun_++;
    200219  double incomingObjective = solutionValue;
     
    208227  int passNumber = model_->getCurrentPassNumber();
    209228  // just do once
    210   if (!atRoot||passNumber!=1)
     229  if (!atRoot)
    211230    return 0;
    212   // probably a good idea
    213   //if (model_->getSolutionCount()) return 0;
     231  int options = feasibilityPumpOptions_;
     232  if ((options%1000000)>0) {
     233    int kOption = options/1000000;
     234    options = options%1000000;
     235    /*
     236      Add 10 to do even if solution
     237      1 - do after cuts
     238      2 - do after cuts (not before)
     239      3 - not used do after every cut round (and after cuts)
     240      k not used do after every (k-2)th round
     241    */
     242    if (kOption<10&&model_->getSolutionCount())
     243      return 0;
     244    if (model_->getSolutionCount())
     245    kOption = kOption %10;
     246    bool good;
     247    if (kOption==1) {
     248      good = (passNumber==999999);
     249    } else if (kOption==2) {
     250      good = (passNumber==999999);
     251      passNumber=2; // so won't run before
     252      //} else if (kOption==3) {
     253      //good = true;
     254    } else {
     255      //good = (((passNumber-1)%(kOption-2))==0);
     256      good = false;
     257    }
     258    if (passNumber!=1&&!good)
     259      return 0;
     260  } else {
     261    if (passNumber!=1)
     262      return 0;
     263  }
    214264  // loop round doing repeated pumps
    215265  double cutoff;
     
    230280      iterationRatio_;
    231281  int totalNumberIterations=0;
    232   int numberIterationsPass1=-1;
     282  int averageIterationsPerTry=-1;
    233283  int numberIterationsLastPass=0;
    234284  // 1. initially check 0-1
     
    279329  int * closestSolution = general ? NULL : new int[numberIntegers];
    280330  double closestObjectiveValue = COIN_DBL_MAX;
    281  
     331
    282332  int numberIntegersOrig = numberIntegers;
    283333  numberIntegers = j;
     
    323373  double * firstPerturbedObjective = NULL;
    324374  double * firstPerturbedSolution = NULL;
     375  double firstPerturbedValue=COIN_DBL_MAX;
    325376  if (when_>=11&&when_<=15) {
    326377    fixInternal = when_ >11&&when_<15;
     
    344395  CoinWarmStartBasis bestBasis;
    345396  bool exitAll=false;
    346   double saveBestObjective = model_->getMinimizationObjValue();
     397  //double saveBestObjective = model_->getMinimizationObjValue();
    347398  int numberSolutions=0;
    348399  OsiSolverInterface * solver = NULL;
     
    354405  int dualPass = 0;
    355406  int secondPassOpt=0;
    356   if (feasibilityPumpOptions_>0) {
    357     secondPassOpt = (feasibilityPumpOptions_/10)%10;
     407#define RAND_RAND
     408#ifdef RAND_RAND
     409  int offRandom=0;
     410#endif
     411  int maximumAllowed=-1;
     412  bool moreIterations=false;
     413  if (options>0) {
     414    if (options>=1000)
     415      maximumAllowed = options/1000;
     416    int options2 = (options%1000)/100;
     417#ifdef RAND_RAND
     418    offRandom=options2&1;
     419#endif
     420    moreIterations = (options2&2)!=0;
     421    secondPassOpt = (options/10)%10;
    358422    /* 1 to 7 - re-use solution
    359423       8 use dual and current solution(ish)
     
    369433    }
    370434  }
     435  // Number of passes to do
     436  int maximumPasses=maximumPasses_;
     437#ifdef COIN_HAS_CLP
     438  if (maximumPasses==30) {
     439    OsiClpSolverInterface * clpSolver
     440      = dynamic_cast<OsiClpSolverInterface *> (model_->solver());
     441    if (clpSolver&&clpSolver->fakeObjective())
     442      maximumPasses=100; // feasibility problem?
     443  }
     444#endif
     445#ifdef RAND_RAND
     446  double * randomFactor = new double [numberColumns];
     447  for (int i=0;i<numberColumns;i++) {
     448    double value = floor(1.0e3*randomNumberGenerator_.randomDouble());
     449    randomFactor[i] = 1.0+value*1.0e-4;
     450  }
     451#endif
    371452  // guess exact multiple of objective
    372453  double exactMultiple = model_->getCutoffIncrement();
     
    383464  //printf("exact multiple %g\n",exactMultiple);
    384465  // Clone solver for rounding
    385   OsiSolverInterface * clonedSolver = model_->solver()->clone();
     466  OsiSolverInterface * clonedSolver = cloneBut(2); // wasmodel_->solver()->clone();
    386467  while (!exitAll) {
    387468    // Cutoff rhs
     
    394475    numberTries++;
    395476    // Clone solver - otherwise annoys root node computations
    396     solver = model_->solver()->clone();
     477    solver = cloneBut(2); // was model_->solver()->clone();
    397478#ifdef COIN_HAS_CLP
    398479    {
     
    405486        lp->setSpecialOptions(options|8192);
    406487        //lp->setSpecialOptions(options|0x01000000);
     488#ifdef CLP_INVESTIGATE
     489        clpSolver->setHintParam(OsiDoReducePrint,false,OsiHintTry);
     490        lp->setLogLevel(CoinMax(1,lp->logLevel()));
     491#endif
    407492      }
    408493    }
     
    416501      if (gap>0.0&&(fixOnReducedCosts_==1||(numberTries==1&&fixOnReducedCosts_==2))) {
    417502        gap += 100.0*tolerance;
     503        gap *= reducedCostMultiplier_;
    418504        int nFix=solver->reducedCostFix(gap);
    419505        if (nFix) {
     
    490576    solver->getDblParam(OsiPrimalTolerance,primalTolerance);
    491577   
    492    
    493578    // 2 space for last rounded solutions
    494579#define NUMBER_OLD 4
     
    534619    if (scaleFactor)
    535620      scaleFactor = (initialWeight_*sqrt(static_cast<double> (numberIntegers)))/sqrt(scaleFactor);
     621#ifdef CLP_INVESTIGATE
    536622#ifdef COIN_DEVELOP
     623    if (scaleFactor||nArtificial)
     624      printf("Using %g fraction of original objective (decay %g) - largest %g - %d artificials\n",scaleFactor,weightFactor_,
     625             largestCost,nArtificial);
     626#else
    537627    if (scaleFactor)
    538       printf("Using %g fraction of original objective - largest %g - %d artificials\n",scaleFactor,
    539              largestCost,nArtificial);
     628      printf("Using %g fraction of original objective (decay %g)\n",
     629             scaleFactor,weightFactor_);
     630#endif
    540631#endif
    541632    // This is an array of sums of infeasibilities so can see if "bobbling"
     
    552643      int newNumberInfeas=0;
    553644      returnCode=0;
    554       if (model_->getCurrentSeconds()>model_->getMaximumSeconds()) {
     645      if (model_->maximumSecondsReached()) {
    555646        exitAll=true;
    556647        break;
     
    564655        }
    565656      }
    566       if (numberIterationsPass1>=0) {
     657      if (averageIterationsPerTry>=0) {
    567658        int n = totalNumberIterations - numberIterationsLastPass;
    568         if (n>CoinMax(15000,3*numberIterationsPass1)
    569             &&(switches_&2)==0&&maximumPasses_<200) {
     659        double perPass = totalNumberIterations/
     660          (totalNumberPasses+numberPasses+1.0e-5);
     661        perPass /= (solver->getNumRows()+numberColumns);
     662        double test = moreIterations ? 0.3 : 0.05;
     663        if (n>CoinMax(20000,3*averageIterationsPerTry)
     664            &&(switches_&2)==0&&maximumPasses<200&&perPass>test) {
    570665          exitAll=true;
    571666        }
    572667      }
    573668      // Exit on exact total number if maximumPasses large
    574       if ((maximumPasses_>=200||(switches_&2)!=0)
     669      if ((maximumPasses>=200||(switches_&2)!=0)
    575670          &&numberPasses+totalNumberPasses>=
    576           maximumPasses_)
     671          maximumPasses)
    577672        exitAll=true;
    578673      bool exitThis=false;
    579674      if (iterationLimit<0.0) {
    580         if (numberPasses>=maximumPasses_) {
    581           // If going well then keep going if maximumPasses_ small
     675        if (numberPasses>=maximumPasses) {
     676          // If going well then keep going if maximumPasses small
    582677          if (lastMove<numberPasses-4||lastMove==1000000)
    583678            exitThis=true;
    584           if (maximumPasses_>20||numberPasses>=40)
     679          if (maximumPasses>20||numberPasses>=40)
    585680            exitThis=true;
    586681        }
     
    590685          // exiting on iteration count
    591686        exitAll=true;
    592       } else if (maximumPasses_<30&&numberPasses>100) {
     687      } else if (maximumPasses<30&&numberPasses>100) {
    593688        // too many passes anyway
    594689        exitAll=true;
    595690      }
    596       if (maximumTime_>0.0&&CoinCpuTime()>=startTime_+maximumTime_)
     691      if (maximumTime_>0.0&&CoinCpuTime()>=startTime_+maximumTime_) {
    597692        exitAll=true;
     693        // force exit
     694        switches_ |= 2048;
     695      }
    598696      if (exitAll||exitThis)
    599697        break;
     
    604702        randomNumberGenerator_.setSeed(987654321);
    605703      }
    606       returnCode = rounds(solver, newSolution,saveObjective,numberIntegers,integerVariable,
    607                           pumpPrint,numberPasses,roundExpensive_,defaultRounding_,&flip);
     704      returnCode = rounds(solver, newSolution,/*saveObjective,*/
     705                          numberIntegers,integerVariable,
     706                          /*pumpPrint,*/numberPasses,
     707                          /*roundExpensive_,*/defaultRounding_,&flip);
    608708      if (numberPasses==0&&false) {
    609709        // Make sure random will be different
     
    677777              bestBasis = * basis;
    678778              delete basis;
    679               CbcEventHandler * handler = model_->getEventHandler();
    680               if (handler) {
     779              int action = model_->dealWithEventHandler(CbcEventHandler::heuristicSolution,newSolutionValue,betterSolution);
     780              if (action==0) {
    681781                double * saveOldSolution = CoinCopyOfArray(model_->bestSolution(),numberColumns);
    682782                double saveObjectiveValue = model_->getMinimizationObjValue();
    683783                model_->setBestSolution(betterSolution,numberColumns,newSolutionValue);
    684                 int action = handler->event(CbcEventHandler::heuristicSolution);
    685784                if (saveOldSolution&&saveObjectiveValue<model_->getMinimizationObjValue())
    686785                  model_->setBestSolution(saveOldSolution,numberColumns,saveObjectiveValue);
    687786                delete [] saveOldSolution;
    688                 if (!action||model_->getCurrentSeconds()>model_->getMaximumSeconds()) {
    689                   exitAll=true; // exit
    690                   break;
    691                 }
     787              }
     788              if (action==0||model_->maximumSecondsReached()) {
     789                exitAll=true; // exit
     790                break;
    692791              }
    693792            }
     
    850949            }
    851950          }
    852           if (newValue!=oldObjective[iColumn])
     951#ifdef RAND_RAND
     952          if (!offRandom)
     953            newValue *= randomFactor[iColumn];
     954#endif
     955          if (newValue!=oldObjective[iColumn]) {
    853956            numberChanged++;
     957          }
    854958          solver->setObjCoeff(iColumn,newValue);
    855959          offset += costValue*newSolution[iColumn];
     
    888992          memcpy(newSolution,solution,numberColumns*sizeof(double));
    889993          int flip;
    890           returnCode = rounds(solver, newSolution,saveObjective,numberIntegers,integerVariable,
    891                               pumpPrint,numberPasses,roundExpensive_,defaultRounding_,&flip);
     994          returnCode = rounds(solver, newSolution,/*saveObjective,*/
     995                              numberIntegers,integerVariable,
     996                              /*pumpPrint,*/numberPasses,
     997                              /*roundExpensive_,*/defaultRounding_,&flip);
    892998          numberPasses++;
    893999          if (returnCode) {
     
    9121018                bestBasis = * basis;
    9131019                delete basis;
    914                 CbcEventHandler * handler = model_->getEventHandler();
    915                 if (handler) {
     1020                int action = model_->dealWithEventHandler(CbcEventHandler::heuristicSolution,newSolutionValue,betterSolution);
     1021                if (!action) {
    9161022                  double * saveOldSolution = CoinCopyOfArray(model_->bestSolution(),numberColumns);
    9171023                  double saveObjectiveValue = model_->getMinimizationObjValue();
    9181024                  model_->setBestSolution(betterSolution,numberColumns,newSolutionValue);
    919                   int action = handler->event(CbcEventHandler::heuristicSolution);
    9201025                  if (saveOldSolution&&saveObjectiveValue<model_->getMinimizationObjValue())
    9211026                    model_->setBestSolution(saveOldSolution,numberColumns,saveObjectiveValue);
    9221027                  delete [] saveOldSolution;
    923                   if (!action||model_->getCurrentSeconds()>model_->getMaximumSeconds()) {
    924                     exitAll=true; // exit
    925                     break;
    926                   }
     1028                }
     1029                if (!action||model_->maximumSecondsReached()) {
     1030                  exitAll=true; // exit
     1031                  break;
    9271032                }
    9281033              }
     
    9531058          OsiHintStrength strength;
    9541059          solver->getHintParam(OsiDoDualInResolve,takeHint,strength);
    955           if (dualPass) {
     1060          if (dualPass&&numberChanged>2) {
    9561061            solver->setHintParam(OsiDoDualInResolve,true); // dual may be better
    957             if (dualPass==1) {
     1062            if (dualPass==1&&2*numberChanged<numberColumns&&
     1063                (numberChanged<5000||6*numberChanged<numberColumns)) {
    9581064              // but we need to make infeasible
    9591065              CoinWarmStartBasis * basis =
     
    9691075                for (i=0;i<numberIntegersOrig;i++) {
    9701076                  int iColumn=integerVariableOrig[i];
     1077#ifdef RAND_RAND
     1078                  if (nChanged>numberChanged)
     1079                    break;
     1080#endif
    9711081                  if (objective[iColumn]>0.0) {
    9721082                    if (basis->getStructStatus(iColumn)==
     
    9781088                  } else if (objective[iColumn]<0.0) {
    9791089                    if (basis->getStructStatus(iColumn)==
    980                         CoinWarmStartBasis::atUpperBound) {
     1090                        CoinWarmStartBasis::atLowerBound) {
    9811091                      solution[iColumn]=upper[iColumn];
    9821092                      basis->setStructStatus(iColumn,CoinWarmStartBasis::atUpperBound);
     
    10251135            // and solution
    10261136            solver->setColSolution(firstPerturbedSolution);
    1027             if (secondPassOpt==2||secondPassOpt==5)
     1137            //if (secondPassOpt==2||secondPassOpt==5||
     1138            if(firstPerturbedValue>cutoff)
    10281139              solver->setHintParam(OsiDoDualInResolve,true); // dual may be better
    10291140          }
     
    10331144            exitAll=true;
    10341145            break;
    1035           }
    1036           if (numberPasses==1&&secondPassOpt) {
    1037             if (numberTries==1||secondPassOpt>3) {
    1038               // save basis
    1039               CoinWarmStartBasis * basis =
    1040                 dynamic_cast<CoinWarmStartBasis *>(solver->getWarmStart()) ;
    1041               if (basis) {
    1042                 saveBasis = * basis;
    1043                 delete basis;
    1044               }
    1045               delete [] firstPerturbedObjective;
    1046               delete [] firstPerturbedSolution;
    1047               firstPerturbedObjective = CoinCopyOfArray(solver->getObjCoefficients(),numberColumns);
    1048               firstPerturbedSolution = CoinCopyOfArray(solver->getColSolution(),numberColumns);
    1049             }
    10501146          }
    10511147          solver->setHintParam(OsiDoDualInResolve,takeHint);
     
    10661162            }
    10671163            newTrueSolutionValue *= direction;
     1164            if (numberPasses==1&&secondPassOpt) {
     1165              if (numberTries==1||secondPassOpt>3) {
     1166                // save basis
     1167                CoinWarmStartBasis * basis =
     1168                  dynamic_cast<CoinWarmStartBasis *>(solver->getWarmStart()) ;
     1169                if (basis) {
     1170                  saveBasis = * basis;
     1171                  delete basis;
     1172                }
     1173                delete [] firstPerturbedObjective;
     1174                delete [] firstPerturbedSolution;
     1175                firstPerturbedObjective = CoinCopyOfArray(solver->getObjCoefficients(),numberColumns);
     1176                firstPerturbedSolution = CoinCopyOfArray(solver->getColSolution(),numberColumns);
     1177                firstPerturbedValue=newTrueSolutionValue;
     1178              }
     1179            }
    10681180            if (newNumberInfeas&&newNumberInfeas<15) {
    10691181#if 0
     
    12131325#endif
    12141326              //roundingObjective = newSolutionValue;
    1215             } else {
    1216               //  roundingObjective = COIN_DBL_MAX;
     1327              //} else {
     1328              //roundingObjective = COIN_DBL_MAX;
    12171329            }
    12181330            model_->swapSolver(saveSolver);
     
    14621574    // see if rounding worked!
    14631575    if (roundingObjective<solutionValue) {
    1464       sprintf(pumpPrint,"Rounding solution of %g is better than previous of %g !\n",
    1465               roundingObjective,solutionValue);
    1466       model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
    1467         << pumpPrint
    1468         <<CoinMessageEol;
     1576      if (roundingObjective<solutionValue-1.0e-6*fabs(roundingObjective)) {
     1577        sprintf(pumpPrint,"Rounding solution of %g is better than previous of %g\n",
     1578                roundingObjective,solutionValue);
     1579        model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
     1580          << pumpPrint
     1581          <<CoinMessageEol;
     1582      }
    14691583      solutionValue=roundingObjective;
    14701584      newSolutionValue = solutionValue;
     
    14881602    delete [] saveObjective;
    14891603    if (usedColumn&&!exitAll) {
    1490       OsiSolverInterface * newSolver = model_->continuousSolver()->clone();
     1604      OsiSolverInterface * newSolver = cloneBut(3); // was model_->continuousSolver()->clone();
    14911605      const double * colLower = newSolver->getColLower();
    14921606      const double * colUpper = newSolver->getColUpper();
    14931607      bool stopBAB=false;
    14941608      int allowedPass=-1;
     1609      if (maximumAllowed>0)
     1610        allowedPass=CoinMax(numberPasses-maximumAllowed,-1);
    14951611      while (!stopBAB) {
    14961612        stopBAB=true;
     
    16131729        if (returnCode&&true) {
    16141730          delete newSolver;
    1615           newSolver = model_->continuousSolver()->clone();
     1731          newSolver = cloneBut(3); // was model_->continuousSolver()->clone();
    16161732          newSolutionValue = -saveOffset;
    16171733          double newSumInfeas=0.0;
     
    16381754          if (fixContinuous&&nFixC+nFixC2>0) {
    16391755            // may be able to do even better
     1756            int nFixed=0;
    16401757            const double * lower = model_->solver()->getColLower();
    16411758            const double * upper = model_->solver()->getColUpper();
    16421759            for (int iColumn=0;iColumn<numberColumns;iColumn++) {
     1760              double value = newSolution[iColumn];
    16431761              if (newSolver->isInteger(iColumn)) {
    1644                 double value=floor(newSolution[iColumn]+0.5);
     1762                value=floor(newSolution[iColumn]+0.5);
    16451763                newSolver->setColLower(iColumn,value);
    16461764                newSolver->setColUpper(iColumn,value);
     1765                nFixed++;
    16471766              } else {
    16481767                newSolver->setColLower(iColumn,lower[iColumn]);
    16491768                newSolver->setColUpper(iColumn,upper[iColumn]);
    1650               }
    1651             }
     1769                if (value<lower[iColumn])
     1770                  value=lower[iColumn];
     1771                else if (value>upper[iColumn])
     1772                  value=upper[iColumn];
     1773               
     1774              }
     1775              newSolution[iColumn]=value;
     1776            }
     1777            newSolver->setColSolution(newSolution);
     1778            //#define CLP_INVESTIGATE2
     1779#ifdef CLP_INVESTIGATE2
     1780            {
     1781              // check
     1782              // get row activities
     1783              int numberRows = newSolver->getNumRows();
     1784              double * rowActivity = new double[numberRows];
     1785              memset(rowActivity,0,numberRows*sizeof(double));
     1786              newSolver->getMatrixByCol()->times(newSolution,rowActivity) ;
     1787              double largestInfeasibility =primalTolerance;
     1788              double sumInfeasibility=0.0;
     1789              int numberBadRows=0;
     1790              const double * rowLower = newSolver->getRowLower();
     1791              const double * rowUpper = newSolver->getRowUpper();
     1792              for (i=0 ; i < numberRows ; i++) {
     1793                double value;
     1794                value = rowLower[i]-rowActivity[i];
     1795                if (value>primalTolerance) {
     1796                  numberBadRows++;
     1797                  largestInfeasibility = CoinMax(largestInfeasibility,value);
     1798                  sumInfeasibility += value;
     1799                }
     1800                value = rowActivity[i]-rowUpper[i];
     1801                if (value>primalTolerance) {
     1802                  numberBadRows++;
     1803                  largestInfeasibility = CoinMax(largestInfeasibility,value);
     1804                  sumInfeasibility += value;
     1805                }
     1806              }
     1807              printf("%d bad rows, largest inf %g sum %g\n",
     1808                     numberBadRows,largestInfeasibility,sumInfeasibility);
     1809              delete [] rowActivity;
     1810            }
     1811#endif
     1812#ifdef COIN_HAS_CLP
     1813            OsiClpSolverInterface * clpSolver
     1814              = dynamic_cast<OsiClpSolverInterface *> (newSolver);
     1815            if (clpSolver) {
     1816              ClpSimplex * simplex = clpSolver->getModelPtr();
     1817              //simplex->writeBasis("test.bas",true,2);
     1818              //simplex->writeMps("test.mps",2,1);
     1819              if (nFixed*3>numberColumns*2)
     1820                simplex->allSlackBasis(); // may as well go from all slack
     1821              simplex->primal(1);
     1822              clpSolver->setWarmStart(NULL);
     1823            }
     1824#endif
    16521825            newSolver->initialSolve();
    16531826            if (newSolver->isProvenOptimal()) {
     
    17411914            bestBasis = * basis;
    17421915            delete basis;
    1743             CbcEventHandler * handler = model_->getEventHandler();
    1744             if (handler) {
     1916            int action = model_->dealWithEventHandler(CbcEventHandler::heuristicSolution,newSolutionValue,betterSolution);
     1917            if (action==0) {
    17451918              double * saveOldSolution = CoinCopyOfArray(model_->bestSolution(),numberColumns);
    17461919              double saveObjectiveValue = model_->getMinimizationObjValue();
    17471920              model_->setBestSolution(betterSolution,numberColumns,newSolutionValue);
    1748               int action = handler->event(CbcEventHandler::heuristicSolution);
    1749               //printf("cutoff %g\n",model_->getCutoff());
    17501921              if (saveOldSolution&&saveObjectiveValue<model_->getMinimizationObjValue())
    17511922                model_->setBestSolution(saveOldSolution,numberColumns,saveObjectiveValue);
    17521923              delete [] saveOldSolution;
    1753               if (!action||model_->getCurrentSeconds()>model_->getMaximumSeconds()) {
    1754                 exitAll=true; // exit
    1755                 break;
    1756               }
     1924            }
     1925            if (!action||model_->getCurrentSeconds()>model_->getMaximumSeconds()) {
     1926              exitAll=true; // exit
     1927              break;
    17571928            }
    17581929          }
     
    17691940      if (absoluteIncrement_>0.0||relativeIncrement_>0.0) {
    17701941        double gap = relativeIncrement_*fabs(solutionValue);
    1771         cutoff -= CoinMax(CoinMax(gap,absoluteIncrement_),model_->getCutoffIncrement());
     1942        double change = CoinMax(gap,absoluteIncrement_);
     1943        cutoff = CoinMin(cutoff,solutionValue-change);
    17721944      } else {
    17731945        //double weights[10]={0.1,0.1,0.2,0.2,0.2,0.3,0.3,0.3,0.4,0.5};
     
    17881960          usedColumn[i]=-1;
    17891961      }
    1790       if (!totalNumberPasses)
    1791         numberIterationsPass1 = totalNumberIterations;
     1962      averageIterationsPerTry = totalNumberIterations/numberTries;
    17921963      numberIterationsLastPass =  totalNumberIterations;
    17931964      totalNumberPasses += numberPasses-1;
    17941965    }
    17951966  }
     1967#ifdef RAND_RAND
     1968  delete [] randomFactor;
     1969#endif
    17961970  delete solver; // probably NULL but do anyway
    1797   if (!finalReturnCode&&closestSolution&&closestObjectiveValue <= 10.0&&usedColumn) {
     1971  if (!finalReturnCode&&closestSolution&&closestObjectiveValue <= 10.0&&
     1972      usedColumn&&!model_->maximumSecondsReached()) {
    17981973    // try a bit of branch and bound
    1799     OsiSolverInterface * newSolver = model_->continuousSolver()->clone();
     1974    OsiSolverInterface * newSolver = cloneBut(1); // was model_->continuousSolver()->clone();
    18001975    const double * colLower = newSolver->getColLower();
    18011976    const double * colUpper = newSolver->getColUpper();
     
    18592034  if (bestBasis.getNumStructural())
    18602035    model_->setBestSolutionBasis(bestBasis);
    1861   model_->setMinimizationObjValue(saveBestObjective);
     2036  //model_->setMinimizationObjValue(saveBestObjective);
    18622037  if ((accumulate_&1)!=0&&numberSolutions>1&&!model_->getSolutionCount()) {
    18632038    model_->setSolutionCount(1); // for local search
     
    18912066int
    18922067CbcHeuristicFPump::rounds(OsiSolverInterface * solver,double * solution,
    1893                           const double * objective,
     2068                          //const double * objective,
    18942069                          int numberIntegers, const int * integerVariable,
    1895                           char * pumpPrint, int iter,
    1896                           bool roundExpensive, double downValue, int *flip)
     2070                          /*char * pumpPrint,*/ int iter,
     2071                          /*bool roundExpensive,*/ double downValue, int *flip)
    18972072{
    18982073  double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance);
     
    19152090  const double * rowUpper = solver->getRowUpper();
    19162091  int numberRows = solver->getNumRows();
    1917   if ((iter&1)!=0) {
     2092  if (false&&(iter&1)!=0) {
    19182093    // Do set covering variables
    19192094    const CoinPackedMatrix * matrixByRow = solver->getMatrixByRow();
Note: See TracChangeset for help on using the changeset viewer.