Changeset 1951 for trunk/Cbc


Ignore:
Timestamp:
Aug 2, 2013 10:26:23 AM (6 years ago)
Author:
forrest
Message:

changes to fix bug on max nodes

Location:
trunk/Cbc
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/MSVisualStudio/v10/libCbc/libCbc.vcxproj

    r1914 r1951  
    1 <?xml version="1.0" encoding="utf-8"?>
     1<?xml version="1.0" encoding="utf-8"?>
    22<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    33  <ItemGroup Label="ProjectConfigurations">
     
    384384      <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
    385385    </ClCompile>
     386    <ClCompile Include="..\..\..\src\CbcHeuristicDW.cpp">
     387      <Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
     388      <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     389      <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
     390      <BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
     391      <Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Disabled</Optimization>
     392      <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     393      <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
     394      <BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">EnableFastChecks</BasicRuntimeChecks>
     395      <Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
     396      <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     397      <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
     398      <Optimization Condition="'$(Configuration)|$(Platform)'=='Release|x64'">MaxSpeed</Optimization>
     399      <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     400      <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
     401    </ClCompile>
    386402    <ClCompile Include="..\..\..\src\CbcHeuristicFPump.cpp">
    387403      <Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
     
    652668    <ClInclude Include="..\..\..\src\CbcHeuristicDivePseudoCost.hpp" />
    653669    <ClInclude Include="..\..\..\src\CbcHeuristicDiveVectorLength.hpp" />
     670    <ClInclude Include="..\..\..\src\CbcHeuristicDW.hpp" />
    654671    <ClInclude Include="..\..\..\src\CbcHeuristicFPump.hpp" />
    655672    <ClInclude Include="..\..\..\src\CbcHeuristicGreedy.hpp" />
  • trunk/Cbc/src/CbcFullNodeInfo.cpp

    r1943 r1951  
    138138    solver->setColLower(lower_);
    139139    solver->setColUpper(upper_);
    140     int numberColumns = model->getNumCols();
    141     // move basis - but make sure size stays
    142     // for bon-min - should not be needed int numberRows = model->getNumRows();
    143     int numberRows = basis->getNumArtificial();
    144     delete basis ;
    145     if (basis_) {
     140    if (basis) {
     141      int numberColumns = model->getNumCols();
     142      // move basis - but make sure size stays
     143      // for bon-min - should not be needed int numberRows = model->getNumRows();
     144      int numberRows = basis->getNumArtificial();
     145      delete basis ;
     146      if (basis_) {
    146147        basis = dynamic_cast<CoinWarmStartBasis *>(basis_->clone()) ;
    147148        basis->resize(numberRows, numberColumns);
     
    150151        basis->print() ;
    151152#endif
    152     } else {
     153      } else {
    153154        // We have a solver without a basis
    154155        basis = NULL;
     156      }
    155157    }
    156158    for (i = 0; i < numberCuts_; i++)
  • trunk/Cbc/src/CbcHeuristicDW.cpp

    r1948 r1951  
    439439        printf("\n");
    440440      }
    441       int * count = new int [numberImproving];
    442       memset(count,0,numberImproving*sizeof(int));
     441      int * count = new int [numberImproving+1];
     442      memset(count,0,(numberImproving+1)*sizeof(int));
    443443      for (int i=0;i<numberBlocks_;i++)
    444444        count[goodBlock[i]]++;
     
    467467        nNeeded_ = CoinMin(nNeeded_,800);
    468468        nNodes_=nNodesBase_;
     469        (*(functionPointer_))(this,NULL,6);
    469470      } else {
    470471        // more nodes fewer in
     
    476477        nNeeded_ -= nNeeded_/20;
    477478        nNeeded_ = CoinMax(nNeeded_,50);
     479        (*(functionPointer_))(this,NULL,7);
    478480      }
    479481    } else {
     
    486488        //nNodesBase_ += nNodesBase_/50;
    487489      }
    488       nNeeded_=nNeededBase_;
     490      nNeeded_ -= nNeeded_/10;
     491      nNeeded_=CoinMax(nNeededBase_,nNeeded_);
    489492      nNodes_=nNodesBase_;
     493      (*(functionPointer_))(this,NULL,8);
    490494    }
    491495    printf("new needed %d, nodes %d\n",nNeeded_,nNodes_);
     
    946950                                   1.0e-3);
    947951        int numberColumns2=model.solver()->getNumCols();
     952#ifdef HOT_START
    948953        // Set up hot start
    949954        const int * originalColumns = pinfo.originalColumns();
     
    987992        delete [] hot;
    988993        delete [] hotPriorities;
     994#endif
    989995        if (nFix)
    990996          printf("Fixed another %d integers\n",nFix);
    991997        {
    992998          // priorities
     999          memset(priorityBlock,0,numberBlocks_*sizeof(int));
    9931000          for (int i=0;i<numberBlocks_;i++) {
    994             priorityBlock[whichBlock[i]]=i+1;
     1001            int iBlock=whichBlock[i];
     1002            if (iBlock>=0)
     1003              priorityBlock[iBlock]=i+1;
    9951004          }
    9961005#if 1
     
    14691478      nColumn+=columnsInBlock_[i];
    14701479    }
     1480    // may not be used - but set anyway
     1481    sizeFingerPrint_ = (maxIntsInBlock+31)/32;
    14711482    startRowBlock_[numberBlocks_]=nRow;
    14721483    startColumnBlock_[numberBlocks_]=nColumn;
     
    16321643      printf("Too many blocks - no affinity\n");
    16331644    }
    1634     if (fullDWEverySoOften_>0) {
    1635       random_=new double [numberMasterRows_];
    1636       for (int i=0;i<numberMasterRows_;i++)
    1637         random_[i]=CoinDrand48();
    1638       weights_ = new double [numberBlocks_];
    1639       dwBlock_ = new int [numberBlocks_];
    1640       sizeFingerPrint_ = (maxIntsInBlock+31)/32;
    1641       fingerPrint_ = new unsigned int[numberBlocks_*sizeFingerPrint_];
    1642       // create dwSolver
    1643       int numberMasterRows=0;
    1644       for (int i=0;i<numberRows;i++) {
    1645         int iBlock=whichRowBlock_[i];
    1646         if (iBlock<0)
    1647           blockStart[numberMasterRows++]=i;
    1648       }
    1649       int numberMasterColumns=0;
    1650       for (int i=0;i<numberColumns;i++) {
    1651         int iBlock=whichColumnBlock_[i];
    1652         if (iBlock<0)
    1653           columnBlock[numberMasterColumns++]=i;
    1654       }
    1655       OsiClpSolverInterface * solver =
    1656         dynamic_cast<OsiClpSolverInterface *>(solver_);
    1657       ClpSimplex * tempModel = new ClpSimplex(solver->getModelPtr(),
    1658                                               numberMasterRows,blockStart,
    1659                                               numberMasterColumns,columnBlock);
    1660       // add convexity constraints
    1661       double * rhs = new double[numberBlocks_];
    1662       for (int i=0;i<numberBlocks_;i++)
    1663         rhs[i]=1.0;
    1664       tempModel->addRows(numberBlocks_,rhs,rhs,NULL,NULL,NULL);
    1665       dwSolver_ = new OsiClpSolverInterface(tempModel,true);
    1666       printf("DW model has %d master rows, %d master columns and %d convexity rows\n",
    1667              numberMasterRows,numberMasterColumns,numberBlocks_);
    1668       // do master integers
    1669       for (int i=0;i<numberMasterColumns;i++) {
    1670         int iColumn=columnBlock[i];
    1671         if (solver->isInteger(iColumn))
    1672           dwSolver_->setInteger(i);
    1673       }
     1645    if (fullDWEverySoOften_>0) {
     1646      setupDWStructures();
    16741647    }
    16751648  }
     
    18361809    delete [] numberColumnsDW_;
    18371810    numberColumnsDW_=temp;
    1838     numberColumnsDW_[numberDWTimes_++]= dwSolver_->getNumCols();
     1811    numberColumnsDW_[numberDWTimes_]= dwSolver_->getNumCols();
    18391812    objectiveDW_[numberDWTimes_++]= objectiveValue(solution);
    18401813  }
     
    19591932    }
    19601933  }
    1961   newSolver->writeMps("dw","mps");
     1934  //newSolver->writeMps("dw","mps");
    19621935  return newSolver;
    19631936}
     1937/* DW Proposal actions
     1938   fullDWEverySoOften -
     1939   0 - off
     1940   k - every k times solution gets better
     1941*/
     1942void
     1943CbcHeuristicDW::setProposalActions(int fullDWEverySoOften)
     1944{
     1945  fullDWEverySoOften_=fullDWEverySoOften;
     1946  if (fullDWEverySoOften_>0&&!random_)
     1947    setupDWStructures();
     1948}
     1949// Set up DW structure
     1950void
     1951CbcHeuristicDW::setupDWStructures()
     1952{
     1953  random_=new double [numberMasterRows_];
     1954  for (int i=0;i<numberMasterRows_;i++)
     1955    random_[i]=CoinDrand48();
     1956  weights_ = new double [numberBlocks_];
     1957  dwBlock_ = new int [numberBlocks_];
     1958  fingerPrint_ = new unsigned int[numberBlocks_*sizeFingerPrint_];
     1959  // create dwSolver
     1960  int numberColumns = solver_->getNumCols();
     1961  int numberRows = solver_->getNumRows();
     1962  int * tempRow = new int [numberRows+numberColumns];
     1963  int * tempColumn = tempRow + numberRows;
     1964  int numberMasterRows=0;
     1965  for (int i=0;i<numberRows;i++) {
     1966    int iBlock=whichRowBlock_[i];
     1967    if (iBlock<0)
     1968      tempRow[numberMasterRows++]=i;
     1969  }
     1970  int numberMasterColumns=0;
     1971  for (int i=0;i<numberColumns;i++) {
     1972    int iBlock=whichColumnBlock_[i];
     1973    if (iBlock<0)
     1974      tempColumn[numberMasterColumns++]=i;
     1975  }
     1976  OsiClpSolverInterface * solver =
     1977    dynamic_cast<OsiClpSolverInterface *>(solver_);
     1978  ClpSimplex * tempModel = new ClpSimplex(solver->getModelPtr(),
     1979                                          numberMasterRows,tempRow,
     1980                                          numberMasterColumns,tempColumn);
     1981  // add convexity constraints
     1982  double * rhs = new double[numberBlocks_];
     1983  for (int i=0;i<numberBlocks_;i++)
     1984    rhs[i]=1.0;
     1985  tempModel->addRows(numberBlocks_,rhs,rhs,NULL,NULL,NULL);
     1986  delete [] rhs;
     1987  dwSolver_ = new OsiClpSolverInterface(tempModel,true);
     1988  printf("DW model has %d master rows, %d master columns and %d convexity rows\n",
     1989         numberMasterRows,numberMasterColumns,numberBlocks_);
     1990  // do master integers
     1991  for (int i=0;i<numberMasterColumns;i++) {
     1992    int iColumn=tempColumn[i];
     1993    if (solver->isInteger(iColumn))
     1994      dwSolver_->setInteger(i);
     1995  }
     1996  delete [] tempRow;
     1997}
    19641998
     1999
  • trunk/Cbc/src/CbcHeuristicDW.hpp

    r1948 r1951  
    7474        k - every k times solution gets better
    7575     */
    76     inline void setProposalActions(int fullDWEverySoOften)
    77     { fullDWEverySoOften_=fullDWEverySoOften;}
     76    void setProposalActions(int fullDWEverySoOften);
    7877    /// Objective value when whichDw created
    7978    double objectiveValueWhen(int whichDW) const;
     
    109108    inline void setNumberPasses(int value)
    110109    { numberPasses_ = value;}
    111     /// Set number free integers needed
     110    /// Set number free integers needed (Base value)
    112111    inline void setNumberNeeded(int value)
    113112    { nNeededBase_ = value;}
     113    /// Get number free integers needed (Base value)
     114    inline int getNumberNeeded() const
     115    {return nNeededBase_;}
     116    /// Set number free integers needed (Current value)
     117    inline void setCurrentNumberNeeded(int value)
     118    { nNeeded_ = value;}
     119    /// Get number free integers needed (Current value)
     120    inline int getCurrentNumberNeeded() const
     121    {return nNeeded_;}
     122    /// Set number nodes (could be done in callback) (Base value)
     123    inline void setNumberNodes(int value)
     124    { nNodesBase_ = value;}
     125    /// Get number nodes (could be done in callback) (Base value)
     126    inline int getNumberNodes() const
     127    {return nNodesBase_;}
     128    /// Set number nodes (could be done in callback) (Current value)
     129    inline void setCurrentNumberNodes(int value)
     130    { nNodes_ = value;}
     131    /// Get number nodes (could be done in callback) (Current value)
     132    inline int getCurrentNumberNodes() const
     133    {return nNodes_;}
    114134    /// Set target objective
    115135    inline void setTargetObjective(double value)
     
    163183    /// Find structure
    164184    void findStructure();
     185    /// Set up DW structure
     186    void setupDWStructures();
    165187    /// Add DW proposals
    166188    int addDW(const double * solution,int numberBlocksUsed,
     
    183205        4 - if better solution found
    184206        5 - every time a block might be used
     207        next few for adjustment of nNeeded etc
     208        6 - complete search done - no solution
     209        7 - stopped on nodes - no improvement
     210        8 - improving (same as 4 but after nNeeded changed
    185211        Pointers to local data given by following pointers
    186212    */
  • trunk/Cbc/src/CbcModel.cpp

    r1949 r1951  
    68426842      easy way to pass in the size. But we take a hit for memory allocation.
    68436843    */
    6844     lastws->setSize(numberColumns, numberRowsAtContinuous_ + currentNumberCuts);
     6844    if (lastws)
     6845      lastws->setSize(numberColumns, numberRowsAtContinuous_ + currentNumberCuts);
    68456846    currentNumberCuts = 0;
    68466847    while (nNode) {
     
    68506851    }
    68516852#ifndef NDEBUG
    6852     if (!lastws->fullBasis()) {
     6853    if (lastws&&!lastws->fullBasis()) {
    68536854#ifdef COIN_DEVELOP
    68546855        printf("******* bad basis\n");
  • trunk/Cbc/src/CbcPartialNodeInfo.cpp

    r1899 r1951  
    129129{
    130130    OsiSolverInterface *solver = model->solver();
    131     if ((active_&4) != 0) {
     131    if ((active_&4) != 0 && basis) {
    132132        basis->applyDiff(basisDiff_) ;
    133133#ifdef CBC_CHECK_BASIS
  • trunk/Cbc/src/CbcTree.cpp

    r1943 r1951  
    621621    for (j = nNodes - 1; j >= kDelete; j--) {
    622622        CbcNode * node = nodeArray[j];
    623         CoinWarmStartBasis *lastws = model->getEmptyBasis() ;
     623        CoinWarmStartBasis *lastws = (cutoff!=-COIN_DBL_MAX) ? model->getEmptyBasis() : NULL;
    624624
    625625        model->addCuts1(node, lastws);
     
    628628        //assert (node->nodeInfo());
    629629        int numberLeft = (node->nodeInfo()) ? node->nodeInfo()->numberBranchesLeft() : 0;
    630         int i;
    631         for (i = 0; i < model->currentNumberCuts(); i++) {
     630        if (cutoff != -COIN_DBL_MAX) {
     631          // normal
     632          for (int i = 0; i < model->currentNumberCuts(); i++) {
    632633            // take off node
    633634            CoinWarmStartBasis::Status status =
     
    638639                    delete model->addedCuts()[i];
    639640            }
    640         }
     641          }
     642        } else {
     643          // quick
     644          for (int i = 0; i < model->currentNumberCuts(); i++) {
     645            // take off node
     646            if (model->addedCuts()[i]) {
     647                if (!model->addedCuts()[i]->decrement(numberLeft))
     648                    delete model->addedCuts()[i];
     649            }
     650          }
     651        }
    641652        // node should not have anything pointing to it
    642653        if (node->nodeInfo())
Note: See TracChangeset for help on using the changeset viewer.