Changeset 1271


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:
104 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/CbcBranchActual.cpp

    r1132 r1271  
     1/* $Id$ */
    12// Copyright (C) 2002, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    122123  delete [] type_;
    123124}
    124 
    125 // Infeasibility - large is 0.5
    126125double
    127 CbcClique::infeasibility(int & preferredWay) const
     126CbcClique::infeasibility(const OsiBranchingInformation * /*info*/,
     127                               int &preferredWay) const
    128128{
    129129  int numberUnsatis=0, numberFree=0;
     
    247247      numberNonSOSMembers_++;
    248248}
    249 
    250 
    251 // Creates a branching object
    252249CbcBranchingObject *
    253 CbcClique::createBranch(int way)
     250CbcClique::createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * /*info*/, int way)
    254251{
    255252  int numberUnsatis=0;
     
    259256  int numberFree=numberMembers_;
    260257  const int * integer = model_->integerVariable();
    261   OsiSolverInterface * solver = model_->solver();
     258  //OsiSolverInterface * solver = model_->solver();
    262259  const double * solution = model_->testSolution();
    263260  const double * lower = solver->getColLower();
     
    476473  delete [] weights_;
    477474}
    478 
    479 // Infeasibility - large is 0.5
    480475double
    481 CbcSOS::infeasibility(int & preferredWay) const
    482 {
    483   int j;
    484   int firstNonZero=-1;
    485   int lastNonZero = -1;
    486   OsiSolverInterface * solver = model_->solver();
    487   const double * solution = model_->testSolution();
    488   //const double * lower = solver->getColLower();
    489   const double * upper = solver->getColUpper();
    490   //double largestValue=0.0;
    491   double integerTolerance =
    492     model_->getDblParam(CbcModel::CbcIntegerTolerance);
    493   double weight = 0.0;
    494   double sum =0.0;
    495 
    496   // check bounds etc
    497   double lastWeight=-1.0e100;
    498   for (j=0;j<numberMembers_;j++) {
    499     int iColumn = members_[j];
    500     if (lastWeight>=weights_[j]-1.0e-7)
    501       throw CoinError("Weights too close together in SOS","infeasibility","CbcSOS");
    502     double value = CoinMax(0.0,solution[iColumn]);
    503     sum += value;
    504     if (value>integerTolerance&&upper[iColumn]) {
    505       // Possibly due to scaling a fixed variable might slip through
    506       if (value>upper[iColumn]) {
    507         value=upper[iColumn];
    508         // Could change to #ifdef CBC_DEBUG
    509 #ifndef NDEBUG
    510         if (model_->messageHandler()->logLevel()>2)
    511           printf("** Variable %d (%d) has value %g and upper bound of %g\n",
    512                  iColumn,j,value,upper[iColumn]);
    513 #endif
    514       }
    515       weight += weights_[j]*value;
    516       if (firstNonZero<0)
    517         firstNonZero=j;
    518       lastNonZero=j;
    519     }
    520   }
    521   preferredWay=1;
    522   if (lastNonZero-firstNonZero>=sosType_) {
    523     // find where to branch
    524     assert (sum>0.0);
    525     weight /= sum;
    526     //int iWhere;
    527     //for (iWhere=firstNonZero;iWhere<lastNonZero;iWhere++)
    528     //if (weight<weights_[iWhere+1])
    529     //break;
    530     // probably best to use pseudo duals
    531     double value = lastNonZero-firstNonZero+1;
    532     value *= 0.5/static_cast<double> (numberMembers_);
    533     // adjust??
    534     return value;
    535   } else {
    536     return 0.0; // satisfied
    537   }
    538 }
    539 // Infeasibility - large is 0.5
    540 double
    541 CbcSOS::infeasibility(const OsiBranchingInformation * info,
    542                       int & preferredWay) const
     476CbcSOS::infeasibility(const OsiBranchingInformation * info,
     477                               int &preferredWay) const
    543478{
    544479  int j;
     
    817752  }
    818753}
    819 
    820 
    821 // Creates a branching object
    822754CbcBranchingObject *
    823 CbcSOS::createBranch(int way)
     755CbcSOS::createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * /*info*/, int way)
    824756{
    825757  int j;
     
    827759  double integerTolerance =
    828760      model_->getDblParam(CbcModel::CbcIntegerTolerance);
    829   OsiSolverInterface * solver = model_->solver();
     761  //OsiSolverInterface * solver = model_->solver();
    830762  const double * upper = solver->getColUpper();
    831763  int firstNonFixed=-1;
     
    11511083  return obj;
    11521084}
    1153 
    1154 double
    1155 CbcSimpleInteger::infeasibility(const OsiSolverInterface * solver, const OsiBranchingInformation * info,
    1156                          int & preferredWay) const
     1085double
     1086CbcSimpleInteger::infeasibility(const OsiBranchingInformation * info,
     1087                               int &preferredWay) const
    11571088{
    11581089  double value = info->solution_[columnNumber_];
     
    11991130*/
    12001131OsiSolverBranch *
    1201 CbcSimpleInteger::solverBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info) const
     1132CbcSimpleInteger::solverBranch(OsiSolverInterface * /*solver*/,
     1133                               const OsiBranchingInformation * info) const
    12021134{
    12031135  double value = info->solution_[columnNumber_];
     
    12151147// Creates a branching object
    12161148CbcBranchingObject *
    1217 CbcSimpleInteger::createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way)
     1149CbcSimpleInteger::createCbcBranch(OsiSolverInterface * /*solver*/,
     1150                               const OsiBranchingInformation * info, int way)
    12181151{
    12191152  CbcIntegerBranchingObject * branch = new CbcIntegerBranchingObject(model_,0,-1,0.5);
     
    12741207 */
    12751208void
    1276 CbcSimpleInteger::resetSequenceEtc(int numberColumns, const int * originalColumns)
    1277 {
    1278   assert (numberColumns>0);
     1209CbcSimpleInteger::resetSequenceEtc(int /*numberColumns*/,
     1210                                   const int * originalColumns)
     1211{
     1212  //assert (numberColumns>0);
    12791213  int iColumn;
    12801214#if 0
     
    12901224  columnNumber_ = iColumn;
    12911225}
    1292 
    1293 // Infeasibility - large is 0.5
    1294 double
    1295 CbcSimpleInteger::infeasibility(int & preferredWay) const
    1296 {
    1297   OsiBranchingInformation info(model_->solver(),model_->normalSolver(),false);
    1298   return infeasibility(model_->solver(),&info,preferredWay);
    1299 }
    1300 
    13011226// This looks at solution and sets bounds to contain solution
    13021227/** More precisely: it first forces the variable within the existing
     
    13081233{
    13091234  abort();
    1310 }
    1311 CbcBranchingObject *
    1312 CbcSimpleInteger::createBranch( int way)
    1313 {
    1314   abort();
    1315   return NULL;
    13161235}
    13171236
     
    14821401  olb = model_->solver()->getColLower()[iColumn] ;
    14831402  oub = model_->solver()->getColUpper()[iColumn] ;
     1403  //#define TIGHTEN_BOUNDS
     1404#ifndef TIGHTEN_BOUNDS
    14841405#ifdef COIN_DEVELOP
    14851406  if (olb!=down_[0]||oub!=up_[1]) {
     
    14921413  }
    14931414#endif
     1415#endif
    14941416  if (way_<0) {
    14951417#ifdef CBC_DEBUG
     
    15001422           iColumn,olb,oub,down_[0],down_[1]) ; }
    15011423#endif
     1424#ifndef TIGHTEN_BOUNDS
    15021425    model_->solver()->setColLower(iColumn,down_[0]);
     1426#else
     1427    model_->solver()->setColLower(iColumn,CoinMax(down_[0],olb));
     1428#endif
    15031429    model_->solver()->setColUpper(iColumn,down_[1]);
    15041430    //#define CBC_PRINT2
     
    15451471#endif
    15461472    model_->solver()->setColLower(iColumn,up_[0]);
     1473#ifndef TIGHTEN_BOUNDS
    15471474    model_->solver()->setColUpper(iColumn,up_[1]);
     1475#else
     1476    model_->solver()->setColUpper(iColumn,CoinMin(up_[1],oub));
     1477#endif
    15481478#ifdef CBC_PRINT2
    15491479    printf("%d branching up has bounds %g %g",iColumn,up_[0],up_[1]);
     
    16041534   branchState is -1 for 'down' +1 for 'up' */
    16051535void
    1606 CbcIntegerBranchingObject::fix(OsiSolverInterface * solver,
     1536CbcIntegerBranchingObject::fix(OsiSolverInterface * /*solver*/,
    16071537                               double * lower, double * upper,
    16081538                               int branchState) const
     
    18011731}
    18021732// Useful constructor - passed and model index and pseudo costs
    1803 CbcSimpleIntegerPseudoCost::CbcSimpleIntegerPseudoCost (CbcModel * model, int dummy,int iColumn,
     1733CbcSimpleIntegerPseudoCost::CbcSimpleIntegerPseudoCost (CbcModel * model,
     1734                                                        int /*dummy*/,
     1735                                                        int iColumn,
    18041736                                                        double downPseudoCost, double upPseudoCost)
    18051737{
     
    18441776{
    18451777}
    1846 // Creates a branching object
    18471778CbcBranchingObject *
    1848 CbcSimpleIntegerPseudoCost::createBranch(int way)
    1849 {
    1850   OsiSolverInterface * solver = model_->solver();
     1779CbcSimpleIntegerPseudoCost::createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * /*info*/, int way)
     1780{
     1781  //OsiSolverInterface * solver = model_->solver();
    18511782  const double * solution = model_->testSolution();
    18521783  const double * lower = solver->getColLower();
     
    18861817  return newObject;
    18871818}
    1888 // Infeasibility - large is 0.5
    18891819double
    1890 CbcSimpleIntegerPseudoCost::infeasibility(int & preferredWay) const
     1820CbcSimpleIntegerPseudoCost::infeasibility(const OsiBranchingInformation * /*info*/,
     1821                               int &preferredWay) const
    18911822{
    18921823  OsiSolverInterface * solver = model_->solver();
     
    20091940                                                      int variable, int way,
    20101941                                                      double lowerValue,
    2011                                                       double upperValue)
     1942                                                                          double /*upperValue*/)
    20121943  :CbcIntegerBranchingObject(model,variable,way,lowerValue)
    20131944{
     
    23062237CbcRangeCompare
    23072238CbcCliqueBranchingObject::compareBranchingObject
    2308 (const CbcBranchingObject* brObj, const bool replaceIfOverlap)
     2239(const CbcBranchingObject* brObj, const bool /*replaceIfOverlap*/)
    23092240{
    23102241  const CbcCliqueBranchingObject* br =
     
    25572488CbcRangeCompare
    25582489CbcLongCliqueBranchingObject::compareBranchingObject
    2559 (const CbcBranchingObject* brObj, const bool replaceIfOverlap)
     2490(const CbcBranchingObject* brObj, const bool /*replaceIfOverlap*/)
    25602491{
    25612492  const CbcLongCliqueBranchingObject* br =
     
    27232654void
    27242655CbcSOSBranchingObject::fix(OsiSolverInterface * solver,
    2725                                double * lower, double * upper,
     2656                           double * /*lower*/, double * upper,
    27262657                               int branchState) const
    27272658{
     
    29552886int
    29562887CbcBranchDefaultDecision::betterBranch(CbcBranchingObject * thisOne,
    2957                             CbcBranchingObject * bestSoFar,
     2888                                       CbcBranchingObject * /*bestSoFar*/,
    29582889                            double changeUp, int numInfUp,
    29592890                            double changeDn, int numInfDn)
     
    35683499  return whichRow;
    35693500}
    3570 
    3571 // Infeasibility - large is 0.5
    35723501double
    3573 CbcFollowOn::infeasibility(int & preferredWay) const
     3502CbcFollowOn::infeasibility(const OsiBranchingInformation * /*info*/,
     3503                               int &preferredWay) const
    35743504{
    35753505  int otherRow=0;
     
    35873517}
    35883518
    3589 
    3590 // Creates a branching object
    35913519CbcBranchingObject *
    3592 CbcFollowOn::createBranch(int way)
     3520CbcFollowOn::createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * /*info*/, int way)
    35933521{
    35943522  int otherRow=0;
     
    36093537  const CoinBigIndex * rowStart = matrixByRow_.getVectorStarts();
    36103538  const int * rowLength = matrixByRow_.getVectorLengths();
    3611   OsiSolverInterface * solver = model_->solver();
     3539  //OsiSolverInterface * solver = model_->solver();
    36123540  const double * columnLower = solver->getColLower();
    36133541  const double * columnUpper = solver->getColUpper();
     
    37783706int
    37793707CbcFixingBranchingObject::compareOriginalObject
    3780 (const CbcBranchingObject* brObj) const
     3708(const CbcBranchingObject* /*brObj*/) const
    37813709{
    37823710  throw("must implement");
     
    37933721CbcRangeCompare
    37943722CbcFixingBranchingObject::compareBranchingObject
    3795 (const CbcBranchingObject* brObj, const bool replaceIfOverlap)
    3796 {
    3797 #ifndef NDEBUG
     3723(const CbcBranchingObject* /*brObj*/, const bool /*replaceIfOverlap*/)
     3724{
     3725#if 0 //ndef NDEBUG
    37983726  const CbcFixingBranchingObject* br =
    37993727    dynamic_cast<const CbcFixingBranchingObject*>(brObj);
     
    39333861  }
    39343862}
    3935  
    3936 // Infeasibility - large is 0.5
    39373863double
    3938 CbcNWay::infeasibility(int & preferredWay) const
     3864CbcNWay::infeasibility(const OsiBranchingInformation * /*info*/,
     3865                               int &preferredWay) const
    39393866{
    39403867  int numberUnsatis=0;
     
    40173944  }
    40183945}
    4019 
    4020 
    4021 // Creates a branching object
    40223946CbcBranchingObject *
    4023 CbcNWay::createBranch(int way)
     3947CbcNWay::createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * /*info*/, int /*way*/)
    40243948{
    40253949  int numberFree=0;
    40263950  int j;
    40273951
    4028   OsiSolverInterface * solver = model_->solver();
     3952  //OsiSolverInterface * solver = model_->solver();
    40293953  const double * solution = model_->testSolution();
    40303954  const double * lower = solver->getColLower();
     
    41894113int
    41904114CbcNWayBranchingObject::compareOriginalObject
    4191 (const CbcBranchingObject* brObj) const
     4115(const CbcBranchingObject* /*brObj*/) const
    41924116{
    41934117  throw("must implement");
     
    42044128CbcRangeCompare
    42054129CbcNWayBranchingObject::compareBranchingObject
    4206 (const CbcBranchingObject* brObj, const bool replaceIfOverlap)
     4130(const CbcBranchingObject* /*brObj*/, const bool /*replaceIfOverlap*/)
    42074131{
    42084132  throw("must implement");
     
    44664390  return *this;
    44674391}
     4392// Infeasibility - large is 0.5
     4393double
     4394CbcGeneral::infeasibility(const OsiBranchingInformation * /*info*/,
     4395                          int &/*preferredWay*/) const
     4396{
     4397  abort();
     4398  return 0.0;
     4399}
     4400CbcBranchingObject *
     4401CbcGeneral::createCbcBranch(OsiSolverInterface * /*solver*/,const OsiBranchingInformation * /*info*/, int /*way*/)
     4402{
     4403  abort();
     4404  return NULL;
     4405}
    44684406
    44694407// Default Constructor
     
    45834521// Infeasibility - large is 0.5
    45844522double
    4585 CbcGeneralDepth::infeasibility(int & preferredWay) const
     4523CbcGeneralDepth::infeasibility(const OsiBranchingInformation * /*info*/,
     4524                               int &/*preferredWay*/) const
    45864525{
    45874526  whichSolution_ = -1;
     
    45984537      info->integerTolerance_=model_->getIntegerTolerance();
    45994538      info->integerIncrement_=model_->getCutoffIncrement();
     4539      info->numberBeforeTrust_ = model_->numberBeforeTrust();
     4540      info->stateOfSearch_=model_->stateOfSearch();
     4541      // Compute "small" change in branch
     4542      int nBranches = model_->getIntParam(CbcModel::CbcNumberBranches);
     4543      if (nBranches) {
     4544        double average = model_->getDblParam(CbcModel::CbcSumChange)/static_cast<double>(nBranches);
     4545        info->smallChange_ =
     4546          CoinMax(average*1.0e-5,model_->getDblParam(CbcModel::CbcSmallestChange));
     4547        info->smallChange_ = CoinMax(info->smallChange_,1.0e-8);
     4548      } else {
     4549        info->smallChange_ = 1.0e-8;
     4550      }
    46004551      int numberIntegers = model_->numberIntegers();
    46014552      double * down = new double[numberIntegers];
    46024553      double * up = new double[numberIntegers];
     4554      int * priority = new int[numberIntegers];
    46034555      int * numberDown = new int[numberIntegers];
    46044556      int * numberUp = new int[numberIntegers];
    46054557      int * numberDownInfeasible = new int[numberIntegers];
    46064558      int * numberUpInfeasible = new int[numberIntegers];
    4607       model_->fillPseudoCosts(down,up,numberDown,numberUp,
     4559      model_->fillPseudoCosts(down,up,priority,numberDown,numberUp,
    46084560                      numberDownInfeasible,numberUpInfeasible);
    4609       info->fillPseudoCosts(down,up,numberDown,numberUp,
     4561      info->fillPseudoCosts(down,up,priority,numberDown,numberUp,
    46104562                            numberDownInfeasible,
    46114563                            numberUpInfeasible,numberIntegers);
     
    46934645// Redoes data when sequence numbers change
    46944646void
    4695 CbcGeneralDepth::redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns)
     4647CbcGeneralDepth::redoSequenceEtc(CbcModel * /*model*/,
     4648                                 int /*numberColumns*/,
     4649                                 const int * /*originalColumns*/)
    46964650{
    46974651}
     
    47034657extern int gotGoodNode_Z;
    47044658#endif
    4705 
    4706 // Creates a branching object
    47074659CbcBranchingObject *
    4708 CbcGeneralDepth::createBranch(int way)
     4660CbcGeneralDepth::createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * /*info*/, int /*way*/)
    47094661{
    47104662  int numberDo = numberNodes_;
     
    47244676  branch->numberRows_ = model_->solver()->getNumRows();
    47254677  int iNode;
    4726   OsiSolverInterface * solver = model_->solver();
     4678  //OsiSolverInterface * solver = model_->solver();
    47274679  OsiClpSolverInterface * clpSolver
    47284680    = dynamic_cast<OsiClpSolverInterface *> (solver);
     
    49914943int
    49924944CbcGeneralBranchingObject::compareOriginalObject
    4993 (const CbcBranchingObject* brObj) const
     4945(const CbcBranchingObject* /*brObj*/) const
    49944946{
    49954947  throw("must implement");
     
    50064958CbcRangeCompare
    50074959CbcGeneralBranchingObject::compareBranchingObject
    5008 (const CbcBranchingObject* brObj, const bool replaceIfOverlap)
     4960(const CbcBranchingObject* /*brObj*/, const bool /*replaceIfOverlap*/)
    50094961{
    50104962  throw("must implement");
     
    50845036   Can change objective etc */
    50855037void
    5086 CbcOneGeneralBranchingObject::checkIsCutoff(double cutoff)
     5038CbcOneGeneralBranchingObject::checkIsCutoff(double /*cutoff*/)
    50875039{
    50885040  assert (numberBranchesLeft());
     
    51035055int
    51045056CbcOneGeneralBranchingObject::compareOriginalObject
    5105 (const CbcBranchingObject* brObj) const
     5057(const CbcBranchingObject* /*brObj*/) const
    51065058{
    51075059  throw("must implement");
     
    51185070CbcRangeCompare
    51195071CbcOneGeneralBranchingObject::compareBranchingObject
    5120 (const CbcBranchingObject* brObj, const bool replaceIfOverlap)
     5072(const CbcBranchingObject* /*brObj*/, const bool /*replaceIfOverlap*/)
    51215073{
    51225074  throw("must implement");
     
    53625314int
    53635315CbcDummyBranchingObject::compareOriginalObject
    5364 (const CbcBranchingObject* brObj) const
     5316(const CbcBranchingObject* /*brObj*/) const
    53655317{
    53665318  throw("must implement");
     
    53775329CbcRangeCompare
    53785330CbcDummyBranchingObject::compareBranchingObject
    5379 (const CbcBranchingObject* brObj, const bool replaceIfOverlap)
     5331(const CbcBranchingObject* /*brObj*/, const bool /*replaceIfOverlap*/)
    53805332{
    53815333  throw("must implement");
  • stable/2.4/Cbc/src/CbcBranchActual.hpp

    r1132 r1271  
     1/* $Id$ */
    12// Copyright (C) 2002, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    3738  virtual ~CbcClique ();
    3839 
    39   using CbcObject::infeasibility ;
    4040  /// Infeasibility - large is 0.5
    41   virtual double infeasibility(int & preferredWay) const;
     41  virtual double infeasibility(const OsiBranchingInformation * info,
     42                               int &preferredWay) const;
    4243
    4344  using CbcObject::feasibleRegion ;
     
    4546  virtual void feasibleRegion();
    4647
    47   using CbcObject::createBranch ;
    4848  /// Creates a branching object
    49   virtual CbcBranchingObject * createBranch(int way) ;
     49  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) ;
    5050  /// Number of members
    5151  inline int numberMembers() const
     
    126126  virtual ~CbcSOS ();
    127127 
    128   using CbcObject::infeasibility ;
    129128  /// Infeasibility - large is 0.5
    130   virtual double infeasibility(int & preferredWay) const;
    131   /// Infeasibility - large is 0.5
    132   virtual double infeasibility(const OsiBranchingInformation * info,
    133                                int & preferredWay) const;
     129  virtual double infeasibility(const OsiBranchingInformation * info,
     130                               int &preferredWay) const;
    134131
    135132  using CbcObject::feasibleRegion ;
     
    137134  virtual void feasibleRegion();
    138135
    139   using CbcObject::createBranch ;
    140136  /// Creates a branching object
    141   virtual CbcBranchingObject * createBranch(int way) ;
     137  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) ;
    142138
    143139
     
    259255  /// Construct an OsiSimpleInteger object
    260256  OsiSimpleInteger * osiObject() const;
    261   using CbcObject::infeasibility ;
    262257  /// Infeasibility - large is 0.5
    263   virtual double infeasibility(const OsiSolverInterface * solver,
    264                                const OsiBranchingInformation * info, int & preferredWay) const;
     258  virtual double infeasibility(const OsiBranchingInformation * info,
     259                               int &preferredWay) const;
    265260
    266261  using CbcObject::feasibleRegion ;
     
    272267  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
    273268
    274   using CbcObject::createBranch ;
    275269  /** Create a branching object and indicate which way to branch first.
    276270     
     
    278272      variables, etc.)
    279273  */
    280   virtual CbcBranchingObject * createBranch(OsiSolverInterface * solver,
    281                                             const OsiBranchingInformation * info, int way) ;
     274  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) ;
    282275  /// Fills in a created branching object
    283276  void fillCreateBranch(CbcIntegerBranchingObject * branching, const OsiBranchingInformation * info, int way) ;
     
    289282  */
    290283  virtual OsiSolverBranch * solverBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
    291   /// Infeasibility - large is 0.5
    292   virtual double infeasibility(int & preferredWay) const;
    293284
    294285  /** Set bounds to fix the variable at the current (integer) value.
     
    300291  virtual void feasibleRegion();
    301292
    302   /** Creates a branching object
    303 
    304     The preferred direction is set by \p way, -1 for down, +1 for up.
    305   */
    306   virtual CbcBranchingObject * createBranch(int way) ;
    307293  /** Column number if single column object -1 otherwise,
    308294      so returns >= 0
     
    389375  void applyConsequence(int iSequence, int state) const;
    390376 
    391   using CbcObject::infeasibility ;
    392377  /// Infeasibility - large is 0.5 (and 0.5 will give this)
    393   virtual double infeasibility(int & preferredWay) const;
     378  virtual double infeasibility(const OsiBranchingInformation * info,
     379                               int &preferredWay) const;
    394380
    395381  using CbcObject::feasibleRegion ;
     
    397383  virtual void feasibleRegion();
    398384
    399   using CbcObject::createBranch ;
    400385  /// Creates a branching object
    401   virtual CbcBranchingObject * createBranch(int way) ;
     386  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) ;
    402387
    403388  /// Number of members
     
    593578  virtual ~CbcSimpleIntegerPseudoCost ();
    594579 
    595   using CbcObject::infeasibility ;
    596580  /// Infeasibility - large is 0.5
    597   virtual double infeasibility(int & preferredWay) const;
    598 
    599   using CbcObject::createBranch ;
     581  virtual double infeasibility(const OsiBranchingInformation * info,
     582                               int &preferredWay) const;
     583
    600584  /// Creates a branching object
    601   virtual CbcBranchingObject * createBranch(int way) ;
     585  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) ;
    602586
    603587  /// Down pseudo cost
     
    11971181  ~CbcFollowOn ();
    11981182 
    1199   using CbcObject::infeasibility ;
    12001183  /// Infeasibility - large is 0.5
    1201   virtual double infeasibility(int & preferredWay) const;
     1184  virtual double infeasibility(const OsiBranchingInformation * info,
     1185                               int &preferredWay) const;
    12021186
    12031187  using CbcObject::feasibleRegion ;
     
    12051189  virtual void feasibleRegion();
    12061190
    1207   using CbcObject::createBranch ;
    12081191  /// Creates a branching object
    1209   virtual CbcBranchingObject * createBranch(int way) ;
     1192  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) ;
    12101193  /// As some computation is needed in more than one place - returns row
    12111194  virtual int gutsOfFollowOn(int & otherRow, int & preferredWay) const;
     
    14491432  ~CbcGeneral ();
    14501433 
    1451   using CbcObject::infeasibility ;
    14521434  /// Infeasibility - large is 0.5
    1453   virtual double infeasibility(int & preferredWay) const=0;
     1435  virtual double infeasibility(const OsiBranchingInformation * info,
     1436                               int &preferredWay) const;
    14541437
    14551438  using CbcObject::feasibleRegion ;
     
    14571440  virtual void feasibleRegion()=0;
    14581441
    1459   using CbcObject::createBranch ;
    14601442  /// Creates a branching object
    1461   virtual CbcBranchingObject * createBranch(int way)=0 ;
     1443  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) ;
    14621444
    14631445  /// Redoes data when sequence numbers change
     
    15021484  ~CbcGeneralDepth ();
    15031485 
    1504   using CbcObject::infeasibility ;
    15051486  /// Infeasibility - large is 0.5
    1506   virtual double infeasibility(int & preferredWay) const;
     1487  virtual double infeasibility(const OsiBranchingInformation * info,
     1488                               int &preferredWay) const;
    15071489
    15081490  using CbcObject::feasibleRegion ;
     
    15101492  virtual void feasibleRegion();
    15111493
    1512   using CbcObject::createBranch ;
    15131494  /// Creates a branching object
    1514   virtual CbcBranchingObject * createBranch(int way) ;
     1495  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) ;
    15151496  /// Return maximum number of nodes
    15161497  inline int maximumNodes() const
  • stable/2.4/Cbc/src/CbcBranchBase.cpp

    r1121 r1271  
     1/* $Id$ */
    12// Copyright (C) 2002, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    8182  ceilingValue = floorValue+1.0;
    8283}
    83 /* Infeasibility of the object
    84      
    85     This is some measure of the infeasibility of the object. 0.0
    86     indicates that the object is satisfied.
    87  
    88     The preferred branching direction is returned in way,
    89  
    90     This is used to prepare for strong branching but should also think of
    91     case when no strong branching
    92  
    93     The object may also compute an estimate of cost of going "up" or "down".
    94     This will probably be based on pseudo-cost ideas
    95 
    96     This should also set mutable infeasibility_ and whichWay_
    97     This is for instant re-use for speed
     84/* For the variable(s) referenced by the object,
     85      look at the current solution and set bounds to match the solution.
     86      Returns measure of how much it had to move solution to make feasible
    9887*/
    9988double
    100 CbcObject::infeasibility(const OsiSolverInterface * solver,int &preferredWay) const
    101 {
    102   assert (solver==model_->solver());
    103   return infeasibility(preferredWay);
     89CbcObject::feasibleRegion(OsiSolverInterface * /*solver*/) const
     90{
     91  //assert (solver==model_->solver());
     92  CbcObject * fudge = const_cast<CbcObject *>(this);
     93  fudge->feasibleRegion();
     94  return 0.0;
    10495}
    10596 
     
    109100*/
    110101double
    111 CbcObject::feasibleRegion(OsiSolverInterface * solver) const
    112 {
    113   assert (solver==model_->solver());
     102CbcObject::feasibleRegion(OsiSolverInterface * /*solver*/,
     103                          const OsiBranchingInformation * /*info*/) const
     104{
     105  //assert (solver==model_->solver());
    114106  CbcObject * fudge = const_cast<CbcObject *>(this);
    115107  fudge->feasibleRegion();
    116108  return 0.0;
    117109}
    118 /* Infeasibility of the object
    119      
    120     This is some measure of the infeasibility of the object. 0.0
    121     indicates that the object is satisfied.
    122  
    123     The preferred branching direction is returned in way,
    124  
    125     This is used to prepare for strong branching but should also think of
    126     case when no strong branching
    127  
    128     The object may also compute an estimate of cost of going "up" or "down".
    129     This will probably be based on pseudo-cost ideas
    130 
    131     This should also set mutable infeasibility_ and whichWay_
    132     This is for instant re-use for speed
    133 */
    134 double
    135 CbcObject::infeasibility(const OsiBranchingInformation * info,
    136                          int &preferredWay) const
    137 {
    138   return infeasibility(preferredWay);
    139 }
    140  
    141 /* For the variable(s) referenced by the object,
    142       look at the current solution and set bounds to match the solution.
    143       Returns measure of how much it had to move solution to make feasible
    144 */
    145 double
    146 CbcObject::feasibleRegion(OsiSolverInterface * solver,const OsiBranchingInformation * info) const
    147 {
    148   assert (solver==model_->solver());
    149   CbcObject * fudge = const_cast<CbcObject *>(this);
    150   fudge->feasibleRegion();
    151   return 0.0;
    152 }
    153  
    154110/* Create a branching object and indicate which way to branch first.
    155111     
     
    158114*/
    159115OsiBranchingObject *
    160 CbcObject::createBranch(OsiSolverInterface * solver, int way) const
    161 {
    162   assert (solver==model_->solver());
     116CbcObject::createOsiBranch(OsiSolverInterface * solver,
     117                        const OsiBranchingInformation * info,
     118                        int way) const
     119{
     120  //assert (solver==model_->solver());
    163121  CbcObject * fudge = const_cast<CbcObject *>(this);
    164   return fudge->createBranch(way);
    165 }
    166 /* Create a branching object and indicate which way to branch first.
    167      
    168       The branching object has to know how to create branches (fix
    169       variables, etc.)
    170 */
    171 OsiBranchingObject *
    172 CbcObject::createBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) const
    173 {
    174   assert (solver==model_->solver());
    175   CbcObject * fudge = const_cast<CbcObject *>(this);
    176   return fudge->createBranch(way);
     122  return fudge->createBranch(solver,info,way);
    177123}
    178124/* Create an OsiSolverBranch object
     
    189135   Assumes can get information from solver */
    190136CbcObjectUpdateData
    191 CbcObject::createUpdateInformation(const OsiSolverInterface * solver,
    192                                                         const CbcNode * node,
    193                                                         const CbcBranchingObject * branchingObject)
     137CbcObject::createUpdateInformation(const OsiSolverInterface * /*solver*/,
     138                                   const CbcNode * /*node*/,
     139                                   const CbcBranchingObject * /*branchingObject*/)
    194140{
    195141  return CbcObjectUpdateData();
     
    273219int
    274220CbcBranchDecision::bestBranch (CbcBranchingObject ** objects, int numberObjects,
    275                                int numberUnsatisfied,
     221                               int /*numberUnsatisfied*/,
    276222                               double * changeUp, int * numberInfeasibilitiesUp,
    277223                               double * changeDown, int * numberInfeasibilitiesDown,
    278                                double objectiveValue)
     224                               double /*objectiveValue*/)
    279225{
    280226  int bestWay=0;
     
    321267
    322268// Copy constructor
    323 CbcConsequence::CbcConsequence ( const CbcConsequence & rhs)
     269CbcConsequence::CbcConsequence ( const CbcConsequence & /*rhs*/)
    324270{
    325271}
  • stable/2.4/Cbc/src/CbcBranchBase.hpp

    r1121 r1271  
     1/* $Id$ */
    12// Copyright (C) 2002, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    4445
    4546  To create a new type of object you need to provide three methods:
    46   #infeasibility(), #feasibleRegion(), and #createBranch(), described below.
     47  #infeasibility(), #feasibleRegion(), and #createCbcBranch(), described below.
    4748
    4849  This base class is primarily virtual to allow for any form of structure.
     
    107108      This will probably be based on pseudo-cost ideas
    108109  */
    109   virtual double infeasibility(int &preferredWay) const = 0;
    110   /// Dummy one for compatibility
     110#ifdef CBC_NEW_STYLE_BRANCH
    111111  virtual double infeasibility(const OsiBranchingInformation * info,
    112                                int &preferredWay) const;
     112                               int &preferredWay) const=0;
     113#else
     114  virtual double infeasibility(const OsiBranchingInformation * /*info*/,
     115                               int &preferredWay) const
     116  {return infeasibility(preferredWay);}
     117  virtual double infeasibility(int &/*preferredWay*/) const
     118  {throw CoinError("Need code","infeasibility","CbcBranchBase");}
     119#endif
    113120
    114121  /** For the variable(s) referenced by the object,
     
    119126  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
    120127
    121   /** Create a branching object and indicate which way to branch first.
    122 
    123       The branching object has to know how to create branches (fix
    124       variables, etc.)
    125   */
    126   virtual CbcBranchingObject * createBranch(int way) = 0;
    127  
    128   /** Infeasibility of the object
    129      
    130     This is some measure of the infeasibility of the object. 0.0
    131     indicates that the object is satisfied.
    132  
    133     The preferred branching direction is returned in way,
    134  
    135     This is used to prepare for strong branching but should also think of
    136     case when no strong branching
    137  
    138     The object may also compute an estimate of cost of going "up" or "down".
    139     This will probably be based on pseudo-cost ideas
    140 
    141     This should also set mutable infeasibility_ and whichWay_
    142     This is for instant re-use for speed
    143   */
    144   virtual double infeasibility(const OsiSolverInterface * solver,int &preferredWay) const;
    145  
    146128  /** For the variable(s) referenced by the object,
    147129      look at the current solution and set bounds to match the solution.
     
    155137      variables, etc.)
    156138  */
    157   virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, int way) const;
    158   /** Create a branching object and indicate which way to branch first.
     139#ifdef CBC_NEW_STYLE_BRANCH
     140  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) =0;
     141#else
     142  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way)
     143  { return createBranch(solver,info,way);}
     144  virtual CbcBranchingObject * createBranch(OsiSolverInterface * /*solver*/,
     145                                            const OsiBranchingInformation * /*info*/, int /*way*/)
     146  {throw CoinError("Need code","createBranch","CbcBranchBase");}
     147#endif
     148  /** Create an Osibranching object and indicate which way to branch first.
    159149     
    160150      The branching object has to know how to create branches (fix
    161151      variables, etc.)
    162152  */
    163   virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) const;
     153  virtual OsiBranchingObject * createOsiBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) const;
    164154  /** Create an OsiSolverBranch object
    165155
     
    194184    Bounds may be tightened, so it may be good to be able to set this info in object.
    195185   */
    196   virtual void resetBounds(const OsiSolverInterface * solver) {}
     186  virtual void resetBounds(const OsiSolverInterface * ) {}
    197187 
    198188  /** Returns floor and ceiling i.e. closest valid points
     
    209199
    210200  /// Update object by CbcObjectUpdateData
    211   virtual void updateInformation(const CbcObjectUpdateData & data) {}
     201  virtual void updateInformation(const CbcObjectUpdateData & ) {}
    212202
    213203  /// Identifier (normally column number in matrix)
    214204  inline int id() const
    215205  { return id_;}
     206 
     207  /** Set identifier (normally column number in matrix)
     208      but 1000000000 to 1100000000 means optional branching object
     209      i.e. code would work without it */
     210  inline void setId(int value)
     211  { id_ = value;}
     212 
     213  /** Return true if optional branching object
     214      i.e. code would work without it */
     215  inline bool optionalObject() const
     216  { return (id_ >= 1000000000 && id_ < 1100000000);}
    216217 
    217218  /// Get position in object_ list
     
    238239  { preferredWay_=value;}
    239240  /// Redoes data when sequence numbers change
    240   virtual void redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns) {}
     241  virtual void redoSequenceEtc(CbcModel * , int , const int * ) {}
    241242 
    242243protected:
     
    298299      The object mention in incoming CbcStrongInfo must match.
    299300      Returns nonzero if skip is wanted */
    300   virtual int fillStrongInfo( CbcStrongInfo & info) {return 0;}
     301  virtual int fillStrongInfo( CbcStrongInfo & ) {return 0;}
    301302  /// Reset number of branches left to original
    302303  inline void resetNumberBranchesLeft()
     
    319320             Returns change in guessed objective on next branch
    320321  */
    321   virtual double branch(OsiSolverInterface * solver)
     322  virtual double branch(OsiSolverInterface * )
    322323  { return branch();}
    323324  /** Update bounds in solver as in 'branch' and update given bounds.
    324325      branchState is -1 for 'down' +1 for 'up' */
    325   virtual void fix(OsiSolverInterface * solver,
    326                    double * lower, double * upper,
    327                    int branchState) const {}
     326  virtual void fix(OsiSolverInterface * ,
     327                   double * , double * ,
     328                   int ) const {}
    328329
    329330  /** Reset every information so that the branching object appears to point to
     
    500501  /** Saves a clone of current branching object.  Can be used to update
    501502      information on object causing branch - after branch */
    502   virtual void saveBranchingObject(OsiBranchingObject * object) {}
     503  virtual void saveBranchingObject(OsiBranchingObject * ) {}
    503504  /** Pass in information on branch just done.
    504505      assumes object can get information from solver */
    505   virtual void updateInformation(OsiSolverInterface * solver,
    506                                  const CbcNode * node) {}
     506  virtual void updateInformation(OsiSolverInterface * ,
     507                                 const CbcNode * ) {}
    507508  /** Sets or gets best criterion so far */
    508   virtual void setBestCriterion(double value) {}
     509  virtual void setBestCriterion(double ) {}
    509510  virtual double getBestCriterion() const {return 0.0;}
    510511  /// Create C++ lines to get to current state
    511   virtual void generateCpp( FILE * fp) {}
     512  virtual void generateCpp( FILE * ) {}
    512513  /// Model
    513514  inline CbcModel * cbcModel() const
  • stable/2.4/Cbc/src/CbcBranchCut.cpp

    r1121 r1271  
     1/* $Id$ */
    12// Copyright (C) 2004, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    4950// Assignment operator
    5051CbcBranchCut &
    51 CbcBranchCut::operator=( const CbcBranchCut& rhs)
     52CbcBranchCut::operator=( const CbcBranchCut& /*rhs*/)
    5253{
    5354  return *this;
     
    5859{
    5960}
    60 
    61 // Infeasibility - large is 0.5
    6261double
    63 CbcBranchCut::infeasibility(int & preferredWay) const
     62CbcBranchCut::infeasibility(const OsiBranchingInformation * /*info*/,
     63                               int &preferredWay) const
    6464{
    6565  throw CoinError("Use of base class","infeasibility","CbcBranchCut");
     
    8282CbcBranchCut::boundBranch() const
    8383{return false;}
    84 
    85 // Creates a branching object
    8684CbcBranchingObject *
    87 CbcBranchCut::createBranch(int way)
    88 {
    89   throw CoinError("Use of base class","createBranch","CbcBranchCut");
     85CbcBranchCut::createCbcBranch(OsiSolverInterface * /*solver*/,const OsiBranchingInformation * /*info*/, int /*way*/)
     86{
     87  throw CoinError("Use of base class","createCbcBranch","CbcBranchCut");
    9088  return new CbcCutBranchingObject();
    9189}
     
    198196    way_=-1;      // Swap direction
    199197  }
     198  printf("CUT %s ",(way_==-1) ? "up" : "down");
     199  cut->print();
    200200  // See if cut just fixes variables
    201201  double lb = cut->lb();
     
    431431  delete [] mark_;
    432432}
    433 // Creates a branching object
    434433CbcBranchingObject *
    435 CbcBranchToFixLots::createBranch(int way)
     434CbcBranchToFixLots::createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * /*info*/, int /*way*/)
    436435{
    437436  // by default way must be -1
    438   assert (way==-1);
    439   OsiSolverInterface * solver = model_->solver();
     437  //assert (way==-1);
     438  //OsiSolverInterface * solver = model_->solver();
    440439  const double * solution = model_->testSolution();
    441440  const double * lower = solver->getColLower();
     
    456455  int * sort = new int[numberColumns];
    457456  double * dsort = new double[numberColumns];
    458   int type = shallWe();
    459   assert (type);
    460   // Take clean first
    461   if (type==1) {
    462     for (i=0;i<numberIntegers;i++) {
    463       int iColumn = integerVariable[i];
    464       if (upper[iColumn]>lower[iColumn]) {
    465         if (!mark_||!mark_[iColumn]) {
    466           if(solution[iColumn]<lower[iColumn]+tolerance) {
    467             if (dj[iColumn]>djTolerance_) {
    468               dsort[nSort]=-dj[iColumn];
    469               sort[nSort++]=iColumn;
     457  if (djTolerance_!=-1.234567) {
     458    int type = shallWe();
     459    assert (type);
     460    // Take clean first
     461    if (type==1) {
     462      for (i=0;i<numberIntegers;i++) {
     463        int iColumn = integerVariable[i];
     464        if (upper[iColumn]>lower[iColumn]) {
     465          if (!mark_||!mark_[iColumn]) {
     466            if(solution[iColumn]<lower[iColumn]+tolerance) {
     467              if (dj[iColumn]>djTolerance_) {
     468                dsort[nSort]=-dj[iColumn];
     469                sort[nSort++]=iColumn;
     470              }
     471            } else if (solution[iColumn]>upper[iColumn]-tolerance) {
     472              if (dj[iColumn]<-djTolerance_) {
     473                dsort[nSort]=dj[iColumn];
     474                sort[nSort++]=iColumn;
     475              }
    470476            }
    471           } else if (solution[iColumn]>upper[iColumn]-tolerance) {
    472             if (dj[iColumn]<-djTolerance_) {
    473               dsort[nSort]=dj[iColumn];
     477          }
     478        } else {
     479          numberFixed++;
     480        }
     481      }
     482      // sort
     483      CoinSort_2(dsort,dsort+nSort,sort);
     484      nSort= CoinMin(nSort,wantedFixed-numberFixed);
     485    } else if (type<10) {
     486      int i;
     487      //const double * rowLower = solver->getRowLower();
     488      const double * rowUpper = solver->getRowUpper();
     489      // Row copy
     490      const double * elementByRow = matrixByRow_.getElements();
     491      const int * column = matrixByRow_.getIndices();
     492      const CoinBigIndex * rowStart = matrixByRow_.getVectorStarts();
     493      const int * rowLength = matrixByRow_.getVectorLengths();
     494      const double * columnLower = solver->getColLower();
     495      const double * columnUpper = solver->getColUpper();
     496      const double * solution = solver->getColSolution();
     497      int numberColumns = solver->getNumCols();
     498      int numberRows = solver->getNumRows();
     499      for (i=0;i<numberColumns;i++) {
     500        sort[i]=i;
     501        if (columnLower[i]!=columnUpper[i]){
     502          dsort[i]=1.0e100;
     503        } else {
     504          dsort[i]=1.0e50;
     505          numberFixed++;
     506        }
     507      }
     508      for (i=0;i<numberRows;i++) {
     509        double rhsValue = rowUpper[i];
     510        bool oneRow=true;
     511        // check elements
     512        int numberUnsatisfied=0;
     513        for (int j=rowStart[i];j<rowStart[i]+rowLength[i];j++) {
     514          int iColumn = column[j];
     515          double value = elementByRow[j];
     516          double solValue = solution[iColumn];
     517          if (columnLower[iColumn]!=columnUpper[iColumn]) {
     518            if (solValue<1.0-integerTolerance&&solValue>integerTolerance)
     519              numberUnsatisfied++;
     520            if (value!=1.0) {
     521              oneRow=false;
     522              break;
     523            }
     524          } else {
     525            rhsValue -= value*floor(solValue+0.5);
     526          }
     527        }
     528        if (oneRow&&rhsValue<=1.0+tolerance) {
     529          if (!numberUnsatisfied) {
     530            for (int j=rowStart[i];j<rowStart[i]+rowLength[i];j++) {
     531              int iColumn = column[j];
     532              if (dsort[iColumn]>1.0e50){
     533                dsort[iColumn]=0;
     534                nSort++;
     535              }
     536            }
     537          }
     538        }
     539      }
     540      // sort
     541      CoinSort_2(dsort,dsort+numberColumns,sort);
     542    } else {
     543      // new way
     544      for (i=0;i<numberIntegers;i++) {
     545        int iColumn = integerVariable[i];
     546        if (upper[iColumn]>lower[iColumn]) {
     547          if (!mark_||!mark_[iColumn]) {
     548            double distanceDown=solution[iColumn]-lower[iColumn];
     549            double distanceUp=upper[iColumn]-solution[iColumn];
     550            double distance = CoinMin(distanceDown,distanceUp);
     551            if (distance>0.001&&distance<0.5) {
     552              dsort[nSort]=distance;
    474553              sort[nSort++]=iColumn;
    475554            }
    476555          }
    477556        }
    478       } else {
    479         numberFixed++;
    480       }
    481     }
    482     // sort
    483     CoinSort_2(dsort,dsort+nSort,sort);
    484     nSort= CoinMin(nSort,wantedFixed-numberFixed);
    485   } else if (type<10) {
    486     int i;
    487     //const double * rowLower = solver->getRowLower();
    488     const double * rowUpper = solver->getRowUpper();
    489     // Row copy
    490     const double * elementByRow = matrixByRow_.getElements();
     557      }
     558      // sort
     559      CoinSort_2(dsort,dsort+nSort,sort);
     560      int n=0;
     561      double sum=0.0;
     562      for (int k=0;k<nSort;k++) {
     563        sum += dsort[k];
     564        if (sum<=djTolerance_)
     565          n=k;
     566        else
     567          break;
     568      }
     569      nSort = CoinMin(n,numberClean_/1000000);
     570    }
     571  } else {
     572#define FIX_IF_LESS -0.1
     573    // 3 in same row and sum <FIX_IF_LESS?
     574    int numberRows = matrixByRow_.getNumRows();
     575    const double * solution = model_->testSolution();
    491576    const int * column = matrixByRow_.getIndices();
    492577    const CoinBigIndex * rowStart = matrixByRow_.getVectorStarts();
    493578    const int * rowLength = matrixByRow_.getVectorLengths();
    494     const double * columnLower = solver->getColLower();
    495     const double * columnUpper = solver->getColUpper();
    496     const double * solution = solver->getColSolution();
    497     int numberColumns = solver->getNumCols();
    498     int numberRows = solver->getNumRows();
    499     for (i=0;i<numberColumns;i++) {
    500       sort[i]=i;
    501       if (columnLower[i]!=columnUpper[i]){
    502         dsort[i]=1.0e100;
    503       } else {
    504         dsort[i]=1.0e50;
    505         numberFixed++;
    506       }
    507     }
    508     for (i=0;i<numberRows;i++) {
    509       double rhsValue = rowUpper[i];
    510       bool oneRow=true;
    511       // check elements
     579    double bestSum=1.0;
     580    int nBest=-1;
     581    int kRow=-1;
     582    OsiSolverInterface * solver = model_->solver();
     583    for (int i=0;i<numberRows;i++) {
    512584      int numberUnsatisfied=0;
     585      double sum=0.0;
    513586      for (int j=rowStart[i];j<rowStart[i]+rowLength[i];j++) {
    514587        int iColumn = column[j];
    515         double value = elementByRow[j];
     588        if (solver->isInteger(iColumn)) {
     589          double solValue = solution[iColumn];
     590          if (solValue>1.0e-5&&solValue<FIX_IF_LESS) {
     591            numberUnsatisfied++;
     592            sum += solValue;
     593          }
     594        }
     595      }
     596      if (numberUnsatisfied>=3&&sum<FIX_IF_LESS) {
     597        // possible
     598        if (numberUnsatisfied>nBest||
     599            (numberUnsatisfied==nBest&&sum<bestSum)) {
     600          nBest=numberUnsatisfied;
     601          bestSum=sum;
     602          kRow=i;
     603        }
     604      }
     605    }
     606    assert (nBest>0);
     607    for (int j=rowStart[kRow];j<rowStart[kRow]+rowLength[kRow];j++) {
     608      int iColumn = column[j];
     609      if (solver->isInteger(iColumn)) {
    516610        double solValue = solution[iColumn];
    517         if (columnLower[iColumn]!=columnUpper[iColumn]) {
    518           if (solValue<1.0-integerTolerance&&solValue>integerTolerance)
    519             numberUnsatisfied++;
    520           if (value!=1.0) {
    521             oneRow=false;
    522             break;
    523           }
    524         } else {
    525           rhsValue -= value*floor(solValue+0.5);
    526         }
    527       }
    528       if (oneRow&&rhsValue<=1.0+tolerance) {
    529         if (!numberUnsatisfied) {
    530           for (int j=rowStart[i];j<rowStart[i]+rowLength[i];j++) {
    531             int iColumn = column[j];
    532             if (dsort[iColumn]>1.0e50){
    533               dsort[iColumn]=0;
    534               nSort++;
    535             }
    536           }
    537         }
    538       }
    539     }
    540     // sort
    541     CoinSort_2(dsort,dsort+numberColumns,sort);
    542   } else {
    543     // new way
    544     for (i=0;i<numberIntegers;i++) {
    545       int iColumn = integerVariable[i];
    546       if (upper[iColumn]>lower[iColumn]) {
    547         if (!mark_||!mark_[iColumn]) {
    548           double distanceDown=solution[iColumn]-lower[iColumn];
    549           double distanceUp=upper[iColumn]-solution[iColumn];
    550           double distance = CoinMin(distanceDown,distanceUp);
    551           if (distance>0.001&&distance<0.5) {
    552             dsort[nSort]=distance;
    553             sort[nSort++]=iColumn;
    554           }
    555         }
    556       }
    557     }
    558     // sort
    559     CoinSort_2(dsort,dsort+nSort,sort);
    560     int n=0;
    561     double sum=0.0;
    562     for (int k=0;k<nSort;k++) {
    563       sum += dsort[k];
    564       if (sum<=djTolerance_)
    565         n=k;
    566       else
    567         break;
    568     }
    569     nSort = CoinMin(n,numberClean_/1000000);
     611        if (solValue>1.0e-5&&solValue<FIX_IF_LESS) {
     612          sort[nSort++]=iColumn;
     613        }
     614      }
     615    }
    570616  }
    571617  OsiRowCut down;
     
    762808  return returnCode;
    763809}
    764 // Infeasibility - large is 0.5
    765810double
    766 CbcBranchToFixLots::infeasibility(int & preferredWay) const
     811CbcBranchToFixLots::infeasibility(const OsiBranchingInformation * /*info*/,
     812                               int &preferredWay) const
    767813{
    768814  preferredWay=-1;
     
    779825      return 0.0;
    780826  }
    781   if (!shallWe())
    782     return 0.0;
    783   else
    784     return 1.0e20;
     827  if (djTolerance_!=-1.234567) {
     828    if (!shallWe())
     829      return 0.0;
     830    else
     831      return 1.0e20;
     832  } else {
     833    // See if 3 in same row and sum <FIX_IF_LESS?
     834    int numberRows = matrixByRow_.getNumRows();
     835    const double * solution = model_->testSolution();
     836    const int * column = matrixByRow_.getIndices();
     837    const CoinBigIndex * rowStart = matrixByRow_.getVectorStarts();
     838    const int * rowLength = matrixByRow_.getVectorLengths();
     839    double bestSum=1.0;
     840    int nBest=-1;
     841    OsiSolverInterface * solver = model_->solver();
     842    for (int i=0;i<numberRows;i++) {
     843      int numberUnsatisfied=0;
     844      double sum=0.0;
     845      for (int j=rowStart[i];j<rowStart[i]+rowLength[i];j++) {
     846        int iColumn = column[j];
     847        if (solver->isInteger(iColumn)) {
     848          double solValue = solution[iColumn];
     849          if (solValue>1.0e-5&&solValue<FIX_IF_LESS) {
     850            numberUnsatisfied++;
     851            sum += solValue;
     852          }
     853        }
     854      }
     855      if (numberUnsatisfied>=3&&sum<FIX_IF_LESS) {
     856        // possible
     857        if (numberUnsatisfied>nBest||
     858            (numberUnsatisfied==nBest&&sum<bestSum)) {
     859          nBest=numberUnsatisfied;
     860          bestSum=sum;
     861        }
     862      }
     863    }
     864    if (nBest>0)
     865      return 1.0e20;
     866    else
     867      return 0.0;
     868  }
     869}
     870// Redoes data when sequence numbers change
     871void
     872CbcBranchToFixLots::redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns)
     873{
     874  model_=model;
     875  if (mark_) {
     876    OsiSolverInterface * solver = model_->solver();
     877    int numberColumnsNow = solver->getNumCols();
     878    char * temp = new char[numberColumnsNow];
     879    memset(temp,0,numberColumnsNow);
     880    for (int i=0;i<numberColumns;i++) {
     881      int j = originalColumns[i];
     882      temp[i]=mark_[j];
     883    }
     884    delete [] mark_;
     885    mark_=temp;
     886  }
     887  OsiSolverInterface * solver = model_->solver();
     888  matrixByRow_ = *solver->getMatrixByRow();
    785889}
    786890
     
    836940  delete [] which_;
    837941}
    838 // Creates a branching object
    839942CbcBranchingObject *
    840 CbcBranchAllDifferent::createBranch(int way)
     943CbcBranchAllDifferent::createCbcBranch(OsiSolverInterface * /*solver*/
     944                                       ,const OsiBranchingInformation * /*info*/,
     945                                       int /*way*/)
    841946{
    842947  // by default way must be -1
    843   assert (way==-1);
     948  //assert (way==-1);
    844949  const double * solution = model_->testSolution();
    845950  double * values = new double[numberInSet_];
     
    884989  return newObject;
    885990}
    886 // Infeasibility - large is 0.5
    887991double
    888 CbcBranchAllDifferent::infeasibility(int & preferredWay) const
     992CbcBranchAllDifferent::infeasibility(const OsiBranchingInformation * /*info*/,
     993                               int &preferredWay) const
    889994{
    890995  preferredWay=-1;
  • stable/2.4/Cbc/src/CbcBranchCut.hpp

    r912 r1271  
     1/* $Id$ */
    12// Copyright (C) 2004, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    3435  ~CbcBranchCut ();
    3536 
    36   using CbcObject::infeasibility ;
    3737  /// Infeasibility
    38   virtual double infeasibility(int & preferredWay) const;
     38  virtual double infeasibility(const OsiBranchingInformation * info,
     39                               int &preferredWay) const;
    3940
    4041  using CbcObject::feasibleRegion ;
     
    5455  virtual bool boundBranch() const ;
    5556
    56   using CbcObject::createBranch ;
    5757  /// Creates a branching object
    58   virtual CbcBranchingObject * createBranch(int way) ;
     58  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) ;
    5959
    6060  /** \brief Given a valid solution (with reduced costs, etc.),
     
    232232  int shallWe() const;
    233233
    234   using CbcObject::infeasibility ;
    235234  /// Infeasibility - large is 0.5
    236   virtual double infeasibility(int & preferredWay) const;
    237 
    238   using CbcObject::createBranch ;
     235  virtual double infeasibility(const OsiBranchingInformation * info,
     236                               int &preferredWay) const;
     237  /** \brief Return true if object can take part in normal heuristics
     238  */
     239  virtual bool canDoHeuristics() const
     240  {return true;}
     241
    239242  /// Creates a branching object
    240   virtual CbcBranchingObject * createBranch(int way);
     243  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) ;
     244  /// Redoes data when sequence numbers change
     245  virtual void redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns);
    241246
    242247
     
    289294  ~CbcBranchAllDifferent ();
    290295
    291   using CbcObject::infeasibility ;
    292296  /// Infeasibility - large is 0.5
    293   virtual double infeasibility(int & preferredWay) const;
    294 
    295   using CbcObject::createBranch ;
     297  virtual double infeasibility(const OsiBranchingInformation * info,
     298                               int &preferredWay) const;
     299
    296300  /// Creates a branching object
    297   virtual CbcBranchingObject * createBranch(int way);
     301  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) ;
    298302
    299303
  • stable/2.4/Cbc/src/CbcBranchDynamic.cpp

    r1132 r1271  
     1/* $Id$ */
    12// Copyright (C) 2002, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    2021#ifdef COIN_DEVELOP
    2122typedef struct {
     23  double sumUp_;
     24  double upEst_; // or change in obj in update
     25  double sumDown_;
     26  double downEst_; // or movement in value in update
     27  int sequence_;
     28  int numberUp_;
     29  int numberUpInf_;
     30  int numberDown_;
     31  int numberDownInf_;
    2232  char where_;
    2333  char status_;
    24   unsigned short sequence_;
    25   int numberUp_;
    26   int numberUpInf_;
    27   float sumUp_;
    28   float upEst_; // or change in obj in update
    29   int numberDown_;
    30   int numberDownInf_;
    31   float sumDown_;
    32   float downEst_; // or movement in value in update
    3334} History;
    3435History * history=NULL;
     
    113114    sumDownChange_(0.0),
    114115    sumUpChange_(0.0),
    115     sumDownCostSquared_(0.0),
    116     sumUpCostSquared_(0.0),
     116    downShadowPrice_(0.0),
     117    upShadowPrice_(0.0),
    117118    sumDownDecrease_(0.0),
    118119    sumUpDecrease_(0.0),
     
    133134    method_(0)
    134135{
    135 #ifdef CBC_INSTRUMENT
    136   numberTimesInfeasible_=0;
    137 #endif
    138136}
    139137
     
    150148    sumDownChange_(0.0),
    151149    sumUpChange_(0.0),
    152     sumDownCostSquared_(0.0),
    153     sumUpCostSquared_(0.0),
     150    downShadowPrice_(0.0),
     151    upShadowPrice_(0.0),
    154152    sumDownDecrease_(0.0),
    155153    sumUpDecrease_(0.0),
     
    170168    method_(0)
    171169{
    172 #ifdef CBC_INSTRUMENT
    173   numberTimesInfeasible_=0;
    174 #endif
    175170  const double * cost = model->getObjCoefficients();
    176171  double costValue = CoinMax(1.0e-5,fabs(cost[iColumn]));
     
    218213    sumDownChange_(0.0),
    219214    sumUpChange_(0.0),
    220     sumDownCostSquared_(0.0),
    221     sumUpCostSquared_(0.0),
     215    downShadowPrice_(0.0),
     216    upShadowPrice_(0.0),
    222217    sumDownDecrease_(0.0),
    223218    sumUpDecrease_(0.0),
     
    238233    method_(0)
    239234{
    240 #ifdef CBC_INSTRUMENT
    241   numberTimesInfeasible_=0;
    242 #endif
    243235  downDynamicPseudoCost_ = downDynamicPseudoCost;
    244236  upDynamicPseudoCost_ = upDynamicPseudoCost;
     
    275267*/
    276268CbcSimpleIntegerDynamicPseudoCost::CbcSimpleIntegerDynamicPseudoCost (CbcModel * model,
    277                                     int dummy, int iColumn, double downDynamicPseudoCost,
     269                                                                      int /*dummy*/,
     270                                                                      int iColumn, double downDynamicPseudoCost,
    278271                                                        double upDynamicPseudoCost)
    279272{
     
    291284   sumDownChange_(rhs.sumDownChange_),
    292285   sumUpChange_(rhs.sumUpChange_),
    293    sumDownCostSquared_(rhs.sumDownCostSquared_),
    294    sumUpCostSquared_(rhs.sumUpCostSquared_),
     286   downShadowPrice_(rhs.downShadowPrice_),
     287   upShadowPrice_(rhs.upShadowPrice_),
    295288   sumDownDecrease_(rhs.sumDownDecrease_),
    296289   sumUpDecrease_(rhs.sumUpDecrease_),
     
    312305
    313306{
    314 #ifdef CBC_INSTRUMENT
    315   numberTimesInfeasible_=rhs.numberTimesInfeasible_;
    316 #endif
    317307}
    318308
     
    337327    sumDownChange_ = rhs.sumDownChange_;
    338328    sumUpChange_ = rhs.sumUpChange_;
    339     sumDownCostSquared_ = rhs.sumDownCostSquared_;
    340     sumUpCostSquared_ = rhs.sumUpCostSquared_;
     329    downShadowPrice_ = rhs.downShadowPrice_;
     330    upShadowPrice_ = rhs.upShadowPrice_;
    341331    sumDownDecrease_ = rhs.sumDownDecrease_;
    342332    sumUpDecrease_ = rhs.sumUpDecrease_;
     
    355345    numberTimesUpTotalFixed_ = rhs.numberTimesUpTotalFixed_;
    356346    numberTimesProbingTotal_ = rhs.numberTimesProbingTotal_;
    357 #ifdef CBC_INSTRUMENT
    358     numberTimesInfeasible_=rhs.numberTimesInfeasible_;
    359 #endif
    360347    method_=rhs.method_;
    361348  }
     
    377364  sumDownChange_ = otherObject->sumDownChange_;
    378365  sumUpChange_ = otherObject->sumUpChange_;
    379   sumDownCostSquared_ = otherObject->sumDownCostSquared_;
    380   sumUpCostSquared_ = otherObject->sumUpCostSquared_;
     366  downShadowPrice_ = otherObject->downShadowPrice_;
     367  upShadowPrice_ = otherObject->upShadowPrice_;
    381368  sumDownDecrease_ = otherObject->sumDownDecrease_;
    382369  sumUpDecrease_ = otherObject->sumUpDecrease_;
     
    447434  sumDownChange_ += rhsObject->sumDownChange_-baseObject->sumDownChange_;
    448435  sumUpChange_ += rhsObject->sumUpChange_-baseObject->sumUpChange_;
    449   sumDownCostSquared_ += rhsObject->sumDownCostSquared_-baseObject->sumDownCostSquared_;
    450   sumUpCostSquared_ += rhsObject->sumUpCostSquared_-baseObject->sumUpCostSquared_;
     436  downShadowPrice_ = 0.0;
     437  upShadowPrice_ = 0.0;
    451438  sumDownDecrease_ += rhsObject->sumDownDecrease_-baseObject->sumDownDecrease_;
    452439  sumUpDecrease_ += rhsObject->sumUpDecrease_-baseObject->sumUpDecrease_;
     
    491478  if (sumUpChange_!= otherObject->sumUpChange_)
    492479    okay=false;
    493   if (sumDownCostSquared_!= otherObject->sumDownCostSquared_)
    494     okay=false;
    495   if (sumUpCostSquared_!= otherObject->sumUpCostSquared_)
     480  if (downShadowPrice_!= otherObject->downShadowPrice_)
     481    okay=false;
     482  if (upShadowPrice_!= otherObject->upShadowPrice_)
    496483    okay=false;
    497484  if (sumDownDecrease_!= otherObject->sumDownDecrease_)
     
    526513    okay=false;
    527514  return okay;
    528 }
    529 // Creates a branching objecty
    530 CbcBranchingObject *
    531 CbcSimpleIntegerDynamicPseudoCost::createBranch(int way)
    532 {
    533   const double * solution = model_->testSolution();
    534   const double * lower = model_->getCbcColLower();
    535   const double * upper = model_->getCbcColUpper();
    536   double value = solution[columnNumber_];
    537   value = CoinMax(value, lower[columnNumber_]);
    538   value = CoinMin(value, upper[columnNumber_]);
    539 #ifndef NDEBUG
    540   double nearest = floor(value+0.5);
    541   double integerTolerance =
    542     model_->getDblParam(CbcModel::CbcIntegerTolerance);
    543   assert (upper[columnNumber_]>lower[columnNumber_]);
    544 #endif
    545   if (!model_->hotstartSolution()) {
    546     assert (fabs(value-nearest)>integerTolerance);
    547   } else {
    548     const double * hotstartSolution = model_->hotstartSolution();
    549     double targetValue = hotstartSolution[columnNumber_];
    550     if (way>0)
    551       value = targetValue-0.1;
    552     else
    553       value = targetValue+0.1;
    554   }
    555   CbcDynamicPseudoCostBranchingObject * newObject =
    556     new CbcDynamicPseudoCostBranchingObject(model_,columnNumber_,way,
    557                                             value,this);
    558   double up =  upDynamicPseudoCost_*(ceil(value)-value);
    559   double down =  downDynamicPseudoCost_*(value-floor(value));
    560   double changeInGuessed=up-down;
    561   if (way>0)
    562     changeInGuessed = - changeInGuessed;
    563   changeInGuessed=CoinMax(0.0,changeInGuessed);
    564   //if (way>0)
    565   //changeInGuessed += 1.0e8; // bias to stay up
    566   newObject->setChangeInGuessed(changeInGuessed);
    567   newObject->setOriginalObject(this);
    568   return newObject;
    569515}
    570516/* Create an OsiSolverBranch object
     
    594540}
    595541//#define FUNNY_BRANCHING 
    596 // Infeasibility - large is 0.5
    597542double
    598 CbcSimpleIntegerDynamicPseudoCost::infeasibility(int & preferredWay) const
     543CbcSimpleIntegerDynamicPseudoCost::infeasibility(const OsiBranchingInformation * info,
     544                               int &preferredWay) const
    599545{
    600546  assert (downDynamicPseudoCost_>1.0e-40&&upDynamicPseudoCost_>1.0e-40);
     
    611557      // Lower bound active
    612558      lastUpDecrease_++;
    613       sumDownCostSquared_ += djValue;
    614559    }
    615560  } else if (djValue<-1.0e-6) {
     
    618563      // Upper bound active
    619564      lastUpDecrease_++;
    620       sumUpCostSquared_ -= djValue;
    621565    }
    622566  }
     
    673617#endif
    674618#endif
    675   if (number>0.0)
    676     downCost *= sum / number;
    677   else
    678     downCost  *=  downDynamicPseudoCost_;
     619#define MOD_SHADOW 1
     620#if MOD_SHADOW>0
     621  if (!downShadowPrice_) {
     622    if (number>0.0)
     623      downCost *= sum / number;
     624    else
     625      downCost  *=  downDynamicPseudoCost_;
     626  } else if (downShadowPrice_>0.0) {
     627    downCost *= downShadowPrice_;
     628  } else {
     629    downCost *= (downDynamicPseudoCost_-downShadowPrice_);
     630  }
     631#else
     632  if (downShadowPrice_<=0.0) {
     633    if (number>0.0)
     634      downCost *= sum / number;
     635    else
     636      downCost  *=  downDynamicPseudoCost_;
     637  } else {
     638    downCost *= downShadowPrice_;
     639  }
     640#endif
    679641  double upCost = CoinMax((above-value),0.0);
    680642#if TYPE2==0
     
    696658#endif
    697659#endif
    698   if (number>0.0)
    699     upCost *= sum / number;
    700   else
    701     upCost  *=  upDynamicPseudoCost_;
     660#if MOD_SHADOW>0
     661  if (!upShadowPrice_) {
     662    if (number>0.0)
     663      upCost *= sum / number;
     664    else
     665      upCost  *=  upDynamicPseudoCost_;
     666  } else if (upShadowPrice_>0.0) {
     667    upCost *= upShadowPrice_;
     668  } else {
     669    upCost *= (upDynamicPseudoCost_-upShadowPrice_);
     670  }
     671#else
     672  if (upShadowPrice_<=0.0) {
     673    if (number>0.0)
     674      upCost *= sum / number;
     675    else
     676      upCost  *=  upDynamicPseudoCost_;
     677  } else {
     678    upCost *= upShadowPrice_;
     679  }
     680#endif
    702681  if (downCost>=upCost)
    703682    preferredWay=1;
     
    714693    upCost *= ratio;
    715694    if ((lastUpDecrease_%100)==-1)
    716       printf("col %d total %d djtimes %d down %g up %g\n",
    717              columnNumber_,lastDownDecrease_,lastUpDecrease_,
    718              sumDownCostSquared_,sumUpCostSquared_);
     695      printf("col %d total %d djtimes %d\n",
     696             columnNumber_,lastDownDecrease_,lastUpDecrease_);
    719697  }
    720698#endif
    721699  if (preferredWay_)
    722700    preferredWay=preferredWay_;
     701  if (info->hotstartSolution_) {
     702    double targetValue = info->hotstartSolution_[columnNumber_];
     703    if (value>targetValue)
     704      preferredWay=-1;
     705    else
     706      preferredWay=1;
     707  }
    723708  // weight at 1.0 is max min
    724709#define WEIGHT_AFTER 0.8
    725710#define WEIGHT_BEFORE 0.1
     711  //Stolen from Constraint Integer Programming book (with epsilon change)
     712#define WEIGHT_PRODUCT
    726713  if (fabs(value-nearest)<=integerTolerance) {
    727714    if (priority_!=-999)
     
    730717      return 1.0e-13;
    731718  } else {
    732 #ifdef CBC_INSTRUMENT
    733     numberTimesInfeasible_++;
    734 #endif
    735719    int stateOfSearch = model_->stateOfSearch()%10;
    736720    double returnValue=0.0;
     
    770754      // some solution
    771755      where='I';
     756#ifndef WEIGHT_PRODUCT
    772757      returnValue = WEIGHT_AFTER*minValue + (1.0-WEIGHT_AFTER)*maxValue;
     758#else
     759      double minProductWeight = model_->getDblParam(CbcModel::CbcSmallChange);
     760      returnValue = CoinMax(minValue,minProductWeight)*CoinMax(maxValue,minProductWeight);
     761      //returnValue += minProductWeight*minValue;
     762#endif
    773763    }
    774764    if (numberTimesUp_<numberBeforeTrust_||
     
    799789      returnValue *= 1.0e-3;
    800790    }
    801 #if 0 //def CBC_INSTRUMENT
    802     int nn = numberTimesInfeasible_  - CoinMax(numberTimesUp_,numberTimesDown_);
    803     if (nn<0) {
    804       // Something to do with parallel synchronization
    805       numberTimesInfeasible_  = CoinMax(numberTimesUp_,numberTimesDown_);
    806     } else if (nn) {
    807       returnValue *= sqrt(static_cast<double> (nn));
    808     }
    809 #endif
    810791#ifdef COIN_DEVELOP
    811792    History hist;
     
    827808  }
    828809}
    829 
    830 double
    831 CbcSimpleIntegerDynamicPseudoCost::infeasibility(const OsiSolverInterface * solver, const OsiBranchingInformation * info,
    832                          int & preferredWay) const
    833 {
    834   double value = info->solution_[columnNumber_];
    835   value = CoinMax(value, info->lower_[columnNumber_]);
    836   value = CoinMin(value, info->upper_[columnNumber_]);
    837   if (info->upper_[columnNumber_]==info->lower_[columnNumber_]) {
    838     // fixed
    839     preferredWay=1;
    840     return 0.0;
    841   }
    842   assert (breakEven_>0.0&&breakEven_<1.0);
    843   double nearest = floor(value+0.5);
    844   double integerTolerance = info->integerTolerance_;
    845   double below = floor(value+integerTolerance);
    846   double above = below+1.0;
    847   if (above>info->upper_[columnNumber_]) {
    848     above=below;
    849     below = above -1;
    850   }
    851 #if INFEAS==1
    852   double objectiveValue = info->objectiveValue_;
    853   double distanceToCutoff =  info->cutoff_  - objectiveValue;
    854   if (distanceToCutoff<1.0e20)
    855     distanceToCutoff *= 10.0;
    856   else
    857     distanceToCutoff = 1.0e2 + fabs(objectiveValue);
    858 #endif
    859   distanceToCutoff = CoinMax(distanceToCutoff,1.0e-12*(1.0+fabs(objectiveValue)));
    860   double sum;
    861   int number;
    862   double downCost = CoinMax(value-below,0.0);
    863   sum = sumDownCost_;
    864   number = numberTimesDown_;
    865 #if INFEAS==1
    866   sum += numberTimesDownInfeasible_*(distanceToCutoff/(downCost+1.0e-12));
    867 #endif
    868   if (number>0)
    869     downCost *= sum / static_cast<double> (number);
    870   else
    871     downCost  *=  downDynamicPseudoCost_;
    872   double upCost = CoinMax((above-value),0.0);
    873   sum = sumUpCost_;
    874   number = numberTimesUp_;
    875 #if INFEAS==1
    876   sum += numberTimesUpInfeasible_*(distanceToCutoff/(upCost+1.0e-12));
    877 #endif
    878   if (number>0)
    879     upCost *= sum / static_cast<double> (number);
    880   else
    881     upCost  *=  upDynamicPseudoCost_;
    882   if (downCost>=upCost)
    883     preferredWay=1;
    884   else
    885     preferredWay=-1;
    886   // See if up down choice set
    887   if (upDownSeparator_>0.0) {
    888     preferredWay = (value-below>=upDownSeparator_) ? 1 : -1;
    889   }
    890   if (preferredWay_)
    891     preferredWay=preferredWay_;
    892   // weight at 1.0 is max min
    893   if (fabs(value-nearest)<=integerTolerance) {
    894     return 0.0;
    895   } else {
    896     double returnValue=0.0;
    897     double minValue = CoinMin(downCost,upCost);
    898     double maxValue = CoinMax(downCost,upCost);
    899     if (!info->numberBranchingSolutions_||info->depth_<=10/* was ||maxValue>0.2*distanceToCutoff*/) {
    900       // no solution
    901       returnValue = WEIGHT_BEFORE*minValue + (1.0-WEIGHT_BEFORE)*maxValue;
    902     } else {
    903       // some solution
    904       returnValue = WEIGHT_AFTER*minValue + (1.0-WEIGHT_AFTER)*maxValue;
    905     }
    906     if (numberTimesUp_<numberBeforeTrust_||
    907         numberTimesDown_<numberBeforeTrust_) {
    908       //if (returnValue<1.0e10)
    909       //returnValue += 1.0e12;
    910       //else
    911       returnValue *= 1.0e3;
    912       if (!numberTimesUp_&&!numberTimesDown_)
    913         returnValue=1.0e50;
    914     }
    915     //if (fabs(value-0.5)<1.0e-5) {
    916     //returnValue = 3.0*returnValue + 0.2;
    917     //} else if (value>0.9) {
    918     //returnValue = 2.0*returnValue + 0.1;
    919     //}
    920     if (method_==1) {
    921       // probing
    922       // average
    923       double up=1.0e-15;
    924       double down=1.0e-15;
    925       if (numberTimesProbingTotal_) {
    926         up += numberTimesUpTotalFixed_/static_cast<double> (numberTimesProbingTotal_);
    927         down += numberTimesDownTotalFixed_/static_cast<double> (numberTimesProbingTotal_);
    928       }
    929       returnValue = 1 + 10.0*CoinMin(numberTimesDownLocalFixed_,numberTimesUpLocalFixed_) +
    930         CoinMin(down,up);
    931       returnValue *= 1.0e-3;
    932     }
    933     return CoinMax(returnValue,1.0e-15);
    934   }
    935 }
    936810// Creates a branching object
    937811CbcBranchingObject *
    938 CbcSimpleIntegerDynamicPseudoCost::createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way)
     812CbcSimpleIntegerDynamicPseudoCost::createCbcBranch(OsiSolverInterface * /*solver*/,
     813                                                const OsiBranchingInformation * info, int way)
    939814{
    940815  double value = info->solution_[columnNumber_];
     
    1046921#endif
    1047922}
     923// Modify down pseudo cost in a slightly different way
     924void
     925CbcSimpleIntegerDynamicPseudoCost::updateDownDynamicPseudoCost(double value)
     926{
     927  sumDownCost_ += value;
     928  numberTimesDown_++;
     929  downDynamicPseudoCost_=sumDownCost_/static_cast<double>(numberTimesDown_);
     930}
    1048931// Set up pseudo cost
    1049932void
     
    1064947  }
    1065948#endif
     949}
     950// Modify up pseudo cost in a slightly different way
     951void
     952CbcSimpleIntegerDynamicPseudoCost::updateUpDynamicPseudoCost(double value)
     953{
     954  sumUpCost_ += value;
     955  numberTimesUp_++;
     956  upDynamicPseudoCost_=sumUpCost_/static_cast<double>(numberTimesUp_);
    1066957}
    1067958/* Pass in information on branch just done and create CbcObjectUpdateData instance.
     
    12851176  //print(1,0.5);
    12861177  assert (downDynamicPseudoCost_>1.0e-40&&upDynamicPseudoCost_>1.0e-40);
     1178#if MOD_SHADOW>1
     1179  if (upShadowPrice_>0.0&&numberTimesDown_>=numberBeforeTrust_
     1180      &&numberTimesUp_>=numberBeforeTrust_) {
     1181    // Set negative
     1182    upShadowPrice_=-upShadowPrice_;
     1183    assert (downShadowPrice_>0.0);
     1184    downShadowPrice_ = - downShadowPrice_;
     1185  }
     1186#endif
    12871187}
    12881188// Updates stuff like pseudocosts after mini branch and bound
     
    12921192                                                   int numberUpInfeasible,double sumUp)
    12931193{
    1294 #ifdef CBC_INSTRUMENT
    1295   int difference = numberDown-numberTimesDown_;
    1296   difference += numberUp-numberTimesUp_;
    1297   numberTimesInfeasible_ += 2*difference;
    1298 #endif
    12991194  numberTimesDown_ = numberDown;
    13001195  numberTimesDownInfeasible_ = numberDownInfeasible;
     
    13321227    if (numberTimesDown_) {
    13331228      meanDown = sumDownCost_/static_cast<double> (numberTimesDown_);
    1334       devDown = meanDown*meanDown + sumDownCostSquared_ -
    1335         2.0*meanDown*sumDownCost_;
     1229      devDown = meanDown*meanDown - 2.0*meanDown*sumDownCost_;
    13361230      if (devDown>=0.0)
    13371231        devDown = sqrt(devDown);
     
    13411235    if (numberTimesUp_) {
    13421236      meanUp = sumUpCost_/static_cast<double> (numberTimesUp_);
    1343       devUp = meanUp*meanUp + sumUpCostSquared_ -
    1344         2.0*meanUp*sumUpCost_;
     1237      devUp = meanUp*meanUp - 2.0*meanUp*sumUpCost_;
    13451238      if (devUp>=0.0)
    13461239        devUp = sqrt(devUp);
    13471240    }
    1348 #if 0
    13491241    printf("%d down %d times (%d inf) mean %g (dev %g) up %d times (%d inf) mean %g (dev %g)\n",
    13501242           columnNumber_,
    13511243           numberTimesDown_,numberTimesDownInfeasible_,meanDown,devDown,
    13521244           numberTimesUp_,numberTimesUpInfeasible_,meanUp,devUp);
    1353 #else
    1354     int n=0;
    1355 #ifdef CBC_INSTRUMENT
    1356     n=numberTimesInfeasible_;
    1357 #endif
    1358     printf("%d down %d times (%d inf) mean %g  up %d times (%d inf) mean %g - pseudocosts %g %g - inftimes %d\n",
    1359            columnNumber_,
    1360            numberTimesDown_,numberTimesDownInfeasible_,meanDown,
    1361            numberTimesUp_,numberTimesUpInfeasible_,meanUp,downDynamicPseudoCost_,upDynamicPseudoCost_,n);
    1362 #endif
    13631245  } else {
    13641246    const double * upper = model_->getCbcColUpper();
     
    14371319                                                      int variable, int way,
    14381320                                                      double lowerValue,
    1439                                                       double upperValue)
     1321                                                                          double /*upperValue*/)
    14401322  :CbcIntegerBranchingObject(model,variable,way,lowerValue)
    14411323{
     
    15641446// Initialize i.e. before start of choosing at a node
    15651447void
    1566 CbcBranchDynamicDecision::initialize(CbcModel * model)
     1448CbcBranchDynamicDecision::initialize(CbcModel * /*model*/)
    15671449{
    15681450  bestCriterion_ = 0.0;
     
    17741656int
    17751657CbcBranchDynamicDecision::betterBranch(CbcBranchingObject * thisOne,
    1776                             CbcBranchingObject * bestSoFar,
     1658                                       CbcBranchingObject * /*bestSoFar*/,
    17771659                            double changeUp, int numInfUp,
    17781660                            double changeDown, int numInfDown)
     
    18751757#endif
    18761758  } else {
    1877     //#define TRY_STUFF 2
     1759#define TRY_STUFF 2
    18781760#if TRY_STUFF > 1
    18791761    // Get current number of infeasibilities, cutoff and current objective
     
    18921774    //maxValue = CoinMin(maxValue,minValue*2.0);
    18931775#endif
     1776#ifndef WEIGHT_PRODUCT
    18941777    value = WEIGHT_AFTER*minValue + (1.0-WEIGHT_AFTER)*maxValue;
     1778#else
     1779    double minProductWeight = model->getDblParam(CbcModel::CbcSmallChange);
     1780    value = CoinMax(minValue,minProductWeight)*CoinMax(maxValue,minProductWeight);
     1781    //value += minProductWeight*minValue;
     1782#endif
    18951783    double useValue = value;
    18961784    double useBest = bestCriterion_;
     
    19041792      // not much in it - look at unsatisfied
    19051793      if (thisNumber<numberUnsatisfied||bestNumber<numberUnsatisfied) {
    1906         double perInteger = distance/ ((double) numberUnsatisfied);
     1794        double perInteger = distance/ (static_cast<double> (numberUnsatisfied));
    19071795        useValue += thisNumber*perInteger;
    19081796        useBest += bestNumber*perInteger;
     
    19891877  FILE * fp = fopen(file,"w");
    19901878  assert(fp);
    1991   unsigned short numberIntegers=0;
     1879  int numberIntegers=0;
    19921880  int i;
    19931881  for (i=0;i<numberHistory;i++) {
  • stable/2.4/Cbc/src/CbcBranchDynamic.hpp

    r1121 r1271  
     1/* $Id$ */
    12// Copyright (C) 2005, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    3233 
    3334  // Useful constructor - passed  model index and pseudo costs
    34   CbcSimpleIntegerDynamicPseudoCost (CbcModel * model, int dummy, int iColumn,
     35  CbcSimpleIntegerDynamicPseudoCost (CbcModel * model,int dummy, int iColumn,
    3536                              double downDynamicPseudoCost, double upDynamicPseudoCost);
    3637 
     
    4748  virtual ~CbcSimpleIntegerDynamicPseudoCost ();
    4849 
    49   using CbcObject::infeasibility ;
    5050  /// Infeasibility - large is 0.5
    51   virtual double infeasibility(int & preferredWay) const;
    52 
    53   using CbcObject::createBranch ;
     51  virtual double infeasibility(const OsiBranchingInformation * info,
     52                               int &preferredWay) const;
     53
    5454  /// Creates a branching object
    55   virtual CbcBranchingObject * createBranch(int way) ;
    56 
    57   /// Infeasibility - large is 0.5
    58   virtual double infeasibility(const OsiSolverInterface * solver,
    59                                const OsiBranchingInformation * info, int & preferredWay) const;
    60 
    61 
    62   /** Create a branching object and indicate which way to branch first.
    63      
    64       The branching object has to know how to create branches (fix
    65       variables, etc.)
    66   */
    67   virtual CbcBranchingObject * createBranch(OsiSolverInterface * solver,
    68                                             const OsiBranchingInformation * info, int way) ;
     55  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) ;
     56
     57
    6958  /// Fills in a created branching object
    7059  void fillCreateBranch(CbcIntegerBranchingObject * branching, const OsiBranchingInformation * info, int way) ;
     
    10190  /// Set down pseudo cost
    10291  void setDownDynamicPseudoCost(double value) ;
     92  /// Modify down pseudo cost in a slightly different way
     93  void updateDownDynamicPseudoCost(double value);
    10394
    10495  /// Up pseudo cost
     
    10798  /// Set up pseudo cost
    10899  void setUpDynamicPseudoCost(double value);
     100  /// Modify up pseudo cost in a slightly different way
     101  void updateUpDynamicPseudoCost(double value);
     102
     103  /// Down pseudo shadow price cost
     104  inline double downShadowPrice() const
     105  { return downShadowPrice_;}
     106  /// Set down pseudo shadow price cost
     107  inline void setDownShadowPrice(double value)
     108  { downShadowPrice_ = value;}
     109  /// Up pseudo shadow price cost
     110  inline double upShadowPrice() const
     111  { return upShadowPrice_;}
     112  /// Set up pseudo shadow price cost
     113  inline void setUpShadowPrice(double value)
     114  { upShadowPrice_ = value;}
    109115
    110116  /// Up down separator
     
    123129  /// Add to down sum cost and set last and square
    124130  inline void addToSumDownCost(double value)
    125   { sumDownCost_+=value;lastDownCost_=value;sumDownCostSquared_ += value*value;}
     131  { sumDownCost_+=value;lastDownCost_=value;}
    126132
    127133  /// Up sum cost
     
    133139  /// Add to up sum cost and set last and square
    134140  inline void addToSumUpCost(double value)
    135   { sumUpCost_+=value;lastUpCost_=value;sumUpCostSquared_ += value*value;}
     141  { sumUpCost_+=value;lastUpCost_=value;}
    136142
    137143  /// Down sum change
     
    268274  /// Sum of all changes to x when going up
    269275  double sumUpChange_;
    270   /// Sum down cost from strong or actual squared
    271   mutable double sumDownCostSquared_;
    272   /// Sum up cost from strong or actual squared
    273   mutable double sumUpCostSquared_;
     276  /// Current pseudo-shadow price estimate down
     277  mutable double downShadowPrice_;
     278  /// Current pseudo-shadow price estimate up
     279  mutable double upShadowPrice_;
    274280  /// Sum down decrease number infeasibilities from strong or actual
    275281  double sumDownDecrease_;
     
    305311  int numberTimesProbingTotal_;
    306312  /// Number of times infeasible when tested
    307 #define CBC_INSTRUMENT
    308 #ifdef CBC_INSTRUMENT
    309   mutable int numberTimesInfeasible_;
    310 #endif
    311313  /** Method -
    312314      0 - pseudo costs
  • stable/2.4/Cbc/src/CbcBranchLotsize.cpp

    r912 r1271  
     1/* $Id$ */
    12// Copyright (C) 2002, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    3031// Just for debug (CBC_PRINT defined in CbcBranchLotsize.cpp)
    3132void
     33#if CBC_PRINT
    3234CbcLotsize::printLotsize(double value,bool condition,int type) const
     35#else
     36CbcLotsize::printLotsize(double ,bool ,int ) const
     37#endif
    3338{
    3439#if CBC_PRINT
     
    398403void
    399404CbcLotsize::floorCeiling(double & floorLotsize, double & ceilingLotsize, double value,
    400                          double tolerance) const
     405                         double /*tolerance*/) const
    401406{
    402407  bool feasible=findRange(value);
     
    416421  }
    417422}
    418 
    419 // Infeasibility - large is 0.5
    420423double
    421 CbcLotsize::infeasibility(int & preferredWay) const
     424CbcLotsize::infeasibility(const OsiBranchingInformation * /*info*/,
     425                               int &preferredWay) const
    422426{
    423427  OsiSolverInterface * solver = model_->solver();
     
    520524#endif
    521525}
    522 
    523 // Creates a branching object
    524526CbcBranchingObject *
    525 CbcLotsize::createBranch(int way)
    526 {
    527   OsiSolverInterface * solver = model_->solver();
     527CbcLotsize::createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * /*info*/, int way)
     528{
     529  //OsiSolverInterface * solver = model_->solver();
    528530  const double * solution = model_->testSolution();
    529531  const double * lower = solver->getColLower();
     
    643645 */
    644646void
    645 CbcLotsize::resetBounds(const OsiSolverInterface * solver)
     647CbcLotsize::resetBounds(const OsiSolverInterface * /*solver*/)
    646648{
    647649}
  • stable/2.4/Cbc/src/CbcBranchLotsize.hpp

    r1052 r1271  
     1/* $Id$ */
    12// Copyright (C) 2004, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    3435  ~CbcLotsize ();
    3536 
    36   using CbcObject::infeasibility ;
    3737  /// Infeasibility - large is 0.5
    38   virtual double infeasibility(int & preferredWay) const;
     38  virtual double infeasibility(const OsiBranchingInformation * info,
     39                               int &preferredWay) const;
    3940
    4041  using CbcObject::feasibleRegion ;
     
    4849  virtual void feasibleRegion();
    4950
    50   using CbcObject::createBranch ;
    5151  /// Creates a branching object
    52   virtual CbcBranchingObject * createBranch(int way) ;
     52  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) ;
    5353
    5454  /** \brief Given a valid solution (with reduced costs, etc.),
  • stable/2.4/Cbc/src/CbcCbcParam.cpp

    r640 r1271  
     1/* $Id: CbcCbcParam.cpp 1173 2009-06-04 09:44:10Z forrest $ */
    12#  include "../../Clp/src/CbcOrClpParam.cpp"
    23
  • stable/2.4/Cbc/src/CbcCompareActual.cpp

    r1136 r1271  
     1/* $Id$ */
    12// Copyright (C) 2004, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    292293#define TRY_THIS 0
    293294#if TRY_THIS==0
    294     double weight = CoinMax(weight_,0.0);
     295    double weight = CoinMax(weight_,1.0e-9);
    295296    double testX =  x->objectiveValue()+ weight*x->numberUnsatisfied();
    296297    double testY = y->objectiveValue() + weight*y->numberUnsatisfied();
     
    310311    double testX = x->guessedObjectiveValue();
    311312    double testY = y->guessedObjectiveValue();
    312 #elif THY_THIS==3
     313#elif TRY_THIS==3
    313314#define THRESH 0.95
     315    // Use estimates
     316    double testX = x->guessedObjectiveValue();
     317    double testY = y->guessedObjectiveValue();
    314318    if (x->objectiveValue()-bestPossible_>THRESH*(cutoff_-bestPossible_))
    315319      testX *= 2.0; // make worse
  • stable/2.4/Cbc/src/CbcCompareActual.hpp

    r1132 r1271  
     1/* $Id$ */
    12// Copyright (C) 2002, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcCompareBase.hpp

    r838 r1271  
     1/* $Id$ */
    12// Copyright (C) 2002, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    2930  // This allows any method to change behavior as it is called
    3031  // after each solution
    31   virtual void newSolution(CbcModel * model) {}
     32  virtual void newSolution(CbcModel * ) {}
    3233
    3334  // This Also allows any method to change behavior as it is called
    3435  // after each solution
    35   virtual void newSolution(CbcModel * model,
    36                            double objectiveAtContinuous,
    37                            int numberInfeasibilitiesAtContinuous) {}
     36  virtual void newSolution(CbcModel * ,
     37                           double ,
     38                           int ) {}
    3839
    3940  // This allows any method to change behavior as it is called
    4041  // after every 1000 nodes.
    4142  // Return true if want tree re-sorted
    42   virtual bool every1000Nodes(CbcModel * model,int numberNodes) {return false;}
     43  virtual bool every1000Nodes(CbcModel * ,int ) {return false;}
    4344
    4445  /** Returns true if wants code to do scan with alternate criterion
     
    4950  virtual ~CbcCompareBase() {}
    5051  /// Create C++ lines to get to current state
    51   virtual void generateCpp( FILE * fp) {}
     52  virtual void generateCpp( FILE * ) {}
    5253
    5354  // Copy constructor
     
    6667
    6768  /// This is test function
    68   virtual bool test (CbcNode * x, CbcNode * y) {return true;}
     69  virtual bool test (CbcNode * , CbcNode * ) {return true;}
    6970
    7071  /// This is alternate test function
  • stable/2.4/Cbc/src/CbcConfig.h

    r892 r1271  
     1/* $Id$ */
    12/*
    23 * Include file for the configuration of Cbc.
     
    9596
    9697#endif /* HAVE_CONFIG_H */
     98// Always make version 2.4
     99#undef CBCVERSION
     100#define CBCVERSION "2.4.0"
    97101
    98102#endif /*__HAVE_COINUTILS_CONFIG_H__*/
  • stable/2.4/Cbc/src/CbcCountRowCut.cpp

    r1121 r1271  
     1/* $Id$ */
    12// Copyright (C) 2002, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcCountRowCut.hpp

    r1121 r1271  
     1/* $Id$ */
    12// Copyright (C) 2002, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcCutGenerator.cpp

    r1226 r1271  
     1/* $Id$ */
    12// Copyright (C) 2003, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    2526// Default Constructor
    2627CbcCutGenerator::CbcCutGenerator ()
    27   : model_(NULL),
     28  : timeInCutGenerator_(0.0),
     29    model_(NULL),
    2830    generator_(NULL),
     31    generatorName_(NULL),
    2932    whenCutGenerator_(-1),
    3033    whenCutGeneratorInSub_(-100),
     
    3235    depthCutGenerator_(-1),
    3336    depthCutGeneratorInSub_(-1),
    34     generatorName_(NULL),
    35     normal_(true),
    36     atSolution_(false),
    37     whenInfeasible_(false),
    38     mustCallAgain_(false),
    39     switchedOff_(false),
    40     globalCutsAtRoot_(false),
    41     timing_(false),
    42     timeInCutGenerator_(0.0),
    4337    inaccuracy_(0),
    4438    numberTimes_(0),
    4539    numberCuts_(0),
     40    numberElements_(0),
    4641    numberColumnCuts_(0),
    4742    numberCutsActive_(0),
    4843    numberCutsAtRoot_(0),
    49     numberActiveCutsAtRoot_(0)
     44    numberActiveCutsAtRoot_(0),
     45    numberShortCutsAtRoot_(0),
     46    switches_(1)
    5047{
    5148}
     
    5855                                 int switchOffIfLessThan)
    5956  :
     57    timeInCutGenerator_(0.0),
    6058    depthCutGenerator_(whatDepth),
    6159    depthCutGeneratorInSub_(whatDepthInSub),
    62     mustCallAgain_(false),
    63     switchedOff_(false),
    64     globalCutsAtRoot_(false),
    65     timing_(false),
    66     timeInCutGenerator_(0.0),
    6760    inaccuracy_(0),
    6861    numberTimes_(0),
    6962    numberCuts_(0),
     63    numberElements_(0),
    7064    numberColumnCuts_(0),
    7165    numberCutsActive_(0),
    7266    numberCutsAtRoot_(0),
    73     numberActiveCutsAtRoot_(0)
    74 {
    75   if (howOften<-1000) {
    76     globalCutsAtRoot_=true;
     67    numberActiveCutsAtRoot_(0),
     68    numberShortCutsAtRoot_(0),
     69    switches_(1)
     70{
     71  if (howOften<-1900) {
     72    setGlobalCuts(true);
     73    howOften+=2000;
     74  } else if (howOften<-900) {
     75    setGlobalCutsAtRoot(true);
    7776    howOften+=1000;
    7877  }
     
    8079  generator_=generator->clone();
    8180  generator_->refreshSolver(model_->solver());
     81  setNeedsOptimalBasis(generator_->needsOptimalBasis());
    8282  whenCutGenerator_=howOften;
    8383  whenCutGeneratorInSub_ = howOftenInSub;
     
    8787  else
    8888    generatorName_ = strdup("Unknown");
    89   normal_=normal;
    90   atSolution_=atSolution;
    91   whenInfeasible_=infeasible;
     89  setNormal(normal);
     90  setAtSolution(atSolution);
     91  setWhenInfeasible(infeasible);
    9292}
    9393
     
    104104  depthCutGeneratorInSub_ = rhs.depthCutGeneratorInSub_;
    105105  generatorName_=strdup(rhs.generatorName_);
    106   normal_=rhs.normal_;
    107   atSolution_=rhs.atSolution_;
    108   whenInfeasible_=rhs.whenInfeasible_;
    109   mustCallAgain_ = rhs.mustCallAgain_;
    110   switchedOff_ = rhs.switchedOff_;
    111   globalCutsAtRoot_ = rhs.globalCutsAtRoot_;
    112   timing_ = rhs.timing_;
     106  switches_ = rhs.switches_;
    113107  timeInCutGenerator_ = rhs.timeInCutGenerator_;
     108  savedCuts_ = rhs.savedCuts_;
    114109  inaccuracy_ = rhs.inaccuracy_;
    115110  numberTimes_ = rhs.numberTimes_;
    116111  numberCuts_ = rhs.numberCuts_;
     112  numberElements_ = rhs.numberElements_;
    117113  numberColumnCuts_ = rhs.numberColumnCuts_;
    118114  numberCutsActive_ = rhs.numberCutsActive_;
    119115  numberCutsAtRoot_  = rhs.numberCutsAtRoot_;
    120116  numberActiveCutsAtRoot_ = rhs.numberActiveCutsAtRoot_;
     117  numberShortCutsAtRoot_ = rhs.numberShortCutsAtRoot_;
    121118}
    122119
     
    137134    depthCutGeneratorInSub_ = rhs.depthCutGeneratorInSub_;
    138135    generatorName_=strdup(rhs.generatorName_);
    139     normal_=rhs.normal_;
    140     atSolution_=rhs.atSolution_;
    141     whenInfeasible_=rhs.whenInfeasible_;
    142     mustCallAgain_ = rhs.mustCallAgain_;
    143     switchedOff_ = rhs.switchedOff_;
    144     globalCutsAtRoot_ = rhs.globalCutsAtRoot_;
    145     timing_ = rhs.timing_;
     136    switches_ = rhs.switches_;
    146137    timeInCutGenerator_ = rhs.timeInCutGenerator_;
     138    savedCuts_ = rhs.savedCuts_;
    147139    inaccuracy_ = rhs.inaccuracy_;
    148140    numberTimes_ = rhs.numberTimes_;
    149141    numberCuts_ = rhs.numberCuts_;
     142    numberElements_ = rhs.numberElements_;
    150143    numberColumnCuts_ = rhs.numberColumnCuts_;
    151144    numberCutsActive_ = rhs.numberCutsActive_;
    152145    numberCutsAtRoot_  = rhs.numberCutsAtRoot_;
    153146    numberActiveCutsAtRoot_ = rhs.numberActiveCutsAtRoot_;
     147    numberShortCutsAtRoot_ = rhs.numberShortCutsAtRoot_;
    154148  }
    155149  return *this;
     
    180174CbcCutGenerator::generateCuts( OsiCuts & cs , int fullScan, OsiSolverInterface * solver, CbcNode * node)
    181175{
    182 #define PROBE1 1
    183 #define PROBE2 0
    184 #define PROBE3 1
    185176  int depth;
    186177  if (node)
     
    189180    depth=0;
    190181  int howOften = whenCutGenerator_;
    191   if (dynamic_cast<CglProbing*>(generator_)&&PROBE1) {
     182  if (dynamic_cast<CglProbing*>(generator_)) {
    192183    if (howOften==-100&&model_->doCutsNow(3)) {
    193184      howOften=1; // do anyway
     
    205196  //OsiSolverInterface * solver = model_->solver();
    206197  int pass=model_->getCurrentPassNumber()-1;
     198  // Reset cuts on first pass
     199  if (!pass)
     200    savedCuts_ = OsiCuts();
    207201  bool doThis=(model_->getNodeCount()%howOften)==0;
    208   CoinThreadRandom * randomNumberGenerator=NULL;
    209 #ifdef COIN_HAS_CLP
    210   {
    211     OsiClpSolverInterface * clpSolver
    212       = dynamic_cast<OsiClpSolverInterface *> (solver);
    213     if (clpSolver)
    214       randomNumberGenerator = clpSolver->getModelPtr()->randomNumberGenerator();
    215   }
    216 #endif
    217202  if (depthCutGenerator_>0) {
    218203    doThis = (depth % depthCutGenerator_) ==0;
     
    229214  }
    230215  if (fullScan||doThis) {
     216    CoinThreadRandom * randomNumberGenerator=NULL;
     217#ifdef COIN_HAS_CLP
     218    {
     219      OsiClpSolverInterface * clpSolver
     220        = dynamic_cast<OsiClpSolverInterface *> (solver);
     221      if (clpSolver)
     222        randomNumberGenerator =
     223          clpSolver->getModelPtr()->randomNumberGenerator();
     224    }
     225#endif
    231226    double time1=0.0;
    232     if (timing_)
     227    if (timing())
    233228      time1 = CoinCpuTime();
    234229    //#define CBC_DEBUG
     
    244239    info.inTree = node!=NULL;
    245240    info.randomNumberGenerator=randomNumberGenerator;
    246     info.options=(globalCutsAtRoot_) ? 8 : 0;
     241    info.options=(globalCutsAtRoot()) ? 8 : 0;
     242    if (ineffectualCuts())
     243      info.options |= 32;
     244    if (globalCuts())
     245      info.options |=16;
     246    if (fullScan<0)
     247      info.options |= 128;
     248    // See if we want alternate set of cuts
     249    if ((model_->moreSpecialOptions()&16384)!=0)
     250      info.options |=256;
     251    if(model_->parentModel())
     252      info.options |=512;
     253    // above had &&!model_->parentModel()&&depth<2)
    247254    incrementNumberTimesEntered();
    248255    CglProbing* generator =
     
    259266      bool doCuts=false;
    260267      if (info2&&!depth) {
    261         info2->options=(globalCutsAtRoot_) ? 8 : 0;
     268        info2->options=(globalCutsAtRoot()) ? 8 : 0;
    262269        info2->level = depth;
    263270        info2->pass = pass;
     
    267274        generator->generateCutsAndModify(*solver,cs,info2);
    268275        doCuts=true;
    269       } else if (depth||PROBE2) {
    270 #if PROBE3
     276      } else if (depth) {
     277        /* The idea behind this is that probing may work in a different
     278           way deep in tree.  So every now and then try various
     279           combinations to see what works.
     280        */
     281#define TRY_NOW_AND_THEN
     282#ifdef TRY_NOW_AND_THEN
    271283        if ((numberTimes_==200||(numberTimes_>200&&(numberTimes_%2000)==0))
    272              &&!model_->parentModel()&&info.formulation_rows>500) {
    273           // in tree, maxStack, maxProbe
     284             &&!model_->parentModel()&&info.formulation_rows>200) {
     285          /* In tree, every now and then try various combinations
     286             maxStack, maxProbe (last 5 digits)
     287             123 is special and means CglProbing will try and
     288             be intelligent.
     289          */
    274290          int test[]= {
    275291            100123,
     
    286302          int saveStack = generator->getMaxLook();
    287303          int saveNumber = generator->getMaxProbe();
    288 #undef CLP_INVESTIGATE
    289 #ifdef CLP_INVESTIGATE
    290304          int kr1=0;
    291305          int kc1=0;
    292 #endif
    293306          int bestStackTree=-1;
    294307          int bestNumberTree=-1;
    295308          for (int i=0;i<n;i++) {
    296             OsiCuts cs2 = cs;
     309            //OsiCuts cs2 = cs;
    297310            int stack = test[i]/100000;
    298311            int number = test[i] - 100000*stack;
    299312            generator->setMaxLook(stack);
    300313            generator->setMaxProbe(number);
    301             generator_->generateCuts(*solver,cs2,info);
     314            int numberRowCutsBefore = cs.sizeRowCuts() ;
     315            int numberColumnCutsBefore = cs.sizeColCuts() ;
     316            generator_->generateCuts(*solver,cs,info);
     317            int numberRowCuts = cs.sizeRowCuts()-numberRowCutsBefore ;
     318            int numberColumnCuts= cs.sizeColCuts()-numberColumnCutsBefore ;
    302319#ifdef CLP_INVESTIGATE
    303             int numberRowCuts = cs2.sizeRowCuts()-numberRowCutsBefore ;
    304             int numberColumnCuts= cs2.sizeColCuts()-numberColumnCutsBefore ;
    305320            if (numberRowCuts<kr1||numberColumnCuts<kc1)
    306321              printf("Odd ");
     322#endif
    307323            if (numberRowCuts>kr1||numberColumnCuts>kc1) {
     324#ifdef CLP_INVESTIGATE
    308325              printf("*** ");
     326#endif
    309327              kr1=numberRowCuts;
    310328              kc1=numberColumnCuts;
    311329              bestStackTree=stack;
    312330              bestNumberTree=number;
    313             }
     331              doCuts=true;
     332            }
     333#ifdef CLP_INVESTIGATE
    314334            printf("maxStack %d number %d gives %d row cuts and %d column cuts\n",
    315335                   stack,number,numberRowCuts,numberColumnCuts);
     
    330350#ifdef CLP_INVESTIGATE
    331351            printf("RRSwitching off number %d -> %d, stack %d -> %d\n",
    332                    saveNumber,saveNumber,saveStack,0);
    333 #endif
    334           }
    335         }
    336 #endif
    337         if (generator->getMaxLook()>0) {
     352                   saveNumber,saveNumber,saveStack,1);
     353#endif
     354          }
     355        }
     356#endif
     357        if (generator->getMaxLook()>0&&!doCuts) {
    338358          generator->generateCutsAndModify(*solver,cs,&info);
    339359          doCuts=true;
     
    341361      } else {
    342362        // at root - don't always do
    343         if (!PROBE3||pass<15||(pass&1)==0) {
     363        if (pass<15||(pass&1)==0) {
    344364          generator->generateCutsAndModify(*solver,cs,&info);
    345365          doCuts=true;
    346366        }
    347367      }
    348       if (doCuts) {
     368      if (doCuts&&generator->tightLower()) {
     369        // probing may have tightened bounds - check
    349370        const double * tightLower = generator->tightLower();
    350371        const double * lower = solver->getColLower();
     
    500521      }
    501522    }
    502     {
    503       int numberRowCutsAfter = cs.sizeRowCuts() ;
    504       if (numberRowCutsBefore<numberRowCutsAfter) {
    505 #if 0
    506         printf("generator %s generated %d row cuts\n",
    507                generatorName_,numberRowCutsAfter-numberRowCutsBefore);
    508 #endif
    509         numberCuts_ += numberRowCutsAfter-numberRowCutsBefore;
    510       }
    511       int numberColumnCutsAfter = cs.sizeColCuts() ;
    512       if (numberColumnCutsBefore<numberColumnCutsAfter) {
    513 #if 0
    514         printf("generator %s generated %d column cuts\n",
    515                generatorName_,numberColumnCutsAfter-numberColumnCutsBefore);
    516 #endif
    517         numberColumnCuts_ += numberColumnCutsAfter-numberColumnCutsBefore;
     523    // Add in saved cuts if violated
     524    if (false&&!depth) {
     525      const double * solution = solver->getColSolution();
     526      double primalTolerance = 1.0e-7;
     527      int numberCuts = savedCuts_.sizeRowCuts() ;
     528      for (int k = numberCuts-1;k>=0;k--) {
     529        const OsiRowCut * thisCut = savedCuts_.rowCutPtr(k) ;
     530        double sum=0.0;
     531        int n=thisCut->row().getNumElements();
     532        const int * column = thisCut->row().getIndices();
     533        const double * element = thisCut->row().getElements();
     534        assert (n);
     535        for (int i=0;i<n;i++) {
     536          double value = element[i];
     537          sum += value*solution[column[i]];
     538        }
     539        if (sum>thisCut->ub()+primalTolerance) {
     540          sum= sum-thisCut->ub();
     541        } else if (sum<thisCut->lb()-primalTolerance) {
     542          sum= thisCut->lb()-sum;
     543        } else {
     544          sum=0.0;
     545        }
     546        if (sum) {
     547          // add to candidates and take out here
     548          cs.insert(*thisCut);
     549          savedCuts_.eraseRowCut(k);
     550        }
    518551      }
    519552    }
     
    528561      bool feasible=true;
    529562      double primalTolerance = 1.0e-7;
     563      int shortCut = (depth) ? -1 : generator_->maximumLengthOfCutInTree();
    530564      for (k = numberRowCutsAfter-1;k>=numberRowCutsBefore;k--) {
    531565        const OsiRowCut * thisCut = cs.rowCutPtr(k) ;
     
    533567        if (thisCut->lb()<=thisCut->ub()) {
    534568          int n=thisCut->row().getNumElements();
     569          if (n<=shortCut)
     570            numberShortCutsAtRoot_++;
    535571          const int * column = thisCut->row().getIndices();
    536572          const double * element = thisCut->row().getElements();
     
    589625        nAdd2 = 5*numberColumns;
    590626        nReasonable = CoinMax(nAdd2,nElsNow/8+nAdd);
     627        if (!depth&&!pass) {
     628          // allow more
     629          nAdd += nElsNow/2;
     630          nAdd2 += nElsNow/2;
     631          nReasonable += nElsNow/2;
     632        }
     633        //if (!depth&&ineffectualCuts())
     634        //nReasonable *= 2;
    591635      } else {
    592636        nAdd = 200;
     
    602646        //printf("need to remove cuts\n");
    603647        // just add most effective
     648#if 1
    604649        int nDelete = nEls - nReasonable;
    605650       
     
    609654        // For parallel cuts
    610655        double * element2 = new double [numberColumns];
     656        //#define USE_OBJECTIVE 2
     657#ifdef USE_OBJECTIVE
     658        const double *objective = solver->getObjCoefficients() ;
     659#if USE_OBJECTIVE>1
     660        double objNorm=0.0;
     661        for (int i=0;i<numberColumns;i++)
     662          objNorm += objective[i]*objective[i];
     663        if (objNorm)
     664          objNorm = 1.0/sqrt(objNorm);
     665        else
     666          objNorm=1.0;
     667        objNorm *= 0.01; // downgrade
     668#endif
     669#endif
    611670        CoinZeroN(element2,numberColumns);
    612671        for (k = numberRowCutsBefore;k<numberRowCutsAfter;k++) {
     
    647706#else
    648707            double norm=1.0e-3;
     708#ifdef USE_OBJECTIVE
     709            double obj=0.0;
     710#endif
    649711            for (int i=0;i<n;i++) {
     712              int iColumn = column[i];
    650713              double value = element[i];
    651               sum += value*solution[column[i]];
     714              sum += value*solution[iColumn];
    652715              norm += value*value;
     716#ifdef USE_OBJECTIVE
     717              obj += value*objective[iColumn];
     718#endif
    653719            }
    654720#endif
     
    660726              sum=0.0;
    661727            }
     728#ifdef USE_OBJECTIVE
     729            if (sum) {
     730#if USE_OBJECTIVE==1
     731              obj = CoinMax(1.0e-6,fabs(obj));
     732              norm=sqrt(obj*norm);
     733              //sum += fabs(obj)*invObjNorm;
     734              //printf("sum %g norm %g normobj %g invNorm %g mod %g\n",
     735              //     sum,norm,obj,invObjNorm,obj*invObjNorm);
     736              // normalize
     737              sum /= sqrt(norm);
     738#else
     739              // normalize
     740              norm = 1.0/sqrt(norm);
     741              sum = (sum+objNorm*obj)*norm;
     742#endif
     743            }
     744#else
    662745            // normalize
    663746            sum /= sqrt(norm);
     747#endif
    664748            //sum /= pow(norm,0.3);
    665749            // adjust for length
     
    750834          const OsiRowCut * thisCut = cs.rowCutPtr(iCut) ;
    751835          int n=thisCut->row().getNumElements();
     836          // may be best, just to save if short
     837          if (false&&n&&sort[k]) {
     838            // add to saved cuts
     839            savedCuts_.insert(*thisCut);
     840          }
    752841          nDelete-=n;
    753842          k++;
     
    763852        delete [] which;
    764853        numberRowCutsAfter = cs.sizeRowCuts() ;
    765 #if 0 //def CLP_INVESTIGATE
    766         nEls=0;
    767         int nCuts2= numberRowCutsAfter-numberRowCutsBefore;
    768         for (k = numberRowCutsBefore;k<numberRowCutsAfter;k++) {
    769           const OsiRowCut * thisCut = cs.rowCutPtr(k) ;
     854#else
     855        double * norm = new double [nCuts];
     856        int * which = new int [2*nCuts];
     857        double * score = new double [nCuts];
     858        double * ortho = new double [nCuts];
     859        int nIn=0;
     860        int nOut=nCuts;
     861        // For parallel cuts
     862        double * element2 = new double [numberColumns];
     863        const double *objective = solver->getObjCoefficients() ;
     864        double objNorm=0.0;
     865        for (int i=0;i<numberColumns;i++)
     866          objNorm += objective[i]*objective[i];
     867        if (objNorm)
     868          objNorm = 1.0/sqrt(objNorm);
     869        else
     870          objNorm=1.0;
     871        objNorm *= 0.1; // weight of 0.1
     872        CoinZeroN(element2,numberColumns);
     873        int numberRowCuts = numberRowCutsAfter-numberRowCutsBefore;
     874        int iBest=-1;
     875        double best=0.0;
     876        int nPossible=0;
     877        double testValue = (depth>1) ? 0.7 : 0.5;
     878        for (k = 0;k<numberRowCuts;k++) {
     879          const OsiRowCut * thisCut = cs.rowCutPtr(k+numberRowCutsBefore) ;
     880          double sum=0.0;
     881          if (thisCut->lb()<=thisCut->ub()) {
     882            int n=thisCut->row().getNumElements();
     883            const int * column = thisCut->row().getIndices();
     884            const double * element = thisCut->row().getElements();
     885            assert (n);
     886            double normThis=1.0e-6;
     887            double obj=0.0;
     888            for (int i=0;i<n;i++) {
     889              int iColumn = column[i];
     890              double value = element[i];
     891              sum += value*solution[iColumn];
     892              normThis += value*value;
     893              obj += value*objective[iColumn];
     894            }
     895            if (sum>thisCut->ub()) {
     896              sum= sum-thisCut->ub();
     897            } else if (sum<thisCut->lb()) {
     898              sum= thisCut->lb()-sum;
     899            } else {
     900              sum=0.0;
     901            }
     902            if (sum) {
     903              normThis =1.0/sqrt(normThis);
     904              norm[k]=normThis;
     905              sum *= normThis;
     906              obj *= normThis;
     907              score[k]=sum+obj*objNorm;
     908              ortho[k]=1.0;
     909            }
     910          } else {
     911            // keep and discard others
     912            nIn=1;
     913            which[0]=k;
     914            for (int j = 0;j<numberRowCuts;j++) {
     915              if (j!=k)
     916                which[nOut++]=j;
     917            }
     918            iBest=-1;
     919            break;
     920          }
     921          if (sum) {
     922            if (score[k]>best) {
     923              best=score[k];
     924              iBest=nPossible;
     925            }
     926            which[nPossible++]=k;
     927          } else {
     928            which[nOut++]=k;
     929          }
     930        }
     931        while (iBest>=0) {
     932          int kBest=which[iBest];
     933          int j=which[nIn];
     934          which[iBest]=j;
     935          which[nIn++]=kBest;
     936          const OsiRowCut * thisCut = cs.rowCutPtr(kBest+numberRowCutsBefore) ;
    770937          int n=thisCut->row().getNumElements();
    771           nEls+= n;
    772         }
    773         if (!model_->parentModel()&&nCuts!=nCuts2)
    774           printf("%s NOW has %d cuts and %d elements( down from %d cuts and %d els) - %d parallel\n",
    775                  generatorName_,
    776                  nCuts2,nEls,nCuts,nElsNow,nParallel);
     938          nReasonable -= n;
     939          if (nReasonable<=0) {
     940            for (k=nIn;k<nPossible;k++)
     941              which[nOut++]=which[k];
     942            break;
     943          }
     944          // Now see which ones are too similar and choose next
     945          iBest=-1;
     946          best=0.0;
     947          int nOld=nPossible;
     948          nPossible=nIn;
     949          const int * column = thisCut->row().getIndices();
     950          const double * element = thisCut->row().getElements();
     951          assert (n);
     952          double normNew = norm[kBest];
     953          for (int i=0;i<n;i++) {
     954            double value = element[i];
     955            element2[column[i]]=value;
     956          }
     957          for (int j=nIn;j<nOld;j++) {
     958            k = which[j];
     959            const OsiRowCut * thisCut2 = cs.rowCutPtr(k+numberRowCutsBefore) ;
     960            int nB=thisCut2->row().getNumElements();
     961            const int * columnB = thisCut2->row().getIndices();
     962            const double * elementB = thisCut2->row().getElements();
     963            assert (nB);
     964            double normB=norm[k];
     965            double product=0.0;
     966            for (int i=0;i<nB;i++) {
     967              double value = elementB[i];
     968              product += value*element2[columnB[i]];
     969            }
     970            double orthoScore = 1.0-product*normNew*normB;
     971            if (orthoScore>=testValue) {
     972              ortho[k]=CoinMin(orthoScore,ortho[k]);
     973              double test=score[k]+ortho[k];
     974              if (test>best) {
     975                best=score[k];
     976                iBest=nPossible;
     977              }
     978              which[nPossible++]=k;
     979            } else {
     980              which[nOut++]=k;
     981            }
     982          }
     983          for (int i=0;i<n;i++) {
     984            element2[column[i]]=0.0;
     985          }
     986        }
     987        delete [] score;
     988        delete [] ortho;
     989        std::sort(which+nCuts,which+nOut);
     990        k=nOut-1;
     991        for (;k>=nCuts;k--) {
     992          cs.eraseRowCut(which[k]+numberRowCutsBefore);
     993        }
     994        delete [] norm;
     995        delete [] which;
     996        numberRowCutsAfter = cs.sizeRowCuts() ;
    777997#endif
    778998      }
     
    8101030    }
    8111031#endif
    812     if (timing_)
     1032    {
     1033      int numberRowCutsAfter = cs.sizeRowCuts() ;
     1034      if (numberRowCutsBefore<numberRowCutsAfter) {
     1035        for (int k = numberRowCutsBefore;k<numberRowCutsAfter;k++) {
     1036          OsiRowCut thisCut = cs.rowCut(k) ;
     1037          int n=thisCut.row().getNumElements();
     1038          numberElements_ += n;
     1039        }
     1040#if 0
     1041        printf("generator %s generated %d row cuts\n",
     1042               generatorName_,numberRowCutsAfter-numberRowCutsBefore);
     1043#endif
     1044        numberCuts_ += numberRowCutsAfter-numberRowCutsBefore;
     1045      }
     1046      int numberColumnCutsAfter = cs.sizeColCuts() ;
     1047      if (numberColumnCutsBefore<numberColumnCutsAfter) {
     1048#if 0
     1049        printf("generator %s generated %d column cuts\n",
     1050               generatorName_,numberColumnCutsAfter-numberColumnCutsBefore);
     1051#endif
     1052        numberColumnCuts_ += numberColumnCutsAfter-numberColumnCutsBefore;
     1053      }
     1054    }
     1055    if (timing())
    8131056      timeInCutGenerator_ += CoinCpuTime()-time1;
    8141057#if 0
     
    8511094  depthCutGeneratorInSub_ = value;
    8521095}
     1096// Create C++ lines to get to current state
     1097void
     1098CbcCutGenerator::generateTuning( FILE * fp)
     1099{
     1100  fprintf(fp,"// Cbc tuning for generator %s\n",generatorName_);
     1101  fprintf(fp,"   generator->setHowOften(%d);\n",whenCutGenerator_);
     1102  fprintf(fp,"   generator->setSwitchOffIfLessThan(%d);\n",switchOffIfLessThan_);
     1103  fprintf(fp,"   generator->setWhatDepth(%d);\n",depthCutGenerator_);
     1104  fprintf(fp,"   generator->setInaccuracy(%d);\n",inaccuracy_);
     1105  if (timing())
     1106    fprintf(fp,"   generator->setTiming(true);\n");
     1107  if (normal())
     1108    fprintf(fp,"   generator->setNormal(true);\n");
     1109  if (atSolution())
     1110    fprintf(fp,"   generator->setAtSolution(true);\n");
     1111  if (whenInfeasible())
     1112    fprintf(fp,"   generator->setWhenInfeasible(true);\n");
     1113  if (needsOptimalBasis())
     1114    fprintf(fp,"   generator->setNeedsOptimalBasis(true);\n");
     1115  if (mustCallAgain())
     1116    fprintf(fp,"   generator->setMustCallAgain(true);\n");
     1117  if (whetherToUse())
     1118    fprintf(fp,"   generator->setWhetherToUse(true);\n");
     1119}
    8531120
    8541121
     
    8651132
    8661133// Copy constructor
    867 CbcCutModifier::CbcCutModifier ( const CbcCutModifier & rhs)
     1134CbcCutModifier::CbcCutModifier ( const CbcCutModifier & /*rhs*/)
    8681135{
    8691136}
     
    9281195*/
    9291196int
    930 CbcCutSubsetModifier::modify(const OsiSolverInterface * solver, OsiRowCut & cut)
     1197CbcCutSubsetModifier::modify(const OsiSolverInterface * /*solver*/,
     1198                             OsiRowCut & cut)
    9311199{
    9321200  int n=cut.row().getNumElements();
  • stable/2.4/Cbc/src/CbcCutGenerator.hpp

    r1132 r1271  
     1/* $Id$ */
    12// Copyright (C) 2003, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    5556    \p cs.
    5657
    57     If \p fullScan is >0, the generator is obliged to call the CGL
     58    If \p fullScan is !=0, the generator is obliged to call the CGL
    5859    \c generateCuts routine.  Otherwise, it is free to make a local decision.
     60    Negative fullScan says things like at integer solution
    5961    The current implementation uses \c whenCutGenerator_ to decide.
    6062
     
    104106  { return generatorName_;}
    105107
     108  /// Create C++ lines to show how to tune
     109  void generateTuning( FILE * fp);
    106110  /** Set the cut generation interval
    107111
     
    155159  /// Get whether the cut generator should be called in the normal place
    156160  inline bool normal() const
    157   { return normal_;}
     161  { return (switches_&1)!=0;}
    158162  /// Set whether the cut generator should be called in the normal place
    159163  inline void setNormal(bool value)
    160   { normal_=value;}
     164  { switches_&=~1;switches_ |= value ? 1 : 0;}
    161165  /// Get whether the cut generator should be called when a solution is found
    162166  inline bool atSolution() const
    163   { return atSolution_;}
     167  { return (switches_&2)!=0;}
    164168  /// Set whether the cut generator should be called when a solution is found
    165169  inline void setAtSolution(bool value)
    166   { atSolution_=value;}
     170  { switches_&=~2;switches_ |= value ? 2 : 0;}
    167171  /** Get whether the cut generator should be called when the subproblem is
    168172      found to be infeasible.
    169173  */
    170174  inline bool whenInfeasible() const
    171   { return whenInfeasible_;}
     175  { return (switches_&4)!=0;}
    172176  /** Set whether the cut generator should be called when the subproblem is
    173177      found to be infeasible.
    174178  */
    175179  inline void setWhenInfeasible(bool value)
    176   { whenInfeasible_=value;}
     180  { switches_&=~4;switches_ |= value ? 4 : 0;}
    177181  /// Get whether the cut generator is being timed
    178182  inline bool timing() const
    179   { return timing_;}
     183  { return (switches_&64)!=0;}
    180184  /// Set whether the cut generator is being timed
    181185  inline void setTiming(bool value)
    182   { timing_=value; timeInCutGenerator_=0.0;}
     186  { switches_&=~64;switches_ |= value ? 64 : 0; timeInCutGenerator_=0.0;}
    183187  /// Return time taken in cut generator
    184188  inline double timeInCutGenerator() const
     
    203207  inline void incrementNumberCutsInTotal(int value=1)
    204208  { numberCuts_ += value;}
     209  /// Total number of elements added
     210  inline int numberElementsInTotal() const
     211  { return numberElements_;}
     212  inline void setNumberElementsInTotal(int value)
     213  { numberElements_ = value;}
     214  inline void incrementNumberElementsInTotal(int value=1)
     215  { numberElements_ += value;}
    205216  /// Total number of column cuts
    206217  inline int numberColumnCuts() const
     
    223234  /// Say if optimal basis needed
    224235  inline bool needsOptimalBasis() const
    225   { return generator_->needsOptimalBasis();}
     236  { return (switches_&128)!=0;}
     237  /// Set if optimal basis needed
     238  inline void setNeedsOptimalBasis(bool yesNo)
     239  { switches_&=~128;switches_ |= yesNo ? 128 : 0;}
    226240  /// Whether generator MUST be called again if any cuts (i.e. ignore break from loop)
    227241  inline bool mustCallAgain() const
    228   { return mustCallAgain_;}
     242  { return (switches_&8)!=0;}
    229243  /// Set whether generator MUST be called again if any cuts (i.e. ignore break from loop)
    230244  inline void setMustCallAgain(bool yesNo)
    231   { mustCallAgain_=yesNo;}
     245  { switches_&=~8;switches_ |= yesNo ? 8 : 0;}
    232246  /// Whether generator switched off for moment
    233247  inline bool switchedOff() const
    234   { return switchedOff_;}
     248  { return (switches_&16)!=0;}
    235249  /// Set whether generator switched off for moment
    236250  inline void setSwitchedOff(bool yesNo)
    237   { switchedOff_=yesNo;}
     251  { switches_&=~16;switches_ |= yesNo ? 16 : 0;}
     252  /// Whether last round of cuts did little
     253  inline bool ineffectualCuts() const
     254  { return (switches_&512)!=0;}
     255  /// Set whether last round of cuts did little
     256  inline void setIneffectualCuts(bool yesNo)
     257  { switches_&=~512;switches_ |= yesNo ? 512 : 0;}
     258  /// Whether to use if any cuts generated
     259  inline bool whetherToUse() const
     260  { return (switches_&1024)!=0;}
     261  /// Set whether to use if any cuts generated
     262  inline void setWhetherToUse(bool yesNo)
     263  { switches_&=~1024;switches_ |= yesNo ? 1024 : 0;}
    238264  /// Number of cuts generated at root
    239265  inline int numberCutsAtRoot() const
     
    246272  inline void setNumberActiveCutsAtRoot(int value)
    247273  { numberActiveCutsAtRoot_ = value;}
     274  /// Number of short cuts at root
     275  inline int numberShortCutsAtRoot() const
     276  { return numberShortCutsAtRoot_;}
    248277  /// Set model
    249278  inline void setModel(CbcModel * model)
     
    252281 
    253282private:
     283  /**@name Private gets and sets */
     284  //@{
     285  /// Whether global cuts at root
     286  inline bool globalCutsAtRoot() const
     287  { return (switches_&32)!=0;}
     288  /// Set whether global cuts at root
     289  inline void setGlobalCutsAtRoot(bool yesNo)
     290  { switches_&=~32;switches_ |= yesNo ? 32 : 0;}
     291  /// Whether global cuts
     292  inline bool globalCuts() const
     293  { return (switches_&256)!=0;}
     294  /// Set whether global cuts
     295  inline void setGlobalCuts(bool yesNo)
     296  { switches_&=~256;switches_ |= yesNo ? 256 : 0;}
     297  //@}
     298  /// Saved cuts
     299  OsiCuts savedCuts_;
     300  /// Time in cut generator
     301  double timeInCutGenerator_;
    254302  /// The client model
    255   CbcModel *model_;
     303  CbcModel *model_; 
    256304
    257305  // The CglCutGenerator object
    258306  CglCutGenerator * generator_;
     307
     308  /// Name of generator
     309  char * generatorName_;
    259310
    260311  /** Number of nodes between calls to the CglCutGenerator::generateCuts
     
    281332  int depthCutGeneratorInSub_;
    282333
    283   /// Name of generator
    284   char * generatorName_;
    285 
    286   /// Whether to call the generator in the normal place
    287   bool normal_;
    288 
    289   /// Whether to call the generator when a new solution is found
    290   bool atSolution_;
    291 
    292   /// Whether to call generator when a subproblem is found to be infeasible
    293   bool whenInfeasible_;
    294   /// Whether generator MUST be called again if any cuts (i.e. ignore break from loop)
    295   bool mustCallAgain_;
    296   /// Temporary switch off marker
    297   bool switchedOff_;
    298   /// Create global cuts (at root)
    299   bool globalCutsAtRoot_;
    300   /// Whether call generator being timed
    301   bool timing_;
    302   /// Time in cut generator
    303   double timeInCutGenerator_;
    304334  /// Level of cut inaccuracy (0 means exact e.g. cliques)
    305335  int inaccuracy_;
     
    308338  /// Total number of cuts added
    309339  int numberCuts_;
     340  /// Total number of elements added
     341  int numberElements_;
    310342  /// Total number of column cuts added
    311343  int numberColumnCuts_;
     
    316348  /// Number of cuts active at root
    317349  int numberActiveCutsAtRoot_;
     350  /// Number of short cuts at root
     351  int numberShortCutsAtRoot_;
     352  /// Switches - see gets and sets
     353  int switches_;
    318354};
    319355/** Abstract cut modifier base class
     
    350386  virtual int modify(const OsiSolverInterface * solver, OsiRowCut & cut) =0;
    351387  /// Create C++ lines to get to current state
    352   virtual void generateCpp( FILE * fp) {}
     388  virtual void generateCpp( FILE * ) {}
    353389protected:
    354390 
     
    394430  virtual int modify(const OsiSolverInterface * solver, OsiRowCut & cut) ;
    395431  /// Create C++ lines to get to current state
    396   virtual void generateCpp( FILE * fp) {}
     432  virtual void generateCpp( FILE * ) {}
    397433protected:
    398434  /// data
  • stable/2.4/Cbc/src/CbcEventHandler.cpp

    r310 r1271  
     1/* $Id$ */
    12// Copyright (C) 2004, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    1718//-------------------------------------------------------------------
    1819
    19 CbcEventHandler::CbcEventHandler (const CbcModel *model)
     20CbcEventHandler::CbcEventHandler (CbcModel *model)
    2021  : model_(model),
    2122    dfltAction_(CbcEventHandler::noAction),
  • stable/2.4/Cbc/src/CbcEventHandler.hpp

    r741 r1271  
    9090    solution,
    9191    /*! A heuristic solution has been found. */
    92     heuristicSolution
     92    heuristicSolution,
     93    /*! A solution will be found unless user takes action (first check). */
     94    beforeSolution1,
     95    /*! A solution will be found unless user takes action (thorough check). */
     96    beforeSolution2,
     97    /*! End of search. */
     98    endSearch
    9399  } ;
    94100
     
    108114    restart,
    109115    /*! RestartRoot --- undo root node and start branch-and-cut afresh. */
    110     restartRoot
     116    restartRoot,
     117    /*! Add special cuts. */
     118    addCuts,
     119    /*! Pretend solution never happened. */
     120    killSolution
     121     
    111122  } ;
    112123
     
    135146  /*! \brief Default constructor. */
    136147
    137   CbcEventHandler(const CbcModel *model = NULL) ;
     148  CbcEventHandler(CbcModel *model = NULL) ;
    138149
    139150  /*! \brief Copy constructor. */
     
    193204  /*! \brief Pointer to associated CbcModel */
    194205
    195   const CbcModel *model_ ;
     206  CbcModel *model_ ;
    196207
    197208  /*! \brief Default action */
  • stable/2.4/Cbc/src/CbcFathom.cpp

    r904 r1271  
     1/* $Id$ */
    12// Copyright (C) 2004, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    6667//-------------------------------------------------------------------
    6768OsiSolverInterface *
    68 CbcOsiSolver::clone(bool copyData) const
     69CbcOsiSolver::clone(bool /*copyData*/) const
    6970{
    70   assert (copyData);
     71  //assert (copyData);
    7172  return new CbcOsiSolver(*this);
    7273}
     
    7879CbcOsiSolver::CbcOsiSolver (
    7980                  const CbcOsiSolver & rhs)
    80   : OsiClpSolverInterface(rhs)
     81  : OsiSolverInterface(), // Should not be needed but get warning
     82  OsiClpSolverInterface(rhs)
    8183{
    8284  cbcModel_ = rhs.cbcModel_;
  • stable/2.4/Cbc/src/CbcFathom.hpp

    r706 r1271  
     1/* $Id$ */
    12// Copyright (C) 2004, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcFathomDynamicProgramming.cpp

    r1121 r1271  
     1/* $Id$ */
    12// Copyright (C) 2004, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcFathomDynamicProgramming.hpp

    r765 r1271  
     1/* $Id$ */
    12// Copyright (C) 2004, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcFeasibilityBase.hpp

    r706 r1271  
     1/* $Id$ */
    12// Copyright (C) 2005, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    3132     1 pretend integer solution
    3233  */
    33   virtual int feasible(CbcModel * model, int mode) {return 0;}
     34  virtual int feasible(CbcModel * , int ) {return 0;}
    3435
    3536  virtual ~CbcFeasibilityBase() {}
    3637
    3738  // Copy constructor
    38   CbcFeasibilityBase ( const CbcFeasibilityBase & rhs)
     39  CbcFeasibilityBase ( const CbcFeasibilityBase & )
    3940  {}
    4041   
    4142  // Assignment operator
    42   CbcFeasibilityBase & operator=( const CbcFeasibilityBase& rhs)
     43  CbcFeasibilityBase & operator=( const CbcFeasibilityBase& )
    4344  { 
    4445    return *this;
  • stable/2.4/Cbc/src/CbcGenBaB.cpp

    r1067 r1271  
    3333namespace {
    3434
    35   char svnid[] = "$Id$" ;
     35  char svnid[] = "$Id: CbcGenBaB.cpp 1173 2009-06-04 09:44:10Z forrest $" ;
    3636
    3737/*
  • stable/2.4/Cbc/src/CbcGenCbcParam.cpp

    r640 r1271  
    2424namespace {
    2525
    26   char svnid[] = "$Id$" ;
     26  char svnid[] = "$Id: CbcGenCbcParam.cpp 1173 2009-06-04 09:44:10Z forrest $" ;
    2727
    2828}
  • stable/2.4/Cbc/src/CbcGenCbcParam.hpp

    r706 r1271  
    1414
    1515/*
    16   $Id$
     16  $Id: CbcGenCbcParam.hpp 1173 2009-06-04 09:44:10Z forrest $
    1717*/
    1818
  • stable/2.4/Cbc/src/CbcGenCbcParamUtils.cpp

    r958 r1271  
    2929namespace {
    3030
    31   char svnid[] = "$Id$" ;
     31  char svnid[] = "$Id: CbcGenCbcParamUtils.cpp 1173 2009-06-04 09:44:10Z forrest $" ;
    3232
    3333}
  • stable/2.4/Cbc/src/CbcGenCtlBlk.cpp

    r640 r1271  
    1515namespace {
    1616
    17   char svnid[] = "$Id$" ;
     17  char svnid[] = "$Id: CbcGenCtlBlk.cpp 1173 2009-06-04 09:44:10Z forrest $" ;
    1818
    1919}
  • stable/2.4/Cbc/src/CbcGenCtlBlk.hpp

    r706 r1271  
    4343
    4444/*
    45   $Id$
     45  $Id: CbcGenCtlBlk.hpp 1173 2009-06-04 09:44:10Z forrest $
    4646*/
    4747
  • stable/2.4/Cbc/src/CbcGenMessages.cpp

    r640 r1271  
    1313namespace {
    1414
    15   char svnid[] = "$Id$" ;
     15  char svnid[] = "$Id: CbcGenMessages.cpp 1173 2009-06-04 09:44:10Z forrest $" ;
    1616
    1717}
  • stable/2.4/Cbc/src/CbcGenMessages.hpp

    r640 r1271  
    1818
    1919/*
    20   $Id$
     20  $Id: CbcGenMessages.hpp 1173 2009-06-04 09:44:10Z forrest $
    2121*/
    2222
  • stable/2.4/Cbc/src/CbcGenOsiParam.cpp

    r640 r1271  
    2525namespace {
    2626
    27   char svnid[] = "$Id$" ;
     27  char svnid[] = "$Id: CbcGenOsiParam.cpp 1173 2009-06-04 09:44:10Z forrest $" ;
    2828
    2929}
  • stable/2.4/Cbc/src/CbcGenOsiParam.hpp

    r706 r1271  
    1414
    1515/*
    16   $Id$
     16  $Id: CbcGenOsiParam.hpp 1173 2009-06-04 09:44:10Z forrest $
    1717*/
    1818
  • stable/2.4/Cbc/src/CbcGenOsiParamUtils.cpp

    r958 r1271  
    3232namespace {
    3333
    34   char svnid[] = "$Id$" ;
     34  char svnid[] = "$Id: CbcGenOsiParamUtils.cpp 1173 2009-06-04 09:44:10Z forrest $" ;
    3535
    3636}
  • stable/2.4/Cbc/src/CbcGenParam.cpp

    r640 r1271  
    2323namespace {
    2424
    25   char svnid[] = "$Id$" ;
     25  char svnid[] = "$Id: CbcGenParam.cpp 1173 2009-06-04 09:44:10Z forrest $" ;
    2626
    2727}
  • stable/2.4/Cbc/src/CbcGenParam.hpp

    r706 r1271  
    1515
    1616/*
    17   $Id$
     17  $Id: CbcGenParam.hpp 1173 2009-06-04 09:44:10Z forrest $
    1818*/
    1919
  • stable/2.4/Cbc/src/CbcGenParamUtils.cpp

    r958 r1271  
    3030namespace {
    3131
    32   char svnid[] = "$Id$" ;
     32  char svnid[] = "$Id: CbcGenParamUtils.cpp 1173 2009-06-04 09:44:10Z forrest $" ;
    3333
    3434}
  • stable/2.4/Cbc/src/CbcGenSolution.cpp

    r640 r1271  
    2020namespace {
    2121
    22   char svnid[] = "$Id$" ;
     22  char svnid[] = "$Id: CbcGenSolution.cpp 1173 2009-06-04 09:44:10Z forrest $" ;
    2323
    2424}
  • stable/2.4/Cbc/src/CbcGenSolvers.cpp

    r855 r1271  
    7575namespace {
    7676
    77   char svnid[] = "$Id$" ;
     77  char svnid[] = "$Id: CbcGenSolvers.cpp 1173 2009-06-04 09:44:10Z forrest $" ;
    7878
    7979}
  • stable/2.4/Cbc/src/CbcGeneric.cpp

    r765 r1271  
    6161namespace {
    6262
    63   char svnid[] = "$Id$" ;
     63  char svnid[] = "$Id: CbcGeneric.cpp 1173 2009-06-04 09:44:10Z forrest $" ;
    6464
    6565}
  • stable/2.4/Cbc/src/CbcHeuristic.cpp

    r1226 r1271  
     1/* $Id$ */
    12// Copyright (C) 2002, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    9192
    9293//==============================================================================
    93 
     94#define DEFAULT_WHERE ((255-2-16)*(1+256))
    9495// Default Constructor
    9596CbcHeuristic::CbcHeuristic() :
     
    103104  decayFactor_(0.0),
    104105  switches_(0),
     106  whereFrom_(DEFAULT_WHERE),
    105107  shallowDepth_(1),
    106108  howOftenShallow_(1),
     
    129131  decayFactor_(0.0),
    130132  switches_(0),
     133  whereFrom_(DEFAULT_WHERE),
    131134  shallowDepth_(1),
    132135  howOftenShallow_(1),
     
    153156  heuristicName_ = rhs.heuristicName_;
    154157  howOften_ = rhs.howOften_;
    155   decayFactor_ = rhs.howOften_;
     158  decayFactor_ = rhs.decayFactor_;
    156159  switches_ = rhs.switches_;
     160  whereFrom_ = rhs.whereFrom_;
    157161  shallowDepth_= rhs.shallowDepth_;
    158162  howOftenShallow_= rhs.howOftenShallow_;
     
    258262
    259263bool
    260 CbcHeuristic::shouldHeurRun()
    261 {
     264CbcHeuristic::shouldHeurRun(int whereFrom)
     265{
     266  assert (whereFrom>=0&&whereFrom<16);
     267  // take off 8 (code - likes new solution)
     268  whereFrom &= 7;
     269  if ((whereFrom_&(1<<whereFrom))==0)
     270    return false;
    262271  // No longer used for original purpose - so use for ever run at all JJF
    263272#if 1
     
    360369    double probability = numerator / denominator;
    361370    double randomNumber = randomNumberGenerator_.randomDouble();
    362     if (when_>2&&when_<8) {
     371    int when = when_%100;
     372    if (when>2&&when<8) {
    363373      /* JJF adjustments
    364374         3 only at root and if no solution
     
    368378         7 run up to 2 times if solution found 4 otherwise
    369379      */
    370       switch(when_) {
     380      switch(when) {
    371381      case 3:
    372382      default:
     
    451461  else
    452462    fprintf(fp,"4  %s.setNumberNodes(%d);\n",heuristic,numberNodes_);
     463  if (feasibilityPumpOptions_!=-1)
     464    fprintf(fp,"3  %s.setFeasibilityPumpOptions(%d);\n",heuristic,feasibilityPumpOptions_);
     465  else
     466    fprintf(fp,"4  %s.setFeasibilityPumpOptions(%d);\n",heuristic,feasibilityPumpOptions_);
    453467  if (fractionSmall_!=1.0)
    454468    fprintf(fp,"3  %s.setFractionSmall(%g);\n",heuristic,fractionSmall_);
     
    461475    fprintf(fp,"4  %s.setHeuristicName(\"%s\");\n",
    462476            heuristic,heuristicName_.c_str()) ;
     477  if (decayFactor_!=0.0)
     478    fprintf(fp,"3  %s.setDecayFactor(%g);\n",heuristic,decayFactor_);
     479  else
     480    fprintf(fp,"4  %s.setDecayFactor(%g);\n",heuristic,decayFactor_);
     481  if (switches_!=0)
     482    fprintf(fp,"3  %s.setSwitches(%d);\n",heuristic,switches_);
     483  else
     484    fprintf(fp,"4  %s.setSwitches(%d);\n",heuristic,switches_);
     485  if (whereFrom_!=DEFAULT_WHERE)
     486    fprintf(fp,"3  %s.setWhereFrom(%d);\n",heuristic,whereFrom_);
     487  else
     488    fprintf(fp,"4  %s.setWhereFrom(%d);\n",heuristic,whereFrom_);
     489  if (shallowDepth_!=1)
     490    fprintf(fp,"3  %s.setShallowDepth(%d);\n",heuristic,shallowDepth_);
     491  else
     492    fprintf(fp,"4  %s.setShallowDepth(%d);\n",heuristic,shallowDepth_);
     493  if (howOftenShallow_!=1)
     494    fprintf(fp,"3  %s.setHowOftenShallow(%d);\n",heuristic,howOftenShallow_);
     495  else
     496    fprintf(fp,"4  %s.setHowOftenShallow(%d);\n",heuristic,howOftenShallow_);
     497  if (minDistanceToRun_!=1)
     498    fprintf(fp,"3  %s.setMinDistanceToRun(%d);\n",heuristic,minDistanceToRun_);
     499  else
     500    fprintf(fp,"4  %s.setMinDistanceToRun(%d);\n",heuristic,minDistanceToRun_);
    463501}
    464502// Destructor
     
    472510{
    473511  model_ = model;
     512}
     513/* Clone but ..
     514   type 0 clone solver, 1 clone continuous solver
     515   Add 2 to say without integer variables which are at low priority
     516   Add 4 to say quite likely infeasible so give up easily.*/
     517OsiSolverInterface *
     518CbcHeuristic::cloneBut(int type)
     519{
     520  OsiSolverInterface * solver;
     521  if ((type&1)==0||!model_->continuousSolver())
     522    solver = model_->solver()->clone();
     523  else
     524    solver = model_->continuousSolver()->clone();
     525#ifdef COIN_HAS_CLP
     526  OsiClpSolverInterface * clpSolver
     527    = dynamic_cast<OsiClpSolverInterface *> (solver);
     528#endif
     529  if ((type&2)!=0) {
     530    int n=model_->numberObjects();
     531    int priority = model_->continuousPriority();
     532    if (priority<COIN_INT_MAX) {
     533      for (int i=0;i<n;i++) {
     534        const OsiObject * obj = model_->object(i);
     535        const CbcSimpleInteger * thisOne =
     536          dynamic_cast <const CbcSimpleInteger *> (obj);
     537        if (thisOne) {
     538          int iColumn=thisOne->columnNumber();
     539          if (thisOne->priority()>=priority)
     540            solver->setContinuous(iColumn);
     541        }
     542      }
     543    }
     544#ifdef COIN_HAS_CLP
     545    if (clpSolver) {
     546      for (int i=0;i<n;i++) {
     547        const OsiObject * obj = model_->object(i);
     548        const CbcSimpleInteger * thisOne =
     549          dynamic_cast <const CbcSimpleInteger *> (obj);
     550        if (thisOne) {
     551          int iColumn=thisOne->columnNumber();
     552          if (clpSolver->isOptionalInteger(iColumn))
     553            clpSolver->setContinuous(iColumn);
     554        }
     555      }
     556    }
     557#endif
     558  }
     559#ifdef COIN_HAS_CLP
     560  if ((type&4)!=0&&clpSolver) {
     561    int options = clpSolver->getModelPtr()->moreSpecialOptions();
     562    clpSolver->getModelPtr()->setMoreSpecialOptions(options|64);
     563  }
     564#endif
     565  return solver;
    474566}
    475567// Whether to exit at once on gap
     
    477569CbcHeuristic::exitNow(double bestObjective) const
    478570{
    479   if ((switches_&1)==0)
     571  if ((switches_&2048)!=0) {
     572    // exit may be forced - but unset for next time
     573    switches_ &= ~2048;
     574    if ((switches_&1024)!=0)
     575      return true;
     576  } else if ((switches_&1)==0) {
    480577    return false;
     578  }
    481579  // See if can stop on gap
    482580  OsiSolverInterface * solver = model_->solver();
    483581  double bestPossibleObjective = solver->getObjValue()*solver->getObjSense();
    484   double testGap = CoinMax(model_->getAllowableGap(),
     582  double absGap = CoinMax(model_->getAllowableGap(),
     583                          model_->getHeuristicGap());
     584  double fracGap = CoinMax(model_->getAllowableFractionGap(),
     585                          model_->getHeuristicFractionGap());
     586  double testGap = CoinMax(absGap,fracGap*
    485587                           CoinMax(fabs(bestObjective),
    486                                    fabs(bestPossibleObjective))
    487                            *model_->getAllowableFractionGap());
     588                                   fabs(bestPossibleObjective)));
     589
    488590  if (bestObjective-bestPossibleObjective < testGap
    489591      && model_->getCutoffIncrement()>=0.0) {
     
    782884        if (numberNodes>=0) {
    783885          // normal
    784           model_->setSpecialOptions(saveModelOptions|2048);
     886          model.setSpecialOptions(saveModelOptions|2048);
    785887          if (logLevel<=1)
    786888            model.setLogLevel(0);
     
    799901          model.setMaximumCutPasses(CoinMin(10,model_->getMaximumCutPasses()));
    800902        } else {
    801           model_->setSpecialOptions(saveModelOptions);
     903          model.setSpecialOptions(saveModelOptions);
    802904          model_->messageHandler()->message(CBC_RESTART,model_->messages())
    803905            <<solver2->getNumRows()<<solver2->getNumCols()
     
    9931095            //printf("added seren\n");
    9941096          } else {
     1097            double value = model_->getMinimizationObjValue();
     1098            model.setCutoff(value+1.0e-7*(1.0+fabs(value)));
    9951099#ifdef CLP_INVESTIGATE
    9961100            printf("NOT added seren\n");
     
    11111215  model_->setSpecialOptions(saveModelOptions);
    11121216  model_->setLogLevel(logLevel);
     1217  if (returnCode==1||returnCode==2) {
     1218    OsiSolverInterface * solverC = model_->continuousSolver();
     1219    if (false&&solverC) {
     1220      const double * lower = solver->getColLower();
     1221      const double * upper = solver->getColUpper();
     1222      const double * lowerC = solverC->getColLower();
     1223      const double * upperC = solverC->getColUpper();
     1224      bool good=true;
     1225      for (int iColumn=0;iColumn<numberColumns;iColumn++) {
     1226        if (solverC->isInteger(iColumn)) {
     1227          if (lower[iColumn]>lowerC[iColumn]&&
     1228              upper[iColumn]<upperC[iColumn]) {
     1229            good=false;
     1230            printf("CUT - can't add\n");
     1231            break;
     1232          }
     1233        }
     1234      }
     1235      if (good) {
     1236        double * cut = new double [numberColumns];
     1237        int * which = new int [numberColumns];
     1238        double rhs=-1.0;
     1239        int n=0;
     1240        for (int iColumn=0;iColumn<numberColumns;iColumn++) {
     1241          if (solverC->isInteger(iColumn)) {
     1242            if (lower[iColumn]==upperC[iColumn]) {
     1243              rhs += lower[iColumn];
     1244              cut[n]=1.0;
     1245              which[n++]=iColumn;
     1246            } else if (upper[iColumn]==lowerC[iColumn]) {
     1247              rhs -= upper[iColumn];
     1248              cut[n]=-1.0;
     1249              which[n++]=iColumn;
     1250            }
     1251          }
     1252        }
     1253        printf("CUT has %d entries\n",n);
     1254        OsiRowCut newCut;
     1255        newCut.setLb(-COIN_DBL_MAX);
     1256        newCut.setUb(rhs);
     1257        newCut.setRow(n,which,cut,false);
     1258        model_->makeGlobalCut(newCut);
     1259        delete [] cut;
     1260        delete [] which;
     1261      }
     1262    }
     1263#ifdef COIN_DEVELOP
     1264    if (status==1)
     1265      printf("heuristic could add cut because infeasible (%s)\n",heuristicName_.c_str());
     1266    else if (status==2)
     1267      printf("heuristic could add cut because optimal (%s)\n",heuristicName_.c_str());
     1268#endif
     1269  }
    11131270  if (reset) {
    11141271    for (int iColumn=0;iColumn<numberColumns;iColumn++) {
     
    11201277#ifdef HISTORY_STATISTICS
    11211278  getHistoryStatistics_=true;
    1122 #endif
    1123 #ifdef COIN_DEVELOP
    1124   if (returnCode==1||returnCode==2) {
    1125     if (status==1)
    1126       printf("heuristic could add cut because infeasible (%s)\n",heuristicName_.c_str());
    1127     else if (status==2)
    1128       printf("heuristic could add cut because optimal (%s)\n",heuristicName_.c_str());
    1129   }
    11301279#endif
    11311280  solver->setHintParam(OsiDoReducePrint,takeHint,strength);
     
    13811530{
    13821531  // matrix and row copy will automatically be empty
    1383   seed_=1;
     1532  seed_=7654321;
    13841533  down_ = NULL;
    13851534  up_ = NULL;
     
    13931542  // Get a copy of original matrix (and by row for rounding);
    13941543  assert(model.solver());
    1395   matrix_ = *model.solver()->getMatrixByCol();
    1396   matrixByRow_ = *model.solver()->getMatrixByRow();
    1397   validate();
     1544  if (model.solver()->getNumRows()) {
     1545    matrix_ = *model.solver()->getMatrixByCol();
     1546    matrixByRow_ = *model.solver()->getMatrixByRow();
     1547    validate();
     1548  }
    13981549  down_ = NULL;
    13991550  up_ = NULL;
    14001551  equal_ = NULL;
    1401   seed_=1;
     1552  seed_=7654321;
    14021553}
    14031554
     
    22442395  // Get a copy of original matrix (and by row for rounding);
    22452396  assert(model_->solver());
    2246   matrix_ = *model_->solver()->getMatrixByCol();
    2247   matrixByRow_ = *model_->solver()->getMatrixByRow();
    2248   // make sure model okay for heuristic
    2249   validate();
     2397  if (model_->solver()->getNumRows()) {
     2398    matrix_ = *model_->solver()->getMatrixByCol();
     2399    matrixByRow_ = *model_->solver()->getMatrixByRow();
     2400    // make sure model okay for heuristic
     2401    validate();
     2402  }
    22502403}
    22512404// Validate model i.e. sets when_ to 0 if necessary (may be NULL)
     
    22532406CbcRounding::validate()
    22542407{
    2255   if (model_&&when()<10) {
     2408  if (model_&&(when()%100)<10) {
    22562409    if (model_->numberIntegers()!=
    22572410        model_->numberObjects()&&(model_->numberObjects()||
    2258                                   (model_->specialOptions()&1024)==0))
    2259       setWhen(0);
     2411                                  (model_->specialOptions()&1024)==0)) {
     2412      int numberOdd=0;
     2413      for (int i=0;i<model_->numberObjects();i++) {
     2414        if (!model_->object(i)->canDoHeuristics())
     2415          numberOdd++;
     2416      }
     2417      if (numberOdd)
     2418        setWhen(0);
     2419    }
    22602420  }
    22612421#ifdef NEW_ROUNDING
     
    24602620CbcHeuristicPartial::validate()
    24612621{
    2462   if (model_&&when()<10) {
     2622  if (model_&&(when()%100)<10) {
    24632623    if (model_->numberIntegers()!=
    24642624        model_->numberObjects())
     
    24672627}
    24682628bool
    2469 CbcHeuristicPartial::shouldHeurRun()
     2629CbcHeuristicPartial::shouldHeurRun(int /*whereFrom*/)
    24702630{
    24712631  return true;
  • stable/2.4/Cbc/src/CbcHeuristic.hpp

    r1127 r1271  
     1/* $Id$ */
    12// Copyright (C) 2002, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    112113      Default is do nothing
    113114  */
    114   virtual int solution(double & objectiveValue,
    115                        double * newSolution,
    116                        OsiCuts & cs) {return 0;}
     115  virtual int solution2(double & /*objectiveValue*/,
     116                       double * /*newSolution*/,
     117                       OsiCuts & /*cs*/) {return 0;}
    117118
    118119  /// Validate model i.e. sets when_ to 0 if necessary (may be NULL)
     
    138139      1 bit - stop once allowable gap on objective reached
    139140      2 bit - always do given number of passes
    140       for other possibilities see switches_
     141      4 bit - weaken cutoff by 5% every 50 passes?
     142      8 bit - if has cutoff and suminf bobbling for 20 passes then
     143              first try halving distance to best possible then
     144              try keep halving distance to known cutoff
     145      1024 bit - stop all heuristics on max time
    141146  */
    142147  inline void setSwitches(int value)
     
    145150      1 bit - stop once allowable gap on objective reached
    146151      2 bit - always do given number of passes
    147       for other possibilities see switches_
     152      4 bit - weaken cutoff by 5% every 50 passes?
     153      8 bit - if has cutoff and suminf bobbling for 20 passes then
     154              first try halving distance to best possible then
     155              try keep halving distance to known cutoff
     156      1024 bit - stop all heuristics on max time
    148157  */
    149158  inline int switches() const
     
    188197                          double cutoff , std::string name) const;
    189198  /// Create C++ lines to get to current state
    190   virtual void generateCpp( FILE * fp) {}
     199  virtual void generateCpp( FILE * ) {}
    191200  /// Create C++ lines to get to current state - does work for base class
    192201  void generateCpp( FILE * fp,const char * heuristic) ;
     
    202211  /// Set random number generator seed
    203212  void setSeed(int value);
     213  /// Sets decay factor (for howOften) on failure
     214  inline void setDecayFactor(double value)
     215  { decayFactor_=value;}
    204216  /// Set input solution
    205217  void setInputSolution(const double * solution, double objValue);
    206 
    207   /** Check whether the heuristic should run at all */
    208   virtual bool shouldHeurRun();
     218  /* Runs if bit set
     219      0 - before cuts at root node (or from doHeuristics)
     220      1 - during cuts at root
     221      2 - after root node cuts
     222      3 - after cuts at other nodes
     223      4 - during cuts at other nodes
     224          8 added if previous heuristic in loop found solution
     225   */
     226  inline void setWhereFrom(int value)
     227  { whereFrom_=value;}
     228  /** Upto this depth we call the tree shallow and the heuristic can be called
     229      multiple times. That is, the test whether the current node is far from
     230      the others where the jeuristic was invoked will not be done, only the
     231      frequency will be tested. After that depth the heuristic will can be
     232      invoked only once per node, right before branching. That's when it'll be
     233      tested whether the heur should run at all. */
     234  inline void setShallowDepth(int value)
     235  { shallowDepth_=value;}
     236  /** How often to invoke the heuristics in the shallow part of the tree */
     237  inline void setHowOftenShallow(int value)
     238  { howOftenShallow_=value;}
     239  /** How "far" should this node be from every other where the heuristic was
     240      run in order to allow the heuristic to run in this node, too. Currently
     241      this is tested, but we may switch to avgDistanceToRun_ in the future. */
     242  inline void setMinDistanceToRun(int value)
     243  { minDistanceToRun_=value;}
     244
     245  /** Check whether the heuristic should run at all
     246      0 - before cuts at root node (or from doHeuristics)
     247      1 - during cuts at root
     248      2 - after root node cuts
     249      3 - after cuts at other nodes
     250      4 - during cuts at other nodes
     251          8 added if previous heuristic in loop found solution
     252  */
     253  virtual bool shouldHeurRun(int whereFrom);
    209254  /** Check whether the heuristic should run this time */
    210255  bool shouldHeurRun_randomChoice();
     
    218263  inline int numCouldRun() const
    219264  { return numCouldRun_;}
    220 
     265  /** Clone but ..
     266      type 0 clone solver, 1 clone continuous solver
     267      Add 2 to say without integer variables which are at low priority
     268      Add 4 to say quite likely infeasible so give up easily.*/
     269  OsiSolverInterface * cloneBut(int type);
    221270protected:
    222271
     
    246295      8 bit - if has cutoff and suminf bobbling for 20 passes then
    247296              first try halving distance to best possible then
    248               try keep halving distance to known cutoff
    249   */
    250   int switches_;
     297              try keep halving distance to known cutoff
     298      1024 bit - stop all heuristics on max time
     299  */
     300  mutable int switches_;
     301  /* Runs if bit set
     302      0 - before cuts at root node (or from doHeuristics)
     303      1 - during cuts at root
     304      2 - after root node cuts
     305      3 - after cuts at other nodes
     306      4 - during cuts at other nodes
     307          8 added if previous heuristic in loop found solution
     308   */
     309  int whereFrom_;
    251310  /** Upto this depth we call the tree shallow and the heuristic can be called
    252311      multiple times. That is, the test whether the current node is far from
     
    426485
    427486  /** Check whether the heuristic should run at all */
    428   virtual bool shouldHeurRun();
     487  virtual bool shouldHeurRun(int whereFrom);
    429488
    430489protected:
     
    532591      This is dummy as never called
    533592  */
    534   virtual bool selectVariableToBranch(OsiSolverInterface* solver,
    535                                       const double* newSolution,
    536                                       int& bestColumn,
    537                                       int& bestRound)
     593  virtual bool selectVariableToBranch(OsiSolverInterface* /*solver*/,
     594                                      const double* /*newSolution*/,
     595                                      int& /*bestColumn*/,
     596                                      int& /*bestRound*/)
    538597  { return true;}
    539598  /// Validate model i.e. sets when_ to 0 if necessary (may be NULL)
  • stable/2.4/Cbc/src/CbcHeuristicDive.cpp

    r1121 r1271  
     1/* $Id: CbcHeuristicDive.cpp 1240 2009-10-02 18:41:44Z forrest $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    89#include "CbcHeuristicDive.hpp"
    910#include "CbcStrategy.hpp"
     11#include "OsiAuxInfo.hpp"
    1012#include  "CoinTime.hpp"
    1113
     
    2426  downLocks_ =NULL;
    2527  upLocks_ = NULL;
     28  downArray_ =NULL;
     29  upArray_ = NULL;
    2630  percentageToFix_ = 0.2;
    2731  maxIterations_ = 100;
     
    2933  maxSimplexIterationsAtRoot_ = 1000000;
    3034  maxTime_ = 600;
     35  whereFrom_=255-2-16+256;
    3136}
    3237
     
    3742  downLocks_ =NULL;
    3843  upLocks_ = NULL;
     44  downArray_ =NULL;
     45  upArray_ = NULL;
    3946  // Get a copy of original matrix
    4047  assert(model.solver());
     
    5158  maxSimplexIterationsAtRoot_ = 1000000;
    5259  maxTime_ = 600;
     60  whereFrom_=255-2-16+256;
    5361}
    5462
     
    5866  delete [] downLocks_;
    5967  delete [] upLocks_;
     68  assert (!downArray_);
    6069}
    6170
     
    7483  else
    7584    fprintf(fp,"4  %s.setMaxIterations(%d);\n",heuristic,maxIterations_);
    76   if (maxSimplexIterations_!=100)
    77     fprintf(fp,"3  %s.setMaxIterations(%d);\n",heuristic,maxSimplexIterations_);
     85  if (maxSimplexIterations_!=10000)
     86    fprintf(fp,"3  %s.setMaxSimplexIterations(%d);\n",heuristic,maxSimplexIterations_);
    7887  else
    79     fprintf(fp,"4  %s.setMaxIterations(%d);\n",heuristic,maxSimplexIterations_);
     88    fprintf(fp,"4  %s.setMaxSimplexIterations(%d);\n",heuristic,maxSimplexIterations_);
    8089  if (maxTime_!=600)
    8190    fprintf(fp,"3  %s.setMaxTime(%.2f);\n",heuristic,maxTime_);
     
    96105  maxTime_(rhs.maxTime_)
    97106{
     107  downArray_ =NULL;
     108  upArray_ = NULL;
    98109  if (rhs.downLocks_) {
    99110    int numberIntegers = model_->numberIntegers();
     
    169180}
    170181
    171 struct PseudoReducedCost {
    172   int var;
    173   double pseudoRedCost;
    174 };
    175 
    176182inline bool compareBinaryVars(const PseudoReducedCost obj1,
    177183                              const PseudoReducedCost obj2)
     
    214220    : maxSimplexIterationsAtRoot_;
    215221
    216   OsiSolverInterface * solver = model_->solver()->clone();
     222  OsiSolverInterface * solver = cloneBut(6); // was model_->solver()->clone();
     223# ifdef COIN_HAS_CLP
     224  OsiClpSolverInterface * clpSolver
     225    = dynamic_cast<OsiClpSolverInterface *> (solver);
     226  if (clpSolver) {
     227    // say give up easily
     228    ClpSimplex * clpSimplex = clpSolver->getModelPtr();
     229    clpSimplex->setMoreSpecialOptions(clpSimplex->moreSpecialOptions()|64);
     230  }
     231# endif
    217232  const double * lower = solver->getColLower();
    218233  const double * upper = solver->getColUpper();
     
    237252  const CoinBigIndex * columnStart = matrix_.getVectorStarts();
    238253  const int * columnLength = matrix_.getVectorLengths();
     254#ifdef DIVE_FIX_BINARY_VARIABLES
    239255  // Row copy
    240   //const double * elementByRow = matrixByRow_.getElements();
    241   //const int * column = matrixByRow_.getIndices();
    242   //const CoinBigIndex * rowStart = matrixByRow_.getVectorStarts();
    243   //const int * rowLength = matrixByRow_.getVectorLengths();
     256  const double * elementByRow = matrixByRow_.getElements();
     257  const int * column = matrixByRow_.getIndices();
     258  const CoinBigIndex * rowStart = matrixByRow_.getVectorStarts();
     259  const int * rowLength = matrixByRow_.getVectorLengths();
     260#endif
    244261
    245262  // Get solution array for heuristic solution
     
    252269  double* originalBound = new double [numberIntegers];
    253270  bool * fixedAtLowerBound = new bool [numberIntegers];
    254   PseudoReducedCost * candidate = NULL;
    255   if(binVarIndex_.size())
    256     candidate = new PseudoReducedCost [binVarIndex_.size()];
    257 
    258   const int maxNumberAtBoundToFix = static_cast<int> (floor(percentageToFix_ * numberIntegers));
     271  PseudoReducedCost * candidate = new PseudoReducedCost [numberIntegers];
     272  double * random = new double [numberIntegers];
     273
     274  int maxNumberAtBoundToFix = static_cast<int> (floor(percentageToFix_ * numberIntegers));
    259275
    260276  // count how many fractional variables
    261277  int numberFractionalVariables = 0;
    262278  for (int i=0; i<numberIntegers; i++) {
     279    random[i]=randomNumberGenerator_.randomDouble()+0.3;
    263280    int iColumn = integerVariable[i];
    264281    double value=newSolution[iColumn];
     
    268285  }
    269286
    270 #ifdef DIVE_FIX_BINARY_VARIABLES
    271   const double* reducedCost = solver->getReducedCost();
    272 #endif
     287  const double* reducedCost = NULL;
     288  // See if not NLP
     289  if(model_->solverCharacteristics()->reducedCostsAccurate())
     290    reducedCost = solver->getReducedCost();
    273291
    274292  int iteration = 0;
    275293  while(numberFractionalVariables) {
    276294    iteration++;
     295   
     296    // initialize any data
     297    initializeData();
    277298
    278299    // select a fractional variable to bound
     
    353374    if(binVarIndex_.size()) {
    354375      int cnt = 0;
    355       for (int j=0; j<(int)binVarIndex_.size(); j++) {
     376      int n = static_cast<int>(binVarIndex_.size());
     377      for (int j=0; j<n; j++) {
    356378        int iColumn1 = binVarIndex_[j];
    357379        double value = newSolution[iColumn1];
    358         double maxPseudoReducedCost = 0.0;
    359380        if(fabs(value)<=integerTolerance &&
    360381           lower[iColumn1] != upper[iColumn1]) {
     382          double maxPseudoReducedCost = 0.0;
    361383#ifdef DIVE_DEBUG
    362384          std::cout<<"iColumn1 = "<<iColumn1<<", value = "<<value<<std::endl;
    363385#endif
    364386          int iRow = vbRowIndex_[j];
     387          double chosenValue=0.0;
    365388          for (int k=rowStart[iRow];k<rowStart[iRow]+rowLength[iRow];k++) {
    366389            int iColumn2 = column[k];
     
    370393            if(iColumn1 != iColumn2) {
    371394              double pseudoReducedCost = fabs(reducedCost[iColumn2] *
    372                                               elementByRow[iColumn2] /
    373                                               elementByRow[iColumn1]);
    374 #ifdef DIVE_DEBUG
     395                                              elementByRow[k]);
     396#ifdef DIVE_DEBUG
     397              int k2;
     398              for (k2=rowStart[iRow];k2<rowStart[iRow]+rowLength[iRow];k2++) {
     399                if (column[k2]==iColumn1)
     400                  break;
     401              }
    375402              std::cout<<"reducedCost["<<iColumn2<<"] = "
    376403                       <<reducedCost[iColumn2]
    377                        <<", elementByRow["<<iColumn2<<"] = "<<elementByRow[iColumn2]
    378                        <<", elementByRow["<<iColumn1<<"] = "<<elementByRow[iColumn1]
     404                       <<", elementByRow["<<iColumn2<<"] = "<<elementByRow[k]
     405                       <<", elementByRow["<<iColumn1<<"] = "<<elementByRow[k2]
    379406                       <<", pseudoRedCost = "<<pseudoReducedCost
    380407                       <<std::endl;
     
    382409              if(pseudoReducedCost > maxPseudoReducedCost)
    383410                maxPseudoReducedCost = pseudoReducedCost;
     411            } else {
     412              // save value
     413              chosenValue = fabs(elementByRow[k]);
    384414            }
    385415          }
     416          assert (chosenValue);
     417          maxPseudoReducedCost /= chosenValue;
    386418#ifdef DIVE_DEBUG
    387419          std::cout<<", maxPseudoRedCost = "<<maxPseudoReducedCost<<std::endl;
     
    411443
    412444    // fix other integer variables that are at their bounds
    413     for (int i=0; i<numberIntegers; i++) {
    414       int iColumn = integerVariable[i];
    415       double value=newSolution[iColumn];
    416       if(fabs(floor(value+0.5)-value)<=integerTolerance &&
    417          numberAtBoundFixed < maxNumberAtBoundToFix) {
    418         // fix the variable at one of its bounds
    419         if (fabs(lower[iColumn]-value)<=integerTolerance &&
    420             lower[iColumn] != upper[iColumn]) {
    421           columnFixed[numberAtBoundFixed] = iColumn;
    422           originalBound[numberAtBoundFixed] = upper[iColumn];
    423           fixedAtLowerBound[numberAtBoundFixed] = true;
    424           solver->setColUpper(iColumn, lower[iColumn]);
    425           numberAtBoundFixed++;
    426         }
    427         else if(fabs(upper[iColumn]-value)<=integerTolerance &&
    428             lower[iColumn] != upper[iColumn]) {
    429           columnFixed[numberAtBoundFixed] = iColumn;
    430           originalBound[numberAtBoundFixed] = lower[iColumn];
    431           fixedAtLowerBound[numberAtBoundFixed] = false;
    432           solver->setColLower(iColumn, upper[iColumn]);
    433           numberAtBoundFixed++;
    434         }
    435         if(numberAtBoundFixed == maxNumberAtBoundToFix)
    436           break;
     445    int cnt=0;
     446#ifdef GAP
     447    double gap=1.0e30;
     448#endif
     449    if (reducedCost&&true) {
     450#if 1
     451      cnt=fixOtherVariables(solver,solution,candidate,random);
     452#else
     453#ifdef GAP
     454      double cutoff = model_->getCutoff() ;
     455      if (cutoff<1.0e20&&false) {
     456        double direction = solver->getObjSense() ;
     457        gap = cutoff - solver->getObjValue()*direction ;
     458        gap *= 0.1; // Fix more if plausible
     459        double tolerance;
     460        solver->getDblParam(OsiDualTolerance,tolerance) ;
     461        if (gap<=0.0)
     462          gap = tolerance;
     463        gap += 100.0*tolerance;
     464      }
     465      int nOverGap=0;
     466#endif
     467      int numberFree=0;
     468      int numberFixed=0;
     469      for (int i=0; i<numberIntegers; i++) {
     470        int iColumn = integerVariable[i];
     471        if (upper[iColumn]>lower[iColumn]) {
     472          numberFree++;
     473          double value=newSolution[iColumn];
     474          if(fabs(floor(value+0.5)-value)<=integerTolerance) {
     475            candidate[cnt].var = iColumn;
     476            candidate[cnt++].pseudoRedCost =
     477              fabs(reducedCost[iColumn]*random[i]);
     478#ifdef GAP
     479            if (fabs(reducedCost[iColumn])>gap)
     480              nOverGap++;
     481#endif
     482          }
     483        } else {
     484          numberFixed++;
     485        }
     486      }
     487#ifdef GAP
     488      int nLeft = maxNumberAtBoundToFix-numberAtBoundFixed;
     489#ifdef CLP_INVESTIGATE
     490      printf("cutoff %g obj %g nover %d - %d free, %d fixed\n",
     491             cutoff,solver->getObjValue(),nOverGap,numberFree,numberFixed);
     492#endif
     493      if (nOverGap>nLeft&&true) {
     494        nOverGap = CoinMin(nOverGap,nLeft+maxNumberAtBoundToFix/2);
     495        maxNumberAtBoundToFix += nOverGap-nLeft;
     496      }
     497#else
     498#ifdef CLP_INVESTIGATE
     499      printf("cutoff %g obj %g - %d free, %d fixed\n",
     500             model_->getCutoff(),solver->getObjValue(),numberFree,numberFixed);
     501#endif
     502#endif
     503#endif
     504    } else {
     505      for (int i=0; i<numberIntegers; i++) {
     506        int iColumn = integerVariable[i];
     507        if (upper[iColumn]>lower[iColumn]) {
     508          double value=newSolution[iColumn];
     509          if(fabs(floor(value+0.5)-value)<=integerTolerance) {
     510            candidate[cnt].var = iColumn;
     511            candidate[cnt++].pseudoRedCost = numberIntegers-i;
     512          }
     513        }
     514      }
     515    }
     516    std::sort(candidate, candidate+cnt, compareBinaryVars);
     517    for (int i=0; i<cnt; i++) {
     518      int iColumn = candidate[i].var;
     519      if (upper[iColumn]>lower[iColumn]) {
     520        double value=newSolution[iColumn];
     521        if(fabs(floor(value+0.5)-value)<=integerTolerance &&
     522           numberAtBoundFixed < maxNumberAtBoundToFix) {
     523          // fix the variable at one of its bounds
     524          if (fabs(lower[iColumn]-value)<=integerTolerance) {
     525            columnFixed[numberAtBoundFixed] = iColumn;
     526            originalBound[numberAtBoundFixed] = upper[iColumn];
     527            fixedAtLowerBound[numberAtBoundFixed] = true;
     528            solver->setColUpper(iColumn, lower[iColumn]);
     529            numberAtBoundFixed++;
     530          }
     531          else if(fabs(upper[iColumn]-value)<=integerTolerance) {
     532            columnFixed[numberAtBoundFixed] = iColumn;
     533            originalBound[numberAtBoundFixed] = lower[iColumn];
     534            fixedAtLowerBound[numberAtBoundFixed] = false;
     535            solver->setColLower(iColumn, upper[iColumn]);
     536            numberAtBoundFixed++;
     537          }
     538          if(numberAtBoundFixed == maxNumberAtBoundToFix)
     539            break;
     540        }
    437541      }
    438542    }
     
    461565      solver->resolve();
    462566      model_->setSpecialOptions(saveModelOptions);
    463 
     567      if(!solver->isAbandoned()) {
     568        numberSimplexIterations+=solver->getIterationCount();
     569      } else {
     570        numberSimplexIterations=maxSimplexIterations+1;
     571        break;
     572      }
     573     
    464574      if(!solver->isProvenOptimal()) {
    465575        if(numberAtBoundFixed > 0) {
     
    514624    }
    515625
    516     numberSimplexIterations+=solver->getIterationCount();
    517626    if(numberSimplexIterations > maxSimplexIterations) {
    518627#ifdef DIVE_DEBUG
     
    625734  delete [] candidate;
    626735  delete [] rowActivity;
     736  delete [] random;
     737  delete [] downArray_;
     738  downArray_=NULL;
     739  delete [] upArray_;
     740  upArray_=NULL;
    627741  delete solver;
    628742  return returnCode;
     
    633747CbcHeuristicDive::validate()
    634748{
    635   if (model_&&when()<10) {
     749  if (model_&&(when()%100)<10) {
    636750    if (model_->numberIntegers()!=
    637751        model_->numberObjects()&&(model_->numberObjects()||
    638                                   (model_->specialOptions()&1024)==0))
    639       setWhen(0);
     752                                  (model_->specialOptions()&1024)==0)) {
     753      int numberOdd=0;
     754      for (int i=0;i<model_->numberObjects();i++) {
     755        if (!model_->object(i)->canDoHeuristics())
     756          numberOdd++;
     757      }
     758      if (numberOdd)
     759        setWhen(0);
     760    }
    640761  }
    641762
     
    795916
    796917{
    797   return 0; // temp
    798 #if 0
    799   if(!solverCharacteristics_->reducedCostsAccurate())
     918  //return 0; // temp
     919#if 1
     920  if(!model_->solverCharacteristics()->reducedCostsAccurate())
    800921    return 0; //NLP
    801922#endif
    802923  double cutoff = model_->getCutoff() ;
     924  if (cutoff>1.0e20)
     925    return 0;
    803926#ifdef DIVE_DEBUG
    804927  std::cout<<"cutoff = "<<cutoff<<std::endl;
     
    806929  double direction = solver->getObjSense() ;
    807930  double gap = cutoff - solver->getObjValue()*direction ;
     931  gap *= 0.5; // Fix more
    808932  double tolerance;
    809933  solver->getDblParam(OsiDualTolerance,tolerance) ;
     
    875999  return numberFixed;
    8761000}
     1001// Fix other variables at bounds
     1002int
     1003CbcHeuristicDive::fixOtherVariables(OsiSolverInterface * solver,
     1004                                    const double * solution,
     1005                                    PseudoReducedCost * candidate,
     1006                                    const double * random)
     1007{
     1008  const double * lower = solver->getColLower();
     1009  const double * upper = solver->getColUpper();
     1010  double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance);
     1011  double primalTolerance;
     1012  solver->getDblParam(OsiPrimalTolerance,primalTolerance);
     1013
     1014  int numberIntegers = model_->numberIntegers();
     1015  const int * integerVariable = model_->integerVariable();
     1016  const double* reducedCost = solver->getReducedCost();
     1017  // fix other integer variables that are at their bounds
     1018  int cnt=0;
     1019#ifdef GAP
     1020  double direction = solver->getObjSense(); // 1 for min, -1 for max
     1021  double gap=1.0e30;
     1022#endif
     1023#ifdef GAP
     1024  double cutoff = model_->getCutoff() ;
     1025  if (cutoff<1.0e20&&false) {
     1026    double direction = solver->getObjSense() ;
     1027    gap = cutoff - solver->getObjValue()*direction ;
     1028    gap *= 0.1; // Fix more if plausible
     1029    double tolerance;
     1030    solver->getDblParam(OsiDualTolerance,tolerance) ;
     1031    if (gap<=0.0)
     1032      gap = tolerance;
     1033    gap += 100.0*tolerance;
     1034  }
     1035  int nOverGap=0;
     1036#endif
     1037  int numberFree=0;
     1038  int numberFixedAlready=0;
     1039  for (int i=0; i<numberIntegers; i++) {
     1040    int iColumn = integerVariable[i];
     1041    if (upper[iColumn]>lower[iColumn]) {
     1042      numberFree++;
     1043      double value=solution[iColumn];
     1044      if(fabs(floor(value+0.5)-value)<=integerTolerance) {
     1045        candidate[cnt].var = iColumn;
     1046        candidate[cnt++].pseudoRedCost =
     1047          fabs(reducedCost[iColumn]*random[i]);
     1048#ifdef GAP
     1049        if (fabs(reducedCost[iColumn])>gap)
     1050          nOverGap++;
     1051#endif
     1052      }
     1053    } else {
     1054      numberFixedAlready++;
     1055    }
     1056  }
     1057#ifdef GAP
     1058  int nLeft = maxNumberToFix-numberFixedAlready;
     1059#ifdef CLP_INVESTIGATE
     1060  printf("cutoff %g obj %g nover %d - %d free, %d fixed\n",
     1061         cutoff,solver->getObjValue(),nOverGap,numberFree,
     1062         numberFixedAlready);
     1063#endif
     1064  if (nOverGap>nLeft&&true) {
     1065    nOverGap = CoinMin(nOverGap,nLeft+maxNumberToFix/2);
     1066    maxNumberToFix += nOverGap-nLeft;
     1067  }
     1068#else
     1069#ifdef CLP_INVESTIGATE
     1070  printf("cutoff %g obj %g - %d free, %d fixed\n",
     1071         model_->getCutoff(),solver->getObjValue(),numberFree,
     1072         numberFixedAlready);
     1073#endif
     1074#endif
     1075  return cnt;
     1076}
  • stable/2.4/Cbc/src/CbcHeuristicDive.hpp

    r1040 r1271  
     1/* $Id: CbcHeuristicDive.hpp 1252 2009-10-20 09:22:24Z stefan $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    56
    67#include "CbcHeuristic.hpp"
     8struct PseudoReducedCost {
     9  int var;
     10  double pseudoRedCost;
     11};
     12
    713
    814/** Dive class
     
    3137
    3238  /// Create C++ lines to get to current state
    33   virtual void generateCpp( FILE * fp) {}
     39  virtual void generateCpp( FILE * ) {}
    3440
    3541  /// Create C++ lines to get to current state - does work for base class
     
    8187  virtual bool canHeuristicRun();
    8288
    83   /// Selects the next variable to branch on
    84   /** Returns true if all the fractional variables can be trivially
     89  /** Selects the next variable to branch on
     90      Returns true if all the fractional variables can be trivially
    8591      rounded. Returns false, if there is at least one fractional variable
    8692      that is not trivially roundable. In this case, the bestColumn
     
    9197                                      int& bestColumn,
    9298                                      int& bestRound) = 0;
     99  /** Initializes any data which is going to be used repeatedly
     100      in selectVariableToBranch */
     101  virtual void initializeData() {}
    93102
    94103  /// Perform reduced cost fixing on integer variables
    95104  int reducedCostFix (OsiSolverInterface* solver);
     105  /// Fix other variables at bounds
     106  virtual int fixOtherVariables(OsiSolverInterface * solver,
     107                                const double * solution,
     108                                PseudoReducedCost * candidate,
     109                                const double * random);
    96110
    97111protected:
     
    109123  // Up locks
    110124  unsigned short * upLocks_;
     125
     126  /// Extra down array (number Integers long)
     127  double * downArray_;
     128
     129  /// Extra up array (number Integers long)
     130  double * upArray_;
    111131
    112132  // Indexes of binary variables with 0 objective coefficient
  • stable/2.4/Cbc/src/CbcHeuristicDiveCoefficient.cpp

    r1103 r1271  
     1/* $Id: CbcHeuristicDiveCoefficient.cpp 1173 2009-06-04 09:44:10Z forrest $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcHeuristicDiveCoefficient.hpp

    r944 r1271  
     1/* $Id: CbcHeuristicDiveCoefficient.hpp 1173 2009-06-04 09:44:10Z forrest $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcHeuristicDiveFractional.cpp

    r944 r1271  
     1/* $Id: CbcHeuristicDiveFractional.cpp 1173 2009-06-04 09:44:10Z forrest $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcHeuristicDiveFractional.hpp

    r944 r1271  
     1/* $Id: CbcHeuristicDiveFractional.hpp 1173 2009-06-04 09:44:10Z forrest $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcHeuristicDiveGuided.cpp

    r944 r1271  
     1/* $Id: CbcHeuristicDiveGuided.cpp 1173 2009-06-04 09:44:10Z forrest $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcHeuristicDiveGuided.hpp

    r944 r1271  
     1/* $Id: CbcHeuristicDiveGuided.hpp 1173 2009-06-04 09:44:10Z forrest $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcHeuristicDiveLineSearch.cpp

    r945 r1271  
     1/* $Id: CbcHeuristicDiveLineSearch.cpp 1173 2009-06-04 09:44:10Z forrest $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcHeuristicDiveLineSearch.hpp

    r945 r1271  
     1/* $Id: CbcHeuristicDiveLineSearch.hpp 1173 2009-06-04 09:44:10Z forrest $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcHeuristicDivePseudoCost.cpp

    r945 r1271  
     1/* $Id: CbcHeuristicDivePseudoCost.cpp 1240 2009-10-02 18:41:44Z forrest $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    89#include "CbcHeuristicDivePseudoCost.hpp"
    910#include "CbcStrategy.hpp"
     11#include "CbcBranchDynamic.hpp"
    1012
    1113// Default Constructor
     
    7577
    7678  // get pseudo costs
    77   double * pseudoCostDown = new double[numberIntegers];
    78   double * pseudoCostUp = new double[numberIntegers];
    79   model_->fillPseudoCosts(pseudoCostDown, pseudoCostUp);
     79  double * pseudoCostDown = downArray_;
     80  double * pseudoCostUp = upArray_;
    8081
    8182  bestColumn = -1;
     
    138139  }
    139140
    140   delete [] pseudoCostDown;
    141   delete [] pseudoCostUp;
    142 
    143141  return allTriviallyRoundableSoFar;
    144142}
     143void
     144CbcHeuristicDivePseudoCost::initializeData()
     145{
     146  int numberIntegers = model_->numberIntegers();
     147  if (!downArray_) {
     148    downArray_ = new double [numberIntegers];
     149    upArray_ = new double [numberIntegers];
     150  }
     151  // get pseudo costs
     152  model_->fillPseudoCosts(downArray_, upArray_);
     153  int diveOptions = when_/100;
     154  if (diveOptions) {
     155    // pseudo shadow prices
     156    int k = diveOptions%100;
     157    if (diveOptions>=100)
     158      k +=32;
     159    model_->pseudoShadow(k-1);
     160    int numberInts=CoinMin(model_->numberObjects(),numberIntegers);
     161    OsiObject ** objects = model_->objects();
     162    for (int i=0;i<numberInts;i++) {
     163      CbcSimpleIntegerDynamicPseudoCost * obj1 =
     164        dynamic_cast <CbcSimpleIntegerDynamicPseudoCost *>(objects[i]) ;
     165      if (obj1) {
     166        //int iColumn = obj1->columnNumber();
     167        double downPseudoCost = 1.0e-2*obj1->downDynamicPseudoCost();
     168        double downShadow = obj1->downShadowPrice();
     169        double upPseudoCost = 1.0e-2*obj1->upDynamicPseudoCost();
     170        double upShadow = obj1->upShadowPrice();
     171        downPseudoCost = CoinMax(downPseudoCost,downShadow);
     172        downPseudoCost = CoinMax(downPseudoCost,0.001*upShadow);
     173        downArray_[i]=downPseudoCost;
     174        upPseudoCost = CoinMax(upPseudoCost,upShadow);
     175        upPseudoCost = CoinMax(upPseudoCost,0.001*downShadow);
     176        upArray_[i]=upPseudoCost;
     177      }
     178    }
     179  }
     180}
     181// Fix other variables at bounds
     182int
     183CbcHeuristicDivePseudoCost::fixOtherVariables(OsiSolverInterface * solver,
     184                                              const double * solution,
     185                                              PseudoReducedCost * candidate,
     186                                              const double * random)
     187{
     188  const double * lower = solver->getColLower();
     189  const double * upper = solver->getColUpper();
     190  double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance);
     191  double primalTolerance;
     192  solver->getDblParam(OsiPrimalTolerance,primalTolerance);
     193
     194  int numberIntegers = model_->numberIntegers();
     195  const int * integerVariable = model_->integerVariable();
     196  const double* reducedCost = solver->getReducedCost();
     197  // fix other integer variables that are at their bounds
     198  int cnt=0;
     199  int numberFree=0;
     200  int numberFixedAlready=0;
     201  for (int i=0; i<numberIntegers; i++) {
     202    int iColumn = integerVariable[i];
     203    if (upper[iColumn]>lower[iColumn]) {
     204      numberFree++;
     205      double value=solution[iColumn];
     206      if(value-lower[iColumn]<=integerTolerance) {
     207        candidate[cnt].var = iColumn;
     208        candidate[cnt++].pseudoRedCost = CoinMax(1.0e-2*reducedCost[iColumn],
     209                                                 downArray_[i])*random[i];
     210      } else if(upper[iColumn]-value<=integerTolerance) {
     211        candidate[cnt].var = iColumn;
     212        candidate[cnt++].pseudoRedCost = CoinMax(-1.0e-2*reducedCost[iColumn],
     213                                                 downArray_[i])*random[i];
     214      }
     215    } else {
     216      numberFixedAlready++;
     217    }
     218  }
     219#ifdef CLP_INVESTIGATE
     220  printf("cutoff %g obj %g - %d free, %d fixed\n",
     221         model_->getCutoff(),solver->getObjValue(),numberFree,
     222         numberFixedAlready);
     223#endif
     224  return cnt;
     225  //return CbcHeuristicDive::fixOtherVariables(solver, solution,
     226  //                                 candidate, random);
     227}
  • stable/2.4/Cbc/src/CbcHeuristicDivePseudoCost.hpp

    r945 r1271  
     1/* $Id: CbcHeuristicDivePseudoCost.hpp 1240 2009-10-02 18:41:44Z forrest $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    4344                                      int& bestColumn,
    4445                                      int& bestRound);
     46  /** Initializes any data which is going to be used repeatedly
     47      in selectVariableToBranch */
     48  virtual void initializeData() ;
     49  /// Fix other variables at bounds
     50  virtual int fixOtherVariables(OsiSolverInterface * solver,
     51                                const double * solution,
     52                                PseudoReducedCost * candidate,
     53                                const double * random);
    4554
    4655};
  • stable/2.4/Cbc/src/CbcHeuristicDiveVectorLength.cpp

    r1121 r1271  
     1/* $Id: CbcHeuristicDiveVectorLength.cpp 1173 2009-06-04 09:44:10Z forrest $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • stable/2.4/Cbc/src/CbcHeuristicDiveVectorLength.hpp

    r944 r1271  
     1/* $Id: CbcHeuristicDiveVectorLength.hpp 1173 2009-06-04 09:44:10Z forrest $ */
    12// Copyright (C) 2008, International Business Machines
    23// Corporation and others.  All Rights Reserved.
  • 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;